41 private $mPageSet =
null;
44 private $expiryEnabled;
58 parent::__construct( $mainModule, $moduleName );
61 $this->titleFormatter = $titleFormatter;
71 $this->
dieWithError(
'watchlistanontext',
'notloggedin' );
81 $pageSet = $this->getPageSet();
84 if ( !isset(
$params[
'title'] ) ) {
86 $res = $pageSet->getInvalidTitlesAndRevisions( [
94 foreach ( $pageSet->getMissingPages() as $page ) {
95 $r = $this->watchTitle( $page, $user,
$params );
100 foreach ( $pageSet->getGoodPages() as $page ) {
101 $r = $this->watchTitle( $page, $user,
$params );
107 $extraParams = array_keys( array_filter( $pageSet->extractRequestParams(),
static function ( $x ) {
108 return $x !==
null && $x !==
false;
111 if ( $extraParams ) {
114 'apierror-invalidparammix-cannotusewith',
116 $pageSet->encodeParamName( $extraParams[0] )
122 $title = Title::newFromText(
$params[
'title'] );
123 if ( !$title || !$this->watchlistManager->isWatchable( $title ) ) {
124 $this->
dieWithError( [
'invalidtitle', $params[
'title'] ] );
126 $res = $this->watchTitle( $title, $user,
$params,
true );
131 $continuationManager->setContinuationIntoResult( $this->
getResult() );
135 $compatibilityMode =
false
137 $res = [
'title' => $this->titleFormatter->getPrefixedText( $page ),
'ns' => $page->
getNamespace() ];
139 if ( !$this->watchlistManager->isWatchable( $page ) ) {
140 $res[
'watchable'] = 0;
145 $status = $this->watchlistManager->removeWatch( $user, $page );
146 $res[
'unwatched'] = $status->isOK();
151 if ( $this->expiryEnabled && isset(
$params[
'expiry'] ) ) {
156 $status = $this->watchlistManager->addWatch( $user, $page, $expiry );
157 $res[
'watched'] = $status->isOK();
160 if ( !$status->isOK() ) {
161 if ( $compatibilityMode ) {
164 $res[
'errors'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'error' );
165 $res[
'warnings'] = $this->
getErrorFormatter()->arrayFromStatus( $status,
'warning' );
166 if ( !$res[
'warnings'] ) {
167 unset( $res[
'warnings'] );
178 private function getPageSet() {
179 $this->mPageSet ??=
new ApiPageSet( $this );
181 return $this->mPageSet;
199 ParamValidator::PARAM_TYPE =>
'string',
200 ParamValidator::PARAM_DEPRECATED =>
true,
203 ParamValidator::PARAM_TYPE =>
'expiry',
204 ExpiryDef::PARAM_MAX => $this->maxDuration,
205 ExpiryDef::PARAM_USE_MAX =>
true,
214 if ( !$this->expiryEnabled ) {
215 unset( $result[
'expiry'] );
219 $result += $this->getPageSet()->getFinalParams( $flags );
226 $title = Title::newMainPage()->getPrefixedText();
227 $mp = rawurlencode( $title );
231 "action=watch&titles={$mp}&token=123ABC"
232 =>
'apihelp-watch-example-watch',
234 if ( $this->expiryEnabled ) {
235 $examples[
"action=watch&titles={$mp}|Foo|Bar&expiry=1%20month&token=123ABC"]
236 =
'apihelp-watch-example-watch-expiry';
239 return array_merge( $examples, [
240 "action=watch&titles={$mp}&unwatch=&token=123ABC"
241 =>
'apihelp-watch-example-unwatch',
242 'action=watch&generator=allpages&gapnamespace=0&token=123ABC'
243 =>
'apihelp-watch-example-generator',
248 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watch';
253class_alias( ApiWatch::class,
'ApiWatch' );
array $params
The job parameters.
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.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
Interface for objects (potentially) representing an editable wiki page.