75 $this->contentHandlerFactory = $contentHandlerFactory;
76 $this->hookRunner =
new HookRunner( $hookContainer );
77 $this->permManager = $permManager;
78 $this->revLookup = $revLookup;
82 $this->newModel = $newModel;
90 $this->logAction =
'';
93 $this->msgPrefix =
'';
112 $current = $this->page->getTitle();
113 $titleWithNewContentModel = clone $current;
114 $titleWithNewContentModel->setContentModel( $this->newModel );
116 $pm = $this->permManager;
118 $creationErrors = [];
119 if ( !$current->exists() ) {
120 $creationErrors = $pm->getPermissionErrors(
'create',
$user, $current );
127 $pm->getPermissionErrors(
'editcontentmodel',
$user, $current ),
129 $pm->getPermissionErrors(
'edit',
$user, $current ),
131 $pm->getPermissionErrors(
'editcontentmodel',
$user, $titleWithNewContentModel ),
133 $pm->getPermissionErrors(
'edit',
$user, $titleWithNewContentModel )
147 if ( $tagStatus->isOK() ) {
149 return Status::newGood();
163 $title = $this->page->getTitle();
164 $latestRevRecord = $this->revLookup->getRevisionByTitle(
$title );
166 if ( $latestRevRecord ) {
167 $latestContent = $latestRevRecord->getContent( SlotRecord::MAIN );
169 $latestModel = $latestContent->getModel();
170 if ( !$latestHandler->supportsDirectEditing() ) {
172 return Status::newFatal(
173 'apierror-changecontentmodel-nodirectediting',
174 ContentHandler::getLocalizedName( $latestModel )
181 return Status::newFatal(
'apierror-nochanges' );
184 if ( !$newHandler->canBeUsedOn(
$title ) ) {
186 return Status::newFatal(
187 'apierror-changecontentmodel-cannotbeused',
188 ContentHandler::getLocalizedName(
$newModel ),
195 $latestContent->serialize()
200 return Status::newFatal(
201 $this->msgPrefix .
'changecontentmodel-cannot-convert',
203 ContentHandler::getLocalizedName(
$newModel )
206 $this->latestRevId = $latestRevRecord->getId();
207 $this->logAction =
'change';
212 ->makeEmptyContent();
213 $this->latestRevId =
false;
214 $this->logAction =
'new';
217 return Status::newGood();
237 if ( !$status->isGood() ) {
251 $log->setPerformer(
$user );
252 $log->setTarget(
$title );
253 $log->setComment( $comment );
254 $log->setParameters( [
255 '4::oldmodel' =>
$title->getContentModel(),
256 '5::newmodel' => $this->newModel
258 $log->addTags( $this->tags );
261 $formatter->setContext( RequestContext::newExtraneousContext(
$title ) );
262 $reason = $formatter->getPlainActionText();
264 if ( $comment !==
'' ) {
265 $reason .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $comment;
270 $derivativeContext->setTitle(
$title );
271 $derivativeContext->setWikiPage(
$page );
276 if ( !$this->hookRunner->onEditFilterMergedContent( $derivativeContext,
$newContent,
277 $status, $reason,
$user,
false )
279 if ( $status->isGood() ) {
281 $status->fatal(
'hookaborted' );
285 if ( !$status->isOK() ) {
286 if ( !$status->getErrors() ) {
287 $status->fatal(
'hookaborted' );
295 if ( $bot && $this->permManager->userHasRight(
$user,
'bot' ) ) {
309 if ( !$status->isOK() ) {
313 $logid = $log->insert();
314 $log->publish( $logid );
320 return Status::newGood( $values );
wfMergeErrorArrays(... $args)
Merge arrays in the style of PermissionManager::getPermissionErrors, with duplicate removal e....
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Helper class to change the content model of pages.
User $user
user making the change
createNewContent()
Create the new content.
string[] $tags
tags to add
IContentHandlerFactory $contentHandlerFactory
doContentModelChange(IContextSource $context, $comment, $bot)
Handle change and logging after validatio.
checkPermissions()
Check user can edit and editcontentmodel before and after.
string $msgPrefix
'apierror-' or empty string, for status messages
string $logAction
'new' or 'change'
PermissionManager $permManager
RevisionLookup $revLookup
setMessagePrefix( $msgPrefix)
Set the message prefix.
__construct(IContentHandlerFactory $contentHandlerFactory, HookContainer $hookContainer, PermissionManager $permManager, RevisionLookup $revLookup, User $user, WikiPage $page, string $newModel)
setTags( $tags)
Specify the tags the user wants to add, and check permissions.
int false $latestRevId
latest revision id, or false if creating
An IContextSource implementation which will inherit context from another source but allow individual ...
Class for creating new log entries and inserting them into the database.
static plaintextParam( $plaintext)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Show an error when the user hits a rate limit.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
pingLimiter( $action='edit', $incrBy=1)
Primitive rate limits: enforce maximum actions per time period to put a brake on flooding.
Class representing a MediaWiki article and history.
doEditContent(Content $content, $summary, $flags=0, $originalRevId=false, User $user=null, $serialFormat=null, $tags=[], $undidRevId=0)
Change an existing article or create a new article.
getTitle()
Get the title object of the article.
Base interface for content objects.
Interface for objects which can provide a MediaWiki context on request.
getContentHandler(string $modelID)
Returns a ContentHandler instance for the given $modelID.