14 private $contentHandlerFactory;
17 private $contentModelChangeFactory;
23 private $revisionLookup;
26 private $wikiPageFactory;
29 private $searchEngineFactory;
47 parent::__construct(
'ChangeContentModel',
'editcontentmodel' );
49 $this->contentHandlerFactory = $contentHandlerFactory;
50 $this->contentModelChangeFactory = $contentModelChangeFactory;
51 $this->spamChecker = $spamChecker;
52 $this->revisionLookup = $revisionLookup;
53 $this->wikiPageFactory = $wikiPageFactory;
54 $this->searchEngineFactory = $searchEngineFactory;
75 $title = Title::newFromText(
$par );
77 $this->title = $title;
87 $contentModelLogPage =
new LogPage(
'contentmodel' );
88 $text = Xml::element(
'h2',
null, $contentModelLogPage->getName()->text() );
90 LogEventsList::showLogExtract( $out,
'contentmodel', $this->title );
103 if ( $this->title ) {
112 if ( $this->title ) {
113 $this->
getOutput()->addBacklinkSubtitle( $this->title );
120 $titleObj = Title::newFromTextThrow( $title );
122 $this->oldRevision = $this->revisionLookup->getRevisionByTitle( $titleObj ) ?:
false;
124 if ( $this->oldRevision ) {
125 $oldContent = $this->oldRevision->getContent( SlotRecord::MAIN );
126 if ( !$oldContent->getContentHandler()->supportsDirectEditing() ) {
127 return $this->
msg(
'changecontentmodel-nodirectediting' )
128 ->params( ContentHandler::getLocalizedName( $oldContent->getModel() ) )
141 'name' =>
'pagetitle',
143 'label-message' =>
'changecontentmodel-title-label',
144 'validation-callback' => [ $this,
'validateTitle' ],
147 if ( $this->title ) {
148 $options = $this->getOptionsForTitle( $this->title );
149 if ( empty( $options ) ) {
151 'changecontentmodel-emptymodels-title',
152 'changecontentmodel-emptymodels-text',
153 [ $this->title->getPrefixedText() ]
156 $fields[
'pagetitle'][
'readonly'] =
true;
160 'name' =>
'currentcontentmodel',
161 'default' => $this->title->getContentModel(),
162 'label-message' =>
'changecontentmodel-current-label',
168 'options' => $options,
169 'label-message' =>
'changecontentmodel-model-label'
173 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
175 'validation-callback' =>
function ( $reason ) {
176 if ( $reason ===
null || $reason ===
'' ) {
181 $match = $this->spamChecker->checkSummary( $reason );
184 return $this->
msg(
'spamprotectionmatch', $match )->parse();
189 'label-message' =>
'changecontentmodel-reason-label',
197 private function getOptionsForTitle(
Title $title =
null ) {
198 $models = $this->contentHandlerFactory->getContentModels();
200 foreach ( $models as $model ) {
201 $handler = $this->contentHandlerFactory->getContentHandler( $model );
202 if ( !$handler->supportsDirectEditing() ) {
209 if ( !$handler->canBeUsedOn( $title ) ) {
220 $this->title = Title::newFromText( $data[
'pagetitle'] );
221 $page = $this->wikiPageFactory->newFromTitle( $this->title );
223 $changer = $this->contentModelChangeFactory->newContentModelChange(
229 $permissionStatus = $changer->authorizeChange();
230 if ( !$permissionStatus->isGood() ) {
232 $wikitext = $out->formatPermissionStatus( $permissionStatus );
234 return Status::newFatal(
new RawMessage(
'$1', [ $wikitext ] ) );
238 $status = $changer->doContentModelChange(
249 $out->setPageTitle( $this->
msg(
'changecontentmodel-success-title' ) );
250 $out->addWikiMsg(
'changecontentmodel-success-text', $this->title );
262 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.
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.
Variant of the Message class.
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 POST 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.
Represents a title within MediaWiki.
getContentModel( $flags=0)
Get the page's content model id, see the CONTENT_MODEL_XXX constants.
getPrefixedText()
Get the prefixed title with spaces.
Service for changing the content model of wiki pages.