4 * @addtogroup SpecialPage
8 * implements Special:Newpages
9 * @addtogroup SpecialPage
11 class NewPagesPage
extends QueryPage
{
16 function NewPagesPage( $namespace = NS_MAIN
, $username = '' ) {
17 $this->namespace = $namespace;
18 $this->username
= $username;
25 function isExpensive() {
26 # Indexed on RC, and will *not* work with querycache yet.
30 function makeUserWhere( &$dbo ) {
31 $title = Title
::makeTitleSafe( NS_USER
, $this->username
);
33 return ' AND rc_user_text = ' . $dbo->addQuotes( $title->getText() );
39 private function makeNamespaceWhere() {
40 return $this->namespace !== 'all'
41 ?
' AND rc_namespace = ' . intval( $this->namespace )
46 global $wgUser, $wgUseRCPatrol;
47 $usepatrol = ( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ) ?
1 : 0;
48 $dbr = wfGetDB( DB_SLAVE
);
49 list( $recentchanges, $page ) = $dbr->tableNamesN( 'recentchanges', 'page' );
51 $nsfilter = $this->makeNamespaceWhere();
52 $uwhere = $this->makeUserWhere( $dbr );
54 # FIXME: text will break with compression
56 "SELECT 'Newpages' as type,
57 rc_namespace AS namespace,
61 rc_user_text AS user_text,
62 rc_comment as \"comment\",
63 rc_timestamp AS timestamp,
64 rc_timestamp AS value,
65 '{$usepatrol}' as usepatrol,
66 rc_patrolled AS patrolled,
70 FROM $recentchanges,$page
71 WHERE rc_cur_id=page_id AND rc_new=1
73 AND page_is_redirect = 0
77 function preprocessResults( &$dbo, &$res ) {
78 # Do a batch existence check on the user and talk pages
79 $linkBatch = new LinkBatch();
80 while( $row = $dbo->fetchObject( $res ) ) {
81 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER
, $row->user_text
) );
82 $linkBatch->addObj( Title
::makeTitleSafe( NS_USER_TALK
, $row->user_text
) );
84 $linkBatch->execute();
86 if( $dbo->numRows( $res ) > 0 )
87 $dbo->dataSeek( $res, 0 );
91 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
93 * @param $skin Skin to use
94 * @param $result Result row
97 function formatResult( $skin, $result ) {
98 global $wgLang, $wgContLang;
99 $dm = $wgContLang->getDirMark();
101 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
102 $time = $wgLang->timeAndDate( $result->timestamp
, true );
103 $plink = $skin->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rcid
: '' );
104 $hist = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
105 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->length
) ) );
106 $ulink = $skin->userLink( $result->user
, $result->user_text
) . ' ' . $skin->userToolLinks( $result->user
, $result->user_text
);
107 $comment = $skin->commentBlock( $result->comment
);
109 return "{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}";
113 * Should a specific result row provide "patrollable" links?
115 * @param $result Result row
118 function patrollable( $result ) {
119 global $wgUser, $wgUseRCPatrol;
120 return $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) && !$result->patrolled
;
123 function feedItemDesc( $row ) {
124 if( isset( $row->rev_id
) ) {
125 $revision = Revision
::newFromId( $row->rev_id
);
127 return '<p>' . htmlspecialchars( wfMsg( 'summary' ) ) . ': ' .
128 htmlspecialchars( $revision->getComment() ) . "</p>\n<hr />\n<div>" .
129 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
132 return parent
::feedItemDesc( $row );
136 * Show a form for filtering namespace and username
140 function getPageHeader() {
141 $self = SpecialPage
::getTitleFor( $this->getName() );
142 $form = Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $self->getLocalUrl() ) );
144 $form .= '<table><tr><td align="right">' . Xml
::label( wfMsg( 'namespace' ), 'namespace' ) . '</td>';
145 $form .= '<td>' . Xml
::namespaceSelector( $this->namespace, 'all' ) . '</td></tr>';
147 $form .= '<tr><td align="right">' . Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) . '</td>';
148 $form .= '<td>' . Xml
::input( 'username', 30, $this->username
, array( 'id' => 'mw-np-username' ) ) . '</td></tr>';
150 $form .= '<tr><td></td><td>' . Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) . '</td></tr></table>';
151 $form .= Xml
::hidden( 'offset', $this->offset
) . Xml
::hidden( 'limit', $this->limit
) . '</form>';
160 function linkParameters() {
161 return( array( 'namespace' => $this->namespace, 'username' => $this->username
) );
169 function wfSpecialNewpages($par, $specialPage) {
170 global $wgRequest, $wgContLang;
172 list( $limit, $offset ) = wfCheckLimits();
173 $namespace = NS_MAIN
;
177 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
178 foreach ( $bits as $bit ) {
179 if ( 'shownav' == $bit )
180 $shownavigation = true;
181 if ( is_numeric( $bit ) )
185 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
186 $limit = intval($m[1]);
187 if ( preg_match( '/^offset=(\d+)$/', $bit, $m ) )
188 $offset = intval($m[1]);
189 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
190 $ns = $wgContLang->getNsIndex( $m[1] );
191 if( $ns !== false ) {
197 if( $ns = $wgRequest->getText( 'namespace', NS_MAIN
) )
199 if( $un = $wgRequest->getText( 'username' ) )
203 if ( ! isset( $shownavigation ) )
204 $shownavigation = ! $specialPage->including();
206 $npp = new NewPagesPage( $namespace, $username );
208 if ( ! $npp->doFeed( $wgRequest->getVal( 'feed' ), $limit ) )
209 $npp->doQuery( $offset, $limit, $shownavigation );