49 parent::__construct( $mainModule, $moduleName );
55 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
56 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
69 if ( isset( $params[
'from'] ) ) {
70 $fromTitle = Title::newFromText( $params[
'from'] );
71 if ( !$fromTitle || $fromTitle->isExternal() ) {
74 } elseif ( isset( $params[
'fromid'] ) ) {
75 $fromTitle = Title::newFromID( $params[
'fromid'] );
77 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
81 if ( !$fromTitle->exists() ) {
84 $fromTalk = $fromTitle->getTalkPage();
86 $toTitle = Title::newFromText( $params[
'to'] );
87 if ( !$toTitle || $toTitle->isExternal() ) {
90 $toTalk = $toTitle->getTalkPageIfDefined();
92 if ( $toTitle->getNamespace() ===
NS_FILE
93 && !$this->repoGroup->getLocalRepo()->findFile( $toTitle )
94 && $this->repoGroup->findFile( $toTitle )
96 if ( !$params[
'ignorewarnings'] &&
97 $this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
98 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
99 } elseif ( !$this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
100 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
105 if ( $user->pingLimiter(
'move' ) ) {
110 if ( $params[
'tags'] ) {
112 if ( !$ableToTag->isOK() ) {
118 $toTitleExists = $toTitle->exists();
119 $status = $this->
movePage( $fromTitle, $toTitle, $params[
'reason'], !$params[
'noredirect'],
120 $params[
'tags'] ?: [] );
121 if ( !$status->isOK() ) {
122 $user->spreadAnyEditBlock();
127 'from' => $fromTitle->getPrefixedText(),
128 'to' => $toTitle->getPrefixedText(),
129 'reason' => $params[
'reason']
136 $r[
'redirectcreated'] = $fromTitle->exists();
138 $r[
'moveoverredirect'] = $toTitleExists;
141 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
142 $toTalkExists = $toTalk->exists();
147 !$params[
'noredirect'],
148 $params[
'tags'] ?: []
150 if ( $status->isOK() ) {
151 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
152 $r[
'talkto'] = $toTalk->getPrefixedText();
153 $r[
'talkmoveoverredirect'] = $toTalkExists;
163 if ( $params[
'movesubpages'] ) {
168 $params[
'noredirect'],
169 $params[
'tags'] ?: []
171 ApiResult::setIndexedTagName( $r[
'subpages'],
'subpage' );
173 if ( $params[
'movetalk'] ) {
178 $params[
'noredirect'],
179 $params[
'tags'] ?: []
181 ApiResult::setIndexedTagName( $r[
'subpages-talk'],
'subpage' );
185 $watch =
'preferences';
186 if ( isset( $params[
'watchlist'] ) ) {
187 $watch = $params[
'watchlist'];
192 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
193 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
207 $mp = $this->movePageFactory->newMovePage( $from, $to );
208 $valid = $mp->isValidMove();
209 if ( !$valid->isOK() ) {
213 $permStatus = $mp->authorizeMove( $this->
getAuthority(), $reason );
214 if ( !$permStatus->isOK() ) {
215 return Status::wrap( $permStatus );
219 if ( !$this->
getAuthority()->isAllowed(
'suppressredirect' ) ) {
220 $createRedirect =
true;
223 return $mp->move( $this->
getUser(), $reason, $createRedirect, $changeTags );
234 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
237 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
239 $mp->moveSubpagesIfAllowed( $this->
getAuthority(), $reason, !$noredirect, $changeTags );
240 if ( !$result->isOK() ) {
247 foreach ( $result->getValue() as $oldTitle => $status ) {
249 $r = [
'from' => $oldTitle ];
250 if ( $status->isOK() ) {
251 $r[
'to'] = $status->getValue();
281 'movesubpages' =>
false,
282 'noredirect' =>
false,
290 'ignorewarnings' =>
false,
304 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
305 'reason=Misspelled%20title&movetalk=&noredirect='
306 =>
'apihelp-move-example-move',
311 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.
WatchlistManager $watchlistManager
UserOptionsLookup $userOptionsLookup
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.
MovePageFactory $movePageFactory
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...
Prioritized list of file repositories.
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...