50 parent::__construct( $mainModule, $moduleName );
52 $this->movePageFactory = $movePageFactory;
53 $this->repoGroup = $repoGroup;
56 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
57 $this->watchlistMaxDuration =
58 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
59 $this->watchlistManager = $watchlistManager;
60 $this->userOptionsLookup = $userOptionsLookup;
71 if ( isset( $params[
'from'] ) ) {
72 $fromTitle = Title::newFromText( $params[
'from'] );
73 if ( !$fromTitle || $fromTitle->isExternal() ) {
76 } elseif ( isset( $params[
'fromid'] ) ) {
77 $fromTitle = Title::newFromID( $params[
'fromid'] );
79 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
82 throw new LogicException(
'Unreachable due to requireOnlyOneParameter' );
85 if ( !$fromTitle->exists() ) {
88 $fromTalk = $fromTitle->getTalkPage();
90 $toTitle = Title::newFromText( $params[
'to'] );
91 if ( !$toTitle || $toTitle->isExternal() ) {
94 $toTalk = $toTitle->getTalkPageIfDefined();
96 if ( $toTitle->getNamespace() ===
NS_FILE
97 && !$this->repoGroup->getLocalRepo()->findFile( $toTitle )
98 && $this->repoGroup->findFile( $toTitle )
100 if ( !$params[
'ignorewarnings'] &&
101 $this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
102 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
103 } elseif ( !$this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
104 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
109 $toTitleExists = $toTitle->exists();
110 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
111 $status = $mp->moveIfAllowed(
114 !$params[
'noredirect'],
115 $params[
'tags'] ?: []
117 if ( !$status->isOK() ) {
122 'from' => $fromTitle->getPrefixedText(),
123 'to' => $toTitle->getPrefixedText(),
124 'reason' => $params[
'reason']
131 $r[
'redirectcreated'] = $fromTitle->exists();
133 $r[
'moveoverredirect'] = $toTitleExists;
136 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
137 $toTalkExists = $toTalk->exists();
138 $mp = $this->movePageFactory->newMovePage( $fromTalk, $toTalk );
139 $status = $mp->moveIfAllowed(
142 !$params[
'noredirect'],
143 $params[
'tags'] ?: []
145 if ( $status->isOK() ) {
146 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
147 $r[
'talkto'] = $toTalk->getPrefixedText();
148 $r[
'talkmoveoverredirect'] = $toTalkExists;
158 if ( $params[
'movesubpages'] ) {
163 $params[
'noredirect'],
164 $params[
'tags'] ?: []
166 ApiResult::setIndexedTagName( $r[
'subpages'],
'subpage' );
168 if ( $params[
'movetalk'] && $toTalk ) {
173 $params[
'noredirect'],
174 $params[
'tags'] ?: []
176 ApiResult::setIndexedTagName( $r[
'subpages-talk'],
'subpage' );
180 $watch = $params[
'watchlist'] ??
'preferences';
184 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
185 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
198 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
201 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
203 $mp->moveSubpagesIfAllowed( $this->
getAuthority(), $reason, !$noredirect, $changeTags );
204 if ( !$result->isOK() ) {
211 foreach ( $result->getValue() as $oldTitle => $status ) {
213 $r = [
'from' => $oldTitle ];
214 if ( $status->isOK() ) {
215 $r[
'to'] = $status->getValue();
237 ParamValidator::PARAM_TYPE =>
'integer'
240 ParamValidator::PARAM_TYPE =>
'string',
241 ParamValidator::PARAM_REQUIRED =>
true
245 'movesubpages' =>
false,
246 'noredirect' =>
false,
254 'ignorewarnings' =>
false,
256 ParamValidator::PARAM_TYPE =>
'tags',
257 ParamValidator::PARAM_ISMULTI =>
true,
268 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
269 'reason=Misspelled%20title&movetalk=&noredirect='
270 =>
'apihelp-move-example-move',
275 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 0 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.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rename actions.