MediaWiki  1.23.0
ApiMove.php
Go to the documentation of this file.
1 <?php
31 class ApiMove extends ApiBase {
32 
33  public function execute() {
34  $user = $this->getUser();
35  $params = $this->extractRequestParams();
36 
37  $this->requireOnlyOneParameter( $params, 'from', 'fromid' );
38 
39  if ( isset( $params['from'] ) ) {
40  $fromTitle = Title::newFromText( $params['from'] );
41  if ( !$fromTitle || $fromTitle->isExternal() ) {
42  $this->dieUsageMsg( array( 'invalidtitle', $params['from'] ) );
43  }
44  } elseif ( isset( $params['fromid'] ) ) {
45  $fromTitle = Title::newFromID( $params['fromid'] );
46  if ( !$fromTitle ) {
47  $this->dieUsageMsg( array( 'nosuchpageid', $params['fromid'] ) );
48  }
49  }
50 
51  if ( !$fromTitle->exists() ) {
52  $this->dieUsageMsg( 'notanarticle' );
53  }
54  $fromTalk = $fromTitle->getTalkPage();
55 
56  $toTitle = Title::newFromText( $params['to'] );
57  if ( !$toTitle || $toTitle->isExternal() ) {
58  $this->dieUsageMsg( array( 'invalidtitle', $params['to'] ) );
59  }
60  $toTalk = $toTitle->getTalkPage();
61 
62  if ( $toTitle->getNamespace() == NS_FILE
63  && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle )
64  && wfFindFile( $toTitle )
65  ) {
66  if ( !$params['ignorewarnings'] && $user->isAllowed( 'reupload-shared' ) ) {
67  $this->dieUsageMsg( 'sharedfile-exists' );
68  } elseif ( !$user->isAllowed( 'reupload-shared' ) ) {
69  $this->dieUsageMsg( 'cantoverwrite-sharedfile' );
70  }
71  }
72 
73  // Move the page
74  $toTitleExists = $toTitle->exists();
75  $retval = $fromTitle->moveTo( $toTitle, true, $params['reason'], !$params['noredirect'] );
76  if ( $retval !== true ) {
77  $this->dieUsageMsg( reset( $retval ) );
78  }
79 
80  $r = array(
81  'from' => $fromTitle->getPrefixedText(),
82  'to' => $toTitle->getPrefixedText(),
83  'reason' => $params['reason']
84  );
85 
86  if ( $fromTitle->exists() ) {
87  //NOTE: we assume that if the old title exists, it's because it was re-created as
88  // a redirect to the new title. This is not safe, but what we did before was
89  // even worse: we just determined whether a redirect should have been created,
90  // and reported that it was created if it should have, without any checks.
91  // Also note that isRedirect() is unreliable because of bug 37209.
92  $r['redirectcreated'] = '';
93  }
94 
95  if ( $toTitleExists ) {
96  $r['moveoverredirect'] = '';
97  }
98 
99  // Move the talk page
100  if ( $params['movetalk'] && $fromTalk->exists() && !$fromTitle->isTalkPage() ) {
101  $toTalkExists = $toTalk->exists();
102  $retval = $fromTalk->moveTo( $toTalk, true, $params['reason'], !$params['noredirect'] );
103  if ( $retval === true ) {
104  $r['talkfrom'] = $fromTalk->getPrefixedText();
105  $r['talkto'] = $toTalk->getPrefixedText();
106  if ( $toTalkExists ) {
107  $r['talkmoveoverredirect'] = '';
108  }
109  } else {
110  // We're not gonna dieUsage() on failure, since we already changed something
111  $parsed = $this->parseMsg( reset( $retval ) );
112  $r['talkmove-error-code'] = $parsed['code'];
113  $r['talkmove-error-info'] = $parsed['info'];
114  }
115  }
116 
117  $result = $this->getResult();
118 
119  // Move subpages
120  if ( $params['movesubpages'] ) {
121  $r['subpages'] = $this->moveSubpages( $fromTitle, $toTitle,
122  $params['reason'], $params['noredirect'] );
123  $result->setIndexedTagName( $r['subpages'], 'subpage' );
124 
125  if ( $params['movetalk'] ) {
126  $r['subpages-talk'] = $this->moveSubpages( $fromTalk, $toTalk,
127  $params['reason'], $params['noredirect'] );
128  $result->setIndexedTagName( $r['subpages-talk'], 'subpage' );
129  }
130  }
131 
132  $watch = 'preferences';
133  if ( isset( $params['watchlist'] ) ) {
134  $watch = $params['watchlist'];
135  } elseif ( $params['watch'] ) {
136  $watch = 'watch';
137  } elseif ( $params['unwatch'] ) {
138  $watch = 'unwatch';
139  }
140 
141  // Watch pages
142  $this->setWatch( $watch, $fromTitle, 'watchmoves' );
143  $this->setWatch( $watch, $toTitle, 'watchmoves' );
144 
145  $result->addValue( null, $this->getModuleName(), $r );
146  }
147 
155  public function moveSubpages( $fromTitle, $toTitle, $reason, $noredirect ) {
156  $retval = array();
157  $success = $fromTitle->moveSubpages( $toTitle, true, $reason, !$noredirect );
158  if ( isset( $success[0] ) ) {
159  return array( 'error' => $this->parseMsg( $success ) );
160  }
161 
162  // At least some pages could be moved
163  // Report each of them separately
164  foreach ( $success as $oldTitle => $newTitle ) {
165  $r = array( 'from' => $oldTitle );
166  if ( is_array( $newTitle ) ) {
167  $r['error'] = $this->parseMsg( reset( $newTitle ) );
168  } else {
169  // Success
170  $r['to'] = $newTitle;
171  }
172  $retval[] = $r;
173  }
174 
175  return $retval;
176  }
177 
178  public function mustBePosted() {
179  return true;
180  }
181 
182  public function isWriteMode() {
183  return true;
184  }
185 
186  public function getAllowedParams() {
187  return array(
188  'from' => null,
189  'fromid' => array(
190  ApiBase::PARAM_TYPE => 'integer'
191  ),
192  'to' => array(
193  ApiBase::PARAM_TYPE => 'string',
195  ),
196  'token' => array(
197  ApiBase::PARAM_TYPE => 'string',
199  ),
200  'reason' => '',
201  'movetalk' => false,
202  'movesubpages' => false,
203  'noredirect' => false,
204  'watch' => array(
205  ApiBase::PARAM_DFLT => false,
207  ),
208  'unwatch' => array(
209  ApiBase::PARAM_DFLT => false,
211  ),
212  'watchlist' => array(
213  ApiBase::PARAM_DFLT => 'preferences',
215  'watch',
216  'unwatch',
217  'preferences',
218  'nochange'
219  ),
220  ),
221  'ignorewarnings' => false
222  );
223  }
224 
225  public function getParamDescription() {
226  $p = $this->getModulePrefix();
227 
228  return array(
229  'from' => "Title of the page you want to move. Cannot be used together with {$p}fromid",
230  'fromid' => "Page ID of the page you want to move. Cannot be used together with {$p}from",
231  'to' => 'Title you want to rename the page to',
232  'token' => 'A move token previously retrieved through prop=info',
233  'reason' => 'Reason for the move',
234  'movetalk' => 'Move the talk page, if it exists',
235  'movesubpages' => 'Move subpages, if applicable',
236  'noredirect' => 'Don\'t create a redirect',
237  'watch' => 'Add the page and the redirect to your watchlist',
238  'unwatch' => 'Remove the page and the redirect from your watchlist',
239  'watchlist' => 'Unconditionally add or remove the page from your ' .
240  'watchlist, use preferences or do not change watch',
241  'ignorewarnings' => 'Ignore any warnings'
242  );
243  }
244 
245  public function getResultProperties() {
246  return array(
247  '' => array(
248  'from' => 'string',
249  'to' => 'string',
250  'reason' => 'string',
251  'redirectcreated' => 'boolean',
252  'moveoverredirect' => 'boolean',
253  'talkfrom' => array(
254  ApiBase::PROP_TYPE => 'string',
255  ApiBase::PROP_NULLABLE => true
256  ),
257  'talkto' => array(
258  ApiBase::PROP_TYPE => 'string',
259  ApiBase::PROP_NULLABLE => true
260  ),
261  'talkmoveoverredirect' => 'boolean',
262  'talkmove-error-code' => array(
263  ApiBase::PROP_TYPE => 'string',
264  ApiBase::PROP_NULLABLE => true
265  ),
266  'talkmove-error-info' => array(
267  ApiBase::PROP_TYPE => 'string',
268  ApiBase::PROP_NULLABLE => true
269  )
270  )
271  );
272  }
273 
274  public function getDescription() {
275  return 'Move a page.';
276  }
277 
278  public function getPossibleErrors() {
279  return array_merge( parent::getPossibleErrors(),
280  $this->getRequireOnlyOneParameterErrorMessages( array( 'from', 'fromid' ) ),
281  array(
282  array( 'invalidtitle', 'from' ),
283  array( 'nosuchpageid', 'fromid' ),
284  array( 'notanarticle' ),
285  array( 'invalidtitle', 'to' ),
286  array( 'sharedfile-exists' ),
287  )
288  );
289  }
290 
291  public function needsToken() {
292  return true;
293  }
294 
295  public function getTokenSalt() {
296  return '';
297  }
298 
299  public function getExamples() {
300  return array(
301  'api.php?action=move&from=Badtitle&to=Goodtitle&token=123ABC&' .
302  'reason=Misspelled%20title&movetalk=&noredirect='
303  );
304  }
305 
306  public function getHelpUrls() {
307  return 'https://www.mediawiki.org/wiki/API:Move';
308  }
309 }
ApiMove\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiMove.php:245
ApiMove\getTokenSalt
getTokenSalt()
Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the mo...
Definition: ApiMove.php:295
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:53
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiMove\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiMove.php:225
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
Definition: ApiBase.php:62
ApiMove\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiMove.php:274
ApiMove\needsToken
needsToken()
Returns whether this module requires a token to execute It is used to show possible errors in action=...
Definition: ApiMove.php:291
ApiBase\parseMsg
parseMsg( $error)
Return the error message related to a certain array.
Definition: ApiBase.php:1978
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1929
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
NS_FILE
const NS_FILE
Definition: Defines.php:85
$params
$params
Definition: styleTest.css.php:40
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiMove\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiMove.php:186
ApiMove\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiMove.php:299
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
Definition: ApiBase.php:60
$success
$success
Definition: Utf8Test.php:91
ApiMove\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiMove.php:182
$oldTitle
versus $oldTitle
Definition: globals.txt:16
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiBase\getRequireOnlyOneParameterErrorMessages
getRequireOnlyOneParameterErrorMessages( $params)
Generates the possible errors requireOnlyOneParameter() can die with.
Definition: ApiBase.php:748
ApiBase\PROP_TYPE
const PROP_TYPE
Definition: ApiBase.php:74
ApiMove
API Module to move pages.
Definition: ApiMove.php:31
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:165
ApiBase\setWatch
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
Definition: ApiBase.php:952
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
ApiBase\requireOnlyOneParameter
requireOnlyOneParameter( $params)
Die if none or more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:722
ApiBase\PROP_NULLABLE
const PROP_NULLABLE
Definition: ApiBase.php:76
ApiMove\getHelpUrls
getHelpUrls()
Definition: ApiMove.php:306
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
ApiMove\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiMove.php:33
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
wfFindFile
wfFindFile( $title, $options=array())
Find a file.
Definition: GlobalFunctions.php:3693
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiMove\getPossibleErrors
getPossibleErrors()
Returns a list of all possible errors returned by the module.
Definition: ApiMove.php:278
ApiMove\moveSubpages
moveSubpages( $fromTitle, $toTitle, $reason, $noredirect)
Definition: ApiMove.php:155
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:297
ApiMove\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiMove.php:178
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237