Go to the documentation of this file.
42 parent::__construct( $mainModule, $moduleName );
46 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
47 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
58 if ( isset( $params[
'from'] ) ) {
60 if ( !$fromTitle || $fromTitle->isExternal() ) {
63 } elseif ( isset( $params[
'fromid'] ) ) {
66 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
70 if ( !$fromTitle->exists() ) {
73 $fromTalk = $fromTitle->getTalkPage();
76 if ( !$toTitle || $toTitle->isExternal() ) {
79 $toTalk = $toTitle->getTalkPageIfDefined();
81 $repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
82 if ( $toTitle->getNamespace() ===
NS_FILE
83 && !$repoGroup->getLocalRepo()->findFile( $toTitle )
84 && $repoGroup->findFile( $toTitle )
86 if ( !$params[
'ignorewarnings'] &&
88 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
90 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
95 if ( $user->pingLimiter(
'move' ) ) {
100 if ( $params[
'tags'] ) {
102 if ( !$ableToTag->isOK() ) {
108 $toTitleExists = $toTitle->exists();
109 $status = $this->
movePage( $fromTitle, $toTitle, $params[
'reason'], !$params[
'noredirect'],
110 $params[
'tags'] ?: [] );
111 if ( !$status->isOK() ) {
112 $user->spreadAnyEditBlock();
117 'from' => $fromTitle->getPrefixedText(),
118 'to' => $toTitle->getPrefixedText(),
119 'reason' => $params[
'reason']
126 $r[
'redirectcreated'] = $fromTitle->exists();
128 $r[
'moveoverredirect'] = $toTitleExists;
131 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
132 $toTalkExists = $toTalk->exists();
137 !$params[
'noredirect'],
138 $params[
'tags'] ?: []
140 if ( $status->isOK() ) {
141 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
142 $r[
'talkto'] = $toTalk->getPrefixedText();
143 $r[
'talkmoveoverredirect'] = $toTalkExists;
153 if ( $params[
'movesubpages'] ) {
158 $params[
'noredirect'],
159 $params[
'tags'] ?: []
163 if ( $params[
'movetalk'] ) {
168 $params[
'noredirect'],
169 $params[
'tags'] ?: []
175 $watch =
'preferences';
176 if ( isset( $params[
'watchlist'] ) ) {
177 $watch = $params[
'watchlist'];
182 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiry );
183 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiry );
197 $mp = $this->movePageFactory->newMovePage( $from, $to );
198 $valid = $mp->isValidMove();
199 if ( !$valid->isOK() ) {
204 $permStatus = $mp->checkPermissions( $user, $reason );
205 if ( !$permStatus->isOK() ) {
211 $createRedirect =
true;
214 return $mp->move( $user, $reason, $createRedirect, $changeTags );
225 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
228 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
230 $mp->moveSubpagesIfAllowed( $this->
getUser(), $reason, !$noredirect, $changeTags );
231 if ( !$result->isOK() ) {
238 foreach ( $result->getValue() as $oldTitle => $status ) {
240 $r = [
'from' => $oldTitle ];
241 if ( $status->isOK() ) {
242 $r[
'to'] = $status->getValue();
272 'movesubpages' =>
false,
273 'noredirect' =>
false,
281 'ignorewarnings' =>
false,
295 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
296 'reason=Misspelled%20title&movetalk=&noredirect='
297 =>
'apihelp-move-example-move',
302 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Move';
This is the main API class, used for both external and internal processing.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
needsToken()
Returns the token type this module requires in order to execute.
MovePageFactory $movePageFactory
moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags=[])
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
getResult()
Get the result object.
getUser()
Stable to override.
__construct(ApiMain $mainModule, $moduleName, MovePageFactory $movePageFactory)
This abstract class implements many basic API functions, and is the base of all API classes.
movePage(Title $from, Title $to, $reason, $createRedirect, $changeTags)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
isWriteMode()
Indicates whether this module requires write mode.
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.
getExamplesMessages()
Returns usage examples for this module.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
API Module to move pages.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getHelpUrls()
Return links to more detailed help pages about the module.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Represents a title within MediaWiki.
getWatchlistParams(array $watchOptions=[])
Get additional allow params specific to watchlisting.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
getModuleName()
Get the name of the module being executed by this instance.
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
getErrorFormatter()
Stable to override.