11 function wfSpecialNewPages( $par, $sp ) {
12 $page = new NewPagesForm();
13 $page->execute( $par, $sp->including() );
17 * implements Special:Newpages
18 * @ingroup SpecialPage
23 protected $opts, $title, $skin;
25 // Some internal settings
26 protected $showNavigation = false;
28 protected function setup( $par ) {
29 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
32 $opts = new FormOptions();
33 $this->opts
= $opts; // bind
34 $opts->add( 'hideliu', false );
35 $opts->add( 'hidepatrolled', false );
36 $opts->add( 'hidebots', false );
37 $opts->add( 'limit', 50 );
38 $opts->add( 'offset', '' );
39 $opts->add( 'namespace', '0' );
40 $opts->add( 'username', '' );
41 $opts->add( 'feed', '' );
44 $opts->fetchValuesFromRequest( $wgRequest );
45 if ( $par ) $this->parseParams( $par );
48 $opts->validateIntBounds( 'limit', 0, 5000 );
49 if( !$wgEnableNewpagesUserFilter ) {
50 $opts->setValue( 'username', '' );
54 $this->skin
= $wgUser->getSkin();
55 $this->title
= SpecialPage
::getTitleFor( 'NewPages' );
58 protected function parseParams( $par ) {
60 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
61 foreach ( $bits as $bit ) {
62 if ( 'shownav' == $bit )
63 $this->showNavigation
= true;
64 if ( 'hideliu' === $bit )
65 $this->opts
->setValue( 'hideliu', true );
66 if ( 'hidepatrolled' == $bit )
67 $this->opts
->setValue( 'hidepatrolled', true );
68 if ( 'hidebots' == $bit )
69 $this->opts
->setValue( 'hidebots', true );
70 if ( is_numeric( $bit ) )
71 $this->opts
->setValue( 'limit', intval( $bit ) );
74 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
75 $this->opts
->setValue( 'limit', intval($m[1]) );
76 // PG offsets not just digits!
77 if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
78 $this->opts
->setValue( 'offset', intval($m[1]) );
79 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
80 $ns = $wgLang->getNsIndex( $m[1] );
82 $this->opts
->setValue( 'namespace', $ns );
89 * Show a form for filtering namespace and username
92 * @param bool $including true if the page is being included with {{Special:Newpages}}
95 public function execute( $par, $including ) {
96 global $wgLang, $wgGroupPermissions, $wgUser, $wgOut;
98 $this->showNavigation
= !$including; // Maybe changed in setup
105 $this->setSyndicated();
106 $feedType = $this->opts
->getValue( 'feed' );
108 return $this->feed( $feedType );
112 $pager = new NewPagesPager( $this, $this->opts
);
113 $pager->mLimit
= $this->opts
->getValue( 'limit' );
114 $pager->mOffset
= $this->opts
->getValue( 'offset' );
116 if( $pager->getNumRows() ) {
118 if ( $this->showNavigation
) $navigation = $pager->getNavigationBar();
119 $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
121 $wgOut->addWikiMsg( 'specialpage-empty' );
125 protected function filterLinks() {
126 global $wgGroupPermissions, $wgUser;
129 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
131 // Option value -> message mapping
133 'hideliu' => 'rcshowhideliu',
134 'hidepatrolled' => 'rcshowhidepatr',
135 'hidebots' => 'rcshowhidebots'
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 foreach ( $filters as $key => $msg ) {
150 $onoff = 1 - $this->opts
->getValue($key);
151 $link = $this->skin
->makeKnownLinkObj( $this->title
, $showhide[$onoff],
152 wfArrayToCGI( array( $key => $onoff ), $changed )
154 $links[$key] = wfMsgHtml( $msg, $link );
157 return implode( ' | ', $links );
160 protected function form() {
161 global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
164 $this->opts
->consumeValue( 'offset' ); // don't carry offset, DWIW
165 $namespace = $this->opts
->consumeValue( 'namespace' );
166 $username = $this->opts
->consumeValue( 'username' );
168 // Check username input validity
169 $ut = Title
::makeTitleSafe( NS_USER
, $username );
170 $userText = $ut ?
$ut->getText() : '';
172 // Store query values in hidden fields so that form submission doesn't lose them
174 foreach ( $this->opts
->getUnconsumedValues() as $key => $value ) {
175 $hidden[] = Xml
::hidden( $key, $value );
177 $hidden = implode( "\n", $hidden );
179 $form = Xml
::openElement( 'form', array( 'action' => $wgScript ) ) .
180 Xml
::hidden( 'title', $this->title
->getPrefixedDBkey() ) .
181 Xml
::fieldset( wfMsg( 'newpages' ) ) .
182 Xml
::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
184 <td class='mw-label'>" .
185 Xml
::label( wfMsg( 'namespace' ), 'namespace' ) .
187 <td class='mw-input'>" .
188 Xml
::namespaceSelector( $namespace, 'all' ) .
191 ($wgEnableNewpagesUserFilter ?
193 <td class='mw-label'>" .
194 Xml
::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
196 <td class='mw-input'>" .
197 Xml
::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
201 <td class='mw-submit'>" .
202 Xml
::submitButton( wfMsg( 'allpagessubmit' ) ) .
207 <td class='mw-input'>" .
208 $this->filterLinks() .
211 Xml
::closeElement( 'table' ) .
212 Xml
::closeElement( 'fieldset' ) .
214 Xml
::closeElement( 'form' );
216 $wgOut->addHTML( $form );
219 protected function setSyndicated() {
221 $queryParams = array(
222 'namespace' => $this->opts
->getValue( 'namespace' ),
223 'username' => $this->opts
->getValue( 'username' )
225 $wgOut->setSyndicated( true );
226 $wgOut->setFeedAppendQuery( wfArrayToCGI( $queryParams ) );
230 * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
232 * @param $skin Skin to use
233 * @param $result Result row
236 public function formatRow( $result ) {
237 global $wgLang, $wgContLang, $wgUser;
238 $dm = $wgContLang->getDirMark();
240 $title = Title
::makeTitleSafe( $result->rc_namespace
, $result->rc_title
);
241 $time = $wgLang->timeAndDate( $result->rc_timestamp
, true );
242 $plink = $this->skin
->makeKnownLinkObj( $title, '', $this->patrollable( $result ) ?
'rcid=' . $result->rc_id
: '' );
243 $hist = $this->skin
->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
244 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
245 $wgLang->formatNum( $result->length
) );
246 $ulink = $this->skin
->userLink( $result->rc_user
, $result->rc_user_text
) . ' ' .
247 $this->skin
->userToolLinks( $result->rc_user
, $result->rc_user_text
);
248 $comment = $this->skin
->commentBlock( $result->rc_comment
);
249 $css = $this->patrollable( $result ) ?
" class='not-patrolled'" : '';
251 return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment}</li>\n";
255 * Should a specific result row provide "patrollable" links?
257 * @param $result Result row
260 protected function patrollable( $result ) {
262 return ( $wgUser->useNPPatrol() && !$result->rc_patrolled
);
266 * Output a subscription feed listing recent edits to this page.
267 * @param string $type
269 protected function feed( $type ) {
270 require_once 'SpecialRecentchanges.php';
272 global $wgFeed, $wgFeedClasses;
276 $wgOut->addWikiMsg( 'feed-unavailable' );
280 if( !isset( $wgFeedClasses[$type] ) ) {
282 $wgOut->addWikiMsg( 'feed-invalid' );
286 $feed = new $wgFeedClasses[$type](
289 $this->title
->getFullUrl() );
291 $pager = new NewPagesPager( $this, $this->opts
);
292 $limit = $this->opts
->getValue( 'limit' );
294 if( $limit > $wgFeedLimit ) {
295 $limit = $wgFeedLimit;
297 $pager->mLimit
= $limit;
300 if( $pager->getNumRows() > 0 ) {
301 while( $row = $pager->mResult
->fetchObject() ) {
302 $feed->outItem( $this->feedItem( $row ) );
308 protected function feedTitle() {
309 global $wgContLanguageCode, $wgSitename;
310 $page = SpecialPage
::getPage( 'Newpages' );
311 $desc = $page->getDescription();
312 return "$wgSitename - $desc [$wgContLanguageCode]";
315 protected function feedItem( $row ) {
316 $title = Title
::MakeTitle( intval( $row->rc_namespace
), $row->rc_title
);
318 $date = $row->rc_timestamp
;
319 $comments = $title->getTalkPage()->getFullURL();
322 $title->getPrefixedText(),
323 $this->feedItemDesc( $row ),
324 $title->getFullURL(),
326 $this->feedItemAuthor( $row ),
334 * Quickie hack... strip out wikilinks to more legible form from the comment.
336 protected function stripComment( $text ) {
337 return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
340 protected function feedItemAuthor( $row ) {
341 return isset( $row->rc_user_text
) ?
$row->rc_user_text
: '';
344 protected function feedItemDesc( $row ) {
345 $revision = Revision
::newFromId( $row->rev_id
);
347 return '<p>' . htmlspecialchars( $revision->getUserText() ) . ': ' .
348 htmlspecialchars( $revision->getComment() ) .
349 "</p>\n<hr />\n<div>" .
350 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
357 * @ingroup SpecialPage Pager
359 class NewPagesPager
extends ReverseChronologicalPager
{
361 protected $opts, $mForm;
363 private $hideliu, $hidepatrolled, $hidebots, $namespace, $user, $spTitle;
365 function __construct( $form, FormOptions
$opts ) {
366 parent
::__construct();
367 $this->mForm
= $form;
372 static $title = null;
373 if ( $title === null )
374 $title = SpecialPage
::getTitleFor( 'Newpages' );
378 function getQueryInfo() {
379 global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
381 $conds['rc_new'] = 1;
383 $namespace = $this->opts
->getValue( 'namespace' );
384 $namespace = ( $namespace === 'all' ) ?
false : intval( $namespace );
386 $username = $this->opts
->getValue( 'username' );
387 $user = Title
::makeTitleSafe( NS_USER
, $username );
389 if( $namespace !== false ) {
390 $conds['rc_namespace'] = $namespace;
391 $rcIndexes = array( 'new_name_timestamp' );
393 $rcIndexes = array( 'rc_timestamp' );
395 $conds[] = 'page_id = rc_cur_id';
396 $conds['page_is_redirect'] = 0;
397 # $wgEnableNewpagesUserFilter - temp WMF hack
398 if( $wgEnableNewpagesUserFilter && $user ) {
399 $conds['rc_user_text'] = $user->getText();
400 $rcIndexes = 'rc_user_text';
401 # If anons cannot make new pages, don't "exclude logged in users"!
402 } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts
->getValue( 'hideliu' ) ) {
403 $conds['rc_user'] = 0;
405 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
406 if( $this->opts
->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
407 $conds['rc_patrolled'] = 0;
409 if( $this->opts
->getValue( 'hidebots' ) ) {
410 $conds['rc_bot'] = 0;
414 'tables' => array( 'recentchanges', 'page' ),
415 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
416 rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id',
418 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) )
422 function getIndexField() {
423 return 'rc_timestamp';
426 function formatRow( $row ) {
427 return $this->mForm
->formatRow( $row );
430 function getStartBody() {
431 # Do a batch existence check on pages
432 $linkBatch = new LinkBatch();
433 while( $row = $this->mResult
->fetchObject() ) {
434 $linkBatch->add( NS_USER
, $row->rc_user_text
);
435 $linkBatch->add( NS_USER_TALK
, $row->rc_user_text
);
436 $linkBatch->add( $row->rc_namespace
, $row->rc_title
);
438 $linkBatch->execute();
442 function getEndBody() {