54 parent::__construct(
'ChangeContentModel',
'editcontentmodel' );
56 $this->contentHandlerFactory = $contentHandlerFactory;
57 $this->contentModelChangeFactory = $contentModelChangeFactory;
58 $this->spamChecker = $spamChecker;
59 $this->revisionLookup = $revisionLookup;
60 $this->wikiPageFactory = $wikiPageFactory;
61 $this->searchEngineFactory = $searchEngineFactory;
62 $this->collationFactory = $collationFactory;
83 $title = Title::newFromText(
$par );
85 $this->title = $title;
95 $contentModelLogPage =
new LogPage(
'contentmodel' );
96 $text = Xml::element(
'h2',
null, $contentModelLogPage->getName()->text() );
98 LogEventsList::showLogExtract( $out,
'contentmodel', $this->title );
111 if ( $this->title ) {
120 if ( $this->title ) {
121 $this->
getOutput()->addBacklinkSubtitle( $this->title );
128 $titleObj = Title::newFromTextThrow( $title );
130 $this->oldRevision = $this->revisionLookup->getRevisionByTitle( $titleObj ) ?:
false;
132 if ( $this->oldRevision ) {
133 $oldContent = $this->oldRevision->getContent( SlotRecord::MAIN );
134 if ( !$oldContent->getContentHandler()->supportsDirectEditing() ) {
135 return $this->
msg(
'changecontentmodel-nodirectediting' )
136 ->params( ContentHandler::getLocalizedName( $oldContent->getModel() ) )
149 'name' =>
'pagetitle',
151 'label-message' =>
'changecontentmodel-title-label',
152 'validation-callback' => [ $this,
'validateTitle' ],
155 if ( $this->title ) {
156 $options = $this->getOptionsForTitle( $this->title );
159 'changecontentmodel-emptymodels-title',
160 'changecontentmodel-emptymodels-text',
161 [ $this->title->getPrefixedText() ]
164 $fields[
'pagetitle'][
'readonly'] =
true;
169 'default' => $this->title->getContentModel(),
170 'options' => $options,
171 'label-message' =>
'changecontentmodel-model-label'
175 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
177 'validation-callback' =>
function ( $reason ) {
178 if ( $reason ===
null || $reason ===
'' ) {
183 $match = $this->spamChecker->checkSummary( $reason );
186 return $this->
msg(
'spamprotectionmatch', $match )->parse();
191 'label-message' =>
'changecontentmodel-reason-label',
204 private function getOptionsForTitle(
Title $title =
null ) {
205 $models = $this->contentHandlerFactory->getContentModels();
207 foreach ( $models as $model ) {
208 $handler = $this->contentHandlerFactory->getContentHandler( $model );
209 if ( !$handler->supportsDirectEditing() ) {
213 if ( !$handler->canBeUsedOn( $title ) ) {
222 $collation = $this->collationFactory->getCategoryCollation();
223 uksort( $options,
static function ( $a, $b ) use ( $collation ) {
224 $a = $collation->getSortKey( $a );
225 $b = $collation->getSortKey( $b );
226 return strcmp( $a, $b );
233 $this->title = Title::newFromText( $data[
'pagetitle'] );
234 $page = $this->wikiPageFactory->newFromTitle( $this->title );
236 $changer = $this->contentModelChangeFactory->newContentModelChange(
242 $permissionStatus = $changer->authorizeChange();
243 if ( !$permissionStatus->isGood() ) {
245 $wikitext = $out->formatPermissionStatus( $permissionStatus );
247 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
250 $status = $changer->doContentModelChange(
261 $out->setPageTitleMsg( $this->
msg(
'changecontentmodel-success-title' ) );
262 $out->addWikiMsg(
'changecontentmodel-success-text', $this->title );
274 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
283class_alias( SpecialChangeContentModel::class,
'SpecialChangeContentModel' );
A content handler knows how do deal with a specific type of content on a wiki page.
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
An error page which can definitely be safely rendered using the OutputPage.
Class to simplify the use of log pages.
Service to check if text (either content or a summary) qualifies as spam.
Service for creating WikiPage objects.
Special page which uses an HTMLForm to handle processing.
string null $par
The sub-page of the special page.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
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.
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 this special page may perform database writes.
onSuccess()
Do something exciting on successful processing of the form, most likely to show a confirmation messag...
Factory class for SearchEngine.
Module of static functions for generating XML.
Service for changing the content model of wiki pages.