19 private $contentHandlerFactory;
22 private $contentModelChangeFactory;
36 parent::__construct( $main, $action );
37 $this->contentHandlerFactory = $contentHandlerFactory;
38 $this->contentModelChangeFactory = $contentModelChangeFactory;
47 $title = $wikiPage->getTitle();
51 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
54 $newModel = $params[
'model'];
57 $changer = $this->contentModelChangeFactory->newContentModelChange(
63 $changer->setMessagePrefix(
'apierror-' );
64 $permissionStatus = $changer->authorizeChange();
65 if ( !$permissionStatus->isGood() ) {
69 if ( $params[
'tags'] ) {
70 $tagStatus = $changer->setTags( $params[
'tags'] );
71 if ( !$tagStatus->isGood() ) {
78 $status = $changer->doContentModelChange(
87 if ( !$status->isGood() ) {
91 $logid = $status->getValue()[
'logid'];
94 'result' =>
'Success',
95 'title' =>
$title->getPrefixedText(),
96 'pageid' =>
$title->getArticleID(),
97 'contentmodel' =>
$title->getContentModel( Title::READ_LATEST ),
99 'revid' =>
$title->getLatestRevID( Title::READ_LATEST ),
106 $models = $this->contentHandlerFactory->getContentModels();
108 foreach ( $models as $model ) {
109 $handler = $this->contentHandlerFactory->getContentHandler( $model );
110 if ( !$handler->supportsDirectEditing() ) {
113 $modelOptions[] = $model;
118 ParamValidator::PARAM_TYPE =>
'string',
121 ParamValidator::PARAM_TYPE =>
'integer',
124 ParamValidator::PARAM_TYPE =>
'string',
127 ParamValidator::PARAM_TYPE =>
'tags',
128 ParamValidator::PARAM_ISMULTI =>
true,
131 ParamValidator::PARAM_TYPE => $modelOptions,
132 ParamValidator::PARAM_REQUIRED =>
true,
151 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
156 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
157 =>
'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)
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.
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.
Service for changing the content model of wiki pages.