33 if ( !$user->isLoggedIn() ) {
34 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
47 if ( !isset( $params[
'title'] ) ) {
49 $res = $pageSet->getInvalidTitlesAndRevisions( [
57 foreach ( $pageSet->getMissingTitles() as
$title ) {
58 $r = $this->
watchTitle( $title, $user, $params );
63 foreach ( $pageSet->getGoodTitles() as
$title ) {
64 $r = $this->
watchTitle( $title, $user, $params );
67 ApiResult::setIndexedTagName(
$res,
'w' );
70 $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(), function ( $x ) {
71 return $x !==
null && $x !==
false;
77 'apierror-invalidparammix-cannotusewith',
79 $pageSet->encodeParamName( $extraParams[0] )
85 $title = Title::newFromText( $params[
'title'] );
87 $this->
dieWithError( [
'invalidtitle', $params[
'title'] ] );
94 $continuationManager->setContinuationIntoResult( $this->
getResult() );
98 $compatibilityMode =
false
100 if ( !
$title->isWatchable() ) {
101 return [
'title' =>
$title->getPrefixedText(),
'watchable' => 0 ];
104 $res = [
'title' =>
$title->getPrefixedText() ];
106 if ( $params[
'unwatch'] ) {
108 $res[
'unwatched'] = $status->isOK();
111 $res[
'watched'] = $status->isOK();
114 if ( !$status->isOK() ) {
115 if ( $compatibilityMode ) {
120 if ( !
$res[
'warnings'] ) {
121 unset(
$res[
'warnings'] );
133 if ( $this->mPageSet ===
null ) {
164 $result += $this->
getPageSet()->getFinalParams( $flags );
172 'action=watch&titles=Main_Page&token=123ABC'
173 =>
'apihelp-watch-example-watch',
174 'action=watch&titles=Main_Page&unwatch=&token=123ABC'
175 =>
'apihelp-watch-example-unwatch',
176 'action=watch&generator=allpages&gapnamespace=0&token=123ABC'
177 =>
'apihelp-watch-example-generator',
182 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watch';
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getErrorFormatter()
Get the error formatter.
setContinuationManager(ApiContinuationManager $manager=null)
Set the continuation manager.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
This manages continuation state.
This class contains a list of pages that the client has requested.
API module to allow users to watch a page.
getAllowedParams( $flags=0)
watchTitle(Title $title, User $user, array $params, $compatibilityMode=false)
isWriteMode()
Indicates whether this module requires write mode.
getPageSet()
Get a cached instance of an ApiPageSet object.
needsToken()
Returns the token type this module requires in order to execute.
getHelpUrls()
Return links to more detailed help pages about the module.
getExamplesMessages()
Returns usage examples for this module.
mustBePosted()
Indicates whether this module must be called with a POST request.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static doWatch(Title $title, User $user, $checkRights=User::CHECK_USER_RIGHTS)
Watch a page.
static doUnwatch(Title $title, User $user)
Unwatch a page.