8 parent::__construct(
'ChangeContentModel',
'editcontentmodel' );
41 $contentModelLogPage =
new LogPage(
'contentmodel' );
42 $text = Xml::element(
'h2',
null, $contentModelLogPage->getName()->text() );
55 if ( !$this->title ) {
73 $titleObj = Title::newFromTextThrow(
$title );
75 $this->oldRevision = Revision::newFromTitle( $titleObj ) ?:
false;
77 if ( $this->oldRevision ) {
78 $oldContent = $this->oldRevision->getContent();
79 if ( !$oldContent->getContentHandler()->supportsDirectEditing() ) {
80 return $this->
msg(
'changecontentmodel-nodirectediting' )
81 ->params( ContentHandler::getLocalizedName( $oldContent->getModel() ) )
94 'name' =>
'pagetitle',
96 'label-message' =>
'changecontentmodel-title-label',
97 'validation-callback' => [ $this,
'validateTitle' ],
100 if ( $this->title ) {
102 if ( empty( $options ) ) {
104 'changecontentmodel-emptymodels-title',
105 'changecontentmodel-emptymodels-text',
106 [ $this->title->getPrefixedText() ]
109 $fields[
'pagetitle'][
'readonly'] =
true;
113 'name' =>
'currentcontentmodel',
114 'default' => $this->title->getContentModel(),
115 'label-message' =>
'changecontentmodel-current-label',
121 'options' => $options,
122 'label-message' =>
'changecontentmodel-model-label'
127 'validation-callback' =>
function ( $reason ) {
130 return $this->
msg(
'spamprotectionmatch', $match )->parse();
135 'label-message' =>
'changecontentmodel-reason-label',
144 $models = ContentHandler::getContentModels();
146 foreach ( $models as $model ) {
147 $handler = ContentHandler::getForModelID( $model );
148 if ( !$handler->supportsDirectEditing() ) {
155 if ( !$handler->canBeUsedOn(
$title ) ) {
159 $options[ContentHandler::getLocalizedName( $model )] = $model;
166 if ( $data[
'pagetitle'] ===
'' ) {
174 throw new RuntimeException(
"Form submission was not POSTed" );
177 $this->title = Title::newFromText( $data[
'pagetitle'] );
184 $this->title->getUserPermissionsErrors(
'editcontentmodel', $user ),
186 $this->title->getUserPermissionsErrors(
'edit', $user ),
188 $titleWithNewContentModel->getUserPermissionsErrors(
'editcontentmodel', $user ),
190 $titleWithNewContentModel->getUserPermissionsErrors(
'edit', $user )
194 $wikitext = $out->formatPermissionsErrorMessage( $errors );
196 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
199 $page = WikiPage::factory( $this->title );
200 if ( $this->oldRevision ===
null ) {
201 $this->oldRevision = $page->getRevision() ?:
false;
203 $oldModel = $this->title->getContentModel();
204 if ( $this->oldRevision ) {
205 $oldContent = $this->oldRevision->getContent();
207 $newContent = ContentHandler::makeContent(
208 $oldContent->serialize(), $this->title, $data[
'model']
211 return Status::newFatal(
212 $this->
msg(
'changecontentmodel-cannot-convert' )
214 $this->title->getPrefixedText(),
215 ContentHandler::getLocalizedName( $data[
'model'] )
221 $newContent = ContentHandler::getForModelID( $data[
'model'] )->makeEmptyContent();
225 if ( $user->pingLimiter(
'editcontentmodel' ) ) {
231 if ( MediaWikiServices::getInstance()
233 ->userHasRight( $user,
'bot' )
238 $log =
new ManualLogEntry(
'contentmodel', $this->oldRevision ?
'change' :
'new' );
240 $log->setTarget( $this->title );
241 $log->setComment( $data[
'reason'] );
242 $log->setParameters( [
243 '4::oldmodel' => $oldModel,
244 '5::newmodel' => $data[
'model']
248 $formatter->setContext( RequestContext::newExtraneousContext( $this->title ) );
249 $reason = $formatter->getPlainActionText();
250 if ( $data[
'reason'] !==
'' ) {
251 $reason .= $this->
msg(
'colon-separator' )->inContentLanguage()->text() . $data[
'reason'];
256 $derivativeContext->setTitle( $this->title );
257 $derivativeContext->setWikiPage( $page );
259 if ( !Hooks::run(
'EditFilterMergedContent',
260 [ $derivativeContext, $newContent, $status, $reason,
263 if ( $status->isGood() ) {
265 $status->fatal(
'hookaborted' );
270 $status = $page->doEditContent(
274 $this->oldRevision ? $this->oldRevision->getId() :
false,
277 if ( !$status->isOK() ) {
281 $logid = $log->insert();
282 $log->publish( $logid );
289 $out->setPageTitle( $this->
msg(
'changecontentmodel-success-title' ) );
290 $out->addWikiMsg(
'changecontentmodel-success-text', $this->title );
wfMergeErrorArrays(... $args)
Merge arrays in the style of getUserPermissionsErrors, with duplicate removal e.g.
An IContextSource implementation which will inherit context from another source but allow individual ...
static matchSummarySpamRegex( $text)
Check given input text against $wgSummarySpamRegex, and return the text of the first match.
An error page which can definitely be safely rendered using the OutputPage.
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Class to simplify the use of log pages.
Class for creating new log entries and inserting them into the database.
setPerformer(UserIdentity $performer)
Set the user that performed the action being logged.
Variant of the Message class.
Revision bool null $oldRevision
A Revision object, false if no revision exists, null if not loaded yet.
setParameter( $par)
Maybe do something interesting with the subpage parameter.
getOptionsForTitle(Title $title=null)
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
getFormFields()
Get an HTMLForm descriptor array.
postText()
Add post-text to the form.
getDisplayFormat()
Get display format for the form.
doesWrites()
Indicates whether this special page may perform database writes.
onSubmit(array $data)
Process the form on POST submission.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getRequest()
Get the WebRequest being used for this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Show an error when the user hits a rate limit.
Represents a title within MediaWiki.
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
setContentModel( $model)
Set a proposed content model for the page for permissions checking.
getPrefixedText()
Get the prefixed title with spaces.