00001 <?php
00002
00007 class SpecialNewpages extends SpecialPage {
00008
00009
00010 protected $opts, $skin;
00011
00012
00013 protected $showNavigation = false;
00014
00015 public function __construct() {
00016 parent::__construct( 'Newpages' );
00017 $this->includable( true );
00018 }
00019
00020 protected function setup( $par ) {
00021 global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
00022
00023
00024 $opts = new FormOptions();
00025 $this->opts = $opts;
00026 $opts->add( 'hideliu', false );
00027 $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
00028 $opts->add( 'hidebots', false );
00029 $opts->add( 'hideredirs', true );
00030 $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
00031 $opts->add( 'offset', '' );
00032 $opts->add( 'namespace', '0' );
00033 $opts->add( 'username', '' );
00034 $opts->add( 'feed', '' );
00035 $opts->add( 'tagfilter', '' );
00036
00037
00038 $opts->fetchValuesFromRequest( $wgRequest );
00039 if ( $par ) $this->parseParams( $par );
00040
00041
00042 $opts->validateIntBounds( 'limit', 0, 5000 );
00043 if( !$wgEnableNewpagesUserFilter ) {
00044 $opts->setValue( 'username', '' );
00045 }
00046
00047
00048 $this->skin = $wgUser->getSkin();
00049 }
00050
00051 protected function parseParams( $par ) {
00052 global $wgLang;
00053 $bits = preg_split( '/\s*,\s*/', trim( $par ) );
00054 foreach ( $bits as $bit ) {
00055 if ( 'shownav' == $bit )
00056 $this->showNavigation = true;
00057 if ( 'hideliu' === $bit )
00058 $this->opts->setValue( 'hideliu', true );
00059 if ( 'hidepatrolled' == $bit )
00060 $this->opts->setValue( 'hidepatrolled', true );
00061 if ( 'hidebots' == $bit )
00062 $this->opts->setValue( 'hidebots', true );
00063 if ( 'showredirs' == $bit )
00064 $this->opts->setValue( 'hideredirs', false );
00065 if ( is_numeric( $bit ) )
00066 $this->opts->setValue( 'limit', intval( $bit ) );
00067
00068 $m = array();
00069 if ( preg_match( '/^limit=(\d+)$/', $bit, $m ) )
00070 $this->opts->setValue( 'limit', intval($m[1]) );
00071
00072 if ( preg_match( '/^offset=([^=]+)$/', $bit, $m ) )
00073 $this->opts->setValue( 'offset', intval($m[1]) );
00074 if ( preg_match( '/^username=(.*)$/', $bit, $m ) )
00075 $this->opts->setValue( 'username', $m[1] );
00076 if ( preg_match( '/^namespace=(.*)$/', $bit, $m ) ) {
00077 $ns = $wgLang->getNsIndex( $m[1] );
00078 if( $ns !== false ) {
00079 $this->opts->setValue( 'namespace', $ns );
00080 }
00081 }
00082 }
00083 }
00084
00091 public function execute( $par ) {
00092 global $wgLang, $wgOut;
00093
00094 $this->setHeaders();
00095 $this->outputHeader();
00096
00097 $this->showNavigation = !$this->including();
00098 $this->setup( $par );
00099
00100 if( !$this->including() ) {
00101
00102 $this->form();
00103
00104 $this->setSyndicated();
00105 $feedType = $this->opts->getValue( 'feed' );
00106 if( $feedType ) {
00107 return $this->feed( $feedType );
00108 }
00109 }
00110
00111 $pager = new NewPagesPager( $this, $this->opts );
00112 $pager->mLimit = $this->opts->getValue( 'limit' );
00113 $pager->mOffset = $this->opts->getValue( 'offset' );
00114
00115 if( $pager->getNumRows() ) {
00116 $navigation = '';
00117 if ( $this->showNavigation ) $navigation = $pager->getNavigationBar();
00118 $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
00119 } else {
00120 $wgOut->addWikiMsg( 'specialpage-empty' );
00121 }
00122 }
00123
00124 protected function filterLinks() {
00125 global $wgGroupPermissions, $wgUser, $wgLang;
00126
00127
00128 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
00129
00130
00131 $filters = array(
00132 'hideliu' => 'rcshowhideliu',
00133 'hidepatrolled' => 'rcshowhidepatr',
00134 'hidebots' => 'rcshowhidebots',
00135 'hideredirs' => 'whatlinkshere-hideredirs'
00136 );
00137
00138
00139 if ( $wgGroupPermissions['*']['createpage'] !== true )
00140 unset($filters['hideliu']);
00141
00142 if ( !$wgUser->useNPPatrol() )
00143 unset($filters['hidepatrolled']);
00144
00145 $links = array();
00146 $changed = $this->opts->getChangedValues();
00147 unset($changed['offset']);
00148
00149 $self = $this->getTitle();
00150 foreach ( $filters as $key => $msg ) {
00151 $onoff = 1 - $this->opts->getValue($key);
00152 $link = $this->skin->link( $self, $showhide[$onoff], array(),
00153 array( $key => $onoff ) + $changed
00154 );
00155 $links[$key] = wfMsgHtml( $msg, $link );
00156 }
00157
00158 return $wgLang->pipeList( $links );
00159 }
00160
00161 protected function form() {
00162 global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
00163
00164
00165 $this->opts->consumeValue( 'offset' );
00166 $namespace = $this->opts->consumeValue( 'namespace' );
00167 $username = $this->opts->consumeValue( 'username' );
00168 $tagFilterVal = $this->opts->consumeValue( 'tagfilter' );
00169
00170
00171 $ut = Title::makeTitleSafe( NS_USER, $username );
00172 $userText = $ut ? $ut->getText() : '';
00173
00174
00175 $hidden = array();
00176 foreach ( $this->opts->getUnconsumedValues() as $key => $value ) {
00177 $hidden[] = Xml::hidden( $key, $value );
00178 }
00179 $hidden = implode( "\n", $hidden );
00180
00181 $tagFilter = ChangeTags::buildTagFilterSelector( $tagFilterVal );
00182 if ($tagFilter)
00183 list( $tagFilterLabel, $tagFilterSelector ) = $tagFilter;
00184
00185 $form = Xml::openElement( 'form', array( 'action' => $wgScript ) ) .
00186 Xml::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
00187 Xml::fieldset( wfMsg( 'newpages' ) ) .
00188 Xml::openElement( 'table', array( 'id' => 'mw-newpages-table' ) ) .
00189 "<tr>
00190 <td class='mw-label'>" .
00191 Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
00192 "</td>
00193 <td class='mw-input'>" .
00194 Xml::namespaceSelector( $namespace, 'all' ) .
00195 "</td>
00196 </tr>" . ( $tagFilter ? (
00197 "<tr>
00198 <td class='mw-label'>" .
00199 $tagFilterLabel .
00200 "</td>
00201 <td class='mw-input'>" .
00202 $tagFilterSelector .
00203 "</td>
00204 </tr>" ) : '' ) .
00205 ($wgEnableNewpagesUserFilter ?
00206 "<tr>
00207 <td class='mw-label'>" .
00208 Xml::label( wfMsg( 'newpages-username' ), 'mw-np-username' ) .
00209 "</td>
00210 <td class='mw-input'>" .
00211 Xml::input( 'username', 30, $userText, array( 'id' => 'mw-np-username' ) ) .
00212 "</td>
00213 </tr>" : "" ) .
00214 "<tr> <td></td>
00215 <td class='mw-submit'>" .
00216 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
00217 "</td>
00218 </tr>" .
00219 "<tr>
00220 <td></td>
00221 <td class='mw-input'>" .
00222 $this->filterLinks() .
00223 "</td>
00224 </tr>" .
00225 Xml::closeElement( 'table' ) .
00226 Xml::closeElement( 'fieldset' ) .
00227 $hidden .
00228 Xml::closeElement( 'form' );
00229
00230 $wgOut->addHTML( $form );
00231 }
00232
00233 protected function setSyndicated() {
00234 global $wgOut;
00235 $wgOut->setSyndicated( true );
00236 $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
00237 }
00238
00246 public function formatRow( $result ) {
00247 global $wgLang, $wgContLang;
00248
00249 $classes = array();
00250
00251 $dm = $wgContLang->getDirMark();
00252
00253 $title = Title::makeTitleSafe( $result->rc_namespace, $result->rc_title );
00254 $time = htmlspecialchars( $wgLang->timeAndDate( $result->rc_timestamp, true ) );
00255
00256 $query = array( 'redirect' => 'no' );
00257
00258 if( $this->patrollable( $result ) )
00259 $query['rcid'] = $result->rc_id;
00260
00261 $plink = $this->skin->linkKnown(
00262 $title,
00263 null,
00264 array(),
00265 $query
00266 );
00267 $hist = $this->skin->linkKnown(
00268 $title,
00269 wfMsgHtml( 'hist' ),
00270 array(),
00271 array( 'action' => 'history' )
00272 );
00273 $length = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
00274 $wgLang->formatNum( $result->length ) );
00275 $ulink = $this->skin->userLink( $result->rc_user, $result->rc_user_text ) . ' ' .
00276 $this->skin->userToolLinks( $result->rc_user, $result->rc_user_text );
00277 $comment = $this->skin->commentBlock( $result->rc_comment );
00278
00279 if ( $this->patrollable( $result ) )
00280 $classes[] = 'not-patrolled';
00281
00282 # Tags, if any.
00283 list( $tagDisplay, $newClasses ) = ChangeTags::formatSummaryRow( $result->ts_tags, 'newpages' );
00284 $classes = array_merge( $classes, $newClasses );
00285
00286 $css = count($classes) ? ' class="'.implode( " ", $classes).'"' : '';
00287
00288 return "<li{$css}>{$time} {$dm}{$plink} ({$hist}) {$dm}[{$length}] {$dm}{$ulink} {$comment} {$tagDisplay}</li>\n";
00289 }
00290
00297 protected function patrollable( $result ) {
00298 global $wgUser;
00299 return ( $wgUser->useNPPatrol() && !$result->rc_patrolled );
00300 }
00301
00306 protected function feed( $type ) {
00307 global $wgFeed, $wgFeedClasses, $wgFeedLimit;
00308
00309 if ( !$wgFeed ) {
00310 global $wgOut;
00311 $wgOut->addWikiMsg( 'feed-unavailable' );
00312 return;
00313 }
00314
00315 if( !isset( $wgFeedClasses[$type] ) ) {
00316 global $wgOut;
00317 $wgOut->addWikiMsg( 'feed-invalid' );
00318 return;
00319 }
00320
00321 $feed = new $wgFeedClasses[$type](
00322 $this->feedTitle(),
00323 wfMsgExt( 'tagline', 'parsemag' ),
00324 $this->getTitle()->getFullUrl() );
00325
00326 $pager = new NewPagesPager( $this, $this->opts );
00327 $limit = $this->opts->getValue( 'limit' );
00328 $pager->mLimit = min( $limit, $wgFeedLimit );
00329
00330 $feed->outHeader();
00331 if( $pager->getNumRows() > 0 ) {
00332 while( $row = $pager->mResult->fetchObject() ) {
00333 $feed->outItem( $this->feedItem( $row ) );
00334 }
00335 }
00336 $feed->outFooter();
00337 }
00338
00339 protected function feedTitle() {
00340 global $wgContLanguageCode, $wgSitename;
00341 $page = SpecialPage::getPage( 'Newpages' );
00342 $desc = $page->getDescription();
00343 return "$wgSitename - $desc [$wgContLanguageCode]";
00344 }
00345
00346 protected function feedItem( $row ) {
00347 $title = Title::MakeTitle( intval( $row->rc_namespace ), $row->rc_title );
00348 if( $title ) {
00349 $date = $row->rc_timestamp;
00350 $comments = $title->getTalkPage()->getFullURL();
00351
00352 return new FeedItem(
00353 $title->getPrefixedText(),
00354 $this->feedItemDesc( $row ),
00355 $title->getFullURL(),
00356 $date,
00357 $this->feedItemAuthor( $row ),
00358 $comments);
00359 } else {
00360 return null;
00361 }
00362 }
00363
00364 protected function feedItemAuthor( $row ) {
00365 return isset( $row->rc_user_text ) ? $row->rc_user_text : '';
00366 }
00367
00368 protected function feedItemDesc( $row ) {
00369 $revision = Revision::newFromId( $row->rev_id );
00370 if( $revision ) {
00371 return '<p>' . htmlspecialchars( $revision->getUserText() ) . wfMsgForContent( 'colon-separator' ) .
00372 htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
00373 "</p>\n<hr />\n<div>" .
00374 nl2br( htmlspecialchars( $revision->getText() ) ) . "</div>";
00375 }
00376 return '';
00377 }
00378 }
00379
00383 class NewPagesPager extends ReverseChronologicalPager {
00384
00385 protected $opts, $mForm;
00386
00387 function __construct( $form, FormOptions $opts ) {
00388 parent::__construct();
00389 $this->mForm = $form;
00390 $this->opts = $opts;
00391 }
00392
00393 function getTitle() {
00394 static $title = null;
00395 if ( $title === null )
00396 $title = $this->mForm->getTitle();
00397 return $title;
00398 }
00399
00400 function getQueryInfo() {
00401 global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
00402 $conds = array();
00403 $conds['rc_new'] = 1;
00404
00405 $namespace = $this->opts->getValue( 'namespace' );
00406 $namespace = ( $namespace === 'all' ) ? false : intval( $namespace );
00407
00408 $username = $this->opts->getValue( 'username' );
00409 $user = Title::makeTitleSafe( NS_USER, $username );
00410
00411 if( $namespace !== false ) {
00412 $conds['rc_namespace'] = $namespace;
00413 $rcIndexes = array( 'new_name_timestamp' );
00414 } else {
00415 $rcIndexes = array( 'rc_timestamp' );
00416 }
00417
00418 # $wgEnableNewpagesUserFilter - temp WMF hack
00419 if( $wgEnableNewpagesUserFilter && $user ) {
00420 $conds['rc_user_text'] = $user->getText();
00421 $rcIndexes = 'rc_user_text';
00422 # If anons cannot make new pages, don't "exclude logged in users"!
00423 } elseif( $wgGroupPermissions['*']['createpage'] && $this->opts->getValue( 'hideliu' ) ) {
00424 $conds['rc_user'] = 0;
00425 }
00426 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
00427 if( $this->opts->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
00428 $conds['rc_patrolled'] = 0;
00429 }
00430 if( $this->opts->getValue( 'hidebots' ) ) {
00431 $conds['rc_bot'] = 0;
00432 }
00433
00434 if ( $this->opts->getValue( 'hideredirs' ) ) {
00435 $conds['page_is_redirect'] = 0;
00436 }
00437
00438 $info = array(
00439 'tables' => array( 'recentchanges', 'page' ),
00440 'fields' => 'rc_namespace,rc_title, rc_cur_id, rc_user,rc_user_text,rc_comment,
00441 rc_timestamp,rc_patrolled,rc_id,page_len as length, page_latest as rev_id, ts_tags',
00442 'conds' => $conds,
00443 'options' => array( 'USE INDEX' => array('recentchanges' => $rcIndexes) ),
00444 'join_conds' => array(
00445 'page' => array('INNER JOIN', 'page_id=rc_cur_id'),
00446 ),
00447 );
00448
00449 ## Empty array for fields, it'll be set by us anyway.
00450 $fields = array();
00451
00452 ## Modify query for tags
00453 ChangeTags::modifyDisplayQuery( $info['tables'],
00454 $fields,
00455 $info['conds'],
00456 $info['join_conds'],
00457 $info['options'],
00458 $this->opts['tagfilter'] );
00459
00460 return $info;
00461 }
00462
00463 function getIndexField() {
00464 return 'rc_timestamp';
00465 }
00466
00467 function formatRow( $row ) {
00468 return $this->mForm->formatRow( $row );
00469 }
00470
00471 function getStartBody() {
00472 # Do a batch existence check on pages
00473 $linkBatch = new LinkBatch();
00474 while( $row = $this->mResult->fetchObject() ) {
00475 $linkBatch->add( NS_USER, $row->rc_user_text );
00476 $linkBatch->add( NS_USER_TALK, $row->rc_user_text );
00477 $linkBatch->add( $row->rc_namespace, $row->rc_title );
00478 }
00479 $linkBatch->execute();
00480 return "<ul>";
00481 }
00482
00483 function getEndBody() {
00484 return "</ul>";
00485 }
00486 }