38 private $movePageFactory;
51 parent::__construct( $mainModule, $moduleName );
53 $this->movePageFactory = $movePageFactory;
54 $this->repoGroup = $repoGroup;
57 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
58 $this->watchlistMaxDuration =
59 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
60 $this->watchlistManager = $watchlistManager;
61 $this->userOptionsLookup = $userOptionsLookup;
72 if ( isset( $params[
'from'] ) ) {
73 $fromTitle = Title::newFromText( $params[
'from'] );
74 if ( !$fromTitle || $fromTitle->isExternal() ) {
77 } elseif ( isset( $params[
'fromid'] ) ) {
78 $fromTitle = Title::newFromID( $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();
91 $toTitle = Title::newFromText( $params[
'to'] );
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'] ?: []
172 ApiResult::setIndexedTagName( $r[
'subpages'],
'subpage' );
174 if ( $params[
'movetalk'] && $toTalk ) {
179 $params[
'noredirect'],
180 $params[
'tags'] ?: []
182 ApiResult::setIndexedTagName( $r[
'subpages-talk'],
'subpage' );
186 $watch = $params[
'watchlist'] ??
'preferences';
190 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
191 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
204 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
207 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
209 $mp->moveSubpagesIfAllowed( $this->
getAuthority(), $reason, !$noredirect, $changeTags );
210 if ( !$result->isOK() ) {
217 foreach ( $result->getValue() as $oldTitle => $status ) {
219 $r = [
'from' => $oldTitle ];
220 if ( $status->isOK() ) {
221 $r[
'to'] = $status->getValue();
243 ParamValidator::PARAM_TYPE =>
'integer'
246 ParamValidator::PARAM_TYPE =>
'string',
247 ParamValidator::PARAM_REQUIRED =>
true
251 'movesubpages' =>
false,
252 'noredirect' =>
false,
260 'ignorewarnings' =>
false,
262 ParamValidator::PARAM_TYPE =>
'tags',
263 ParamValidator::PARAM_ISMULTI =>
true,
274 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
275 'reason=Misspelled%20title&movetalk=&noredirect='
276 =>
'apihelp-move-example-move',
281 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.