00001 <?php
00012 function wfSpecialWatchlist( $par ) {
00013 global $wgUser, $wgOut, $wgLang, $wgRequest;
00014 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
00015
00016
00017 $wlToken = $wgUser->getOption( 'watchlisttoken' );
00018 if (!$wlToken) {
00019 $wlToken = sha1( mt_rand() . microtime( true ) );
00020 $wgUser->setOption( 'watchlisttoken', $wlToken );
00021 $wgUser->saveSettings();
00022 }
00023
00024 global $wgServer, $wgScriptPath, $wgFeedClasses;
00025 $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
00026 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
00027 $feedTemplate = wfScript('api').'?';
00028
00029 foreach( $wgFeedClasses as $format => $class ) {
00030 $theseParams = $apiParams + array( 'feedformat' => $format );
00031 $url = $feedTemplate . wfArrayToCGI( $theseParams );
00032 $wgOut->addFeedLink( $format, $url );
00033 }
00034
00035 $skin = $wgUser->getSkin();
00036 $specialTitle = SpecialPage::getTitleFor( 'Watchlist' );
00037 $wgOut->setRobotPolicy( 'noindex,nofollow' );
00038
00039 # Anons don't get a watchlist
00040 if( $wgUser->isAnon() ) {
00041 $wgOut->setPageTitle( wfMsg( 'watchnologin' ) );
00042 $llink = $skin->linkKnown(
00043 SpecialPage::getTitleFor( 'Userlogin' ),
00044 wfMsgHtml( 'loginreqlink' ),
00045 array(),
00046 array( 'returnto' => $specialTitle->getPrefixedText() )
00047 );
00048 $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) );
00049 return;
00050 }
00051
00052 $wgOut->setPageTitle( wfMsg( 'watchlist' ) );
00053
00054 $sub = wfMsgExt( 'watchlistfor', 'parseinline', $wgUser->getName() );
00055 $sub .= '<br />' . WatchlistEditor::buildTools( $wgUser->getSkin() );
00056 $wgOut->setSubtitle( $sub );
00057
00058 if( ( $mode = WatchlistEditor::getMode( $wgRequest, $par ) ) !== false ) {
00059 $editor = new WatchlistEditor();
00060 $editor->execute( $wgUser, $wgOut, $wgRequest, $mode );
00061 return;
00062 }
00063
00064 $uid = $wgUser->getId();
00065 if( ($wgEnotifWatchlist || $wgShowUpdatedMarker) && $wgRequest->getVal( 'reset' ) &&
00066 $wgRequest->wasPosted() )
00067 {
00068 $wgUser->clearAllNotifications( $uid );
00069 $wgOut->redirect( $specialTitle->getFullUrl() );
00070 return;
00071 }
00072
00073 $defaults = array(
00074 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ),
00075 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ),
00076 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ),
00077 'hideAnons' => (int)$wgUser->getBoolOption( 'watchlisthideanons' ),
00078 'hideLiu' => (int)$wgUser->getBoolOption( 'watchlisthideliu' ),
00079 'hidePatrolled' => (int)$wgUser->getBoolOption( 'watchlisthidepatrolled' ),
00080 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ),
00081 'namespace' => 'all',
00082 'invert' => false,
00083 );
00084
00085 extract($defaults);
00086
00087 # Extract variables from the request, falling back to user preferences or
00088 # other default values if these don't exist
00089 $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) );
00090 $prefs['hideminor'] = $wgUser->getBoolOption( 'watchlisthideminor' );
00091 $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' );
00092 $prefs['hideanons'] = $wgUser->getBoolOption( 'watchlisthideanon' );
00093 $prefs['hideliu'] = $wgUser->getBoolOption( 'watchlisthideliu' );
00094 $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' );
00095 $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' );
00096
00097 # Get query variables
00098 $days = $wgRequest->getVal( 'days' , $prefs['days'] );
00099 $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] );
00100 $hideBots = $wgRequest->getBool( 'hideBots' , $prefs['hidebots'] );
00101 $hideAnons = $wgRequest->getBool( 'hideAnons', $prefs['hideanons'] );
00102 $hideLiu = $wgRequest->getBool( 'hideLiu' , $prefs['hideliu'] );
00103 $hideOwn = $wgRequest->getBool( 'hideOwn' , $prefs['hideown'] );
00104 $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] );
00105
00106 # Get namespace value, if supplied, and prepare a WHERE fragment
00107 $nameSpace = $wgRequest->getIntOrNull( 'namespace' );
00108 $invert = $wgRequest->getIntOrNull( 'invert' );
00109 if( !is_null( $nameSpace ) ) {
00110 $nameSpace = intval( $nameSpace );
00111 if( $invert && $nameSpace !== 'all' )
00112 $nameSpaceClause = "rc_namespace != $nameSpace";
00113 else
00114 $nameSpaceClause = "rc_namespace = $nameSpace";
00115 } else {
00116 $nameSpace = '';
00117 $nameSpaceClause = '';
00118 }
00119
00120 $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
00121 $recentchanges = $dbr->tableName( 'recentchanges' );
00122
00123 $watchlistCount = $dbr->selectField( 'watchlist', 'COUNT(*)',
00124 array( 'wl_user' => $uid ), __METHOD__ );
00125
00126
00127 $nitems = floor($watchlistCount / 2);
00128
00129 if( is_null($days) || !is_numeric($days) ) {
00130 $big = 1000;
00131 if($nitems > $big) {
00132 # Set default cutoff shorter
00133 $days = $defaults['days'] = (12.0 / 24.0); # 12 hours...
00134 } else {
00135 $days = $defaults['days']; # default cutoff for shortlisters
00136 }
00137 } else {
00138 $days = floatval($days);
00139 }
00140
00141
00142 $nondefaults = array();
00143
00144 wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults);
00145 wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults );
00146 wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults);
00147 wfAppendToArrayIfNotDefault( 'hideAnons', (int)$hideAnons, $defaults, $nondefaults );
00148 wfAppendToArrayIfNotDefault( 'hideLiu' , (int)$hideLiu , $defaults, $nondefaults );
00149 wfAppendToArrayIfNotDefault( 'hideOwn' , (int)$hideOwn , $defaults, $nondefaults);
00150 wfAppendToArrayIfNotDefault( 'namespace', $nameSpace , $defaults, $nondefaults);
00151 wfAppendToArrayIfNotDefault( 'hidePatrolled', (int)$hidePatrolled, $defaults, $nondefaults );
00152
00153 if( $nitems == 0 ) {
00154 $wgOut->addWikiMsg( 'nowatchlist' );
00155 return;
00156 }
00157
00158 if( $days <= 0 ) {
00159 $andcutoff = '';
00160 } else {
00161 $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'";
00162 }
00163
00164 # If the watchlist is relatively short, it's simplest to zip
00165 # down its entirety and then sort the results.
00166
00167 # If it's relatively long, it may be worth our while to zip
00168 # through the time-sorted page list checking for watched items.
00169
00170 # Up estimate of watched items by 15% to compensate for talk pages...
00171
00172 # Toggles
00173 $andHideOwn = $hideOwn ? "rc_user != $uid" : '';
00174 $andHideBots = $hideBots ? "rc_bot = 0" : '';
00175 $andHideMinor = $hideMinor ? "rc_minor = 0" : '';
00176 $andHideLiu = $hideLiu ? "rc_user = 0" : '';
00177 $andHideAnons = $hideAnons ? "rc_user != 0" : '';
00178 $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ? "rc_patrolled != 1" : '';
00179
00180 # Toggle watchlist content (all recent edits or just the latest)
00181 if( $wgUser->getOption( 'extendwatchlist' )) {
00182 $andLatest='';
00183 $limitWatchlist = intval( $wgUser->getOption( 'wllimit' ) );
00184 $usePage = false;
00185 } else {
00186 # Top log Ids for a page are not stored
00187 $andLatest = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG;
00188 $limitWatchlist = 0;
00189 $usePage = true;
00190 }
00191
00192 # Show a message about slave lag, if applicable
00193 if( ( $lag = $dbr->getLag() ) > 0 )
00194 $wgOut->showLagWarning( $lag );
00195
00196 # Create output form
00197 $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) );
00198
00199 # Show watchlist header
00200 $form .= wfMsgExt( 'watchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) );
00201
00202 if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) {
00203 $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n";
00204 }
00205 if( $wgShowUpdatedMarker ) {
00206 $form .= Xml::openElement( 'form', array( 'method' => 'post',
00207 'action' => $specialTitle->getLocalUrl(),
00208 'id' => 'mw-watchlist-resetbutton' ) ) .
00209 wfMsgExt( 'wlheader-showupdated', array( 'parseinline' ) ) . ' ' .
00210 Xml::submitButton( wfMsg( 'enotif_reset' ), array( 'name' => 'dummy' ) ) .
00211 Xml::hidden( 'reset', 'all' ) .
00212 Xml::closeElement( 'form' );
00213 }
00214 $form .= '<hr />';
00215
00216 $tables = array( 'recentchanges', 'watchlist' );
00217 $fields = array( "{$recentchanges}.*" );
00218 $conds = array();
00219 $join_conds = array(
00220 'watchlist' => array('INNER JOIN',"wl_user='{$uid}' AND wl_namespace=rc_namespace AND wl_title=rc_title"),
00221 );
00222 $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
00223 if( $wgShowUpdatedMarker ) {
00224 $fields[] = 'wl_notificationtimestamp';
00225 }
00226 if( $limitWatchlist ) {
00227 $options['LIMIT'] = $limitWatchlist;
00228 }
00229 if( $andcutoff ) $conds[] = $andcutoff;
00230 if( $andLatest ) $conds[] = $andLatest;
00231 if( $andHideOwn ) $conds[] = $andHideOwn;
00232 if( $andHideBots ) $conds[] = $andHideBots;
00233 if( $andHideMinor ) $conds[] = $andHideMinor;
00234 if( $andHideLiu ) $conds[] = $andHideLiu;
00235 if( $andHideAnons ) $conds[] = $andHideAnons;
00236 if( $andHidePatrolled ) $conds[] = $andHidePatrolled;
00237 if( $nameSpaceClause ) $conds[] = $nameSpaceClause;
00238
00239 $rollbacker = $wgUser->isAllowed('rollback');
00240 if ( $usePage || $rollbacker ) {
00241 $tables[] = 'page';
00242 $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page_id');
00243 if ($rollbacker)
00244 $fields[] = 'page_latest';
00245 }
00246
00247 ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' );
00248 wfRunHooks('SpecialWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) );
00249
00250 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds );
00251 $numRows = $dbr->numRows( $res );
00252
00253
00254
00255 $wlInfo = '';
00256 if( $days >= 1 ) {
00257 $wlInfo = wfMsgExt( 'rcnote', 'parseinline',
00258 $wgLang->formatNum( $numRows ),
00259 $wgLang->formatNum( $days ),
00260 $wgLang->timeAndDate( wfTimestampNow(), true ),
00261 $wgLang->date( wfTimestampNow(), true ),
00262 $wgLang->time( wfTimestampNow(), true )
00263 ) . '<br />';
00264 } elseif( $days > 0 ) {
00265 $wlInfo = wfMsgExt( 'wlnote', 'parseinline',
00266 $wgLang->formatNum( $numRows ),
00267 $wgLang->formatNum( round($days*24) )
00268 ) . '<br />';
00269 }
00270
00271 $cutofflinks = "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "<br />\n";
00272
00273 $thisTitle = SpecialPage::getTitleFor( 'Watchlist' );
00274
00275 # Spit out some control panel links
00276 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor );
00277 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots );
00278 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideanons', 'hideAnons', $hideAnons );
00279 $links[] = wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu );
00280 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn );
00281
00282 if( $wgUser->useRCPatrol() ) {
00283 $links[] = wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled );
00284 }
00285
00286 # Namespace filter and put the whole form together.
00287 $form .= $wlInfo;
00288 $form .= $cutofflinks;
00289 $form .= $wgLang->pipeList( $links );
00290 $form .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
00291 $form .= '<hr /><p>';
00292 $form .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ';
00293 $form .= Xml::namespaceSelector( $nameSpace, '' ) . ' ';
00294 $form .= Xml::checkLabel( wfMsg('invert'), 'invert', 'nsinvert', $invert ) . ' ';
00295 $form .= Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . '</p>';
00296 $form .= Xml::hidden( 'days', $days );
00297 if( $hideMinor )
00298 $form .= Xml::hidden( 'hideMinor', 1 );
00299 if( $hideBots )
00300 $form .= Xml::hidden( 'hideBots', 1 );
00301 if( $hideAnons )
00302 $form .= Xml::hidden( 'hideAnons', 1 );
00303 if( $hideLiu )
00304 $form .= Xml::hidden( 'hideLiu', 1 );
00305 if( $hideOwn )
00306 $form .= Xml::hidden( 'hideOwn', 1 );
00307 $form .= Xml::closeElement( 'form' );
00308 $form .= Xml::closeElement( 'fieldset' );
00309 $wgOut->addHTML( $form );
00310
00311 $wgOut->addHTML( ChangesList::flagLegend() );
00312
00313 # If there's nothing to show, stop here
00314 if( $numRows == 0 ) {
00315 $wgOut->addWikiMsg( 'watchnochange' );
00316 return;
00317 }
00318
00319
00320
00321
00322 $linkBatch = new LinkBatch;
00323 while ( $row = $dbr->fetchObject( $res ) ) {
00324 $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text );
00325 if ( $row->rc_user != 0 ) {
00326 $linkBatch->add( NS_USER, $userNameUnderscored );
00327 }
00328 $linkBatch->add( NS_USER_TALK, $userNameUnderscored );
00329
00330 $linkBatch->add( $row->rc_namespace, $row->rc_title );
00331 }
00332 $linkBatch->execute();
00333 $dbr->dataSeek( $res, 0 );
00334
00335 $list = ChangesList::newFromUser( $wgUser );
00336 $list->setWatchlistDivs();
00337
00338 $s = $list->beginRecentChangesList();
00339 $counter = 1;
00340 while ( $obj = $dbr->fetchObject( $res ) ) {
00341 # Make RC entry
00342 $rc = RecentChange::newFromRow( $obj );
00343 $rc->counter = $counter++;
00344
00345 if ( $wgShowUpdatedMarker ) {
00346 $updated = $obj->wl_notificationtimestamp;
00347 } else {
00348 $updated = false;
00349 }
00350
00351 if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
00352 $rc->numberofWatchingusers = $dbr->selectField( 'watchlist',
00353 'COUNT(*)',
00354 array(
00355 'wl_namespace' => $obj->rc_namespace,
00356 'wl_title' => $obj->rc_title,
00357 ),
00358 __METHOD__ );
00359 } else {
00360 $rc->numberofWatchingusers = 0;
00361 }
00362
00363 $s .= $list->recentChangesLine( $rc, $updated, $counter );
00364 }
00365 $s .= $list->endRecentChangesList();
00366
00367 $dbr->freeResult( $res );
00368 $wgOut->addHTML( $s );
00369 }
00370
00371 function wlShowHideLink( $options, $message, $name, $value ) {
00372 global $wgUser;
00373
00374 $showLinktext = wfMsgHtml( 'show' );
00375 $hideLinktext = wfMsgHtml( 'hide' );
00376 $title = SpecialPage::getTitleFor( 'Watchlist' );
00377 $skin = $wgUser->getSkin();
00378
00379 $label = $value ? $showLinktext : $hideLinktext;
00380 $options[$name] = 1 - (int) $value;
00381
00382 return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) );
00383 }
00384
00385
00386 function wlHoursLink( $h, $page, $options = array() ) {
00387 global $wgUser, $wgLang, $wgContLang;
00388
00389 $sk = $wgUser->getSkin();
00390 $title = Title::newFromText( $wgContLang->specialPage( $page ) );
00391 $options['days'] = ($h / 24.0);
00392
00393 $s = $sk->linkKnown(
00394 $title,
00395 $wgLang->formatNum( $h ),
00396 array(),
00397 $options
00398 );
00399
00400 return $s;
00401 }
00402
00403 function wlDaysLink( $d, $page, $options = array() ) {
00404 global $wgUser, $wgLang, $wgContLang;
00405
00406 $sk = $wgUser->getSkin();
00407 $title = Title::newFromText( $wgContLang->specialPage( $page ) );
00408 $options['days'] = $d;
00409 $message = ($d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) );
00410
00411 $s = $sk->linkKnown(
00412 $title,
00413 $message,
00414 array(),
00415 $options
00416 );
00417
00418 return $s;
00419 }
00420
00424 function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) {
00425 global $wgLang;
00426
00427 $hours = array( 1, 2, 6, 12 );
00428 $days = array( 1, 3, 7 );
00429 $i = 0;
00430 foreach( $hours as $h ) {
00431 $hours[$i++] = wlHoursLink( $h, $page, $options );
00432 }
00433 $i = 0;
00434 foreach( $days as $d ) {
00435 $days[$i++] = wlDaysLink( $d, $page, $options );
00436 }
00437 return wfMsgExt('wlshowlast',
00438 array('parseinline', 'replaceafter'),
00439 $wgLang->pipeList( $hours ),
00440 $wgLang->pipeList( $days ),
00441 wlDaysLink( 0, $page, $options ) );
00442 }
00443
00450 function wlCountItems( &$user, $talk = true ) {
00451 $dbr = wfGetDB( DB_SLAVE, 'watchlist' );
00452
00453 # Fetch the raw count
00454 $res = $dbr->select( 'watchlist', 'COUNT(*) AS count',
00455 array( 'wl_user' => $user->mId ), 'wlCountItems' );
00456 $row = $dbr->fetchObject( $res );
00457 $count = $row->count;
00458 $dbr->freeResult( $res );
00459
00460 # Halve to remove talk pages if needed
00461 if( !$talk )
00462 $count = floor( $count / 2 );
00463
00464 return( $count );
00465 }