22 $title = $wikiPage->getTitle();
25 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
29 $newModel = $params[
'model'];
33 $changer = MediaWikiServices::getInstance()
34 ->getContentModelChangeFactory()
35 ->newContentModelChange(
41 $changer->setMessagePrefix(
'apierror-' );
42 $errors = $changer->checkPermissions();
43 if ( $errors !== [] ) {
47 if ( $params[
'tags'] ) {
48 $tagStatus = $changer->setTags( $params[
'tags'] );
49 if ( !$tagStatus->isGood() ) {
56 $status = $changer->doContentModelChange(
65 if ( !$status->isGood() ) {
69 $logid = $status->getValue()[
'logid'];
72 'result' =>
'Success',
73 'title' =>
$title->getPrefixedText(),
74 'pageid' =>
$title->getArticleID(),
75 'contentmodel' =>
$title->getContentModel( Title::READ_LATEST ),
77 'revid' =>
$title->getLatestRevID( Title::READ_LATEST ),
84 $models = ContentHandler::getContentModels();
86 foreach ( $models as $model ) {
87 $handler = ContentHandler::getForModelID( $model );
88 if ( !$handler->supportsDirectEditing() ) {
91 $modelOptions[] = $model;
127 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
132 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
133 =>
'apihelp-changecontentmodel-example'
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.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
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.
getTitleOrPageId( $params, $load=false)
Get a WikiPage object from a title or pageid param, if possible.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Api module to change the content model of existing pages.
execute()
A lot of this code is based on SpecialChangeContentModel.
needsToken()
Returns the token type this module requires in order to execute.
getHelpUrls()
Return links to more detailed help pages about the module.
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
isWriteMode()
Indicates whether this module requires write mode.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
getUser()
Stable to override.
getContext()
Get the base IContextSource object.
static plaintextParam( $plaintext)
Show an error when the user hits a rate limit.