Merge "Further improve load order of RC and watchlist styling"
[lhc/web/wiklou.git] / includes / api / ApiWatch.php
index 2454e33..c7d636a 100644 (file)
@@ -36,17 +36,20 @@ class ApiWatch extends ApiBase {
                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 behaviour of uselang
+               // 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() ) {
@@ -57,19 +60,19 @@ class ApiWatch extends ApiBase {
                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 ( !is_null( $oldLang ) ) {
                        $this->getContext()->setLanguage( $oldLang ); // Reset language to $oldLang
                }
 
-               if ( !$success ) {
-                       $this->dieUsageMsg( 'hookaborted' );
+               if ( !$status->isOK() ) {
+                       $this->dieStatus( $status );
                }
                $this->getResult()->addValue( null, $this->getModuleName(), $res );
        }