4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
21 * implements Special:Newpages
22 * @ingroup SpecialPage
24 class SpecialNewpages
extends IncludableSpecialPage
{
27 protected $opts, $skin;
29 // Some internal settings
30 protected $showNavigation = false;
32 public function __construct() {
33 parent
::__construct( 'Newpages' );
36 protected function setup( $par ) {
37 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
40 $opts = new FormOptions();
41 $this->opts
= $opts; // bind
42 $opts->add( 'hideliu', false );
43 $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
44 $opts->add( 'hidebots', false );
45 $opts->add( 'hideredirs', true );
46 $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
47 $opts->add( 'offset', '' );
48 $opts->add( 'namespace', '0' );
49 $opts->add( 'username', '' );
50 $opts->add( 'feed', '' );
51 $opts->add( 'tagfilter', '' );
54 $opts->fetchValuesFromRequest( $wgRequest );
55 if ( $par ) $this->parseParams( $par );
58 $opts->validateIntBounds( 'limit', 0, 5000 );
59 if( !$wgEnableNewpagesUserFilter ) {
60 $opts->setValue( 'username', '' );
64 $this->skin
= $wgUser->getSkin();
67 protected function parseParams( $par ) {
69 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
70 foreach ( $bits as $bit ) {
71 if ( 'shownav' == $bit )
72 $this->showNavigation
= true;
73 if ( 'hideliu' === $bit )
74 $this->opts
->setValue( 'hideliu', true );
75 if ( 'hidepatrolled' == $bit )
76 $this->opts
->setValue( 'hidepatrolled', true );
77 if ( 'hidebots' == $bit )
78 $this->opts
->setValue( 'hidebots', true );
79 if ( 'showredirs' == $bit )
80 $this->opts
->setValue( 'hideredirs', false );
81 if ( is_numeric( $bit ) )
82 $this->opts
->setValue( 'limit', intval( $bit ) );
85 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
86 $this->opts
->setValue( 'limit', intval($m[1]) );
87 // PG offsets not just digits!
88 if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
89 $this->opts
->setValue( 'offset', intval($m[1]) );
90 if ( preg_match( '/^username=(.*)$/', $bit, $m ) )
91 $this->opts
->setValue( 'username', $m[1] );
92 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
93 $ns = $wgLang->getNsIndex( $m[1] );
95 $this->opts
->setValue( 'namespace', $ns );
102 * Show a form for filtering namespace and username
107 public function execute( $par ) {
111 $this->outputHeader();
113 $this->showNavigation
= !$this->including(); // Maybe changed in setup
114 $this->setup( $par );
116 if( !$this->including() ) {
120 $this->setSyndicated();
121 $feedType = $this->opts
->getValue( 'feed' );
123 return $this->feed( $feedType );
127 $pager = new NewPagesPager( $this, $this->opts
);
128 $pager->mLimit
= $this->opts
->getValue( 'limit' );
129 $pager->mOffset
= $this->opts
->getValue( 'offset' );
131 if( $pager->getNumRows() ) {
133 if ( $this->showNavigation
) $navigation = $pager->getNavigationBar();
134 $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
136 $wgOut->addWikiMsg( 'specialpage-empty' );
140 protected function filterLinks() {
141 global $wgGroupPermissions, $wgUser, $wgLang;
144 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
146 // Option value -> message mapping
148 'hideliu' => 'rcshowhideliu',
149 'hidepatrolled' => 'rcshowhidepatr',
150 'hidebots' => 'rcshowhidebots',
151 'hideredirs' => 'whatlinkshere-hideredirs'
154 // Disable some if needed
155 # FIXME: throws E_NOTICEs if not set; and doesn't obey hooks etc
156 if ( $wgGroupPermissions['*']['createpage'] !== true )
157 unset($filters['hideliu']);
159 if ( !$wgUser->useNPPatrol() )
160 unset($filters['hidepatrolled']);
163 $changed = $this->opts
->getChangedValues();
164 unset($changed['offset']); // Reset offset if query type changes
166 $self = $this->getTitle();
167 foreach ( $filters as $key => $msg ) {
168 $onoff = 1 - $this->opts
->getValue($key);
169 $link = $this->skin
->link( $self, $showhide[$onoff], array(),
170 array( $key => $onoff ) +
$changed
172 $links[$key] = wfMsgHtml( $msg, $link );
175 return $wgLang->pipeList( $links );
178 protected function form() {
179 global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
182 $this->opts
->consumeValue( 'offset' ); // don't carry offset, DWIW
183 $namespace = $this->opts
->consumeValue( 'namespace' );
184 $username = $this->opts
->consumeValue( 'username' );
185 $tagFilterVal = $this->opts
->consumeValue( 'tagfilter' );
187 // Check username input validity
188 $ut = Title
::makeTitleSafe( NS_USER
, $username );
189 $userText = $ut ?
$ut->getText() : '';
191 // Store query values in hidden fields so that form submission doesn't lose them
193 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
194 $hidden[] = Xml
::hidden( $key, $value );
196 $hidden = implode( "\n", $hidden );
198 $tagFilter = ChangeTags
::buildTagFilterSelector( $tagFilterVal );
200 list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
202 $form = Xml
::openElement( 'form', array( 'action' => $wgScript ) ) .
203 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
204 Xml
::fieldset( wfMsg( 'newpages' ) ) .
205 Xml
::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
207 <td class='mw-label'>" .
208 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
210 <td class='mw-input'>" .
211 Xml
::namespaceSelector( $namespace, 'all' ) .
213 </tr>" . ( $tagFilter ?
(
215 <td class='mw-label'>" .
218 <td class='mw-input'>" .
222 ($wgEnableNewpagesUserFilter ?
224 <td class='mw-label'>" .
225 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
227 <td class='mw-input'>" .
228 Xml
::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
232 <td class='mw-submit'>" .
233 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
238 <td class='mw-input'>" .
239 $this->filterLinks() .
242 Xml
::closeElement( 'table' ) .
243 Xml
::closeElement( 'fieldset' ) .
245 Xml
::closeElement( 'form' );
247 $wgOut->addHTML( $form );
250 protected function setSyndicated() {
252 $wgOut->setSyndicated( true );
253 $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts
->getAllValues() ) );
257 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
259 * @param $result Result row
262 public function formatRow( $result ) {
263 global $wgLang, $wgContLang;
267 $dm = $wgContLang->getDirMark();
269 $title = Title
::makeTitleSafe( $result->rc_namespace
, $result->rc_title
);
270 $time = htmlspecialchars( $wgLang->timeAndDate( $result->rc_timestamp
, true ) );
272 $query = array( 'redirect' => 'no' );
274 if( $this->patrollable( $result ) )
275 $query['rcid'] = $result->rc_id
;
277 $plink = $this->skin
->linkKnown(
283 $hist = $this->skin
->linkKnown(
287 array( 'action' => 'history' )
289 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
290 $wgLang->formatNum( $result->length
) );
291 $ulink = $this->skin
->userLink( $result->rc_user
, $result->rc_user_text
) . ' ' .
292 $this->skin
->userToolLinks( $result->rc_user
, $result->rc_user_text
);
293 $comment = $this->skin
->commentBlock( $result->rc_comment
);
295 if ( $this->patrollable( $result ) )
296 $classes[] = 'not-patrolled';
298 # Tags, if any. check for including due to bug 23293
299 if ( !$this->including() ) {
300 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $result->ts_tags
, 'newpages' );
301 $classes = array_merge( $classes, $newClasses );
306 $css = count($classes) ?
' class="'.implode( " ", $classes).'"' : '';
308 return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
312 * Should a specific result row provide "patrollable" links?
314 * @param $result Result row
317 protected function patrollable( $result ) {
319 return ( $wgUser->useNPPatrol() && !$result->rc_patrolled
);
323 * Output a subscription feed listing recent edits to this page.
325 * @param $type String
327 protected function feed( $type ) {
328 global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgOut;
331 $wgOut->addWikiMsg( 'feed-unavailable' );
335 if( !isset( $wgFeedClasses[$type] ) ) {
336 $wgOut->addWikiMsg( 'feed-invalid' );
340 $feed = new $wgFeedClasses[$type](
342 wfMsgExt( 'tagline', 'parsemag' ),
343 $this->getTitle()->getFullUrl() );
345 $pager = new NewPagesPager( $this, $this->opts
);
346 $limit = $this->opts
->getValue( 'limit' );
347 $pager->mLimit
= min( $limit, $wgFeedLimit );
350 if( $pager->getNumRows() > 0 ) {
351 while( $row = $pager->mResult
->fetchObject() ) {
352 $feed->outItem( $this->feedItem( $row ) );
358 protected function feedTitle() {
359 global $wgContLanguageCode, $wgSitename;
360 $page = SpecialPage
::getPage( 'Newpages' );
361 $desc = $page->getDescription();
362 return "$wgSitename - $desc [$wgContLanguageCode]";
365 protected function feedItem( $row ) {
366 $title = Title
::MakeTitle( intval( $row->rc_namespace
), $row->rc_title
);
368 $date = $row->rc_timestamp
;
369 $comments = $title->getTalkPage()->getFullURL();
372 $title->getPrefixedText(),
373 $this->feedItemDesc( $row ),
374 $title->getFullURL(),
376 $this->feedItemAuthor( $row ),
383 protected function feedItemAuthor( $row ) {
384 return isset( $row->rc_user_text
) ?
$row->rc_user_text
: '';
387 protected function feedItemDesc( $row ) {
388 $revision = Revision
::newFromId( $row->rev_id
);
390 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
391 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
392 "</p>\n<hr />\n<div>" .
393 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
400 * @ingroup SpecialPage Pager
402 class NewPagesPager
extends ReverseChronologicalPager
{
404 protected $opts, $mForm;
406 function __construct( $form, FormOptions
$opts ) {
407 parent
::__construct();
408 $this->mForm
= $form;
412 function getTitle() {
413 static $title = null;
414 if ( $title === null )
415 $title = $this->mForm
->getTitle();
419 function getQueryInfo() {
420 global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
422 $conds['rc_new'] = 1;
424 $namespace = $this->opts
->getValue( 'namespace' );
425 $namespace = ( $namespace === 'all' ) ?
false : intval( $namespace );
427 $username = $this->opts
->getValue( 'username' );
428 $user = Title
::makeTitleSafe( NS_USER
, $username );
430 if( $namespace !== false ) {
431 $conds['rc_namespace'] = $namespace;
432 $rcIndexes = array( 'new_name_timestamp' );
434 $rcIndexes = array( 'rc_timestamp' );
437 # $wgEnableNewpagesUserFilter - temp WMF hack
438 if( $wgEnableNewpagesUserFilter && $user ) {
439 $conds['rc_user_text'] = $user->getText();
440 $rcIndexes = 'rc_user_text';
441 # If anons cannot make new pages, don't "exclude logged in users"!
442 } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts
->getValue( 'hideliu' ) ) {
443 $conds['rc_user'] = 0;
445 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
446 if( $this->opts
->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
447 $conds['rc_patrolled'] = 0;
449 if( $this->opts
->getValue( 'hidebots' ) ) {
450 $conds['rc_bot'] = 0;
453 if ( $this->opts
->getValue( 'hideredirs' ) ) {
454 $conds['page_is_redirect'] = 0;
457 // Allow changes to the New Pages query
458 wfRunHooks('SpecialNewpagesConditions', array(&$this, $this->opts
, &$conds));
461 'tables' => array( 'recentchanges', 'page' ),
462 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
463 rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
465 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
466 'join_conds' => array(
467 'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
471 ## Empty array for fields, it'll be set by us anyway.
474 ## Modify query for tags
475 ChangeTags
::modifyDisplayQuery( $info['tables'],
480 $this->opts
['tagfilter'] );
485 function getIndexField() {
486 return 'rc_timestamp';
489 function formatRow( $row ) {
490 return $this->mForm
->formatRow( $row );
493 function getStartBody() {
494 # Do a batch existence check on pages
495 $linkBatch = new LinkBatch();
496 while( $row = $this->mResult
->fetchObject() ) {
497 $linkBatch->add( NS_USER
, $row->rc_user_text
);
498 $linkBatch->add( NS_USER_TALK
, $row->rc_user_text
);
499 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
501 $linkBatch->execute();
505 function getEndBody() {