42 parent::__construct( $mainModule, $moduleName );
44 $this->movePageFactory = $movePageFactory;
45 $this->repoGroup = $repoGroup;
49 $this->watchlistMaxDuration =
51 $this->watchlistManager = $watchlistManager;
52 $this->watchedItemStore = $watchedItemStore;
53 $this->userOptionsLookup = $userOptionsLookup;
64 if ( isset( $params[
'from'] ) ) {
65 $fromTitle = Title::newFromText( $params[
'from'] );
66 if ( !$fromTitle || $fromTitle->isExternal() ) {
69 } elseif ( isset( $params[
'fromid'] ) ) {
70 $fromTitle = Title::newFromID( $params[
'fromid'] );
72 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
'fromid'] ] );
75 throw new LogicException(
'Unreachable due to requireOnlyOneParameter' );
78 if ( !$fromTitle->exists() ) {
81 $fromTalk = $fromTitle->getTalkPage();
83 $toTitle = Title::newFromText( $params[
'to'] );
84 if ( !$toTitle || $toTitle->isExternal() ) {
87 $toTalk = $toTitle->getTalkPageIfDefined();
89 if ( $toTitle->getNamespace() ===
NS_FILE
90 && !$this->repoGroup->getLocalRepo()->findFile( $toTitle )
91 && $this->repoGroup->findFile( $toTitle )
93 if ( !$params[
'ignorewarnings'] &&
94 $this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
95 $this->
dieWithError(
'apierror-fileexists-sharedrepo-perm' );
96 } elseif ( !$this->
getAuthority()->isAllowed(
'reupload-shared' ) ) {
97 $this->
dieWithError(
'apierror-cantoverwrite-sharedfile' );
102 $toTitleExists = $toTitle->exists();
103 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
104 $status = $mp->moveIfAllowed(
107 !$params[
'noredirect'],
108 $params[
'tags'] ?: []
110 if ( !$status->isOK() ) {
115 'from' => $fromTitle->getPrefixedText(),
116 'to' => $toTitle->getPrefixedText(),
117 'reason' => $params[
'reason']
124 $r[
'redirectcreated'] = $fromTitle->exists();
126 $r[
'moveoverredirect'] = $toTitleExists;
129 if ( $params[
'movetalk'] && $toTalk && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
130 $toTalkExists = $toTalk->exists();
131 $mp = $this->movePageFactory->newMovePage( $fromTalk, $toTalk );
132 $status = $mp->moveIfAllowed(
135 !$params[
'noredirect'],
136 $params[
'tags'] ?: []
138 if ( $status->isOK() ) {
139 $r[
'talkfrom'] = $fromTalk->getPrefixedText();
140 $r[
'talkto'] = $toTalk->getPrefixedText();
141 $r[
'talkmoveoverredirect'] = $toTalkExists;
151 if ( $params[
'movesubpages'] ) {
156 $params[
'noredirect'],
157 $params[
'tags'] ?: []
161 if ( $params[
'movetalk'] && $toTalk ) {
166 $params[
'noredirect'],
167 $params[
'tags'] ?: []
173 $watch = $params[
'watchlist'] ??
'preferences';
178 $this->
setWatch( $watch, $fromTitle, $user,
'watchmoves', $watchlistExpiryFrom );
179 $this->
setWatch( $watch, $toTitle, $user,
'watchmoves', $watchlistExpiryTo );
192 public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect, $changeTags = [] ) {
195 $mp = $this->movePageFactory->newMovePage( $fromTitle, $toTitle );
197 $mp->moveSubpagesIfAllowed( $this->
getAuthority(), $reason, !$noredirect, $changeTags );
198 if ( !$result->isOK() ) {
205 foreach ( $result->getValue() as $oldTitle => $status ) {
207 $r = [
'from' => $oldTitle ];
208 if ( $status->isOK() ) {
209 $r[
'to'] = $status->getValue();
234 ParamValidator::PARAM_TYPE =>
'integer'
237 ParamValidator::PARAM_TYPE =>
'string',
238 ParamValidator::PARAM_REQUIRED => true
242 'movesubpages' =>
false,
243 'noredirect' =>
false,
251 'ignorewarnings' =>
false,
253 ParamValidator::PARAM_TYPE =>
'tags',
254 ParamValidator::PARAM_ISMULTI =>
true,
267 'action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
268 'reason=Misspelled%20title&movetalk=&noredirect='
269 =>
'apihelp-move-example-move',
275 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Move';
280class_alias( ApiMove::class,
'ApiMove' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page rename actions.