From 4e80be15d46036a597c9d37a32bd75759f94aca1 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 11 Sep 2012 15:39:52 +0200 Subject: [PATCH] Introducing ContentHandler::canBeUsedOn() ContentHandler::canBeUsedOn() is called by WikiPage::doEditContent to determine whether the requested kind of content can be used on the present page. Change-Id: I37b0e42eea2376b7485581f779b2520caa3b7fe2 --- includes/ContentHandler.php | 17 +++++++++++++++++ includes/WikiPage.php | 7 +++++++ languages/messages/MessagesEn.php | 1 + languages/messages/MessagesQqq.php | 3 +++ 4 files changed, 28 insertions(+) diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php index 614082498c..584a6adc08 100644 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@ -612,6 +612,23 @@ abstract class ContentHandler { return $pageLang; } + /** + * Determines whether the content type handled by this ContentHandler + * can be used on the given page. + * + * This default implementation always returns true. + * Subclasses may override this to restrict the use of this content model to specific locations, + * typically based on the namespace or some other aspect of the title, such as a special suffix + * (e.g. ".svg" for SVG content). + * + * @param Title $title the page's title. + * + * @return bool true if content of this kind can be used on the given page, false otherwise. + */ + public function canBeUsedOn( Title $title ) { + return true; + } + /** * Returns the name of the diff engine to use. * diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 65ccc0bfa6..6c7b335106 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -1616,6 +1616,13 @@ class WikiPage extends Page implements IDBAccessObject { wfProfileIn( __METHOD__ ); + if ( !$content->getContentHandler()->canBeUsedOn( $this->getTitle() ) ) { + wfProfileOut( __METHOD__ ); + return Status::newFatal( 'content-not-allowed-here', + ContentHandler::getLocalizedName( $content->getModel() ), + $this->getTitle()->getPrefixedText() ); + } + $user = is_null( $user ) ? $wgUser : $user; $status = Status::newGood( array() ); diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index acad936072..2b2a884609 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1488,6 +1488,7 @@ It already exists.', 'addsection-editintro' => '', # do not translate or duplicate this message to other languages 'defaultmessagetext' => 'Default message text', 'invalid-content-data' => 'Invalid content data', +'content-not-allowed-here' => '"$1" content is not allowed on page [[$2]]', # Parser/template warnings 'expensive-parserfunction-warning' => "'''Warning:''' This page contains too many expensive parser function calls. diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 3dda8ee0eb..49cf0d7807 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -1054,6 +1054,9 @@ Please report at [[Support]] if you are unable to properly translate this messag 'edit-conflict' => "An 'Edit conflict' happens when more than one edit is being made to a page at the same time. This would usually be caused by separate individuals working on the same page. However, if the system is slow, several edits from one individual could back up and attempt to apply simultaneously - causing the conflict.", 'defaultmessagetext' => 'Caption above the default message text shown on the left-hand side of a diff displayed after clicking “Show changes” when creating a new page in the MediaWiki: namespace', 'invalid-content-data' => 'Error message indicating that the page\'s content can not be saved because it is invalid. This may occurr for some non-text content types.', +'content-not-allowed-here' => 'Error message indicating that the desired content model is not supported in given localtion. +* $1 is the human readable name of the content model +* $1 is the title of the page in question.', # Parser/template warnings 'expensive-parserfunction-warning' => 'On some (expensive) [[MetaWikipedia:Help:ParserFunctions|parser functions]] (e.g. {{#ifexist:}}) there is a limit of how many times it may be used. This is an error message shown when the limit is exceeded. -- 2.20.1