2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
|
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-05-07 13:43:10 +00:00
|
|
|
require_once( "SpecialRecentchanges.php" );
|
|
|
|
|
require_once( "WatchedItem.php" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* constructor
|
|
|
|
|
*/
|
|
|
|
|
function wfSpecialWatchlist() {
|
2004-08-13 11:57:20 +00:00
|
|
|
global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest;
|
2004-07-10 03:09:26 +00:00
|
|
|
global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname;
|
2003-04-14 23:10:40 +00:00
|
|
|
$fname = "wfSpecialWatchlist";
|
|
|
|
|
|
|
|
|
|
$wgOut->setPagetitle( wfMsg( "watchlist" ) );
|
2003-11-15 13:26:37 +00:00
|
|
|
$sub = wfMsg( "watchlistsub", $wgUser->getName() );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->setSubtitle( $sub );
|
2003-08-08 05:13:09 +00:00
|
|
|
$wgOut->setRobotpolicy( "noindex,nofollow" );
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-03-06 01:49:16 +00:00
|
|
|
$specialTitle = Title::makeTitle( NS_SPECIAL, "Watchlist" );
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$uid = $wgUser->getID();
|
|
|
|
|
if( $uid == 0 ) {
|
|
|
|
|
$wgOut->addHTML( wfMsg( "nowatchlist" ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-13 11:57:20 +00:00
|
|
|
# Get query variables
|
|
|
|
|
$days = $wgRequest->getVal( 'days' );
|
|
|
|
|
$action = $wgRequest->getVal( 'action' );
|
|
|
|
|
$remove = $wgRequest->getVal( 'remove' );
|
|
|
|
|
$id = $wgRequest->getVal( 'id' );
|
|
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
if(($action == "submit") && isset($remove) && is_array($id)) {
|
|
|
|
|
$wgOut->addHTML( wfMsg( "removingchecked" ) );
|
|
|
|
|
foreach($id as $one) {
|
|
|
|
|
$t = Title::newFromURL( $one );
|
|
|
|
|
if($t->getDBkey() != "") {
|
2003-11-09 11:45:12 +00:00
|
|
|
$wl = WatchedItem::fromUserTitle( $wgUser, $t );
|
|
|
|
|
if( $wl->removeWatch() === false ) {
|
2003-08-07 11:54:16 +00:00
|
|
|
$wgOut->addHTML( "<br />\n" . wfMsg( "couldntremove", htmlspecialchars($one) ) );
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->addHTML( " (" . htmlspecialchars($one) . ")" );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->addHTML( "<br />\n" . wfMsg( "iteminvalidname", htmlspecialchars($one) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$wgOut->addHTML( "done.\n<p>" );
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-25 02:33:34 +00:00
|
|
|
if ( $wgUseWatchlistCache ) {
|
|
|
|
|
$memckey = "$wgDBname:watchlist:id:" . $wgUser->getId();
|
|
|
|
|
$cache_s = @$wgMemc->get( $memckey );
|
|
|
|
|
if( $cache_s ){
|
|
|
|
|
$wgOut->addHTML( wfMsg("wlsaved") );
|
|
|
|
|
$wgOut->addHTML( $cache_s );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
extract( $dbr->tableNames( 'cur', 'watchlist', 'recentchanges' ) );
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid";
|
|
|
|
|
$res = $dbr->query( $sql );
|
|
|
|
|
$s = $dbr->fetchObject( $res );
|
2003-08-07 11:54:16 +00:00
|
|
|
$nitems = $s->n;
|
|
|
|
|
if($nitems == 0) {
|
|
|
|
|
$wgOut->addHTML( wfMsg( "nowatchlist" ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2004-08-13 11:57:20 +00:00
|
|
|
|
|
|
|
|
if ( is_null( $days ) ) {
|
2003-12-03 15:18:38 +00:00
|
|
|
$big = 1000;
|
2003-08-08 05:13:09 +00:00
|
|
|
if($nitems > $big) {
|
|
|
|
|
# Set default cutoff shorter
|
2003-12-03 15:18:38 +00:00
|
|
|
$days = (12.0 / 24.0); # 12 hours...
|
2003-08-08 05:13:09 +00:00
|
|
|
} else {
|
2003-12-05 04:46:43 +00:00
|
|
|
$days = 3; # longer cutoff for shortlisters
|
2003-08-08 05:13:09 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$days = floatval($days);
|
|
|
|
|
}
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-08 05:13:09 +00:00
|
|
|
if ( $days <= 0 ) {
|
|
|
|
|
$docutoff = '';
|
|
|
|
|
$cutoff = false;
|
|
|
|
|
$npages = wfMsg( "all" );
|
|
|
|
|
} else {
|
2004-07-10 01:05:36 +00:00
|
|
|
$docutoff = "AND cur_timestamp > '" .
|
2004-08-10 13:22:15 +00:00
|
|
|
( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) )
|
2003-08-08 05:13:09 +00:00
|
|
|
. "'";
|
2004-07-18 08:48:43 +00:00
|
|
|
$sql = "SELECT COUNT(*) AS n FROM $cur WHERE cur_timestamp>'$cutoff'";
|
|
|
|
|
$res = $dbr->query( $sql );
|
|
|
|
|
$s = $dbr->fetchObject( $res );
|
2003-08-08 05:13:09 +00:00
|
|
|
$npages = $s->n;
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-08 05:13:09 +00:00
|
|
|
}
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
if(isset($_REQUEST['magic'])) {
|
2004-03-06 03:03:14 +00:00
|
|
|
$wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
|
2003-08-07 11:54:16 +00:00
|
|
|
"<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
$wgOut->addHTML( "<form action='" .
|
2004-03-07 07:26:56 +00:00
|
|
|
$specialTitle->escapeLocalUrl( "action=submit" ) .
|
2003-08-07 11:54:16 +00:00
|
|
|
"' method='post'>\n" .
|
|
|
|
|
"<ul>\n" );
|
2004-07-18 08:48:43 +00:00
|
|
|
$sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid";
|
|
|
|
|
$res = $dbr->query( $sql );
|
2003-08-07 11:54:16 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2004-07-18 08:48:43 +00:00
|
|
|
while( $s = $dbr->fetchObject( $res ) ) {
|
2003-08-07 11:54:16 +00:00
|
|
|
$t = Title::makeTitle( $s->wl_namespace, $s->wl_title );
|
2004-06-12 01:37:42 +00:00
|
|
|
if( is_null( $t ) ) {
|
2004-06-12 01:47:13 +00:00
|
|
|
$wgOut->addHTML( '<!-- bad title "' . htmlspecialchars( $s->wl_title ) . '" in namespace ' . IntVal( $s->wl_namespace ) . " -->\n" );
|
2004-06-12 01:37:42 +00:00
|
|
|
} else {
|
|
|
|
|
$t = $t->getPrefixedText();
|
|
|
|
|
$wgOut->addHTML( "<li><input type='checkbox' name='id[]' value=\"" . htmlspecialchars($t) . "\" />" .
|
2004-08-09 10:03:39 +00:00
|
|
|
$sk->makeLink( $t, $t ) .
|
2004-06-12 01:37:42 +00:00
|
|
|
"</li>\n" );
|
|
|
|
|
}
|
2003-08-07 11:54:16 +00:00
|
|
|
}
|
|
|
|
|
$wgOut->addHTML( "</ul>\n" .
|
2004-10-14 04:40:58 +00:00
|
|
|
"<input type='submit' name='remove' value=\"" .
|
|
|
|
|
htmlspecialchars( wfMsg( "removechecked" ) ) . "\" />\n" .
|
2003-08-07 11:54:16 +00:00
|
|
|
"</form>\n" );
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
# If the watchlist is relatively short, it's simplest to zip
|
|
|
|
|
# down its entirety and then sort the results.
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
# If it's relatively long, it may be worth our while to zip
|
2003-08-08 05:13:09 +00:00
|
|
|
# through the time-sorted page list checking for watched items.
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
# Up estimate of watched items by 15% to compensate for talk pages...
|
2003-08-08 05:13:09 +00:00
|
|
|
if( $cutoff && ( $nitems*1.15 > $npages ) ) {
|
2003-08-07 11:54:16 +00:00
|
|
|
$x = "cur_timestamp";
|
|
|
|
|
$y = wfMsg( "watchmethod-recent" );
|
|
|
|
|
$z = "wl_namespace=cur_namespace&65534";
|
|
|
|
|
} else {
|
|
|
|
|
$x = "name_title_timestamp";
|
|
|
|
|
$y = wfMsg( "watchmethod-list" );
|
|
|
|
|
$z = "(wl_namespace=cur_namespace OR wl_namespace+1=cur_namespace)";
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2004-03-06 03:03:14 +00:00
|
|
|
$wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
|
|
|
|
|
$wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
|
2004-04-03 11:31:05 +00:00
|
|
|
$specialTitle->escapeLocalUrl( "magic=yes" ) ) . "</i><br />\n" );
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$use_index = $dbr->useIndexClause( $x );
|
2003-08-07 11:54:16 +00:00
|
|
|
$sql = "SELECT
|
2004-01-31 12:00:32 +00:00
|
|
|
cur_namespace,cur_title,cur_comment, cur_id,
|
2003-08-07 11:54:16 +00:00
|
|
|
cur_user,cur_user_text,cur_timestamp,cur_minor_edit,cur_is_new
|
2004-07-18 08:48:43 +00:00
|
|
|
FROM $watchlist,$cur $use_index
|
2003-08-07 11:54:16 +00:00
|
|
|
WHERE wl_user=$uid
|
|
|
|
|
AND $z
|
|
|
|
|
AND wl_title=cur_title
|
2003-08-08 05:13:09 +00:00
|
|
|
$docutoff
|
2003-08-07 11:54:16 +00:00
|
|
|
ORDER BY cur_timestamp DESC";
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$res = $dbr->query( $sql, $fname );
|
2004-08-13 11:57:20 +00:00
|
|
|
$numRows = $dbr->numRows( $res );
|
2003-08-07 11:54:16 +00:00
|
|
|
if($days >= 1)
|
2004-08-13 11:57:20 +00:00
|
|
|
$note = wfMsg( "rcnote", $wgLang->formatNum( $numRows ), $wgLang->formatNum( $days ) );
|
2003-08-08 05:13:09 +00:00
|
|
|
elseif($days > 0)
|
2004-08-13 11:57:20 +00:00
|
|
|
$note = wfMsg( "wlnote", $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) );
|
2003-08-08 05:13:09 +00:00
|
|
|
else
|
|
|
|
|
$note = "";
|
2004-04-03 11:31:05 +00:00
|
|
|
$wgOut->addHTML( "\n<hr />\n{$note}\n<br />" );
|
2004-08-13 11:57:20 +00:00
|
|
|
$note = wlCutoffLinks( $days );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->addHTML( "{$note}\n" );
|
|
|
|
|
|
2004-08-13 11:57:20 +00:00
|
|
|
if ( $numRows == 0 ) {
|
2003-08-07 11:54:16 +00:00
|
|
|
$wgOut->addHTML( "<p><i>" . wfMsg( "watchnochange" ) . "</i></p>" );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
$s = $sk->beginRecentChangesList();
|
2004-04-09 23:58:52 +00:00
|
|
|
$counter = 1;
|
2004-07-18 08:48:43 +00:00
|
|
|
while ( $obj = $dbr->fetchObject( $res ) ) {
|
2004-01-17 09:49:43 +00:00
|
|
|
# Make fake RC entry
|
|
|
|
|
$rc = RecentChange::newFromCurRow( $obj );
|
2004-04-09 23:58:52 +00:00
|
|
|
$rc->counter = $counter++;
|
2004-01-17 09:49:43 +00:00
|
|
|
$s .= $sk->recentChangesLine( $rc, true );
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
$s .= $sk->endRecentChangesList();
|
|
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
$dbr->freeResult( $res );
|
2003-04-14 23:10:40 +00:00
|
|
|
$wgOut->addHTML( $s );
|
2004-01-25 02:33:34 +00:00
|
|
|
|
|
|
|
|
if ( $wgUseWatchlistCache ) {
|
|
|
|
|
$wgMemc->set( $memckey, $s, $wgWLCacheTimeout);
|
|
|
|
|
}
|
2004-08-09 10:03:39 +00:00
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-08-07 11:54:16 +00:00
|
|
|
|
|
|
|
|
function wlHoursLink( $h, $page ) {
|
2004-09-24 16:45:31 +00:00
|
|
|
global $wgUser, $wgLang, $wgContLang;
|
2003-08-07 11:54:16 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
$s = $sk->makeKnownLink(
|
2004-09-24 16:45:31 +00:00
|
|
|
$wgContLang->specialPage( $page ),
|
2004-03-06 03:03:14 +00:00
|
|
|
$wgLang->formatNum( $h ),
|
|
|
|
|
"days=" . ($h / 24.0) );
|
2003-08-07 11:54:16 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function wlDaysLink( $d, $page ) {
|
2004-09-24 16:45:31 +00:00
|
|
|
global $wgUser, $wgLang, $wgContLang;
|
2003-08-07 11:54:16 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
$s = $sk->makeKnownLink(
|
2004-09-24 16:45:31 +00:00
|
|
|
$wgContLang->specialPage( $page ),
|
2004-03-06 03:03:14 +00:00
|
|
|
($d ? $wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
|
2003-08-07 11:54:16 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-13 11:57:20 +00:00
|
|
|
function wlCutoffLinks( $days, $page = "Watchlist" )
|
2003-08-07 11:54:16 +00:00
|
|
|
{
|
|
|
|
|
$hours = array( 1, 2, 6, 12 );
|
|
|
|
|
$days = array( 1, 3, 7 );
|
|
|
|
|
$cl = "";
|
|
|
|
|
$i = 0;
|
|
|
|
|
foreach( $hours as $h ) {
|
|
|
|
|
$hours[$i++] = wlHoursLink( $h, $page );
|
|
|
|
|
}
|
|
|
|
|
$i = 0;
|
|
|
|
|
foreach( $days as $d ) {
|
|
|
|
|
$days[$i++] = wlDaysLink( $d, $page );
|
|
|
|
|
}
|
2003-11-19 00:56:59 +00:00
|
|
|
return wfMsg ("wlshowlast",
|
|
|
|
|
implode(" | ", $hours),
|
|
|
|
|
implode(" | ", $days),
|
|
|
|
|
wlDaysLink( 0, $page ) );
|
2003-08-07 11:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
2003-04-14 23:10:40 +00:00
|
|
|
?>
|