Followup r64197
authorSam Reed <reedy@users.mediawiki.org>
Sun, 28 Mar 2010 15:08:45 +0000 (15:08 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sun, 28 Mar 2010 15:08:45 +0000 (15:08 +0000)
Return null in getWatchlistValue if no change

Fixup unneccessary watch/unwatch calls

Remove useless unwatch from ApiUpload

includes/api/ApiBase.php
includes/api/ApiDelete.php
includes/api/ApiEditPage.php
includes/api/ApiMove.php
includes/api/ApiProtect.php
includes/api/ApiRollback.php
includes/api/ApiUndelete.php
includes/api/ApiUpload.php

index 1cc1e30..0570421 100644 (file)
@@ -542,14 +542,14 @@ abstract class ApiBase {
                        case 'unwatch':
                                return false;
                        case 'preferences':
-                               if ( $titleObj->exists() ) {
-                                       global $wgUser;
-                                       return $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching();
+                               global $wgUser;
+                               if ( $titleObj->exists() && !$titleObj->userIsWatching() && $wgUser->getOption( 'watchdefault' ) ) {                            
+                                       return true;
                                }
-                               return false;
+                               return null;
                        case 'nochange':
                        default:
-                               return $titleObj->userIsWatching();
+                               return null;
                }
        }
 
index 1b6b394..df16682 100644 (file)
@@ -85,10 +85,18 @@ class ApiDelete extends ApiBase {
                        $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchdeletion' );
 
                        // Deprecated parameters
-                       if ( $params['watch'] || $watch ) {
-                               $articleObj->doWatch();
-                       } elseif ( $params['unwatch'] || !$watch ) {
-                               $articleObj->doUnwatch();
+                       if ( $params['watch'] ) {
+                               $watch = true;
+                       } elseif ( $params['unwatch'] ) {
+                               $watch = false;
+                       }
+                       
+                       if ( $watch !== null ) {
+                               if ( $watch ) {
+                                       $articleObj->doWatch();
+                               } else {
+                                       $articleObj->doUnwatch();
+                               }
                        }
                }
 
index ea3bcd6..77377b0 100644 (file)
@@ -211,7 +211,7 @@ class ApiEditPage extends ApiBase {
                        $watch = false;
                }
 
-               if ( $watch ) {
+               if ( $watch || $titleObj->userIsWatching() ) {
                        $reqArr['wpWatchthis'] = '';
                }
 
index 62609fd..603ef59 100644 (file)
@@ -124,14 +124,22 @@ class ApiMove extends ApiBase {
                
                // Watch pages
                $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchmoves' );
-
+               
                // Deprecated parameters
-               if ( $params['watch'] || $watch ) {
-                       $wgUser->addWatch( $fromTitle );
-                       $wgUser->addWatch( $toTitle );
-               } elseif ( $params['unwatch'] || !$watch ) {
-                       $wgUser->removeWatch( $fromTitle );
-                       $wgUser->removeWatch( $toTitle );
+               if ( $params['watch'] ) {
+                       $watch = true;
+               } elseif ( $params['unwatch'] ) {
+                       $watch = false;
+               }
+
+               if ( $watch !== null ) {
+                       if ( $watch ) {
+                               $wgUser->addWatch( $fromTitle );
+                               $wgUser->addWatch( $toTitle );
+                       } else {
+                               $wgUser->removeWatch( $fromTitle );
+                               $wgUser->removeWatch( $toTitle );
+                       }
                }
                $this->getResult()->addValue( null, $this->getModuleName(), $r );
        }
index 4c0398e..4e7f1fc 100644 (file)
@@ -116,10 +116,16 @@ class ApiProtect extends ApiBase {
                
                $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
                
-               if ( $params['watch'] || $watch ) {
-                       $articleObj->doWatch();
-               } else {
-                       $articleObj->doUnwatch();
+               if ( $params['watch'] ) {
+                       $watch = true;
+               }
+               
+               if ( $watch !== null ) {
+                       if ( $watch ) {
+                               $articleObj->doWatch();
+                       } else {
+                               $articleObj->doUnwatch();
+                       }
                }
 
                if ( $titleObj->exists() ) {
index 263a78a..70dbc56 100644 (file)
@@ -75,10 +75,12 @@ class ApiRollback extends ApiBase {
                
                $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
                
-               if ( $watch ) {
-                       $articleObj->doWatch();
-               } else if ( !$watch ) {
-                       $articleObj->doUnwatch();
+               if ( $watch !== null) {
+                       if ( $watch ) {
+                               $articleObj->doWatch();
+                       } else {
+                               $articleObj->doUnwatch();
+                       }
                }
 
                $info = array(
index 1fed5ca..421744f 100644 (file)
@@ -84,10 +84,12 @@ class ApiUndelete extends ApiBase {
                
                $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
                
-               if ( $params['watch'] || $watch ) {
-                       $wgUser->addWatch( $titleObj );
-               } else {
-                       $wgUser->removeWatch( $titleObj );
+               if ( $watch !== null ) {
+                       if ( $watch ) {
+                               $wgUser->addWatch( $titleObj );
+                       } else {
+                               $wgUser->removeWatch( $titleObj );
+                       }
                }
 
                $info['title'] = $titleObj->getPrefixedText();
index 0206744..0fb17cc 100644 (file)
@@ -239,10 +239,6 @@ class ApiUpload extends ApiBase {
                
                $file = $this->mUpload->getLocalFile();
                
-               if ( !$watch ) {
-                       $wgUser->removeWatch( $file->getTitle() );
-               }
-               
                $result['result'] = 'Success';
                $result['filename'] = $file->getName();
                $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() );
@@ -274,7 +270,6 @@ class ApiUpload extends ApiBase {
                                ApiBase::PARAM_DFLT => 'preferences',
                                ApiBase::PARAM_TYPE => array(
                                        'watch',
-                                       'unwatch',
                                        'preferences',
                                        'nochange'
                                ),