20 private $contentHandlerFactory;
23 private $contentModelChangeFactory;
37 parent::__construct( $main, $action );
38 $this->contentHandlerFactory = $contentHandlerFactory;
39 $this->contentModelChangeFactory = $contentModelChangeFactory;
48 $title = $wikiPage->getTitle();
52 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
55 $newModel = $params[
'model'];
58 $changer = $this->contentModelChangeFactory->newContentModelChange(
64 $changer->setMessagePrefix(
'apierror-' );
65 $permissionStatus = $changer->authorizeChange();
66 if ( !$permissionStatus->isGood() ) {
70 if ( $params[
'tags'] ) {
71 $tagStatus = $changer->setTags( $params[
'tags'] );
72 if ( !$tagStatus->isGood() ) {
79 $status = $changer->doContentModelChange(
88 if ( !$status->isGood() ) {
92 $logid = $status->getValue()[
'logid'];
95 'result' =>
'Success',
96 'title' =>
$title->getPrefixedText(),
97 'pageid' =>
$title->getArticleID(),
98 'contentmodel' =>
$title->getContentModel( Title::READ_LATEST ),
100 'revid' =>
$title->getLatestRevID( Title::READ_LATEST ),
107 $models = $this->contentHandlerFactory->getContentModels();
109 foreach ( $models as $model ) {
110 $handler = $this->contentHandlerFactory->getContentHandler( $model );
111 if ( !$handler->supportsDirectEditing() ) {
114 $modelOptions[] = $model;
119 ParamValidator::PARAM_TYPE =>
'string',
122 ParamValidator::PARAM_TYPE =>
'integer',
125 ParamValidator::PARAM_TYPE =>
'string',
128 ParamValidator::PARAM_TYPE =>
'tags',
129 ParamValidator::PARAM_ISMULTI =>
true,
132 ParamValidator::PARAM_TYPE => $modelOptions,
133 ParamValidator::PARAM_REQUIRED =>
true,
152 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
157 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
158 =>
'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.