39 if ( isset( $params[
'from'] ) ) {
40 $fromTitle = Title::newFromText( $params[
'from'] );
41 if ( !$fromTitle || $fromTitle->isExternal() ) {
44 } elseif ( isset( $params[
'fromid'] ) ) {
45 $fromTitle = Title::newFromID( $params[
'fromid'] );
47 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
51 if ( !$fromTitle->exists() ) {
54 $fromTalk = $fromTitle->getTalkPage();
56 $toTitle = Title::newFromText( $params[
'to'] );
57 if ( !$toTitle || $toTitle->isExternal() ) {
60 $toTalk = $toTitle->getTalkPageIfDefined();
62 $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
63 if ( $toTitle->getNamespace() ==
NS_FILE
64 && !$repoGroup->getLocalRepo()->findFile( $toTitle )
65 && $repoGroup->findFile( $toTitle )
67 if ( !$params[
'ignorewarnings'] &&
69 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
71 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
76 if ( $user->pingLimiter(
'move' ) ) {
81 if ( $params[
'tags'] ) {
83 if ( !$ableToTag->isOK() ) {
89 $toTitleExists = $toTitle->exists();
90 $status = $this->
movePage( $fromTitle, $toTitle, $params[
'reason'], !$params[
'noredirect'],
91 $params[
'tags'] ?: [] );
92 if ( !$status->isOK() ) {
93 $user->spreadAnyEditBlock();
98 'from' => $fromTitle->getPrefixedText(),
99 'to' => $toTitle->getPrefixedText(),
100 'reason' => $params[
'reason']
107 $r[
'redirectcreated'] = $fromTitle->exists();
109 $r[
'moveoverredirect'] = $toTitleExists;
112 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
113 $toTalkExists = $toTalk->exists();
118 !$params[
'noredirect'],
119 $params[
'tags'] ?: []
121 if ( $status->isOK() ) {
122 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
123 $r[
'talkto'] = $toTalk->getPrefixedText();
124 $r[
'talkmoveoverredirect'] = $toTalkExists;
134 if ( $params[
'movesubpages'] ) {
139 $params[
'noredirect'],
140 $params[
'tags'] ?: []
144 if ( $params[
'movetalk'] ) {
149 $params[
'noredirect'],
150 $params[
'tags'] ?: []
156 $watch =
'preferences';
157 if ( isset( $params[
'watchlist'] ) ) {
158 $watch = $params[
'watchlist'];
162 $this->
setWatch( $watch, $fromTitle,
'watchmoves' );
163 $this->
setWatch( $watch, $toTitle,
'watchmoves' );
177 $mp = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $from, $to );
178 $valid = $mp->isValidMove();
179 if ( !$valid->isOK() ) {
184 $permStatus = $mp->checkPermissions( $user, $reason );
185 if ( !$permStatus->isOK() ) {
191 $createRedirect =
true;
194 return $mp->move( $user, $reason, $createRedirect, $changeTags );
205 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
208 $mp =
new MovePage( $fromTitle, $toTitle );
210 $mp->moveSubpagesIfAllowed( $this->
getUser(), $reason, !$noredirect, $changeTags );
211 if ( !$result->isOK() ) {
218 foreach ( $result->getValue() as $oldTitle => $status ) {
219 $r = [
'from' => $oldTitle ];
220 if ( $status->isOK() ) {
221 $r[
'to'] = $status->getValue();
251 'movesubpages' =>
false,
252 'noredirect' =>
false,
262 'ignorewarnings' =>
false,
276 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
277 'reason=Misspelled%20title&movetalk=&noredirect='
278 =>
'apihelp-move-example-move',
283 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Move';
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.
const PARAM_REQUIRED
(boolean) Is the parameter required?
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.
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getErrorFormatter()
Get the error formatter.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
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.
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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.
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.
movePage(Title $from, Title $to, $reason, $createRedirect, $changeTags)
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.
Handles the backend logic of moving a page from one title to another.
Represents a title within MediaWiki.