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 SpecialPage
{
27 protected $opts, $skin;
29 // Some internal settings
30 protected $showNavigation = false;
32 public function __construct() {
33 parent
::__construct( 'Newpages' );
34 $this->includable( true );
37 protected function setup( $par ) {
38 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
41 $opts = new FormOptions();
42 $this->opts
= $opts; // bind
43 $opts->add( 'hideliu', false );
44 $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
45 $opts->add( 'hidebots', false );
46 $opts->add( 'hideredirs', true );
47 $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
48 $opts->add( 'offset', '' );
49 $opts->add( 'namespace', '0' );
50 $opts->add( 'username', '' );
51 $opts->add( 'feed', '' );
52 $opts->add( 'tagfilter', '' );
55 $opts->fetchValuesFromRequest( $wgRequest );
56 if ( $par ) $this->parseParams( $par );
59 $opts->validateIntBounds( 'limit', 0, 5000 );
60 if( !$wgEnableNewpagesUserFilter ) {
61 $opts->setValue( 'username', '' );
65 $this->skin
= $wgUser->getSkin();
68 protected function parseParams( $par ) {
70 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
71 foreach ( $bits as $bit ) {
72 if ( 'shownav' == $bit )
73 $this->showNavigation
= true;
74 if ( 'hideliu' === $bit )
75 $this->opts
->setValue( 'hideliu', true );
76 if ( 'hidepatrolled' == $bit )
77 $this->opts
->setValue( 'hidepatrolled', true );
78 if ( 'hidebots' == $bit )
79 $this->opts
->setValue( 'hidebots', true );
80 if ( 'showredirs' == $bit )
81 $this->opts
->setValue( 'hideredirs', false );
82 if ( is_numeric( $bit ) )
83 $this->opts
->setValue( 'limit', intval( $bit ) );
86 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
87 $this->opts
->setValue( 'limit', intval($m[1]) );
88 // PG offsets not just digits!
89 if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
90 $this->opts
->setValue( 'offset', intval($m[1]) );
91 if ( preg_match( '/^username=(.*)$/', $bit, $m ) )
92 $this->opts
->setValue( 'username', $m[1] );
93 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
94 $ns = $wgLang->getNsIndex( $m[1] );
96 $this->opts
->setValue( 'namespace', $ns );
103 * Show a form for filtering namespace and username
108 public function execute( $par ) {
109 global $wgLang, $wgOut;
112 $this->outputHeader();
114 $this->showNavigation
= !$this->including(); // Maybe changed in setup
115 $this->setup( $par );
117 if( !$this->including() ) {
121 $this->setSyndicated();
122 $feedType = $this->opts
->getValue( 'feed' );
124 return $this->feed( $feedType );
128 $pager = new NewPagesPager( $this, $this->opts
);
129 $pager->mLimit
= $this->opts
->getValue( 'limit' );
130 $pager->mOffset
= $this->opts
->getValue( 'offset' );
132 if( $pager->getNumRows() ) {
134 if ( $this->showNavigation
) $navigation = $pager->getNavigationBar();
135 $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
137 $wgOut->addWikiMsg( 'specialpage-empty' );
141 protected function filterLinks() {
142 global $wgGroupPermissions, $wgUser, $wgLang;
145 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
147 // Option value -> message mapping
149 'hideliu' => 'rcshowhideliu',
150 'hidepatrolled' => 'rcshowhidepatr',
151 'hidebots' => 'rcshowhidebots',
152 'hideredirs' => 'whatlinkshere-hideredirs'
155 // Disable some if needed
156 # FIXME: throws E_NOTICEs if not set; and doesn't obey hooks etc
157 if ( $wgGroupPermissions['*']['createpage'] !== true )
158 unset($filters['hideliu']);
160 if ( !$wgUser->useNPPatrol() )
161 unset($filters['hidepatrolled']);
164 $changed = $this->opts
->getChangedValues();
165 unset($changed['offset']); // Reset offset if query type changes
167 $self = $this->getTitle();
168 foreach ( $filters as $key => $msg ) {
169 $onoff = 1 - $this->opts
->getValue($key);
170 $link = $this->skin
->link( $self, $showhide[$onoff], array(),
171 array( $key => $onoff ) +
$changed
173 $links[$key] = wfMsgHtml( $msg, $link );
176 return $wgLang->pipeList( $links );
179 protected function form() {
180 global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
183 $this->opts
->consumeValue( 'offset' ); // don't carry offset, DWIW
184 $namespace = $this->opts
->consumeValue( 'namespace' );
185 $username = $this->opts
->consumeValue( 'username' );
186 $tagFilterVal = $this->opts
->consumeValue( 'tagfilter' );
188 // Check username input validity
189 $ut = Title
::makeTitleSafe( NS_USER
, $username );
190 $userText = $ut ?
$ut->getText() : '';
192 // Store query values in hidden fields so that form submission doesn't lose them
194 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
195 $hidden[] = Xml
::hidden( $key, $value );
197 $hidden = implode( "\n", $hidden );
199 $tagFilter = ChangeTags
::buildTagFilterSelector( $tagFilterVal );
201 list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
203 $form = Xml
::openElement( 'form', array( 'action' => $wgScript ) ) .
204 Xml
::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
205 Xml
::fieldset( wfMsg( 'newpages' ) ) .
206 Xml
::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
208 <td class='mw-label'>" .
209 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
211 <td class='mw-input'>" .
212 Xml
::namespaceSelector( $namespace, 'all' ) .
214 </tr>" . ( $tagFilter ?
(
216 <td class='mw-label'>" .
219 <td class='mw-input'>" .
223 ($wgEnableNewpagesUserFilter ?
225 <td class='mw-label'>" .
226 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
228 <td class='mw-input'>" .
229 Xml
::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
233 <td class='mw-submit'>" .
234 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
239 <td class='mw-input'>" .
240 $this->filterLinks() .
243 Xml
::closeElement( 'table' ) .
244 Xml
::closeElement( 'fieldset' ) .
246 Xml
::closeElement( 'form' );
248 $wgOut->addHTML( $form );
251 protected function setSyndicated() {
253 $wgOut->setSyndicated( true );
254 $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts
->getAllValues() ) );
258 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
260 * @param $result Result row
263 public function formatRow( $result ) {
264 global $wgLang, $wgContLang;
268 $dm = $wgContLang->getDirMark();
270 $title = Title
::makeTitleSafe( $result->rc_namespace
, $result->rc_title
);
271 $time = htmlspecialchars( $wgLang->timeAndDate( $result->rc_timestamp
, true ) );
273 $query = array( 'redirect' => 'no' );
275 if( $this->patrollable( $result ) )
276 $query['rcid'] = $result->rc_id
;
278 $plink = $this->skin
->linkKnown(
284 $hist = $this->skin
->linkKnown(
288 array( 'action' => 'history' )
290 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
291 $wgLang->formatNum( $result->length
) );
292 $ulink = $this->skin
->userLink( $result->rc_user
, $result->rc_user_text
) . ' ' .
293 $this->skin
->userToolLinks( $result->rc_user
, $result->rc_user_text
);
294 $comment = $this->skin
->commentBlock( $result->rc_comment
);
296 if ( $this->patrollable( $result ) )
297 $classes[] = 'not-patrolled';
300 list( $tagDisplay, $newClasses ) = ChangeTags
::formatSummaryRow( $result->ts_tags
, 'newpages' );
301 $classes = array_merge( $classes, $newClasses );
303 $css = count($classes) ?
' class="'.implode( " ", $classes).'"' : '';
305 return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
309 * Should a specific result row provide "patrollable" links?
311 * @param $result Result row
314 protected function patrollable( $result ) {
316 return ( $wgUser->useNPPatrol() && !$result->rc_patrolled
);
320 * Output a subscription feed listing recent edits to this page.
322 * @param $type String
324 protected function feed( $type ) {
325 global $wgFeed, $wgFeedClasses, $wgFeedLimit;
329 $wgOut->addWikiMsg( 'feed-unavailable' );
333 if( !isset( $wgFeedClasses[$type] ) ) {
335 $wgOut->addWikiMsg( 'feed-invalid' );
339 $feed = new $wgFeedClasses[$type](
341 wfMsgExt( 'tagline', 'parsemag' ),
342 $this->getTitle()->getFullUrl() );
344 $pager = new NewPagesPager( $this, $this->opts
);
345 $limit = $this->opts
->getValue( 'limit' );
346 $pager->mLimit
= min( $limit, $wgFeedLimit );
349 if( $pager->getNumRows() > 0 ) {
350 while( $row = $pager->mResult
->fetchObject() ) {
351 $feed->outItem( $this->feedItem( $row ) );
357 protected function feedTitle() {
358 global $wgContLanguageCode, $wgSitename;
359 $page = SpecialPage
::getPage( 'Newpages' );
360 $desc = $page->getDescription();
361 return "$wgSitename - $desc [$wgContLanguageCode]";
364 protected function feedItem( $row ) {
365 $title = Title
::MakeTitle( intval( $row->rc_namespace
), $row->rc_title
);
367 $date = $row->rc_timestamp
;
368 $comments = $title->getTalkPage()->getFullURL();
371 $title->getPrefixedText(),
372 $this->feedItemDesc( $row ),
373 $title->getFullURL(),
375 $this->feedItemAuthor( $row ),
382 protected function feedItemAuthor( $row ) {
383 return isset( $row->rc_user_text
) ?
$row->rc_user_text
: '';
386 protected function feedItemDesc( $row ) {
387 $revision = Revision
::newFromId( $row->rev_id
);
389 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
390 htmlspecialchars( FeedItem
::stripComment( $revision->getComment() ) ) .
391 "</p>\n<hr />\n<div>" .
392 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
399 * @ingroup SpecialPage Pager
401 class NewPagesPager
extends ReverseChronologicalPager
{
403 protected $opts, $mForm;
405 function __construct( $form, FormOptions
$opts ) {
406 parent
::__construct();
407 $this->mForm
= $form;
411 function getTitle() {
412 static $title = null;
413 if ( $title === null )
414 $title = $this->mForm
->getTitle();
418 function getQueryInfo() {
419 global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
421 $conds['rc_new'] = 1;
423 $namespace = $this->opts
->getValue( 'namespace' );
424 $namespace = ( $namespace === 'all' ) ?
false : intval( $namespace );
426 $username = $this->opts
->getValue( 'username' );
427 $user = Title
::makeTitleSafe( NS_USER
, $username );
429 if( $namespace !== false ) {
430 $conds['rc_namespace'] = $namespace;
431 $rcIndexes = array( 'new_name_timestamp' );
433 $rcIndexes = array( 'rc_timestamp' );
436 # $wgEnableNewpagesUserFilter - temp WMF hack
437 if( $wgEnableNewpagesUserFilter && $user ) {
438 $conds['rc_user_text'] = $user->getText();
439 $rcIndexes = 'rc_user_text';
440 # If anons cannot make new pages, don't "exclude logged in users"!
441 } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts
->getValue( 'hideliu' ) ) {
442 $conds['rc_user'] = 0;
444 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
445 if( $this->opts
->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
446 $conds['rc_patrolled'] = 0;
448 if( $this->opts
->getValue( 'hidebots' ) ) {
449 $conds['rc_bot'] = 0;
452 if ( $this->opts
->getValue( 'hideredirs' ) ) {
453 $conds['page_is_redirect'] = 0;
456 // Allow changes to the New Pages query
457 wfRunHooks('SpecialNewpagesConditions', array(&$this, $this->opts
, &$conds));
460 'tables' => array( 'recentchanges', 'page' ),
461 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
462 rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
464 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
465 'join_conds' => array(
466 'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
470 ## Empty array for fields, it'll be set by us anyway.
473 ## Modify query for tags
474 ChangeTags
::modifyDisplayQuery( $info['tables'],
479 $this->opts
['tagfilter'] );
484 function getIndexField() {
485 return 'rc_timestamp';
488 function formatRow( $row ) {
489 return $this->mForm
->formatRow( $row );
492 function getStartBody() {
493 # Do a batch existence check on pages
494 $linkBatch = new LinkBatch();
495 while( $row = $this->mResult
->fetchObject() ) {
496 $linkBatch->add( NS_USER
, $row->rc_user_text
);
497 $linkBatch->add( NS_USER_TALK
, $row->rc_user_text
);
498 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
500 $linkBatch->execute();
504 function getEndBody() {