17 private $contentHandlerFactory;
20 private $contentModelChangeFactory;
26 private $revisionLookup;
29 private $wikiPageFactory;
32 private $searchEngineFactory;
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;
78 $title = Title::newFromText(
$par );
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 );
123 $titleObj = Title::newFromTextThrow( $title );
125 $this->oldRevision = $this->revisionLookup->getRevisionByTitle( $titleObj ) ?:
false;
127 if ( $this->oldRevision ) {
128 $oldContent = $this->oldRevision->getContent( SlotRecord::MAIN );
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 );
152 if ( empty( $options ) ) {
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'
176 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
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 ) ) {
223 $this->title = Title::newFromText( $data[
'pagetitle'] );
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 );
241 $status = $changer->doContentModelChange(
252 $out->setPageTitle( $this->
msg(
'changecontentmodel-success-title' ) );
253 $out->addWikiMsg(
'changecontentmodel-success-text', $this->title );
265 return $this->
prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
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.
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.
Service to check if text (either content or a summary) qualifies as spam.
Service for creating WikiPage objects.
Factory class for SearchEngine.
setParameter( $par)
Maybe do something interesting with the subpage parameter.
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.
getDisplayFormat()
Get display format for the form.
doesWrites()
Indicates whether this special page may perform database writes.
onSubmit(array $data)
Process the form on submission.
postHtml()
Add post-HTML to the form.
__construct(IContentHandlerFactory $contentHandlerFactory, ContentModelChangeFactory $contentModelChangeFactory, SpamChecker $spamChecker, RevisionLookup $revisionLookup, WikiPageFactory $wikiPageFactory, SearchEngineFactory $searchEngineFactory)
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.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getAuthority()
Shortcut to get the Authority executing this instance.
getRequest()
Get the WebRequest being used for this instance.
prefixSearchString( $search, $limit, $offset, SearchEngineFactory $searchEngineFactory=null)
Perform a regular substring search for prefixSearchSubpages.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
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.