38 private $mPageSet =
null;
41 private $expiryEnabled;
55 parent::__construct( $mainModule, $moduleName );
58 $this->titleFormatter = $titleFormatter;
59 $this->expiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
60 $this->maxDuration = $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
68 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
78 $pageSet = $this->getPageSet();
81 if ( !isset(
$params[
'title'] ) ) {
83 $res = $pageSet->getInvalidTitlesAndRevisions( [
91 foreach ( $pageSet->getMissingPages() as $page ) {
92 $r = $this->watchTitle( $page, $user,
$params );
97 foreach ( $pageSet->getGoodPages() as $page ) {
98 $r = $this->watchTitle( $page, $user,
$params );
101 ApiResult::setIndexedTagName( $res,
'w' );
104 $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(),
static function ( $x ) {
105 return $x !==
null && $x !==
false;
108 if ( $extraParams ) {
111 'apierror-invalidparammix-cannotusewith',
113 $pageSet->encodeParamName( $extraParams[0] )
119 $title = Title::newFromText(
$params[
'title'] );
120 if ( !$title || !$this->watchlistManager->isWatchable( $title ) ) {
121 $this->
dieWithError( [
'invalidtitle', $params[
'title'] ] );
123 $res = $this->watchTitle( $title, $user,
$params,
true );
128 $continuationManager->setContinuationIntoResult( $this->
getResult() );
132 $compatibilityMode =
false
134 $res = [
'title' => $this->titleFormatter->getPrefixedText( $page ),
'ns' => $page->
getNamespace() ];
136 if ( !$this->watchlistManager->isWatchable( $page ) ) {
137 $res[
'watchable'] = 0;
142 $status = $this->watchlistManager->removeWatch( $user, $page );
143 $res[
'unwatched'] = $status->isOK();
148 if ( $this->expiryEnabled && isset(
$params[
'expiry'] ) ) {
153 $status = $this->watchlistManager->addWatch( $user, $page, $expiry );
154 $res[
'watched'] = $status->isOK();
157 if ( !$status->isOK() ) {
158 if ( $compatibilityMode ) {
161 $res[
'errors'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'error' );
162 $res[
'warnings'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'warning' );
163 if ( !$res[
'warnings'] ) {
164 unset( $res[
'warnings'] );
175 private function getPageSet() {
178 return $this->mPageSet;
196 ParamValidator::PARAM_TYPE =>
'string',
197 ParamValidator::PARAM_DEPRECATED =>
true,
200 ParamValidator::PARAM_TYPE =>
'expiry',
201 ExpiryDef::PARAM_MAX => $this->maxDuration,
202 ExpiryDef::PARAM_USE_MAX =>
true,
211 if ( !$this->expiryEnabled ) {
212 unset( $result[
'expiry'] );
216 $result += $this->getPageSet()->getFinalParams( $flags );
223 $title = Title::newMainPage()->getPrefixedText();
224 $mp = rawurlencode( $title );
228 "action=watch&titles={$mp}&token=123ABC"
229 =>
'apihelp-watch-example-watch',
231 if ( $this->expiryEnabled ) {
232 $examples[
"action=watch&titles={$mp}|Foo|Bar&expiry=1%20month&token=123ABC"]
233 =
'apihelp-watch-example-watch-expiry';
236 return array_merge( $examples, [
237 "action=watch&titles={$mp}&unwatch=&token=123ABC"
238 =>
'apihelp-watch-example-unwatch',
239 'action=watch&generator=allpages&gapnamespace=0&token=123ABC'
240 =>
'apihelp-watch-example-generator',
245 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watch';
array $params
The job parameters.
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
checkUserRightsAny( $rights)
Helper function for permission-denied errors.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
setContinuationManager(ApiContinuationManager $manager=null)
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 is the main API class, used for both external and internal processing.
This class contains a list of pages that the client has requested.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
API module to allow users to watch a page.
getAllowedParams( $flags=0)
isWriteMode()
Indicates whether this module requires write mode.
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.
WatchlistManager $watchlistManager
__construct(ApiMain $mainModule, $moduleName, WatchlistManager $watchlistManager, TitleFormatter $titleFormatter)
A class containing constants representing the names of configuration variables.
Interface for objects (potentially) representing an editable wiki page.