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, $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 # FIXME: throws E_NOTICEs if not set; and doesn't obey hooks etc
140 if ( $wgGroupPermissions['*']['createpage'] !== true )
141 unset($filters['hideliu']);
143 if ( !$wgUser->useNPPatrol() )
144 unset($filters['hidepatrolled']);
147 $changed = $this->opts
->getChangedValues();
148 unset($changed['offset']); // Reset offset if query type changes
150 $self = $this->getTitle();
151 foreach ( $filters as $key => $msg ) {
152 $onoff = 1 - $this->opts
->getValue($key);
153 $link = $this->skin
->link( $self, $showhide[$onoff], array(),
154 array( $key => $onoff ) +
$changed
156 $links[$key] = wfMsgHtml( $msg, $link );
159 return $wgLang->pipeList( $links );
162 protected function form() {
163 global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
166 $this->opts
->consumeValue( 'offset' ); // don't carry offset, DWIW
167 $namespace = $this->opts
->consumeValue( 'namespace' );
168 $username = $this->opts
->consumeValue( 'username' );
169 $tagFilterVal = $this->opts
->consumeValue( 'tagfilter' );
171 // Check username input validity
172 $ut = Title
::makeTitleSafe( NS_USER
, $username );
173 $userText = $ut ?
$ut->getText() : '';
175 // Store query values in hidden fields so that form submission doesn't lose them
177 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
178 $hidden[] = Xml
::hidden( $key, $value );
180 $hidden = implode( "\n", $hidden );
182 $tagFilter = ChangeTags
::buildTagFilterSelector( $tagFilterVal );
184 list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
186 $form = Xml
::openElement( 'form', array( 'action' => $wgScript ) ) .
187 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
188 Xml
::fieldset( wfMsg( 'newpages' ) ) .
189 Xml
::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
191 <td class='mw-label'>" .
192 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
194 <td class='mw-input'>" .
195 Xml
::namespaceSelector( $namespace, 'all' ) .
197 </tr>" . ( $tagFilter ?
(
199 <td class='mw-label'>" .
202 <td class='mw-input'>" .
206 ($wgEnableNewpagesUserFilter ?
208 <td class='mw-label'>" .
209 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
211 <td class='mw-input'>" .
212 Xml
::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
216 <td class='mw-submit'>" .
217 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
222 <td class='mw-input'>" .
223 $this->filterLinks() .
226 Xml
::closeElement( 'table' ) .
227 Xml
::closeElement( 'fieldset' ) .
229 Xml
::closeElement( 'form' );
231 $wgOut->addHTML( $form );
234 protected function setSyndicated() {
236 $wgOut->setSyndicated( true );
237 $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts
->getAllValues() ) );
241 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
243 * @param $result Result row
246 public function formatRow( $result ) {
247 global $wgLang, $wgContLang;
251 $dm = $wgContLang->getDirMark();
253 $title = Title
::makeTitleSafe( $result->rc_namespace
, $result->rc_title
);
254 $time = htmlspecialchars( $wgLang->timeAndDate( $result->rc_timestamp
, true ) );
256 $query = array( 'redirect' => 'no' );
258 if( $this->patrollable( $result ) )
259 $query['rcid'] = $result->rc_id
;
261 $plink = $this->skin
->linkKnown(
267 $hist = $this->skin
->linkKnown(
271 array( 'action' => 'history' )
273 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
274 $wgLang->formatNum( $result->length
) );
275 $ulink = $this->skin
->userLink( $result->rc_user
, $result->rc_user_text
) . ' ' .
276 $this->skin
->userToolLinks( $result->rc_user
, $result->rc_user_text
);
277 $comment = $this->skin
->commentBlock( $result->rc_comment
);
279 if ( $this->patrollable( $result ) )
280 $classes[] = 'not-patrolled';
283 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $result->ts_tags
, 'newpages' );
284 $classes = array_merge( $classes, $newClasses );
286 $css = count($classes) ?
' class="'.implode( " ", $classes).'"' : '';
288 return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
292 * Should a specific result row provide "patrollable" links?
294 * @param $result Result row
297 protected function patrollable( $result ) {
299 return ( $wgUser->useNPPatrol() && !$result->rc_patrolled
);
303 * Output a subscription feed listing recent edits to this page.
305 * @param $type String
307 protected function feed( $type ) {
308 global $wgFeed, $wgFeedClasses, $wgFeedLimit;
312 $wgOut->addWikiMsg( 'feed-unavailable' );
316 if( !isset( $wgFeedClasses[$type] ) ) {
318 $wgOut->addWikiMsg( 'feed-invalid' );
322 $feed = new $wgFeedClasses[$type](
324 wfMsgExt( 'tagline', 'parsemag' ),
325 $this->getTitle()->getFullUrl() );
327 $pager = new NewPagesPager( $this, $this->opts
);
328 $limit = $this->opts
->getValue( 'limit' );
329 $pager->mLimit
= min( $limit, $wgFeedLimit );
332 if( $pager->getNumRows() > 0 ) {
333 while( $row = $pager->mResult
->fetchObject() ) {
334 $feed->outItem( $this->feedItem( $row ) );
340 protected function feedTitle() {
341 global $wgContLanguageCode, $wgSitename;
342 $page = SpecialPage
::getPage( 'Newpages' );
343 $desc = $page->getDescription();
344 return "$wgSitename - $desc [$wgContLanguageCode]";
347 protected function feedItem( $row ) {
348 $title = Title
::MakeTitle( intval( $row->rc_namespace
), $row->rc_title
);
350 $date = $row->rc_timestamp
;
351 $comments = $title->getTalkPage()->getFullURL();
354 $title->getPrefixedText(),
355 $this->feedItemDesc( $row ),
356 $title->getFullURL(),
358 $this->feedItemAuthor( $row ),
365 protected function feedItemAuthor( $row ) {
366 return isset( $row->rc_user_text
) ?
$row->rc_user_text
: '';
369 protected function feedItemDesc( $row ) {
370 $revision = Revision
::newFromId( $row->rev_id
);
372 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
373 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
374 "</p>\n<hr />\n<div>" .
375 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
382 * @ingroup SpecialPage Pager
384 class NewPagesPager
extends ReverseChronologicalPager
{
386 protected $opts, $mForm;
388 function __construct( $form, FormOptions
$opts ) {
389 parent
::__construct();
390 $this->mForm
= $form;
394 function getTitle() {
395 static $title = null;
396 if ( $title === null )
397 $title = $this->mForm
->getTitle();
401 function getQueryInfo() {
402 global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
404 $conds['rc_new'] = 1;
406 $namespace = $this->opts
->getValue( 'namespace' );
407 $namespace = ( $namespace === 'all' ) ?
false : intval( $namespace );
409 $username = $this->opts
->getValue( 'username' );
410 $user = Title
::makeTitleSafe( NS_USER
, $username );
412 if( $namespace !== false ) {
413 $conds['rc_namespace'] = $namespace;
414 $rcIndexes = array( 'new_name_timestamp' );
416 $rcIndexes = array( 'rc_timestamp' );
419 # $wgEnableNewpagesUserFilter - temp WMF hack
420 if( $wgEnableNewpagesUserFilter && $user ) {
421 $conds['rc_user_text'] = $user->getText();
422 $rcIndexes = 'rc_user_text';
423 # If anons cannot make new pages, don't "exclude logged in users"!
424 } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts
->getValue( 'hideliu' ) ) {
425 $conds['rc_user'] = 0;
427 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
428 if( $this->opts
->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
429 $conds['rc_patrolled'] = 0;
431 if( $this->opts
->getValue( 'hidebots' ) ) {
432 $conds['rc_bot'] = 0;
435 if ( $this->opts
->getValue( 'hideredirs' ) ) {
436 $conds['page_is_redirect'] = 0;
439 // Allow changes to the New Pages query
440 wfRunHooks('SpecialNewpagesConditions', array(&$this, $this->opts
, &$conds));
443 'tables' => array( 'recentchanges', 'page' ),
444 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
445 rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
447 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
448 'join_conds' => array(
449 'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
453 ## Empty array for fields, it'll be set by us anyway.
456 ## Modify query for tags
457 ChangeTags
::modifyDisplayQuery( $info['tables'],
462 $this->opts
['tagfilter'] );
467 function getIndexField() {
468 return 'rc_timestamp';
471 function formatRow( $row ) {
472 return $this->mForm
->formatRow( $row );
475 function getStartBody() {
476 # Do a batch existence check on pages
477 $linkBatch = new LinkBatch();
478 while( $row = $this->mResult
->fetchObject() ) {
479 $linkBatch->add( NS_USER
, $row->rc_user_text
);
480 $linkBatch->add( NS_USER_TALK
, $row->rc_user_text
);
481 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
483 $linkBatch->execute();
487 function getEndBody() {