3 namespace MediaWiki\Specials;
50 parent::__construct(
'ChangeContentModel',
'editcontentmodel' );
52 $this->contentHandlerFactory = $contentHandlerFactory;
53 $this->contentModelChangeFactory = $contentModelChangeFactory;
54 $this->spamChecker = $spamChecker;
55 $this->revisionLookup = $revisionLookup;
56 $this->wikiPageFactory = $wikiPageFactory;
57 $this->searchEngineFactory = $searchEngineFactory;
80 $this->title = $title;
90 $contentModelLogPage =
new LogPage(
'contentmodel' );
91 $text =
Xml::element(
'h2',
null, $contentModelLogPage->getName()->text() );
106 if ( $this->title ) {
115 if ( $this->title ) {
116 $this->
getOutput()->addBacklinkSubtitle( $this->title );
125 $this->oldRevision = $this->revisionLookup->getRevisionByTitle( $titleObj ) ?:
false;
127 if ( $this->oldRevision ) {
129 if ( !$oldContent->getContentHandler()->supportsDirectEditing() ) {
130 return $this->
msg(
'changecontentmodel-nodirectediting' )
144 'name' =>
'pagetitle',
146 'label-message' =>
'changecontentmodel-title-label',
147 'validation-callback' => [ $this,
'validateTitle' ],
150 if ( $this->title ) {
151 $options = $this->getOptionsForTitle( $this->title );
154 'changecontentmodel-emptymodels-title',
155 'changecontentmodel-emptymodels-text',
156 [ $this->title->getPrefixedText() ]
159 $fields[
'pagetitle'][
'readonly'] =
true;
163 'name' =>
'currentcontentmodel',
164 'default' => $this->title->getContentModel(),
165 'label-message' =>
'changecontentmodel-current-label',
171 'options' => $options,
172 'label-message' =>
'changecontentmodel-model-label'
178 'validation-callback' =>
function ( $reason ) {
179 if ( $reason ===
null || $reason ===
'' ) {
184 $match = $this->spamChecker->checkSummary( $reason );
187 return $this->
msg(
'spamprotectionmatch', $match )->parse();
192 'label-message' =>
'changecontentmodel-reason-label',
200 private function getOptionsForTitle(
Title $title =
null ) {
201 $models = $this->contentHandlerFactory->getContentModels();
203 foreach ( $models as $model ) {
204 $handler = $this->contentHandlerFactory->getContentHandler( $model );
205 if ( !$handler->supportsDirectEditing() ) {
212 if ( !$handler->canBeUsedOn( $title ) ) {
224 $page = $this->wikiPageFactory->newFromTitle( $this->title );
226 $changer = $this->contentModelChangeFactory->newContentModelChange(
232 $permissionStatus = $changer->authorizeChange();
233 if ( !$permissionStatus->isGood() ) {
235 $wikitext = $out->formatPermissionStatus( $permissionStatus );
240 $status = $changer->doContentModelChange(
251 $out->setPageTitleMsg( $this->
msg(
'changecontentmodel-success-title' ) );
252 $out->addWikiMsg(
'changecontentmodel-success-text', $this->title );
264 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
275 class_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.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
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.
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.
__construct(IContentHandlerFactory $contentHandlerFactory, ContentModelChangeFactory $contentModelChangeFactory, SpamChecker $spamChecker, RevisionLookup $revisionLookup, WikiPageFactory $wikiPageFactory, SearchEngineFactory $searchEngineFactory)
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.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
Module of static functions for generating XML.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Service for changing the content model of wiki pages.