From 6aa89efb5a8a743840f106f0ac9782192b0cd6cd Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 15 Mar 2016 00:36:36 +0000 Subject: [PATCH] Use WatchedItemStore clearing in SpecialEditWatchlist This switches to using the WatchedItemStore that has the ability to delete all watchlist items for a user using the jobqueue. The job was introduced in: Icea573a10078ea3f09dc2e4e9fdc737bf639935d Functionality added to the store in: I2f8c8be860a03116535dbd1e6a18ce2e8bc546b4 This patch is the first code calling the new functionality. If the number of watched items for the user is less than the number that can be completed in a single batch then they will still be deleted during the interactive session. Bug: T68212 Bug: T129481 Change-Id: I2f8c8be860a03116535dbd1e6a18ce2e8bc546b4 --- includes/specials/SpecialEditWatchlist.php | 50 +++++++++------------- languages/i18n/en.json | 1 + languages/i18n/qqq.json | 1 + 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/includes/specials/SpecialEditWatchlist.php b/includes/specials/SpecialEditWatchlist.php index e3c5d8c4a6..0a38ad160a 100644 --- a/includes/specials/SpecialEditWatchlist.php +++ b/includes/specials/SpecialEditWatchlist.php @@ -29,7 +29,6 @@ use MediaWiki\Linker\LinkRenderer; use MediaWiki\Linker\LinkTarget; use MediaWiki\MediaWikiServices; -use Wikimedia\Rdbms\DBReadOnlyError; /** * Provides the UI through which users can perform editing @@ -244,17 +243,12 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { $this->showTitles( $toUnwatch, $this->successMessage ); } } else { - $this->clearWatchlist(); - $this->getUser()->invalidateCache(); - if ( count( $current ) > 0 ) { - $this->successMessage = $this->msg( 'watchlistedit-raw-done' )->parse(); - } else { + if ( count( $current ) === 0 ) { return false; } - $this->successMessage .= ' ' . $this->msg( 'watchlistedit-raw-removed' ) - ->numParams( count( $current ) )->parse(); + $this->clearUserWatchedItems( $current, 'raw' ); $this->showTitles( $current, $this->successMessage ); } @@ -263,16 +257,28 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { 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->clearUserWatchedItems( $current, 'clear' ); $this->showTitles( $current, $this->successMessage ); - return true; } + /** + * @param array $current + * @param string $messageFor 'raw' or 'clear' + */ + private function clearUserWatchedItems( $current, $messageFor ) { + $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore(); + if ( $watchedItemStore->clearUserWatchedItems( $this->getUser() ) ) { + $this->successMessage = $this->msg( 'watchlistedit-' . $messageFor . '-done' )->parse(); + $this->successMessage .= ' ' . $this->msg( 'watchlistedit-' . $messageFor . '-removed' ) + ->numParams( count( $current ) )->parse(); + $this->getUser()->invalidateCache(); + } else { + $watchedItemStore->clearUserWatchedItemsUsingJobQueue( $this->getUser() ); + $this->successMessage = $this->msg( 'watchlistedit-clear-jobqueue' )->parse(); + } + } + /** * Print out a list of linked titles * @@ -448,22 +454,6 @@ class SpecialEditWatchlist extends UnlistedSpecialPage { } ); } - /** - * Remove all titles from a user's watchlist - */ - private function clearWatchlist() { - if ( $this->getConfig()->get( 'ReadOnlyWatchedItemStore' ) ) { - throw new DBReadOnlyError( null, 'The watchlist is currently readonly.' ); - } - - $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( - 'watchlist', - [ 'wl_user' => $this->getUser()->getId() ], - __METHOD__ - ); - } - /** * Add a list of targets to a user's watchlist * diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 7316448307..9d06c96e67 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3707,6 +3707,7 @@ "watchlistedit-clear-titles": "Titles:", "watchlistedit-clear-submit": "Clear the watchlist (This is permanent!)", "watchlistedit-clear-done": "Your watchlist has been cleared.", + "watchlistedit-clear-jobqueue": "Your watchlist is being cleared. This may take some time!", "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", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index a4f1d64592..f3cbb7baf4 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3902,6 +3902,7 @@ "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{{Identical|Clear watchlist}}", "watchlistedit-clear-done": "A message which appears after the watchlist has been cleared using [[Special:Watchlist/clear]].", + "watchlistedit-clear-jobqueue": "A message which appears after the watchlist has been scheduled to be cleared using [[Special:Watchlist/clear]] and the Job Queue.", "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.\n\nShown instead of list of the pages.", "watchlisttools-clear": "[[Special:Watchlist]]: Navigation link under the title.\n{{Identical|Clear watchlist}}", -- 2.20.1