43 parent::__construct(
'ChangeContentModel' );
63 private string $oldContentModel;
65 private bool $titleExisted;
67 private string $newContentModel;
72 $title = Title::newFromText(
$par );
74 $this->title = $title;
85 $contentModelLogPage =
new LogPage(
'contentmodel' );
86 $text =
Html::element(
'h2', [], $contentModelLogPage->getName()->text() );
88 LogEventsList::showLogExtract( $out,
'contentmodel', $this->title );
102 if ( $this->title ) {
104 if ( $this->title->exists() ) {
110 $this->
getOutput()->addBacklinkSubtitle( $this->title );
121 if ( $this->title ) {
122 $perm = $this->title->exists() ?
'editcontentmodel' :
'createwithcontentmodel';
123 $this->permissionManager->throwPermissionErrors( $perm, $user, $this->title );
124 } elseif ( !$this->permissionManager->userHasAnyRight( $user,
'editcontentmodel',
'createwithcontentmodel' ) ) {
136 private function validateTitle( $title ) {
139 $titleObj = Title::newFromTextThrow( $title );
141 $this->oldRevision = $this->revisionLookup->getRevisionByTitle( $titleObj ) ?:
false;
143 if ( $this->oldRevision ) {
144 $oldContent = $this->oldRevision->getContent( SlotRecord::MAIN );
145 if ( !$oldContent->getContentHandler()->supportsDirectEditing() ) {
146 return $this->
msg(
'changecontentmodel-nodirectediting' )
147 ->params( ContentHandler::getLocalizedName( $oldContent->getModel() ) )
157 if ( $this->title ) {
159 if ( $this->title->exists() ) {
160 $msg = $this->
msg(
'changecontentmodel-editing', $this->title->getPrefixedText() );
162 $msg = $this->
msg(
'changecontentmodel-create', $this->title->getPrefixedText() );
164 } elseif ( !$this->permissionManager->userHasRight( $this->getUser(),
'editcontentmodel' ) ) {
165 $msg = $this->
msg(
'changecontentmodel-create-only' );
167 $msg = $this->
msg(
'changecontentmodel-edit' );
169 return $msg->parseAsBlock();
178 'name' =>
'pagetitle',
180 'label-message' =>
'changecontentmodel-title-label',
181 'validation-callback' => $this->validateTitle( ... ),
183 'suggestions' => $this->permissionManager->userHasRight( $this->
getUser(),
'editcontentmodel' ),
186 if ( $this->title ) {
187 $options = $this->getOptionsForTitle( $this->title );
190 'changecontentmodel-emptymodels-title',
191 'changecontentmodel-emptymodels-text',
192 [ $this->title->getPrefixedText() ]
195 $fields[
'pagetitle'][
'readonly'] =
true;
200 'default' => $this->title->getContentModel(),
201 'options' => $options,
202 'label-message' =>
'changecontentmodel-model-label'
206 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
208 'validation-callback' =>
function ( $reason ) {
209 if ( $reason ===
null || $reason ===
'' ) {
214 $match = $this->spamChecker->checkSummary( $reason );
217 return $this->
msg(
'spamprotectionmatch', $match )->parse();
222 'label-message' =>
'changecontentmodel-reason-label',
235 private function getOptionsForTitle( ?
Title $title =
null ) {
236 $models = $this->contentHandlerFactory->getContentModels();
238 foreach ( $models as $model ) {
239 $handler = $this->contentHandlerFactory->getContentHandler( $model );
240 if ( !$handler->supportsDirectEditing() ) {
244 if ( !$handler->canBeUsedOn( $title ) ) {
248 $options[ContentHandler::getLocalizedName( $model )] = $model;
253 $collation = $this->collationFactory->getCategoryCollation();
254 uksort( $options,
static function ( $a, $b ) use ( $collation ) {
255 $a = $collation->getSortKey( $a );
256 $b = $collation->getSortKey( $b );
257 return strcmp( $a, $b );
265 $this->title = Title::newFromText( $data[
'pagetitle'] );
266 $this->titleExisted = $this->title->exists();
267 $this->oldContentModel = $this->title->getContentModel();
268 $this->newContentModel = $data[
'model'];
269 $page = $this->wikiPageFactory->newFromTitle( $this->title );
271 $changer = $this->contentModelChangeFactory->newContentModelChange(
277 $permissionStatus = $changer->authorizeChange();
278 if ( !$permissionStatus->isGood() ) {
280 $wikitext = $out->formatPermissionStatus( $permissionStatus );
282 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
285 $status = $changer->doContentModelChange(
296 if ( $this->titleExisted ) {
297 $out->setPageTitleMsg( $this->
msg(
'changecontentmodel-success-title' ) );
298 $out->addWikiMsg(
'changecontentmodel-success-text',
299 $this->title->getPrefixedText(),
300 ContentHandler::getLocalizedName( $this->oldContentModel, $this->getLanguage() ),
301 ContentHandler::getLocalizedName( $this->newContentModel, $this->getLanguage() )
304 $out->setPageTitleMsg( $this->
msg(
'changecontentmodel-create-success-title' ) );
305 $out->addWikiMsg(
'changecontentmodel-create-success-text',
306 $this->title->getPrefixedText(),
307 ContentHandler::getLocalizedName( $this->newContentModel, $this->getLanguage() )
321 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
331class_alias( SpecialChangeContentModel::class,
'SpecialChangeContentModel' );
Base class for content handling.
Service to check if text (either content or a summary) qualifies as spam.
An error page which can definitely be safely rendered using the OutputPage.
Class to simplify the use of log pages.
Service for creating WikiPage objects.
Special page which uses an HTMLForm to handle processing.
string null $par
The subpage of the special page.
getUser()
Shortcut to get the User executing this instance.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
prefixSearchString( $search, $limit, $offset, ?SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
getAuthority()
Shortcut to get the Authority executing this instance.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
postHtml()
Add post-HTML to the form.string HTML which will be sent to $form->addPostHtml() 1....
setParameter( $par)
Maybe do something interesting with the subpage parameter.
getDisplayFormat()
Get display format for the form.See HTMLForm documentation for available values.1....
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.to override 1.19 void
onSubmit(array $data)
Process the form on submission.bool|string|array|Status As documented for HTMLForm::trySubmit.
__construct(private readonly IContentHandlerFactory $contentHandlerFactory, private readonly ContentModelChangeFactory $contentModelChangeFactory, private readonly SpamChecker $spamChecker, private readonly RevisionLookup $revisionLookup, private readonly WikiPageFactory $wikiPageFactory, private readonly SearchEngineFactory $searchEngineFactory, private readonly CollationFactory $collationFactory, private readonly PermissionManager $permissionManager,)
getFormFields()
Get an HTMLForm descriptor array.array
preHtml()
Add pre-HTML to the form.string HTML which will be sent to $form->addPreHtml() 1.38
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
doesWrites()
Indicates whether POST requests to this special page require write access to the wiki....
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Service for changing the content model of wiki pages.