diff options
Diffstat (limited to 'includes/api/ApiWatch.php')
-rw-r--r-- | includes/api/ApiWatch.php | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index 0509f1f8..c7d636a1 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -31,36 +31,48 @@ */ class ApiWatch extends ApiBase { - public function __construct( $main, $action ) { - parent::__construct( $main, $action ); - } - public function execute() { $user = $this->getUser(); if ( !$user->isLoggedIn() ) { $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); } + if ( !$user->isAllowed( 'editmywatchlist' ) ) { + $this->dieUsage( 'You don\'t have permission to edit your watchlist', 'permissiondenied' ); + } $params = $this->extractRequestParams(); $title = Title::newFromText( $params['title'] ); - if ( !$title || $title->getNamespace() < 0 ) { + if ( !$title || $title->isExternal() || !$title->canExist() ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } $res = array( 'title' => $title->getPrefixedText() ); + // Currently unnecessary, code to act as a safeguard against any change in current behavior of uselang + // Copy from ApiParse + $oldLang = null; + if ( isset( $params['uselang'] ) && $params['uselang'] != $this->getContext()->getLanguage()->getCode() ) { + $oldLang = $this->getContext()->getLanguage(); // Backup language + $this->getContext()->setLanguage( Language::factory( $params['uselang'] ) ); + } + if ( $params['unwatch'] ) { $res['unwatched'] = ''; $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); - $success = UnwatchAction::doUnwatch( $title, $user ); + $status = UnwatchAction::doUnwatch( $title, $user ); } else { $res['watched'] = ''; $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() )->title( $title )->parseAsBlock(); - $success = WatchAction::doWatch( $title, $user ); + $status = WatchAction::doWatch( $title, $user ); } - if ( !$success ) { - $this->dieUsageMsg( 'hookaborted' ); + + if ( !is_null( $oldLang ) ) { + $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang + } + + if ( !$status->isOK() ) { + $this->dieStatus( $status ); } $this->getResult()->addValue( null, $this->getModuleName(), $res ); } @@ -88,6 +100,7 @@ class ApiWatch extends ApiBase { ApiBase::PARAM_REQUIRED => true ), 'unwatch' => false, + 'uselang' => null, 'token' => array( ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true @@ -99,6 +112,7 @@ class ApiWatch extends ApiBase { return array( 'title' => 'The page to (un)watch', 'unwatch' => 'If set the page will be unwatched rather than watched', + 'uselang' => 'Language to show the message in', 'token' => 'A token previously acquired via prop=info', ); } @@ -136,8 +150,4 @@ class ApiWatch extends ApiBase { public function getHelpUrls() { return 'https://www.mediawiki.org/wiki/API:Watch'; } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } } |