5 * @subpackage SpecialPage
11 * @subpackage SpecialPage
13 class NewPagesPage
extends QueryPage
{
16 function NewPagesPage( $namespace = NS_MAIN
) {
17 $this->namespace = $namespace;
24 function isExpensive() {
25 # Indexed on RC, and will *not* work with querycache yet.
30 global $wgUser, $wgUseRCPatrol;
31 $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ?
1 : 0;
32 $dbr =& wfGetDB( DB_SLAVE
);
33 extract( $dbr->tableNames( 'recentchanges', 'page', 'text' ) );
35 # FIXME: text will break with compression
37 "SELECT 'Newpages' as type,
38 rc_namespace AS namespace,
42 rc_user_text AS user_text,
43 rc_comment as comment,
44 rc_timestamp AS timestamp,
45 rc_timestamp AS value,
46 '{$usepatrol}' as usepatrol,
47 rc_patrolled AS patrolled,
51 FROM $recentchanges,$page
52 WHERE rc_cur_id=page_id AND rc_new=1
53 AND rc_namespace=" . $this->namespace . " AND page_is_redirect=0";
56 function preprocessResults( &$dbo, &$res ) {
57 # Do a batch existence check on the user and talk pages
58 $linkBatch = new LinkBatch();
59 while( $row = $dbo->fetchObject( $res ) ) {
60 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_text
) );
61 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_text
) );
63 $linkBatch->execute();
65 if( $dbo->numRows( $res ) > 0 )
66 $dbo->dataSeek( $res, 0 );
70 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
72 * @param $skin Skin to use
73 * @param $result Result row
76 function formatResult( $skin, $result ) {
77 global $wgLang, $wgContLang;
78 $dm = $wgContLang->getDirMark();
80 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
81 $time = $wgLang->timeAndDate( $result->timestamp
, true );
82 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
83 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
84 $length = wfMsgHtml( 'nbytes', $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
85 $ulink = $skin->userLink( $result->user
, $result->user_text
) . $skin->userToolLinks( $result->user
, $result->user_text
);
86 $comment = $skin->commentBlock( $result->comment
);
88 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
92 * Should a specific result row provide "patrollable" links?
94 * @param $result Result row
97 function patrollable( $result ) {
98 global $wgUser, $wgUseRCPatrol;
99 return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled
;
102 function feedItemDesc( $row ) {
103 if( isset( $row->rev_id
) ) {
104 $revision = Revision
::newFromId( $row->rev_id
);
106 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
107 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
108 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
111 return parent
::feedItemDesc( $row );
115 * Show a namespace selection form for filtering
119 function getPageHeader() {
120 $thisTitle = Title
::makeTitle( NS_SPECIAL
, $this->getName() );
121 $form = wfOpenElement( 'form', array(
123 'action' => $thisTitle->getLocalUrl() ) );
124 $form .= wfElement( 'label', array( 'for' => 'namespace' ),
125 wfMsg( 'namespace' ) ) . ' ';
126 $form .= HtmlNamespaceSelector( $this->namespace );
127 # Preserve the offset and limit
128 $form .= wfElement( 'input', array(
131 'value' => $this->offset
) );
132 $form .= wfElement( 'input', array(
135 'value' => $this->limit
) );
136 $form .= wfElement( 'input', array(
140 'value' => wfMsg( 'allpagessubmit' ) ) );
141 $form .= wfCloseElement( 'form' );
150 function linkParameters() {
151 return( array( 'namespace' => $this->namespace ) );
159 function wfSpecialNewpages($par, $specialPage) {
160 global $wgRequest, $wgContLang;
162 list( $limit, $offset ) = wfCheckLimits();
163 $namespace = NS_MAIN
;
166 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
167 foreach ( $bits as $bit ) {
168 if ( 'shownav' == $bit )
169 $shownavigation = true;
170 if ( is_numeric( $bit ) )
173 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
174 $limit = intval($m[1]);
175 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
176 $offset = intval($m[1]);
177 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
178 $ns = $wgContLang->getNsIndex( $m[1] );
179 if( $ns !== false ) {
185 if( $ns = $wgRequest->getInt( 'namespace', 0 ) )
189 if ( ! isset( $shownavigation ) )
190 $shownavigation = ! $specialPage->including();
192 $npp = new NewPagesPage( $namespace );
194 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
195 $npp->doQuery( $offset, $limit, $shownavigation );