34 parent::__construct( $mainModule, $moduleName, $modulePrefix );
36 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
37 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
48 if ( isset( $params[
'from'] ) ) {
49 $fromTitle = Title::newFromText( $params[
'from'] );
50 if ( !$fromTitle || $fromTitle->isExternal() ) {
53 } elseif ( isset( $params[
'fromid'] ) ) {
54 $fromTitle = Title::newFromID( $params[
'fromid'] );
56 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
60 if ( !$fromTitle->exists() ) {
63 $fromTalk = $fromTitle->getTalkPage();
65 $toTitle = Title::newFromText( $params[
'to'] );
66 if ( !$toTitle || $toTitle->isExternal() ) {
69 $toTalk = $toTitle->getTalkPageIfDefined();
71 $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
72 if ( $toTitle->getNamespace() ==
NS_FILE
73 && !$repoGroup->getLocalRepo()->findFile( $toTitle )
74 && $repoGroup->findFile( $toTitle )
76 if ( !$params[
'ignorewarnings'] &&
78 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
80 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
85 if ( $user->pingLimiter(
'move' ) ) {
90 if ( $params[
'tags'] ) {
92 if ( !$ableToTag->isOK() ) {
98 $toTitleExists = $toTitle->exists();
99 $status = $this->
movePage( $fromTitle, $toTitle, $params[
'reason'], !$params[
'noredirect'],
100 $params[
'tags'] ?: [] );
101 if ( !$status->isOK() ) {
102 $user->spreadAnyEditBlock();
107 'from' => $fromTitle->getPrefixedText(),
108 'to' => $toTitle->getPrefixedText(),
109 'reason' => $params[
'reason']
116 $r[
'redirectcreated'] = $fromTitle->exists();
118 $r[
'moveoverredirect'] = $toTitleExists;
121 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
122 $toTalkExists = $toTalk->exists();
127 !$params[
'noredirect'],
128 $params[
'tags'] ?: []
130 if ( $status->isOK() ) {
131 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
132 $r[
'talkto'] = $toTalk->getPrefixedText();
133 $r[
'talkmoveoverredirect'] = $toTalkExists;
143 if ( $params[
'movesubpages'] ) {
148 $params[
'noredirect'],
149 $params[
'tags'] ?: []
151 ApiResult::setIndexedTagName( $r[
'subpages'],
'subpage' );
153 if ( $params[
'movetalk'] ) {
158 $params[
'noredirect'],
159 $params[
'tags'] ?: []
161 ApiResult::setIndexedTagName( $r[
'subpages-talk'],
'subpage' );
165 $watch =
'preferences';
166 if ( isset( $params[
'watchlist'] ) ) {
167 $watch = $params[
'watchlist'];
172 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
173 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
187 $mp = MediaWikiServices::getInstance()->getMovePageFactory()->newMovePage( $from, $to );
188 $valid = $mp->isValidMove();
189 if ( !$valid->isOK() ) {
194 $permStatus = $mp->checkPermissions( $user, $reason );
195 if ( !$permStatus->isOK() ) {
201 $createRedirect =
true;
204 return $mp->move( $user, $reason, $createRedirect, $changeTags );
215 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
218 $mp =
new MovePage( $fromTitle, $toTitle );
220 $mp->moveSubpagesIfAllowed( $this->
getUser(), $reason, !$noredirect, $changeTags );
221 if ( !$result->isOK() ) {
228 foreach ( $result->getValue() as $oldTitle => $status ) {
230 $r = [
'from' => $oldTitle ];
231 if ( $status->isOK() ) {
232 $r[
'to'] = $status->getValue();
262 'movesubpages' =>
false,
263 'noredirect' =>
false,
271 'ignorewarnings' =>
false,
285 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
286 'reason=Misspelled%20title&movetalk=&noredirect='
287 =>
'apihelp-move-example-move',
292 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.
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=0)
Abort execution with an error.
getErrorFormatter()
Get the error formatter Stable to override.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
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, $modulePrefix='')
Stable to call.
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 Stable to override.
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...
getUser()
Stable to override.
Handles the backend logic of moving a page from one title to another.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Represents a title within MediaWiki.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...