39 private $movePageFactory;
52 parent::__construct( $mainModule, $moduleName );
54 $this->movePageFactory = $movePageFactory;
55 $this->repoGroup = $repoGroup;
58 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
59 $this->watchlistMaxDuration =
60 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
61 $this->watchlistManager = $watchlistManager;
62 $this->userOptionsLookup = $userOptionsLookup;
73 if ( isset( $params[
'from'] ) ) {
74 $fromTitle = Title::newFromText( $params[
'from'] );
75 if ( !$fromTitle || $fromTitle->isExternal() ) {
78 } elseif ( isset( $params[
'fromid'] ) ) {
79 $fromTitle = Title::newFromID( $params[
'fromid'] );
81 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
84 throw new LogicException(
'Unreachable due to requireOnlyOneParameter' );
87 if ( !$fromTitle->exists() ) {
90 $fromTalk = $fromTitle->getTalkPage();
92 $toTitle = Title::newFromText( $params[
'to'] );
93 if ( !$toTitle || $toTitle->isExternal() ) {
96 $toTalk = $toTitle->getTalkPageIfDefined();
98 if ( $toTitle->getNamespace() ===
NS_FILE
99 && !$this->repoGroup->getLocalRepo()->findFile( $toTitle )
100 && $this->repoGroup->findFile( $toTitle )
102 if ( !$params[
'ignorewarnings'] &&
103 $this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
104 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
105 } elseif ( !$this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
106 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
111 if ( $user->pingLimiter(
'move' ) ) {
116 $toTitleExists = $toTitle->exists();
117 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
118 $status = $mp->moveIfAllowed(
121 !$params[
'noredirect'],
122 $params[
'tags'] ?: []
124 if ( !$status->isOK() ) {
129 'from' => $fromTitle->getPrefixedText(),
130 'to' => $toTitle->getPrefixedText(),
131 'reason' => $params[
'reason']
138 $r[
'redirectcreated'] = $fromTitle->exists();
140 $r[
'moveoverredirect'] = $toTitleExists;
143 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
144 $toTalkExists = $toTalk->exists();
145 $mp = $this->movePageFactory->newMovePage( $fromTalk, $toTalk );
146 $status = $mp->moveIfAllowed(
149 !$params[
'noredirect'],
150 $params[
'tags'] ?: []
152 if ( $status->isOK() ) {
153 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
154 $r[
'talkto'] = $toTalk->getPrefixedText();
155 $r[
'talkmoveoverredirect'] = $toTalkExists;
165 if ( $params[
'movesubpages'] ) {
170 $params[
'noredirect'],
171 $params[
'tags'] ?: []
173 ApiResult::setIndexedTagName( $r[
'subpages'],
'subpage' );
175 if ( $params[
'movetalk'] && $toTalk ) {
180 $params[
'noredirect'],
181 $params[
'tags'] ?: []
183 ApiResult::setIndexedTagName( $r[
'subpages-talk'],
'subpage' );
187 $watch = $params[
'watchlist'] ??
'preferences';
191 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
192 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
205 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
208 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
210 $mp->moveSubpagesIfAllowed( $this->
getAuthority(), $reason, !$noredirect, $changeTags );
211 if ( !$result->isOK() ) {
218 foreach ( $result->getValue() as $oldTitle => $status ) {
220 $r = [
'from' => $oldTitle ];
221 if ( $status->isOK() ) {
222 $r[
'to'] = $status->getValue();
244 ParamValidator::PARAM_TYPE =>
'integer'
247 ParamValidator::PARAM_TYPE =>
'string',
248 ParamValidator::PARAM_REQUIRED =>
true
252 'movesubpages' =>
false,
253 'noredirect' =>
false,
261 'ignorewarnings' =>
false,
263 ParamValidator::PARAM_TYPE =>
'tags',
264 ParamValidator::PARAM_ISMULTI =>
true,
275 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
276 'reason=Misspelled%20title&movetalk=&noredirect='
277 =>
'apihelp-move-example-move',
282 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.
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.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
A class containing constants representing the names of configuration variables.
Prioritized list of file repositories.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rename actions.