27 parent::__construct( $main, $action );
36 $title = $wikiPage->getTitle();
39 if ( !$title->exists() ) {
40 $this->
dieWithError(
'apierror-changecontentmodel-missingtitle' );
43 $newModel = $params[
'model'];
46 $changer = $this->contentModelChangeFactory->newContentModelChange(
52 $changer->setMessagePrefix(
'apierror-' );
53 $permissionStatus = $changer->authorizeChange();
54 if ( !$permissionStatus->isGood() ) {
58 if ( $params[
'tags'] ) {
59 $tagStatus = $changer->setTags( $params[
'tags'] );
60 if ( !$tagStatus->isGood() ) {
66 $status = $changer->doContentModelChange(
68 $params[
'summary'] ??
'',
72 if ( !$status->isGood() ) {
76 $logid = $status->getValue()[
'logid'];
79 'result' =>
'Success',
80 'title' => $title->getPrefixedText(),
81 'pageid' => $title->getArticleID(),
82 'contentmodel' => $title->getContentModel( IDBAccessObject::READ_LATEST ),
84 'revid' => $title->getLatestRevID( IDBAccessObject::READ_LATEST ),
92 $models = $this->contentHandlerFactory->getContentModels();
94 foreach ( $models as $model ) {
95 $handler = $this->contentHandlerFactory->getContentHandler( $model );
96 if ( !$handler->supportsDirectEditing() ) {
99 $modelOptions[] = $model;
104 ParamValidator::PARAM_TYPE =>
'string',
107 ParamValidator::PARAM_TYPE =>
'integer',
110 ParamValidator::PARAM_TYPE =>
'string',
113 ParamValidator::PARAM_TYPE =>
'tags',
114 ParamValidator::PARAM_ISMULTI =>
true,
117 ParamValidator::PARAM_TYPE => $modelOptions,
118 ParamValidator::PARAM_REQUIRED =>
true,
141 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
147 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
148 =>
'apihelp-changecontentmodel-example'
154class_alias( ApiChangeContentModel::class,
'ApiChangeContentModel' );
Api module to change the content model of existing pages.
mustBePosted()
Indicates whether this module must be called with a POST request.Implementations of this method must ...
__construct(ApiMain $main, string $action, private readonly IContentHandlerFactory $contentHandlerFactory, private readonly ContentModelChangeFactory $contentModelChangeFactory,)
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
execute()
A lot of this code is based on SpecialChangeContentModel.
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
needsToken()
Returns the token type this module requires in order to execute.Modules are strongly encouraged to us...
isWriteMode()
Indicates whether this module requires write access to the wiki.API modules must override this method...
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.