45 parent::__construct( $mainModule, $moduleName );
48 $this->expiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
49 $this->maxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
54 if ( !$user->isRegistered() ) {
55 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
68 if ( !isset( $params[
'title'] ) ) {
70 $res = $pageSet->getInvalidTitlesAndRevisions( [
78 foreach ( $pageSet->getMissingTitles() as
$title ) {
79 $r = $this->
watchTitle( $title, $user, $params );
84 foreach ( $pageSet->getGoodTitles() as
$title ) {
85 $r = $this->
watchTitle( $title, $user, $params );
88 ApiResult::setIndexedTagName(
$res,
'w' );
91 $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(),
static function ( $x ) {
92 return $x !==
null && $x !==
false;
98 'apierror-invalidparammix-cannotusewith',
100 $pageSet->encodeParamName( $extraParams[0] )
106 $title = Title::newFromText( $params[
'title'] );
107 if ( !
$title || !$this->watchlistManager->isWatchable(
$title ) ) {
108 $this->
dieWithError( [
'invalidtitle', $params[
'title'] ] );
115 $continuationManager->setContinuationIntoResult( $this->
getResult() );
119 $compatibilityMode =
false
121 $res = [
'title' =>
$title->getPrefixedText(),
'ns' =>
$title->getNamespace() ];
123 if ( !$this->watchlistManager->isWatchable(
$title ) ) {
124 $res[
'watchable'] = 0;
128 if ( $params[
'unwatch'] ) {
129 $status = $this->watchlistManager->removeWatch( $user,
$title );
130 $res[
'unwatched'] = $status->isOK();
135 if ( $this->expiryEnabled && isset( $params[
'expiry'] ) ) {
136 $expiry = $params[
'expiry'];
137 $res[
'expiry'] = ApiResult::formatExpiry( $expiry );
140 $status = $this->watchlistManager->addWatch( $user,
$title, $expiry );
141 $res[
'watched'] = $status->isOK();
144 if ( !$status->isOK() ) {
145 if ( $compatibilityMode ) {
150 if ( !
$res[
'warnings'] ) {
151 unset(
$res[
'warnings'] );
163 if ( $this->mPageSet ===
null ) {
185 ParamValidator::PARAM_TYPE =>
'string',
186 ParamValidator::PARAM_DEPRECATED =>
true,
189 ParamValidator::PARAM_TYPE =>
'expiry',
191 ExpiryDef::PARAM_USE_MAX =>
true,
200 if ( !$this->expiryEnabled ) {
201 unset( $result[
'expiry'] );
205 $result += $this->
getPageSet()->getFinalParams( $flags );
214 'action=watch&titles=Main_Page&token=123ABC'
215 =>
'apihelp-watch-example-watch',
217 if ( $this->expiryEnabled ) {
218 $examples[
'action=watch&titles=Main_Page|Foo|Bar&expiry=1%20month&token=123ABC']
219 =
'apihelp-watch-example-watch-expiry';
222 return array_merge( $examples, [
223 'action=watch&titles=Main_Page&unwatch=&token=123ABC'
224 =>
'apihelp-watch-example-unwatch',
225 'action=watch&generator=allpages&gapnamespace=0&token=123ABC'
226 =>
'apihelp-watch-example-generator',
231 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.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
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.
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.
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.
__construct(ApiMain $mainModule, $moduleName, WatchlistManager $watchlistManager)
string $maxDuration
Relative maximum expiry.
needsToken()
Returns the token type this module requires in order to execute.
getHelpUrls()
Return links to more detailed help pages about the module.
bool $expiryEnabled
Whether watchlist expiries are enabled.
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
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...