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' );
48 $newModel = $params[
'model'];
51 $changer = $this->contentModelChangeFactory->newContentModelChange(
57 $changer->setMessagePrefix(
'apierror-' );
58 $permissionStatus = $changer->authorizeChange();
59 if ( !$permissionStatus->isGood() ) {
63 if ( $params[
'tags'] ) {
64 $tagStatus = $changer->setTags( $params[
'tags'] );
65 if ( !$tagStatus->isGood() ) {
71 $status = $changer->doContentModelChange(
73 $params[
'summary'] ??
'',
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 ),
97 $models = $this->contentHandlerFactory->getContentModels();
99 foreach ( $models as $model ) {
100 $handler = $this->contentHandlerFactory->getContentHandler( $model );
101 if ( !$handler->supportsDirectEditing() ) {
104 $modelOptions[] = $model;
109 ParamValidator::PARAM_TYPE =>
'string',
112 ParamValidator::PARAM_TYPE =>
'integer',
115 ParamValidator::PARAM_TYPE =>
'string',
118 ParamValidator::PARAM_TYPE =>
'tags',
119 ParamValidator::PARAM_ISMULTI =>
true,
122 ParamValidator::PARAM_TYPE => $modelOptions,
123 ParamValidator::PARAM_REQUIRED =>
true,
146 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Help:ChangeContentModel';
152 'action=changecontentmodel&title=Main Page&model=text&token=123ABC'
153 =>
'apihelp-changecontentmodel-example'
159class_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 ...
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...
__construct(ApiMain $main, string $action, IContentHandlerFactory $contentHandlerFactory, ContentModelChangeFactory $contentModelChangeFactory)
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.