35 parent::__construct( $main, $action );
46 $title = $wikiPage->getTitle();
50 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
53 $newModel = $params[
'model'];
56 $changer = $this->contentModelChangeFactory->newContentModelChange(
62 $changer->setMessagePrefix(
'apierror-' );
63 $permissionStatus = $changer->authorizeChange();
64 if ( !$permissionStatus->isGood() ) {
68 if ( $params[
'tags'] ) {
69 $tagStatus = $changer->setTags( $params[
'tags'] );
70 if ( !$tagStatus->isGood() ) {
77 $status = $changer->doContentModelChange(
86 if ( !$status->isGood() ) {
90 $logid = $status->getValue()[
'logid'];
93 'result' =>
'Success',
94 'title' =>
$title->getPrefixedText(),
95 'pageid' =>
$title->getArticleID(),
96 'contentmodel' =>
$title->getContentModel( Title::READ_LATEST ),
98 'revid' =>
$title->getLatestRevID( Title::READ_LATEST ),
105 $models = $this->contentHandlerFactory->getContentModels();
107 foreach ( $models as $model ) {
108 $handler = $this->contentHandlerFactory->getContentHandler( $model );
109 if ( !$handler->supportsDirectEditing() ) {
112 $modelOptions[] = $model;
148 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
153 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
154 =>
'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.
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.
__construct(ApiMain $main, $action, IContentHandlerFactory $contentHandlerFactory, ContentModelChangeFactory $contentModelChangeFactory)
ContentModelChangeFactory $contentModelChangeFactory
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.
isWriteMode()
Indicates whether this module requires write mode.
IContentHandlerFactory $contentHandlerFactory
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
This is the main API class, used for both external and internal processing.
getContext()
Get the base IContextSource object.
Show an error when the user hits a rate limit.