cleanup EditWatchlist a bit
authorumherirrender <umherirrender_de.wp@web.de>
Thu, 31 May 2012 15:23:50 +0000 (17:23 +0200)
committerumherirrender <umherirrender_de.wp@web.de>
Thu, 31 May 2012 15:23:50 +0000 (17:23 +0200)
* set fields explict in select statement
* get database connection only, if there is anything to do
* store often used object in local var

Change-Id: I41325ee0fdd935e48e2539668dfa0a46ff04af51

includes/specials/SpecialEditWatchlist.php

index b7f1e61..3d43831 100644 (file)
@@ -241,8 +241,9 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
                $dbr = wfGetDB( DB_MASTER );
                $res = $dbr->select(
                        'watchlist',
-                       '*',
                        array(
+                               'wl_namespace', 'wl_title'
+                       ), array(
                                'wl_user' => $this->getUser()->getId(),
                        ),
                        __METHOD__
@@ -321,16 +322,20 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
         * Attempts to clean up broken items
         */
        private function cleanupWatchlist() {
+               if( !count( $this->badItems ) ) {
+                       return; //nothing to do
+               }
                $dbw = wfGetDB( DB_MASTER );
+               $user = $this->getUser();
                foreach ( $this->badItems as $row ) {
                        list( $title, $namespace, $dbKey ) = $row;
-                       wfDebug( "User {$this->getUser()} has broken watchlist item ns($namespace):$dbKey, "
+                       wfDebug( "User {$user->getName()} has broken watchlist item ns($namespace):$dbKey, "
                                . ( $title ? 'cleaning up' : 'deleting' ) . ".\n"
                        );
 
                        $dbw->delete( 'watchlist',
                                array(
-                                       'wl_user' => $this->getUser()->getId(),
+                                       'wl_user' => $user->getId(),
                                        'wl_namespace' => $namespace,
                                        'wl_title' => $dbKey,
                                ),
@@ -339,7 +344,7 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
 
                        // Can't just do an UPDATE instead of DELETE/INSERT due to unique index
                        if ( $title ) {
-                               $this->getUser()->addWatch( $title );
+                               $user->addWatch( $title );
                        }
                }
        }