Merge "Use {{int:}} on MediaWiki:Blockedtext and MediaWiki:Autoblockedtext"
[lhc/web/wiklou.git] / includes / specials / SpecialEditWatchlist.php
index e3c5d8c..5e04d8d 100644 (file)
@@ -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
         *
@@ -667,7 +657,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
         * @return HTMLForm
         */
        protected function getRawForm() {
-               $titles = implode( $this->getWatchlist(), "\n" );
+               $titles = implode( "\n", $this->getWatchlist() );
                $fields = [
                        'Titles' => [
                                'type' => 'textarea',
@@ -677,7 +667,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                ];
                $context = new DerivativeContext( $this->getContext() );
                $context->setTitle( $this->getPageTitle( 'raw' ) ); // Reset subpage
-               $form = new HTMLForm( $fields, $context );
+               $form = new OOUIHTMLForm( $fields, $context );
                $form->setSubmitTextMsg( 'watchlistedit-raw-submit' );
                # Used message keys: 'accesskey-watchlistedit-raw-submit', 'tooltip-watchlistedit-raw-submit'
                $form->setSubmitTooltip( 'watchlistedit-raw-submit' );
@@ -696,7 +686,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
        protected function getClearForm() {
                $context = new DerivativeContext( $this->getContext() );
                $context->setTitle( $this->getPageTitle( 'clear' ) ); // Reset subpage
-               $form = new HTMLForm( [], $context );
+               $form = new OOUIHTMLForm( [], $context );
                $form->setSubmitTextMsg( 'watchlistedit-clear-submit' );
                # Used message keys: 'accesskey-watchlistedit-clear-submit', 'tooltip-watchlistedit-clear-submit'
                $form->setSubmitTooltip( 'watchlistedit-clear-submit' );