X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiWatch.php;h=88aff4154ec191d285e7d7c90188ea1dc5aab841;hp=f09fdcb063c9cc927482729afacd013e44e04a83;hb=ce079cf6ad79ca8d3360817f809b219d166f9153;hpb=e3bd13db0c285f312e31bb1b7271af4628cca80c diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php index f09fdcb063..88aff4154e 100644 --- a/includes/api/ApiWatch.php +++ b/includes/api/ApiWatch.php @@ -35,12 +35,10 @@ class ApiWatch extends ApiBase { public function execute() { $user = $this->getUser(); if ( !$user->isLoggedIn() ) { - $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); + $this->dieWithError( 'watchlistanontext', 'notloggedin' ); } - if ( !$user->isAllowed( 'editmywatchlist' ) ) { - $this->dieUsage( 'You don\'t have permission to edit your watchlist', 'permissiondenied' ); - } + $this->checkUserRightsAny( 'editmywatchlist' ); $params = $this->extractRequestParams(); @@ -78,16 +76,19 @@ class ApiWatch extends ApiBase { } ) ); if ( $extraParams ) { - $p = $this->getModulePrefix(); - $this->dieUsage( - "The parameter {$p}title can not be used with " . implode( ', ', $extraParams ), + $this->dieWithError( + [ + 'apierror-invalidparammix-cannotusewith', + $this->encodeParamName( 'title' ), + $pageSet->encodeParamName( $extraParams[0] ) + ], 'invalidparammix' ); } $title = Title::newFromText( $params['title'] ); if ( !$title || !$title->isWatchable() ) { - $this->dieUsageMsg( [ 'invalidtitle', $params['title'] ] ); + $this->dieWithError( [ 'invalidtitle', $params['title'] ] ); } $res = $this->watchTitle( $title, $user, $params, true ); } @@ -109,24 +110,20 @@ class ApiWatch extends ApiBase { if ( $params['unwatch'] ) { $status = UnwatchAction::doUnwatch( $title, $user ); $res['unwatched'] = $status->isOK(); - if ( $status->isOK() ) { - $res['message'] = $this->msg( 'removedwatchtext', $title->getPrefixedText() ) - ->title( $title )->parseAsBlock(); - } } else { $status = WatchAction::doWatch( $title, $user ); $res['watched'] = $status->isOK(); - if ( $status->isOK() ) { - $res['message'] = $this->msg( 'addedwatchtext', $title->getPrefixedText() ) - ->title( $title )->parseAsBlock(); - } } if ( !$status->isOK() ) { if ( $compatibilityMode ) { $this->dieStatus( $status ); } - $res['error'] = $this->getErrorFromStatus( $status ); + $res['errors'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'error' ); + $res['warnings'] = $this->getErrorFormatter()->arrayFromStatus( $status, 'warning' ); + if ( !$res['warnings'] ) { + unset( $res['warnings'] ); + } } return $res;