From 38389e6a2e21fb43c0a5d5db21fe81a7c4dd579c Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 17 Apr 2006 18:23:37 +0000 Subject: [PATCH] Add watchlist clear function to allow quick purging of all items --- RELEASE-NOTES | 2 +- includes/SpecialWatchlist.php | 71 +++++++++++++++++++++++++++++++++++ languages/Messages.php | 8 +++- 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 75c3910b13..7bc683bcee 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -85,7 +85,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 5572) Edit toolbar enabled in compatible versions of Konqueror (3.5+) * (bug 5235) Edit toolbar tooltips no longer show JavaScript junk in Opera * Edit toolbar now works in pure XHTML mode (application/xhtml+xml) - +* Add watchlist clear function to allow quick purging of all items == Compatibility == diff --git a/includes/SpecialWatchlist.php b/includes/SpecialWatchlist.php index 816b82cd5a..c9405de099 100644 --- a/includes/SpecialWatchlist.php +++ b/includes/SpecialWatchlist.php @@ -33,6 +33,10 @@ function wfSpecialWatchlist( $par ) { return; } + if( wlHandleClear( $wgOut, $wgRequest, $par ) ) { + return; + } + $defaults = array( /* float */ 'days' => 3.0, /* or 0.5, watch further below */ /* bool */ 'hideOwn' => false, @@ -415,4 +419,71 @@ function wlCutoffLinks( $days, $page = 'Watchlist', $options = array() ) { 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( wfElement( 'input', array( 'type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken( 'clearwatchlist' ) ), '' ) ); + $out->addHTML( wfElement( 'input', array( 'type' => 'submit', 'name' => 'submit', 'value' => wfMsgHtml( 'watchlistclearbutton' ) ), '' ) ); + $out->addHTML( wfCloseElement( 'form' ) ); + } + return( true ); + } else { + # Nothing on the watchlist; nothing to do here + $out->addWikiText( wfMsg( 'nowatchlist' ) ); + $out->returnToMain(); + return( true ); + } + } else { + return( false ); + } +} + ?> diff --git a/languages/Messages.php b/languages/Messages.php index 2e8982ed8f..a9d899fdc5 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -1053,6 +1053,11 @@ or has chosen not to receive e-mail from other users.', 'watchlist' => 'My watchlist', 'watchlistsub' => "(for user \"$1\")", 'nowatchlist' => 'You have no items on your watchlist.', +'watchlistcount' => "'''You have $1 items on your watchlist, including talk pages.'''", +'clearwatchlist' => 'Clear watchlist', +'watchlistcleartext' => 'Are you sure you wish to remove them?', +'watchlistclearbutton' => 'Clear watchlist', +'watchlistcleardone' => 'Your watchlist has been cleared. $1 items were removed.', 'watchnologin' => 'Not logged in', 'watchnologintext' => 'You must be [[Special:Userlogin|logged in]] to modify your watchlist.', 'addedwatch' => 'Added to watchlist', @@ -1071,7 +1076,8 @@ make it easier to pick out. 'notanarticle' => 'Not a content page', 'watchnochange' => 'None of your watched items was edited in the time period displayed.', 'watchdetails' => '* $1 pages watched not counting talk pages -* [[Special:Watchlist/edit|Show and edit complete watchlist]]', +* [[Special:Watchlist/edit|Show and edit complete watchlist]] +* [[Special:Watchlist/clear|Remove all pages]]', 'wlheader-enotif' => "* E-mail notification is enabled.", 'wlheader-showupdated' => "* Pages which have been changed since you last visited them are shown in '''bold'''", 'watchmethod-recent'=> 'checking recent edits for watched pages', -- 2.20.1