X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialWatchlist.php;h=e02250f5667c48132604ec759662ba03dc49c2b0;hb=dfaa474400f1739914a26a4dfdd0fe3d667abe44;hp=f534905e565558db7c6664ec2611f5181b117a41;hpb=86fa8a9fd3a43eb52ee723307f60d3b20c4161f5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index f534905e56..e02250f566 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -9,42 +9,67 @@ * */ require_once( 'SpecialRecentchanges.php' ); -require_once( 'WatchedItem.php' ); /** - * constructor + * Constructor + * @todo Document $par parameter. + * @param $par String: FIXME */ function wfSpecialWatchlist( $par ) { - global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgRequest, $wgContLang; + global $wgUser, $wgOut, $wgLang, $wgMemc, $wgRequest, $wgContLang; global $wgUseWatchlistCache, $wgWLCacheTimeout, $wgDBname; global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker; - global $wgEnotifWatchlist, $wgFilterRobotsWL; + global $wgEnotifWatchlist; $fname = 'wfSpecialWatchlist'; - $wgOut->setPagetitle( wfMsg( 'watchlist' ) ); - $sub = htmlspecialchars( wfMsg( 'watchlistsub', $wgUser->getName() ) ); - $wgOut->setSubtitle( $sub ); - $wgOut->setRobotpolicy( 'noindex,nofollow' ); - + $skin =& $wgUser->getSkin(); $specialTitle = Title::makeTitle( NS_SPECIAL, 'Watchlist' ); + $wgOut->setRobotPolicy( 'noindex,nofollow' ); + # Anons don't get a watchlist if( $wgUser->isAnon() ) { - $wgOut->addWikiText( wfMsg( 'nowatchlist' ) ); + $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); + $llink = $skin->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogin' ), wfMsgHtml( 'loginreqlink' ), 'returnto=' . $specialTitle->getPrefixedUrl() ); + $wgOut->addHtml( wfMsgWikiHtml( 'watchlistanontext', $llink ) ); + return; + } else { + $wgOut->setPageTitle( wfMsg( 'watchlist' ) ); + $wgOut->setSubtitle( wfMsgWikiHtml( 'watchlistfor', htmlspecialchars( $wgUser->getName() ) ) ); + } + + if( wlHandleClear( $wgOut, $wgRequest, $par ) ) { return; } $defaults = array( - /* float */ 'days' => 3.0, /* or 0.5, watch further below */ - /* bool */ 'hideOwn' => false, - /* bool */ 'hideBots' => false, + /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */ + /* bool */ 'hideOwn' => (int)$wgUser->getBoolOption( 'watchlisthideown' ), + /* bool */ 'hideBots' => (int)$wgUser->getBoolOption( 'watchlisthidebots' ), + /* ? */ 'namespace' => 'all', ); extract($defaults); + # Extract variables from the request, falling back to user preferences or + # other default values if these don't exist + $prefs['days' ] = floatval( $wgUser->getOption( 'watchlistdays' ) ); + $prefs['hideown' ] = $wgUser->getBoolOption( 'watchlisthideown' ); + $prefs['hidebots'] = $wgUser->getBoolOption( 'watchlisthidebots' ); + # Get query variables - $days = $wgRequest->getVal( 'days' ); - $hideOwn = $wgRequest->getBool( 'hideOwn' ); - $hideBots = $wgRequest->getBool( 'hideBots' ); + $days = $wgRequest->getVal( 'days', $prefs['days'] ); + $hideOwn = $wgRequest->getBool( 'hideOwn', $prefs['hideown'] ); + $hideBots = $wgRequest->getBool( 'hideBots', $prefs['hidebots'] ); + + # Get namespace value, if supplied, and prepare a WHERE fragment + $nameSpace = $wgRequest->getIntOrNull( 'namespace' ); + if( !is_null( $nameSpace ) ) { + $nameSpace = intval( $nameSpace ); + $nameSpaceClause = " AND rc_namespace = $nameSpace"; + } else { + $nameSpace = ''; + $nameSpaceClause = ''; + } # Watchlist editing $action = $wgRequest->getVal( 'action' ); @@ -67,13 +92,14 @@ function wfSpecialWatchlist( $par ) { if( $wl->removeWatch() === false ) { $wgOut->addHTML( "
\n" . wfMsg( 'couldntremove', htmlspecialchars($one) ) ); } else { + wfRunHooks('UnwatchArticle', array(&$wgUser, new Article($t))); $wgOut->addHTML( ' (' . htmlspecialchars($one) . ')' ); } } else { $wgOut->addHTML( "
\n" . wfMsg( 'iteminvalidname', htmlspecialchars($one) ) ); } } - $wgOut->addHTML( "done.

\n" ); + $wgOut->addHTML( "
\n" . wfMsg( 'wldone' ) . "

\n" ); } if ( $wgUseWatchlistCache ) { @@ -89,11 +115,11 @@ function wfSpecialWatchlist( $par ) { $dbr =& wfGetDB( DB_SLAVE ); extract( $dbr->tableNames( 'page', 'revision', 'watchlist', 'recentchanges' ) ); - $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid"; - $res = $dbr->query( $sql, $fname ); - $s = $dbr->fetchObject( $res ); - - # Patch *** A1 *** (see A2 below) + $sql = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_user=$uid"; + $res = $dbr->query( $sql, $fname ); + $s = $dbr->fetchObject( $res ); + +# Patch *** A1 *** (see A2 below) # adjust for page X, talk:page X, which are both stored separately, but treated together $nitems = floor($s->n / 2); # $nitems = $s->n; @@ -119,8 +145,9 @@ function wfSpecialWatchlist( $par ) { $nondefaults = array(); wfAppendToArrayIfNotDefault( 'days', $days, $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hideOwn', $hideOwn, $defaults, $nondefaults); - wfAppendToArrayIfNotDefault( 'hideBots', $hideBots, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideOwn', (int)$hideOwn, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'hideBots', (int)$hideBots, $defaults, $nondefaults); + wfAppendToArrayIfNotDefault( 'namespace', $nameSpace, $defaults, $nondefaults ); if ( $days <= 0 ) { $docutoff = ''; @@ -130,13 +157,13 @@ function wfSpecialWatchlist( $par ) { $docutoff = "AND rev_timestamp > '" . ( $cutoff = $dbr->timestamp( time() - intval( $days * 86400 ) ) ) . "'"; - /* - $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page"; - $res = $dbr->query( $sql, $fname ); - $s = $dbr->fetchObject( $res ); - $npages = $s->n; - */ - $npages = 40000 * $days; + /* + $sql = "SELECT COUNT(*) AS n FROM $page, $revision WHERE rev_timestamp>'$cutoff' AND page_id=rev_page"; + $res = $dbr->query( $sql, $fname ); + $s = $dbr->fetchObject( $res ); + $npages = $s->n; + */ + $npages = 40000 * $days; } @@ -152,14 +179,23 @@ function wfSpecialWatchlist( $par ) { # Patch A2 # The following was proposed by KTurner 07.11.2004 to T.Gries # $sql = "SELECT distinct (wl_namespace & ~1),wl_title FROM $watchlist WHERE wl_user=$uid"; - $sql = "SELECT wl_namespace,wl_title FROM $watchlist WHERE wl_user=$uid"; + $sql = "SELECT wl_namespace, wl_title, page_is_redirect FROM $watchlist LEFT JOIN $page ON wl_namespace = page_namespace AND wl_title = page_title WHERE wl_user=$uid"; $res = $dbr->query( $sql, $fname ); + + # Batch existence check + $linkBatch = new LinkBatch(); + while( $row = $dbr->fetchObject( $res ) ) + $linkBatch->addObj( Title::makeTitleSafe( $row->wl_namespace, $row->wl_title ) ); + $linkBatch->execute(); + if( $dbr->numRows( $res ) > 0 ) + $dbr->dataSeek( $res, 0 ); # Let's do the time warp again! + $sk = $wgUser->getSkin(); $list = array(); while( $s = $dbr->fetchObject( $res ) ) { - $list[$s->wl_namespace][] = $s->wl_title; + $list[$s->wl_namespace][$s->wl_title] = $s->page_is_redirect; } // TODO: Display a TOC @@ -169,28 +205,38 @@ function wfSpecialWatchlist( $par ) { if ($ns != NS_MAIN) $wgOut->addHTML( '

' . $wgContLang->getFormattedNsText( $ns ) . '

' ); $wgOut->addHTML( '' ); } $wgOut->addHTML( - "\n" . - "\n" + wfSubmitButton( wfMsg('removechecked'), array('name' => 'remove') ) . + "\n\n" ); return; @@ -204,14 +250,10 @@ function wfSpecialWatchlist( $par ) { # Up estimate of watched items by 15% to compensate for talk pages... + # Toggles $andHideOwn = $hideOwn ? "AND (rc_user <> $uid)" : ''; - if( $wgFilterRobotsWL ) { - $andHideBotsOptional = $hideBots ? "AND (rc_bot = 0)" : ''; - } else { - $andHideBotsOptional = "AND rc_this_oldid=page_latest"; - } - - + $andHideBots = $hideBots ? "AND (rc_bot = 0)" : ''; + # Show watchlist header $header = ''; if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { @@ -221,12 +263,21 @@ function wfSpecialWatchlist( $par ) { $header .= wfMsg( 'wlheader-showupdated' ) . "\n"; } + # Toggle watchlist content (all recent edits or just the latest) + if( $wgUser->getOption( 'extendwatchlist' )) { + $andLatest=''; + $limitWatchlist = 'LIMIT ' . intval( $wgUser->getOption( 'wllimit' ) ); + } else { + $andLatest= 'AND rc_this_oldid=page_latest'; + $limitWatchlist = ''; + } + # TODO: Consider removing the third parameter - $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ), + $header .= wfMsg( 'watchdetails', $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), '', $specialTitle->getFullUrl( 'edit=yes' ) ); $wgOut->addWikiText( $header ); - + if ( $wgEnotifWatchlist && $wgShowUpdatedMarker ) { $wgOut->addHTML( '
query( $sql, $fname ); $numRows = $dbr->numRows( $res ); /* Start bottom header */ - $wgOut->addHTML( "
\n

" ); + $wgOut->addHTML( "


\n" ); - if($days >= 1) + if($days >= 1) { $wgOut->addWikiText( wfMsg( 'rcnote', $wgLang->formatNum( $numRows ), - $wgLang->formatNum( $days ) ) . '
' , false ); - elseif($days > 0) + $wgLang->formatNum( $days ), $wgLang->timeAndDate( wfTimestampNow(), true ) ) . '
' , false ); + } elseif($days > 0) { $wgOut->addWikiText( wfMsg( 'wlnote', $wgLang->formatNum( $numRows ), $wgLang->formatNum( round($days*24) ) ) . '
' , false ); + } $wgOut->addHTML( "\n" . wlCutoffLinks( $days, 'Watchlist', $nondefaults ) . "
\n" ); + + # Spit out some control panel links + $thisTitle = Title::makeTitle( NS_SPECIAL, 'Watchlist' ); + $skin = $wgUser->getSkin(); + $linkElements = array( 'hideOwn' => 'wlhideshowown', 'hideBots' => 'wlhideshowbots' ); - $sk = $wgUser->getSkin(); - $s = $sk->makeKnownLink( - $wgContLang->specialPage( 'Watchlist' ), - (0 == $hideOwn) ? wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ), - wfArrayToCGI( array('hideOwn' => 1-$hideOwn ), $nondefaults ) ); - $wgOut->addHTML( wfMsgHtml( "wlhideshowown", $s ) ); - - if( $wgFilterRobotsWL ) { - $s = $sk->makeKnownLink( - $wgContLang->specialPage( 'Watchlist' ), - (0 == $hideBots) ? wfMsgHtml( 'wlhide' ) : wfMsgHtml( 'wlshow' ), - wfArrayToCGI( array('hideBots' => 1-$hideBots ), $nondefaults ) ); - $wgOut->addHTML( wfMsgHtml( "wlhideshowbots", " $s" ) ); - } - + # Problems encountered using the fancier method + $label = $hideBots ? wfMsgHtml( 'show' ) : wfMsgHtml( 'hide' ); + $linkBits = wfArrayToCGI( array( 'hideBots' => 1 - (int)$hideBots ), $nondefaults ); + $link = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ); + $links[] = wfMsgHtml( 'wlhideshowbots', $link ); + + $label = $hideOwn ? wfMsgHtml( 'show' ) : wfMsgHtml( 'hide' ); + $linkBits = wfArrayToCGI( array( 'hideOwn' => 1 - (int)$hideOwn ), $nondefaults ); + $link = $skin->makeKnownLinkObj( $thisTitle, $label, $linkBits ); + $links[] = wfMsgHtml( 'wlhideshowown', $link ); + + $wgOut->addHTML( implode( ' | ', $links ) ); + + # Form for namespace filtering + $wgOut->addHTML( "\n" . + wfOpenElement( 'form', array( + 'method' => 'post', + 'action' => $thisTitle->getLocalURL(), + ) ) . + wfMsgExt( 'namespace', array( 'parseinline') ) . + HTMLnamespaceselector( $nameSpace, '' ) . "\n" . + ( $hideOwn ? wfHidden('hideown', 1)."\n" : '' ) . + ( $hideBots ? wfHidden('hidebots', 1)."\n" : '' ) . + wfHidden( 'days', $days ) . "\n" . + wfSubmitButton( wfMsgExt( 'allpagessubmit', array( 'escape') ) ) . "\n" . + wfCloseElement( 'form' ) . "\n" + ); + if ( $numRows == 0 ) { $wgOut->addWikitext( "
" . wfMsg( 'watchnochange' ), false ); - $wgOut->addHTML( "

\n" ); return; } - $wgOut->addHTML( "

\n" ); /* End bottom header */ - $sk = $wgUser->getSkin(); - $list =& new ChangesList( $sk ); + $list = ChangesList::newFromUser( $wgUser ); + $s = $list->beginRecentChangesList(); $counter = 1; while ( $obj = $dbr->fetchObject( $res ) ) { @@ -351,6 +422,9 @@ function wlDaysLink( $d, $page, $options = array() ) { return $s; } +/** + * Returns html + */ function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) { $hours = array( 1, 2, 6, 12 ); $days = array( 1, 3, 7 ); @@ -363,10 +437,79 @@ function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) { foreach( $days as $d ) { $days[$i++] = wlDaysLink( $d, $page, $options ); } - return wfMsg ('wlshowlast', + return wfMsgExt('wlshowlast', + array('parseinline', 'replaceafter'), implode(' | ', $hours), implode(' | ', $days), wlDaysLink( 0, $page, $options ) ); } +/** + * Count the number of items on a user's watchlist + * + * @param $talk Include talk pages + * @return integer + */ +function wlCountItems( &$user, $talk = true ) { + $dbr =& wfGetDB( DB_SLAVE ); + + # Fetch the raw count + $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', array( 'wl_user' => $user->mId ), 'wlCountItems' ); + $row = $dbr->fetchObject( $res ); + $count = $row->count; + $dbr->freeResult( $res ); + + # Halve to remove talk pages if needed + if( !$talk ) + $count = floor( $count / 2 ); + + return( $count ); +} + +/** + * Allow the user to clear their watchlist + * + * @param $out Output object + * @param $request Request object + * @param $par Parameters passed to the watchlist page + * @return bool True if it's been taken care of; false indicates the watchlist + * code needs to do something further + */ +function wlHandleClear( &$out, &$request, $par ) { + # Check this function has something to do + if( $request->getText( 'action' ) == 'clear' || $par == 'clear' ) { + global $wgUser; + $out->setPageTitle( wfMsgHtml( 'clearwatchlist' ) ); + $count = wlCountItems( $wgUser ); + if( $count > 0 ) { + # See if we're clearing or confirming + if( $request->wasPosted() && $wgUser->matchEditToken( $request->getText( 'token' ), 'clearwatchlist' ) ) { + # Clearing, so do it and report the result + $dbw =& wfGetDB( DB_MASTER ); + $dbw->delete( 'watchlist', array( 'wl_user' => $wgUser->mId ), 'wlHandleClear' ); + $out->addWikiText( wfMsg( 'watchlistcleardone', $count ) ); + $out->returnToMain(); + } else { + # Confirming, so show a form + $wlTitle = Title::makeTitle( NS_SPECIAL, 'Watchlist' ); + $out->addHTML( wfElement( 'form', array( 'method' => 'post', 'action' => $wlTitle->getLocalUrl( 'action=clear' ) ), NULL ) ); + $out->addWikiText( wfMsg( 'watchlistcount', $count ) ); + $out->addWikiText( wfMsg( 'watchlistcleartext' ) ); + $out->addHTML( + wfHidden( 'token', $wgUser->editToken( 'clearwatchlist' ) ) . + wfElement( 'input', array( 'type' => 'submit', 'name' => 'submit', 'value' => wfMsgHtml( 'watchlistclearbutton' ) ), '' ) . + wfCloseElement( 'form' ) + ); + } + return( true ); + } else { + # Nothing on the watchlist; nothing to do here + $out->addWikiText( wfMsg( 'nowatchlist' ) ); + $out->returnToMain(); + return( true ); + } + } else { + return( false ); + } +} ?>