51 parent::__construct( $mainModule, $moduleName );
57 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
58 $this->watchlistMaxDuration =
59 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
72 if ( isset( $params[
'from'] ) ) {
74 if ( !$fromTitle || $fromTitle->isExternal() ) {
77 } elseif ( isset( $params[
'fromid'] ) ) {
80 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
83 throw new LogicException(
'Unreachable due to requireOnlyOneParameter' );
86 if ( !$fromTitle->exists() ) {
89 $fromTalk = $fromTitle->getTalkPage();
92 if ( !$toTitle || $toTitle->isExternal() ) {
95 $toTalk = $toTitle->getTalkPageIfDefined();
97 if ( $toTitle->getNamespace() ===
NS_FILE
98 && !$this->repoGroup->getLocalRepo()->findFile( $toTitle )
99 && $this->repoGroup->findFile( $toTitle )
101 if ( !$params[
'ignorewarnings'] &&
102 $this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
103 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
104 } elseif ( !$this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
105 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
110 if ( $user->pingLimiter(
'move' ) ) {
115 $toTitleExists = $toTitle->exists();
116 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
117 $status = $mp->moveIfAllowed(
120 !$params[
'noredirect'],
121 $params[
'tags'] ?: []
123 if ( !$status->isOK() ) {
128 'from' => $fromTitle->getPrefixedText(),
129 'to' => $toTitle->getPrefixedText(),
130 'reason' => $params[
'reason']
137 $r[
'redirectcreated'] = $fromTitle->exists();
139 $r[
'moveoverredirect'] = $toTitleExists;
142 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
143 $toTalkExists = $toTalk->exists();
144 $mp = $this->movePageFactory->newMovePage( $fromTalk, $toTalk );
145 $status = $mp->moveIfAllowed(
148 !$params[
'noredirect'],
149 $params[
'tags'] ?: []
151 if ( $status->isOK() ) {
152 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
153 $r[
'talkto'] = $toTalk->getPrefixedText();
154 $r[
'talkmoveoverredirect'] = $toTalkExists;
164 if ( $params[
'movesubpages'] ) {
169 $params[
'noredirect'],
170 $params[
'tags'] ?: []
174 if ( $params[
'movetalk'] && $toTalk ) {
179 $params[
'noredirect'],
180 $params[
'tags'] ?: []
186 $watch =
'preferences';
187 if ( isset( $params[
'watchlist'] ) ) {
188 $watch = $params[
'watchlist'];
193 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
194 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
207 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
210 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
212 $mp->moveSubpagesIfAllowed( $this->
getAuthority(), $reason, !$noredirect, $changeTags );
213 if ( !$result->isOK() ) {
220 foreach ( $result->getValue() as $oldTitle => $status ) {
222 $r = [
'from' => $oldTitle ];
223 if ( $status->isOK() ) {
224 $r[
'to'] = $status->getValue();
246 ParamValidator::PARAM_TYPE =>
'integer'
249 ParamValidator::PARAM_TYPE =>
'string',
250 ParamValidator::PARAM_REQUIRED =>
true
254 'movesubpages' =>
false,
255 'noredirect' =>
false,
263 'ignorewarnings' =>
false,
265 ParamValidator::PARAM_TYPE =>
'tags',
266 ParamValidator::PARAM_ISMULTI =>
true,
277 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
278 'reason=Misspelled%20title&movetalk=&noredirect='
279 =>
'apihelp-move-example-move',
284 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Move';
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
setWatch(string $watch, Title $title, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistParams(array $watchOptions=[])
Get additional allow params specific to watchlisting.
WatchlistManager $watchlistManager
UserOptionsLookup $userOptionsLookup
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
This is the main API class, used for both external and internal processing.
API Module to move pages.
needsToken()
Returns the token type this module requires in order to execute.
isWriteMode()
Indicates whether this module requires write mode.
__construct(ApiMain $mainModule, $moduleName, MovePageFactory $movePageFactory, RepoGroup $repoGroup, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup)
moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags=[])
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
mustBePosted()
Indicates whether this module must be called with a POST request.
getHelpUrls()
Return links to more detailed help pages about the module.
MovePageFactory $movePageFactory
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
A class containing constants representing the names of configuration variables.
Prioritized list of file repositories.
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rename actions.