From 6b0f075d400994bb795144ceaec45e13924317ff Mon Sep 17 00:00:00 2001 From: Ocean behind ears Date: Fri, 9 May 2014 21:45:22 +0200 Subject: [PATCH] Restored method for clearing a watchlist in web UI, and rebuilt code. People have been asking about this, as raw can cause problems for those with massive lists (upwards of 1 million). Bug: 13250 Change-Id: I17dde71858fa65532fbe5d9c2ee2a65a39b2aa87 --- includes/specials/SpecialEditWatchlist.php | 45 ++++++++++++++++++++++ includes/specials/SpecialWatchlist.php | 2 + languages/i18n/en.json | 21 +++++++--- languages/i18n/qqq.json | 9 +++++ 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index 0c860a5b9d..f918708d81 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -93,6 +93,14 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) ); } break; + case self::EDIT_CLEAR: + $out->setPageTitle( $this->msg( 'watchlistedit-clear-title' ) ); + $form = $this->getClearForm(); + if ( $form->show() ) { + $out->addHTML( $this->successMessage ); + $out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) ); + } + break; case self::EDIT_NORMAL: default: @@ -191,6 +199,18 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { return true; } + public function submitClear( $data ) { + $current = $this->getWatchlist(); + $this->clearWatchlist(); + $this->getUser()->invalidateCache(); + $this->successMessage = $this->msg( 'watchlistedit-clear-done' )->parse(); + $this->successMessage .= ' ' . $this->msg( 'watchlistedit-clear-removed' ) + ->numParams( count( $current ) )->parse(); + $this->showTitles( $current, $this->successMessage ); + + return true; +} + /** * Print out a list of linked titles * @@ -204,6 +224,10 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $talk = $this->msg( 'talkpagelinktext' )->escaped(); // Do a batch existence check $batch = new LinkBatch(); + if (count($titles) >= 100) { + $output = wfMessage( 'watchlistedit-too-many' )->parse(); + return; + } foreach ( $titles as $title ) { if ( !$title instanceof Title ) { $title = Title::newFromText( $title ); @@ -611,6 +635,25 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { return $form; } + /** + * Get a form for clearing the watchlist + * + * @return HTMLForm + */ + protected function getClearForm() { + $context = new DerivativeContext( $this->getContext() ); + $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage + $form = new HTMLForm( array(), $context ); + $form->setSubmitTextMsg( 'watchlistedit-clear-submit' ); + # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit' + $form->setSubmitTooltip( 'watchlistedit-clear-submit' ); + $form->setWrapperLegendMsg( 'watchlistedit-clear-legend' ); + $form->addHeaderText( $this->msg( 'watchlistedit-clear-explain' )->parse() ); + $form->setSubmitCallback( array( $this, 'submitClear' ) ); + + return $form; + } + /** * Determine whether we are editing the watchlist, and if so, what * kind of editing operation @@ -625,6 +668,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { switch ( $mode ) { case 'clear': case self::EDIT_CLEAR: + return self::EDIT_CLEAR; case 'raw': case self::EDIT_RAW: return self::EDIT_RAW; @@ -651,6 +695,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { 'view' => array( 'Watchlist', false ), 'edit' => array( 'EditWatchlist', false ), 'raw' => array( 'EditWatchlist', 'raw' ), + 'clear' => array( 'EditWatchlist', 'clear' ), ); foreach ( $modes as $mode => $arr ) { diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index fc39ef538b..bae5ab30b1 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -50,6 +50,8 @@ class SpecialWatchlist extends ChangesListSpecialPage { if ( $mode !== false ) { if ( $mode === SpecialEditWatchlist::EDIT_RAW ) { $title = SpecialPage::getTitleFor( 'EditWatchlist', 'raw' ); + } elseif ( $mode === SpecialEditWatchlist::EDIT_CLEAR ) { + $title = SpecialPage::getTitleFor( 'EditWatchlist', 'clear' ); } else { $title = SpecialPage::getTitleFor( 'EditWatchlist' ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index a38a4ba052..c44b2f29ef 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3151,13 +3151,22 @@ "watchlistedit-normal-submit": "Remove titles", "watchlistedit-normal-done": "{{PLURAL:$1|1 title was|$1 titles were}} removed from your watchlist:", "watchlistedit-raw-title": "Edit raw watchlist", - "watchlistedit-raw-legend": "Edit raw watchlist", + "watchlistedit-raw-legend": "Edit raw watchlist", "watchlistedit-raw-explain": "Titles on your watchlist are shown below, and can be edited by adding to and removing from the list;\none title per line.\nWhen finished, click \"{{int:Watchlistedit-raw-submit}}\".\nYou can also [[Special:EditWatchlist|use the standard editor]].", - "watchlistedit-raw-titles": "Titles:", - "watchlistedit-raw-submit": "Update watchlist", - "watchlistedit-raw-done": "Your watchlist has been updated.", - "watchlistedit-raw-added": "{{PLURAL:$1|1 title was|$1 titles were}} added:", - "watchlistedit-raw-removed": "{{PLURAL:$1|1 title was|$1 titles were}} removed:", + "watchlistedit-raw-titles": "Titles:", + "watchlistedit-raw-submit": "Update watchlist", + "watchlistedit-raw-done": "Your watchlist has been updated.", + "watchlistedit-raw-added": "{{PLURAL:$1|1 title was|$1 titles were}} added:", + "watchlistedit-raw-removed": "{{PLURAL:$1|1 title was|$1 titles were}} removed:", + "watchlistedit-clear-title": "Cleared watchlist", + "watchlistedit-clear-legend": "Clear watchlist", + "watchlistedit-clear-explain": "All of the titles will be removed from your watchlist", + "watchlistedit-clear-titles": "Titles:", + "watchlistedit-clear-submit": "Clear the watchlist (This is permanent!)", + "watchlistedit-clear-done": "Your watchlist has been cleared.", + "watchlistedit-clear-removed": "{{PLURAL:$1|1 title was|$1 titles were}} removed:", + "watchlistedit-too-many": "There are too many pages to display here.", + "watchlisttools-clear": "Clear the watchlist", "watchlisttools-view": "View relevant changes", "watchlisttools-edit": "View and edit watchlist", "watchlisttools-raw": "Edit raw watchlist", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 9444a33f76..c53656d59e 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3320,6 +3320,15 @@ "watchlistedit-raw-done": "A message which appears after the raw watchlist has been updated using [[Special:Watchlist/raw]].", "watchlistedit-raw-added": "Message on [[Special:EditWatchlist/raw]].\n\nThe message appears after at least 1 message is added to the raw watchlist.\n\nFollowed by list of page titles which are added.\n\nParameters:\n* $1 - number of page titles which are added\nSee also:\n* {{msg-mw|Watchlistedit-normal-done}}\n* {{msg-mw|Watchlistedit-raw-removed}}", "watchlistedit-raw-removed": "Message on [[Special:EditWatchlist/raw]].\n\nThe message appears after at least 1 message is deleted from the raw watchlist.\n\nFollowed by list of page titles which are removed.\n\nParameters:\n* $1 - number of page titles which are removed\nSee also:\n* {{msg-mw|Watchlistedit-normal-done}}\n* {{msg-mw|Watchlistedit-raw-added}}", + "watchlistedit-clear-title": "Title of [[Special:Watchlist/clear|Special page]].\n\n{{Identical|Clear watchlist}}", + "watchlistedit-clear-legend": "Heading of dialogue box on [[Special:Watchlist/clear]].\n\n{{Identical|Edit clear watchlist}}", + "watchlistedit-clear-explain": "All of the titles will be removed from your watchlist", + "watchlistedit-clear-titles": "Text above edit box containing items being watched on [[Special:Watchlist/clear]].\n{{Identical|Title}}", + "watchlistedit-clear-submit": "Text of submit button on [[Special:Watchlist/clear]].\n\nSee also:\n* {{msg-mw|Watchlistedit-clear-submit}}\n* {{msg-mw|Tooltip-watchlistedit-clear-submit}}", + "watchlistedit-clear-done": "A message which appears after the watchlist has been cleared using [[Special:Watchlist/clear]].", + "watchlistedit-clear-removed": "Message on [[Special:EditWatchlist/clear]].\n\nThe message appears once the watchlist has been cleared.", + "watchlistedit-too-many": "Message on [[Special:EditWatchlist]] that is used when there are too many titles to display.", + "watchlisttools-clear": "[[Special:Watchlist]]: Navigation link under the title.\n\nSee also:\n* {{msg-mw|watchlisttools-clear}}\n* {{msg-mw|watchlisttools-clear}}", "watchlisttools-view": "[[Special:Watchlist]]: Navigation link under the title.\n\nSee also:\n* {{msg-mw|watchlisttools-edit}}\n* {{msg-mw|watchlisttools-raw}}", "watchlisttools-edit": "[[Special:Watchlist]]: Navigation link under the title.\n\nSee also:\n* {{msg-mw|Watchlisttools-view}}\n* {{msg-mw|Watchlisttools-raw}}", "watchlisttools-raw": "[[Special:Watchlist]]: Navigation link under the title.\n\nSee also:\n* {{msg-mw|watchlisttools-view}}\n* {{msg-mw|watchlisttools-edit}}\n{{Identical|Edit raw watchlist}}", -- 2.20.1