30 parent::__construct( $main, $action );
31 $this->contentHandlerFactory = $contentHandlerFactory;
32 $this->contentModelChangeFactory = $contentModelChangeFactory;
41 $title = $wikiPage->getTitle();
44 if ( !$title->exists() ) {
45 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
51 $changer = $this->contentModelChangeFactory->newContentModelChange(
57 $changer->setMessagePrefix(
'apierror-' );
58 $permissionStatus = $changer->authorizeChange();
59 if ( !$permissionStatus->isGood() ) {
64 $tagStatus = $changer->setTags(
$params[
'tags'] );
65 if ( !$tagStatus->isGood() ) {
71 $status = $changer->doContentModelChange(
77 if ( !$status->isGood() ) {
81 $logid = $status->getValue()[
'logid'];
84 'result' =>
'Success',
85 'title' => $title->getPrefixedText(),
86 'pageid' => $title->getArticleID(),
87 'contentmodel' => $title->getContentModel( IDBAccessObject::READ_LATEST ),
89 'revid' => $title->getLatestRevID( IDBAccessObject::READ_LATEST ),
96 $models = $this->contentHandlerFactory->getContentModels();
98 foreach ( $models as $model ) {
99 $handler = $this->contentHandlerFactory->getContentHandler( $model );
100 if ( !$handler->supportsDirectEditing() ) {
103 $modelOptions[] = $model;
108 ParamValidator::PARAM_TYPE =>
'string',
111 ParamValidator::PARAM_TYPE =>
'integer',
114 ParamValidator::PARAM_TYPE =>
'string',
117 ParamValidator::PARAM_TYPE =>
'tags',
118 ParamValidator::PARAM_ISMULTI =>
true,
121 ParamValidator::PARAM_TYPE => $modelOptions,
122 ParamValidator::PARAM_REQUIRED =>
true,
141 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
146 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
147 =>
'apihelp-changecontentmodel-example'
153class_alias( ApiChangeContentModel::class,
'ApiChangeContentModel' );
array $params
The job parameters.
Api module to change the content model of existing pages.
mustBePosted()
Indicates whether this module must be called with a POST request.
getExamplesMessages()
Returns usage examples for this module.
execute()
A lot of this code is based on SpecialChangeContentModel.
getHelpUrls()
Return links to more detailed help pages about the module.
needsToken()
Returns the token type this module requires in order to execute.
__construct(ApiMain $main, string $action, IContentHandlerFactory $contentHandlerFactory, ContentModelChangeFactory $contentModelChangeFactory)
isWriteMode()
Indicates whether this module requires write access to the wiki.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
This is the main API class, used for both external and internal processing.
Service for changing the content model of wiki pages.