Restored method for clearing a watchlist in web UI, and rebuilt code.
authorOcean behind ears <basil@everybody.org>
Fri, 9 May 2014 19:45:22 +0000 (21:45 +0200)
committerBrion Vibber <brion@pobox.com>
Sat, 10 May 2014 13:35:34 +0000 (15:35 +0200)
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
includes/specials/SpecialWatchlist.php
languages/i18n/en.json
languages/i18n/qqq.json

index 0c860a5..f918708 100644 (file)
@@ -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 ) {
index fc39ef5..bae5ab3 100644 (file)
@@ -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' );
                        }
index a38a4ba..c44b2f2 100644 (file)
        "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",
index 9444a33..c53656d 100644 (file)
        "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}}",