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