4 * implements Special:Newpages
7 class SpecialNewpages
extends SpecialPage
{
10 protected $opts, $skin;
12 // Some internal settings
13 protected $showNavigation = false;
15 public function __construct() {
16 parent
::__construct( 'Newpages' );
17 $this->includable( true );
20 protected function setup( $par ) {
21 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
24 $opts = new FormOptions();
25 $this->opts
= $opts; // bind
26 $opts->add( 'hideliu', false );
27 $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
28 $opts->add( 'hidebots', false );
29 $opts->add( 'hideredirs', true );
30 $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
31 $opts->add( 'offset', '' );
32 $opts->add( 'namespace', '0' );
33 $opts->add( 'username', '' );
34 $opts->add( 'feed', '' );
35 $opts->add( 'tagfilter', '' );
38 $opts->fetchValuesFromRequest( $wgRequest );
39 if ( $par ) $this->parseParams( $par );
42 $opts->validateIntBounds( 'limit', 0, 5000 );
43 if( !$wgEnableNewpagesUserFilter ) {
44 $opts->setValue( 'username', '' );
48 $this->skin
= $wgUser->getSkin();
51 protected function parseParams( $par ) {
53 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
54 foreach ( $bits as $bit ) {
55 if ( 'shownav' == $bit )
56 $this->showNavigation
= true;
57 if ( 'hideliu' === $bit )
58 $this->opts
->setValue( 'hideliu', true );
59 if ( 'hidepatrolled' == $bit )
60 $this->opts
->setValue( 'hidepatrolled', true );
61 if ( 'hidebots' == $bit )
62 $this->opts
->setValue( 'hidebots', true );
63 if ( 'showredirs' == $bit )
64 $this->opts
->setValue( 'hideredirs', false );
65 if ( is_numeric( $bit ) )
66 $this->opts
->setValue( 'limit', intval( $bit ) );
69 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
70 $this->opts
->setValue( 'limit', intval($m[1]) );
71 // PG offsets not just digits!
72 if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
73 $this->opts
->setValue( 'offset', intval($m[1]) );
74 if ( preg_match( '/^username=(.*)$/', $bit, $m ) )
75 $this->opts
->setValue( 'username', $m[1] );
76 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
77 $ns = $wgLang->getNsIndex( $m[1] );
79 $this->opts
->setValue( 'namespace', $ns );
86 * Show a form for filtering namespace and username
91 public function execute( $par ) {
92 global $wgLang, $wgUser, $wgOut;
95 $this->outputHeader();
97 $this->showNavigation
= !$this->including(); // Maybe changed in setup
100 if( !$this->including() ) {
104 $this->setSyndicated();
105 $feedType = $this->opts
->getValue( 'feed' );
107 return $this->feed( $feedType );
111 $pager = new NewPagesPager( $this, $this->opts
);
112 $pager->mLimit
= $this->opts
->getValue( 'limit' );
113 $pager->mOffset
= $this->opts
->getValue( 'offset' );
115 if( $pager->getNumRows() ) {
117 if ( $this->showNavigation
) $navigation = $pager->getNavigationBar();
118 $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
120 $wgOut->addWikiMsg( 'specialpage-empty' );
124 protected function filterLinks() {
125 global $wgGroupPermissions, $wgUser, $wgLang;
128 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
130 // Option value -> message mapping
132 'hideliu' => 'rcshowhideliu',
133 'hidepatrolled' => 'rcshowhidepatr',
134 'hidebots' => 'rcshowhidebots',
135 'hideredirs' => 'whatlinkshere-hideredirs'
138 // Disable some if needed
139 if ( $wgGroupPermissions['*']['createpage'] !== true )
140 unset($filters['hideliu']);
142 if ( !$wgUser->useNPPatrol() )
143 unset($filters['hidepatrolled']);
146 $changed = $this->opts
->getChangedValues();
147 unset($changed['offset']); // Reset offset if query type changes
149 $self = $this->getTitle();
150 foreach ( $filters as $key => $msg ) {
151 $onoff = 1 - $this->opts
->getValue($key);
152 $link = $this->skin
->link( $self, $showhide[$onoff], array(),
153 array( $key => $onoff ) +
$changed
155 $links[$key] = wfMsgHtml( $msg, $link );
158 return $wgLang->pipeList( $links );
161 protected function form() {
162 global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
165 $this->opts
->consumeValue( 'offset' ); // don't carry offset, DWIW
166 $namespace = $this->opts
->consumeValue( 'namespace' );
167 $username = $this->opts
->consumeValue( 'username' );
169 // Check username input validity
170 $ut = Title
::makeTitleSafe( NS_USER
, $username );
171 $userText = $ut ?
$ut->getText() : '';
173 // Store query values in hidden fields so that form submission doesn't lose them
175 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
176 $hidden[] = Xml
::hidden( $key, $value );
178 $hidden = implode( "\n", $hidden );
180 $tagFilter = ChangeTags
::buildTagFilterSelector( $this->opts
['tagfilter'] );
182 list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
184 $form = Xml
::openElement( 'form', array( 'action' => $wgScript ) ) .
185 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
186 Xml
::fieldset( wfMsg( 'newpages' ) ) .
187 Xml
::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
189 <td class='mw-label'>" .
190 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
192 <td class='mw-input'>" .
193 Xml
::namespaceSelector( $namespace, 'all' ) .
195 </tr>" . ( $tagFilter ?
(
197 <td class='mw-label'>" .
200 <td class='mw-input'>" .
204 ($wgEnableNewpagesUserFilter ?
206 <td class='mw-label'>" .
207 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
209 <td class='mw-input'>" .
210 Xml
::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
214 <td class='mw-submit'>" .
215 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
220 <td class='mw-input'>" .
221 $this->filterLinks() .
224 Xml
::closeElement( 'table' ) .
225 Xml
::closeElement( 'fieldset' ) .
227 Xml
::closeElement( 'form' );
229 $wgOut->addHTML( $form );
232 protected function setSyndicated() {
234 $queryParams = array(
235 'namespace' => $this->opts
->getValue( 'namespace' ),
236 'username' => $this->opts
->getValue( 'username' )
238 $wgOut->setSyndicated( true );
239 $wgOut->setFeedAppendQuery( wfArrayToCGI( $queryParams ) );
243 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
245 * @param $skin Skin to use
246 * @param $result Result row
249 public function formatRow( $result ) {
250 global $wgLang, $wgContLang, $wgUser;
254 $dm = $wgContLang->getDirMark();
256 $title = Title
::makeTitleSafe( $result->rc_namespace
, $result->rc_title
);
257 $time = $wgLang->timeAndDate( $result->rc_timestamp
, true );
258 $query = $this->patrollable( $result ) ?
"rcid={$result->rc_id}&redirect=no" : 'redirect=no';
259 $plink = $this->skin
->makeKnownLinkObj( $title, '', $query );
260 $hist = $this->skin
->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
261 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
262 $wgLang->formatNum( $result->length
) );
263 $ulink = $this->skin
->userLink( $result->rc_user
, $result->rc_user_text
) . ' ' .
264 $this->skin
->userToolLinks( $result->rc_user
, $result->rc_user_text
);
265 $comment = $this->skin
->commentBlock( $result->rc_comment
);
267 if ( $this->patrollable( $result ) )
268 $classes[] = 'not-patrolled';
271 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $result->ts_tags
, 'newpages' );
272 $classes = array_merge( $classes, $newClasses );
274 $css = count($classes) ?
' class="'.implode( " ", $classes).'"' : '';
276 return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
280 * Should a specific result row provide "patrollable" links?
282 * @param $result Result row
285 protected function patrollable( $result ) {
287 return ( $wgUser->useNPPatrol() && !$result->rc_patrolled
);
291 * Output a subscription feed listing recent edits to this page.
292 * @param string $type
294 protected function feed( $type ) {
295 global $wgFeed, $wgFeedClasses, $wgFeedLimit;
299 $wgOut->addWikiMsg( 'feed-unavailable' );
303 if( !isset( $wgFeedClasses[$type] ) ) {
305 $wgOut->addWikiMsg( 'feed-invalid' );
309 $feed = new $wgFeedClasses[$type](
311 wfMsgExt( 'tagline', 'parsemag' ),
312 $this->getTitle()->getFullUrl() );
314 $pager = new NewPagesPager( $this, $this->opts
);
315 $limit = $this->opts
->getValue( 'limit' );
316 $pager->mLimit
= min( $limit, $wgFeedLimit );
319 if( $pager->getNumRows() > 0 ) {
320 while( $row = $pager->mResult
->fetchObject() ) {
321 $feed->outItem( $this->feedItem( $row ) );
327 protected function feedTitle() {
328 global $wgContLanguageCode, $wgSitename;
329 $page = SpecialPage
::getPage( 'Newpages' );
330 $desc = $page->getDescription();
331 return "$wgSitename - $desc [$wgContLanguageCode]";
334 protected function feedItem( $row ) {
335 $title = Title
::MakeTitle( intval( $row->rc_namespace
), $row->rc_title
);
337 $date = $row->rc_timestamp
;
338 $comments = $title->getTalkPage()->getFullURL();
341 $title->getPrefixedText(),
342 $this->feedItemDesc( $row ),
343 $title->getFullURL(),
345 $this->feedItemAuthor( $row ),
352 protected function feedItemAuthor( $row ) {
353 return isset( $row->rc_user_text
) ?
$row->rc_user_text
: '';
356 protected function feedItemDesc( $row ) {
357 $revision = Revision
::newFromId( $row->rev_id
);
359 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
360 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
361 "</p>\n<hr />\n<div>" .
362 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
369 * @ingroup SpecialPage Pager
371 class NewPagesPager
extends ReverseChronologicalPager
{
373 protected $opts, $mForm;
375 function __construct( $form, FormOptions
$opts ) {
376 parent
::__construct();
377 $this->mForm
= $form;
381 function getTitle() {
382 static $title = null;
383 if ( $title === null )
384 $title = $this->mForm
->getTitle();
388 function getQueryInfo() {
389 global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
391 $conds['rc_new'] = 1;
393 $namespace = $this->opts
->getValue( 'namespace' );
394 $namespace = ( $namespace === 'all' ) ?
false : intval( $namespace );
396 $username = $this->opts
->getValue( 'username' );
397 $user = Title
::makeTitleSafe( NS_USER
, $username );
399 if( $namespace !== false ) {
400 $conds['rc_namespace'] = $namespace;
401 $rcIndexes = array( 'new_name_timestamp' );
403 $rcIndexes = array( 'rc_timestamp' );
406 # $wgEnableNewpagesUserFilter - temp WMF hack
407 if( $wgEnableNewpagesUserFilter && $user ) {
408 $conds['rc_user_text'] = $user->getText();
409 $rcIndexes = 'rc_user_text';
410 # If anons cannot make new pages, don't "exclude logged in users"!
411 } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts
->getValue( 'hideliu' ) ) {
412 $conds['rc_user'] = 0;
414 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
415 if( $this->opts
->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
416 $conds['rc_patrolled'] = 0;
418 if( $this->opts
->getValue( 'hidebots' ) ) {
419 $conds['rc_bot'] = 0;
422 if ( $this->opts
->getValue( 'hideredirs' ) ) {
423 $conds['page_is_redirect'] = 0;
427 'tables' => array( 'recentchanges', 'page' ),
428 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
429 rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
431 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
432 'join_conds' => array(
433 'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
437 ## Empty array for fields, it'll be set by us anyway.
440 ## Modify query for tags
441 ChangeTags
::modifyDisplayQuery( $info['tables'],
446 $this->opts
['tagfilter'] );
451 function getIndexField() {
452 return 'rc_timestamp';
455 function formatRow( $row ) {
456 return $this->mForm
->formatRow( $row );
459 function getStartBody() {
460 # Do a batch existence check on pages
461 $linkBatch = new LinkBatch();
462 while( $row = $this->mResult
->fetchObject() ) {
463 $linkBatch->add( NS_USER
, $row->rc_user_text
);
464 $linkBatch->add( NS_USER_TALK
, $row->rc_user_text
);
465 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
467 $linkBatch->execute();
471 function getEndBody() {