33 parent::__construct( $main, $action );
34 $this->contentHandlerFactory = $contentHandlerFactory;
35 $this->contentModelChangeFactory = $contentModelChangeFactory;
44 $title = $wikiPage->getTitle();
47 if ( !$title->exists() ) {
48 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
54 $changer = $this->contentModelChangeFactory->newContentModelChange(
60 $changer->setMessagePrefix(
'apierror-' );
61 $permissionStatus = $changer->authorizeChange();
62 if ( !$permissionStatus->isGood() ) {
67 $tagStatus = $changer->setTags(
$params[
'tags'] );
68 if ( !$tagStatus->isGood() ) {
74 $status = $changer->doContentModelChange(
80 if ( !$status->isGood() ) {
84 $logid = $status->getValue()[
'logid'];
87 'result' =>
'Success',
88 'title' => $title->getPrefixedText(),
89 'pageid' => $title->getArticleID(),
90 'contentmodel' => $title->getContentModel( IDBAccessObject::READ_LATEST ),
92 'revid' => $title->getLatestRevID( IDBAccessObject::READ_LATEST ),
99 $models = $this->contentHandlerFactory->getContentModels();
101 foreach ( $models as $model ) {
102 $handler = $this->contentHandlerFactory->getContentHandler( $model );
103 if ( !$handler->supportsDirectEditing() ) {
106 $modelOptions[] = $model;
111 ParamValidator::PARAM_TYPE =>
'string',
114 ParamValidator::PARAM_TYPE =>
'integer',
117 ParamValidator::PARAM_TYPE =>
'string',
120 ParamValidator::PARAM_TYPE =>
'tags',
121 ParamValidator::PARAM_ISMULTI =>
true,
124 ParamValidator::PARAM_TYPE => $modelOptions,
125 ParamValidator::PARAM_REQUIRED =>
true,
144 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
149 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
150 =>
'apihelp-changecontentmodel-example'
array $params
The job parameters.
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)
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)
Attempts to load a WikiPage object from a title or pageid parameter, 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.
Service for changing the content model of wiki pages.