Fix bug 22944 in a much better fashion (using watchlist parameter)
authorSam Reed <reedy@users.mediawiki.org>
Thu, 25 Mar 2010 22:15:08 +0000 (22:15 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Thu, 25 Mar 2010 22:15:08 +0000 (22:15 +0000)
Deprecate old watch/unwatch parameters

Move generic watchlist stuff to ApiBase/getWatchlistValue (maybe needs renaming better?)

Tweak some braces in ApiEditPage

RELEASE-NOTES
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 f3a1ec6..0acf75f 100644 (file)
@@ -60,6 +60,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 == API changes in 1.17 ==
 * (bug 22738) Allow filtering by action type on query=logevent
 * (bug 22764) uselang parameter for action=parse
+* (bug 22944) API: watchlist options are inconsistent
 
 === Languages updated in 1.17 ===
 
index 7fd2dcf..2c3164d 100644 (file)
@@ -532,6 +532,31 @@ abstract class ApiBase {
 
                return $mValidNamespaces;
        }
+       /**
+       * Handle watchlist settings
+       */
+       protected function getWatchlistValue ( $watchlist, $titleObj ) {
+               switch ( $watchlist ) {
+                       case 'watch':
+                               $watch = true;
+                               break;
+                       case 'unwatch':
+                               $watch = false;
+                               break;
+                       case 'preferences':
+                               global $wgUser;
+                       
+                               if ( $titleObj->exists() ) {
+                                       $watch = $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching();
+                               }
+                               break;
+                       case 'nochange':
+                       default:
+                               $watch = $titleObj->userIsWatching();
+               }
+               
+               return $watch;
+       }
 
        /**
         * Using the settings determine the value for the given parameter
index 9689c97..1b6b394 100644 (file)
@@ -81,10 +81,13 @@ class ApiDelete extends ApiBase {
                        if ( count( $retval ) ) {
                                $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them
                        }
+                       
+                       $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchdeletion' );
 
-                       if ( $params['watch'] || $wgUser->getOption( 'watchdeletion' ) ) {
+                       // Deprecated parameters
+                       if ( $params['watch'] || $watch ) {
                                $articleObj->doWatch();
-                       } elseif ( $params['unwatch'] ) {
+                       } elseif ( $params['unwatch'] || !$watch ) {
                                $articleObj->doUnwatch();
                        }
                }
@@ -197,7 +200,19 @@ class ApiDelete extends ApiBase {
                        ),
                        'token' => null,
                        'reason' => null,
-                       'watch' => false,
+                       'watch' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'watchlist' => array(
+                               ApiBase::PARAM_DFLT => 'preferences',
+                               ApiBase::PARAM_TYPE => array(
+                                       'watch',
+                                       'unwatch',
+                                       'preferences',
+                                       'nochange'
+                               ),
+                       ),
                        'unwatch' => false,
                        'oldimage' => null
                );
@@ -210,6 +225,7 @@ class ApiDelete extends ApiBase {
                        'token' => 'A delete token previously retrieved through prop=info',
                        'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.',
                        'watch' => 'Add the page to your watchlist',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
                        'unwatch' => 'Remove the page from your watchlist',
                        'oldimage' => 'The name of the old image to delete as provided by iiprop=archivename'
                );
index 261db6f..ea3bcd6 100644 (file)
@@ -177,15 +177,13 @@ class ApiEditPage extends ApiBase {
                        $reqArr['wpEdittime'] = $articleObj->getTimestamp();
                }
 
-               if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' )
-               {
+               if ( !is_null( $params['starttimestamp'] ) && $params['starttimestamp'] != '' ) {
                        $reqArr['wpStarttime'] = wfTimestamp( TS_MW, $params['starttimestamp'] );
                } else {
                        $reqArr['wpStarttime'] = $reqArr['wpEdittime']; // Fake wpStartime
                }
 
-               if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) )
-               {
+               if ( $params['minor'] || ( !$params['notminor'] && $wgUser->getOption( 'minordefault' ) ) )     {
                        $reqArr['wpMinoredit'] = '';
                }
 
@@ -204,25 +202,8 @@ class ApiEditPage extends ApiBase {
                        $reqArr['wpSection'] = '';
                }
 
-               // Handle watchlist settings
-               switch ( $params['watchlist'] ) {
-                       case 'watch':
-                               $watch = true;
-                               break;
-                       case 'unwatch':
-                               $watch = false;
-                               break;
-                       case 'preferences':
-                               if ( $titleObj->exists() ) {
-                                       $watch = $wgUser->getOption( 'watchdefault' ) || $titleObj->userIsWatching();
-                               } else {
-                                       $watch = $wgUser->getOption( 'watchcreations' );
-                               }
-                               break;
-                       case 'nochange':
-                       default:
-                               $watch = $titleObj->userIsWatching();
-               }
+               $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchcreations' );
+
                // Deprecated parameters
                if ( $params['watch'] ) {
                        $watch = true;
index 3b2fe99..62609fd 100644 (file)
@@ -121,12 +121,15 @@ class ApiMove extends ApiBase {
                                $this->getResult()->setIndexedTagName( $r['subpages-talk'], 'subpage' );
                        }
                }
-
+               
                // Watch pages
-               if ( $params['watch'] || $wgUser->getOption( 'watchmoves' ) ) {
+               $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj ) || $wgUser->getOption( 'watchmoves' );
+
+               // Deprecated parameters
+               if ( $params['watch'] || $watch ) {
                        $wgUser->addWatch( $fromTitle );
                        $wgUser->addWatch( $toTitle );
-               } elseif ( $params['unwatch'] ) {
+               } elseif ( $params['unwatch'] || !$watch ) {
                        $wgUser->removeWatch( $fromTitle );
                        $wgUser->removeWatch( $toTitle );
                }
@@ -175,8 +178,23 @@ class ApiMove extends ApiBase {
                        'movetalk' => false,
                        'movesubpages' => false,
                        'noredirect' => false,
-                       'watch' => false,
-                       'unwatch' => false,
+                       'watch' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'unwatch' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'watchlist' => array(
+                               ApiBase::PARAM_DFLT => 'preferences',
+                               ApiBase::PARAM_TYPE => array(
+                                       'watch',
+                                       'unwatch',
+                                       'preferences',
+                                       'nochange'
+                               ),
+                       ),
                        'ignorewarnings' => false
                );
        }
@@ -193,6 +211,7 @@ class ApiMove extends ApiBase {
                        'noredirect' => 'Don\'t create a redirect',
                        'watch' => 'Add the page and the redirect to your watchlist',
                        'unwatch' => 'Remove the page and the redirect from your watchlist',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
                        'ignorewarnings' => 'Ignore any warnings'
                );
        }
index 3c9b423..bb32cda 100644 (file)
@@ -113,9 +113,15 @@ class ApiProtect extends ApiBase {
 
                $cascade = $params['cascade'];
                $articleObj = new Article( $titleObj );
-               if ( $params['watch'] ) {
+               
+               $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
+               
+               if ( $params['watch'] || $watch ) {
                        $articleObj->doWatch();
+               } else if ( !$watch ) {
+                       $articleObj->doUnwatch();
                }
+
                if ( $titleObj->exists() ) {
                        $ok = $articleObj->updateRestrictions( $protections, $params['reason'], $cascade, $expiryarray );
                } else {
@@ -160,7 +166,19 @@ class ApiProtect extends ApiBase {
                        ),
                        'reason' => '',
                        'cascade' => false,
-                       'watch' => false,
+                       'watch' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'watchlist' => array(
+                               ApiBase::PARAM_DFLT => 'preferences',
+                               ApiBase::PARAM_TYPE => array(
+                                       'watch',
+                                       'unwatch',
+                                       'preferences',
+                                       'nochange'
+                               ),
+                       ),
                );
        }
 
@@ -175,6 +193,7 @@ class ApiProtect extends ApiBase {
                        'cascade' => array( 'Enable cascading protection (i.e. protect pages included in this page)',
                                        'Ignored if not all protection levels are \'sysop\' or \'protect\'' ),
                        'watch' => 'If set, add the page being (un)protected to your watchlist',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
                );
        }
 
index d4b3d81..263a78a 100644 (file)
@@ -72,6 +72,14 @@ class ApiRollback extends ApiBase {
                        // We don't care about multiple errors, just report one of them
                        $this->dieUsageMsg( reset( $retval ) );
                }
+               
+               $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
+               
+               if ( $watch ) {
+                       $articleObj->doWatch();
+               } else if ( !$watch ) {
+                       $articleObj->doUnwatch();
+               }
 
                $info = array(
                        'title' => $titleObj->getPrefixedText(),
@@ -99,7 +107,16 @@ class ApiRollback extends ApiBase {
                        'user' => null,
                        'token' => null,
                        'summary' => null,
-                       'markbot' => false
+                       'markbot' => false,
+                       'watchlist' => array(
+                               ApiBase::PARAM_DFLT => 'preferences',
+                               ApiBase::PARAM_TYPE => array(
+                                       'watch',
+                                       'unwatch',
+                                       'preferences',
+                                       'nochange'
+                               ),
+                       ),
                );
        }
 
@@ -109,7 +126,8 @@ class ApiRollback extends ApiBase {
                        'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
                        'token' => 'A rollback token previously retrieved through prop=revisions',
                        'summary' => 'Custom edit summary. If not set, default summary will be used.',
-                       'markbot' => 'Mark the reverted edits and the revert as bot edits'
+                       'markbot' => 'Mark the reverted edits and the revert as bot edits',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
                );
        }
 
index b4abec7..46b0118 100644 (file)
@@ -81,6 +81,14 @@ class ApiUndelete extends ApiBase {
                        wfRunHooks( 'FileUndeleteComplete',
                                array( $titleObj, array(), $wgUser, $params['reason'] ) );
                }
+               
+               $watch = $this->getWatchlistValue( $params['watchlist'], $titleObj );
+               
+               if ( $params['watch'] || $watch ) {
+                       $wgUser->addWatch( $titleObj );
+               } else if ( !$watch ) {
+                       $wgUser->removeWatch( $titleObj );
+               }
 
                $info['title'] = $titleObj->getPrefixedText();
                $info['revisions'] = intval( $retval[0] );
@@ -104,7 +112,16 @@ class ApiUndelete extends ApiBase {
                        'reason' => '',
                        'timestamps' => array(
                                ApiBase::PARAM_ISMULTI => true
-                       )
+                       ),
+                       'watchlist' => array(
+                               ApiBase::PARAM_DFLT => 'preferences',
+                               ApiBase::PARAM_TYPE => array(
+                                       'watch',
+                                       'unwatch',
+                                       'preferences',
+                                       'nochange'
+                               ),
+                       ),
                );
        }
 
@@ -113,7 +130,8 @@ class ApiUndelete extends ApiBase {
                        'title' => 'Title of the page you want to restore.',
                        'token' => 'An undelete token previously retrieved through list=deletedrevs',
                        'reason' => 'Reason for restoring (optional)',
-                       'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'
+                       'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
                );
        }
 
index 7f0d857..eabb7e2 100644 (file)
@@ -218,10 +218,17 @@ class ApiUpload extends ApiBase {
                if ( is_null( $this->mParams['text'] ) ) {
                        $this->mParams['text'] = $this->mParams['comment'];
                }
-
+               
+               $watch = $this->getWatchlistValue( $params['watchlist'] );
+               
+               // Deprecated parameters
+               if ( $this->mParams['watch'] ) {
+                       $watch = true;
+               }
+               
                // No errors, no warnings: do the upload
                $status = $this->mUpload->performUpload( $this->mParams['comment'],
-                       $this->mParams['text'], $this->mParams['watch'], $wgUser );
+                       $this->mParams['text'], $watch, $wgUser );
 
                if ( !$status->isGood() ) {
                        $error = $status->getErrorsArray();
@@ -254,7 +261,19 @@ class ApiUpload extends ApiBase {
                        ),
                        'text' => null,
                        'token' => null,
-                       'watch' => false,
+                       'watch' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
+                       'watchlist' => array(
+                               ApiBase::PARAM_DFLT => 'preferences',
+                               ApiBase::PARAM_TYPE => array(
+                                       'watch',
+                                       'unwatch',
+                                       'preferences',
+                                       'nochange'
+                               ),
+                       ),
                        'ignorewarnings' => false,
                        'file' => null,
                        'url' => null,
@@ -270,6 +289,7 @@ class ApiUpload extends ApiBase {
                        'comment' => 'Upload comment. Also used as the initial page text for new files if "text" is not specified',
                        'text' => 'Initial page text for new files',
                        'watch' => 'Watch the page',
+                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
                        'ignorewarnings' => 'Ignore any warnings',
                        'file' => 'File contents',
                        'url' => 'Url to fetch the file from',