48 parent::__construct(
'ChangeContentModel',
'editcontentmodel' );
50 $this->contentHandlerFactory = $contentHandlerFactory;
51 $this->contentModelChangeFactory = $contentModelChangeFactory;
52 $this->spamChecker = $spamChecker;
53 $this->revisionLookup = $revisionLookup;
54 $this->wikiPageFactory = $wikiPageFactory;
55 $this->searchEngineFactory = $searchEngineFactory;
56 $this->collationFactory = $collationFactory;
77 $title = Title::newFromText(
$par );
79 $this->title = $title;
89 $contentModelLogPage =
new LogPage(
'contentmodel' );
90 $text =
Html::element(
'h2', [], $contentModelLogPage->getName()->text() );
92 LogEventsList::showLogExtract( $out,
'contentmodel', $this->title );
105 if ( $this->title ) {
114 if ( $this->title ) {
115 $this->
getOutput()->addBacklinkSubtitle( $this->title );
122 $titleObj = Title::newFromTextThrow( $title );
124 $this->oldRevision = $this->revisionLookup->getRevisionByTitle( $titleObj ) ?:
false;
126 if ( $this->oldRevision ) {
127 $oldContent = $this->oldRevision->getContent( SlotRecord::MAIN );
128 if ( !$oldContent->getContentHandler()->supportsDirectEditing() ) {
129 return $this->
msg(
'changecontentmodel-nodirectediting' )
130 ->params( ContentHandler::getLocalizedName( $oldContent->getModel() ) )
143 'name' =>
'pagetitle',
145 'label-message' =>
'changecontentmodel-title-label',
146 'validation-callback' => [ $this,
'validateTitle' ],
149 if ( $this->title ) {
150 $options = $this->getOptionsForTitle( $this->title );
153 'changecontentmodel-emptymodels-title',
154 'changecontentmodel-emptymodels-text',
155 [ $this->title->getPrefixedText() ]
158 $fields[
'pagetitle'][
'readonly'] =
true;
163 'default' => $this->title->getContentModel(),
164 'options' => $options,
165 'label-message' =>
'changecontentmodel-model-label'
169 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
171 'validation-callback' =>
function ( $reason ) {
172 if ( $reason ===
null || $reason ===
'' ) {
177 $match = $this->spamChecker->checkSummary( $reason );
180 return $this->
msg(
'spamprotectionmatch', $match )->parse();
185 'label-message' =>
'changecontentmodel-reason-label',
198 private function getOptionsForTitle( ?
Title $title =
null ) {
199 $models = $this->contentHandlerFactory->getContentModels();
201 foreach ( $models as $model ) {
202 $handler = $this->contentHandlerFactory->getContentHandler( $model );
203 if ( !$handler->supportsDirectEditing() ) {
207 if ( !$handler->canBeUsedOn( $title ) ) {
211 $options[ContentHandler::getLocalizedName( $model )] = $model;
216 $collation = $this->collationFactory->getCategoryCollation();
217 uksort( $options,
static function ( $a, $b ) use ( $collation ) {
218 $a = $collation->getSortKey( $a );
219 $b = $collation->getSortKey( $b );
220 return strcmp( $a, $b );
227 $this->title = Title::newFromText( $data[
'pagetitle'] );
228 $page = $this->wikiPageFactory->newFromTitle( $this->title );
230 $changer = $this->contentModelChangeFactory->newContentModelChange(
236 $permissionStatus = $changer->authorizeChange();
237 if ( !$permissionStatus->isGood() ) {
239 $wikitext = $out->formatPermissionStatus( $permissionStatus );
241 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
244 $status = $changer->doContentModelChange(
255 $out->setPageTitleMsg( $this->
msg(
'changecontentmodel-success-title' ) );
256 $out->addWikiMsg(
'changecontentmodel-success-text', $this->title );
268 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
277class_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.
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.
__construct(IContentHandlerFactory $contentHandlerFactory, ContentModelChangeFactory $contentModelChangeFactory, SpamChecker $spamChecker, RevisionLookup $revisionLookup, WikiPageFactory $wikiPageFactory, SearchEngineFactory $searchEngineFactory, CollationFactory $collationFactory)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
postHtml()
Add post-HTML to the form.
setParameter( $par)
Maybe do something interesting with the subpage parameter.
getDisplayFormat()
Get display format for the form.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
onSubmit(array $data)
Process the form on submission.
getFormFields()
Get an HTMLForm descriptor array.
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...
Factory class for SearchEngine.
Service for changing the content model of wiki pages.