Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/277436

Change subject: Use WatchedItemStore in SpecialEditWatchlist
......................................................................

Use WatchedItemStore in SpecialEditWatchlist

This includes the ability to delete all
watchlist items for a user using the jobqueue.

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: T129481
Change-Id: I2f8c8be860a03116535dbd1e6a18ce2e8bc546b4
---
M includes/specials/SpecialEditWatchlist.php
M languages/i18n/en.json
M languages/i18n/qqq.json
3 files changed, 27 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/36/277436/1

diff --git a/includes/specials/SpecialEditWatchlist.php 
b/includes/specials/SpecialEditWatchlist.php
index 1a9d096..1c1d1f5 100644
--- a/includes/specials/SpecialEditWatchlist.php
+++ b/includes/specials/SpecialEditWatchlist.php
@@ -218,17 +218,22 @@
                                $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();
+                       $watchedItemStore = 
WatchedItemStore::getDefaultInstance();
+                       if( $watchedItemStore->clearUserWatchedItems( 
$this->getUser() ) ) {
+                               $this->successMessage = $this->msg( 
'watchlistedit-raw-done' )->parse();
+                               $this->successMessage .= ' ' . $this->msg( 
'watchlistedit-raw-removed' )
+                                               ->numParams( count( $current ) 
)->parse();
+                               $this->getUser()->invalidateCache();
+                       } else {
+                               
$watchedItemStore->clearUserWatchedItemsUsingJobQueue( $this->getUser() );
+                               $this->successMessage = $this->msg( 
'watchlistedit-clear-jobqueue' )->parse();
+                       }
+
                        $this->showTitles( $current, $this->successMessage );
                }
 
@@ -237,11 +242,19 @@
 
        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();
+
+               $watchedItemStore = WatchedItemStore::getDefaultInstance();
+
+               if( $watchedItemStore->clearUserWatchedItems( $this->getUser() 
) ) {
+                       $this->successMessage = $this->msg( 
'watchlistedit-clear-done' )->parse();
+                       $this->successMessage .= ' ' . $this->msg( 
'watchlistedit-clear-removed' )
+                                       ->numParams( count( $current ) 
)->parse();
+                       $this->getUser()->invalidateCache();
+               } else {
+                       $watchedItemStore->clearUserWatchedItemsUsingJobQueue( 
$this->getUser() );
+                       $this->successMessage = $this->msg( 
'watchlistedit-clear-jobqueue' )->parse();
+               }
+
                $this->showTitles( $current, $this->successMessage );
 
                return true;
@@ -435,18 +448,6 @@
                                $user->addWatch( $title );
                        }
                }
-       }
-
-       /**
-        * Remove all titles from a user's watchlist
-        */
-       private function clearWatchlist() {
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->delete(
-                       'watchlist',
-                       [ 'wl_user' => $this->getUser()->getId() ],
-                       __METHOD__
-               );
        }
 
        /**
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index fea9fbd..a0627d7 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -3444,6 +3444,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 93a3e79..f60171a 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -3620,6 +3620,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}}",

-- 
To view, visit https://gerrit.wikimedia.org/r/277436
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f8c8be860a03116535dbd1e6a18ce2e8bc546b4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to