From: daniel Date: Mon, 16 Apr 2012 09:52:37 +0000 (+0200) Subject: Merge branch 'Wikidata' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata X-Git-Tag: 1.31.0-rc.0~22097^2^2~253 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=ef27863d9f46e43ef0b2aeeeb02602fee6c5ef26;p=lhc%2Fweb%2Fwiklou.git Merge branch 'Wikidata' of ssh://gerrit.wikimedia.org:29418/mediawiki/core into Wikidata Getting synced after Jeroen and Jens essentially rebased the core branch. Conflicts: includes/ContentHandler.php Change-Id: I82efd272694ec5761fedf52f85b153a140e268e5 --- ef27863d9f46e43ef0b2aeeeb02602fee6c5ef26 diff --cc includes/Article.php index 7fc436f236,d516ce91a7..31c0ac48ce --- a/includes/Article.php +++ b/includes/Article.php @@@ -210,9 -213,9 +216,9 @@@ class Article extends Page * This function has side effects! Do not use this function if you * only want the real revision text if any. * - * @return Return the content of this revision + * @return Content */ - public function getContentObject() { + protected function getContentObject() { global $wgUser; wfProfileIn( __METHOD__ ); diff --cc includes/ContentHandler.php index 9bc2f451e3,1a55788d67..7201cc42f2 --- a/includes/ContentHandler.php +++ b/includes/ContentHandler.php @@@ -19,26 -19,29 +20,52 @@@ class MWContentSerializationException e */ abstract class ContentHandler { ++ + /** + * Conveniance function for getting flat text from a Content object. This shleould only + * be used in the context of backwards compatibility with code that is not yet able + * to handle Content objects! + * + * If $content is equal to null or false, this method returns the empty string. + * + * If $content is an instance of TextContent, this method returns the flat text as returned by $content->getnativeData(). + * + * If $content is not a TextContent object, the bahaviour of this method depends on the global $wgContentHandlerTextFallback: + * If $wgContentHandlerTextFallback is 'fail' and $content is not a TextContent object, an MWException is thrown. + * If $wgContentHandlerTextFallback is 'serialize' and $content is not a TextContent object, $content->serialize() + * is called to get a string form of the content. + * Otherwise, this method returns null. + * + * @static + * @param Content|null $content + * @return null|string the textual form of $content, if available + * @throws MWException if $content is not an instance of TextContent and $wgContentHandlerTextFallback was set to 'fail'. + */ ++ + /** + * @abstract + * @param Content $content + * @param null $format + * @return String + */ + public abstract function serialize( Content $content, $format = null ); + + /** + * TODO: calling unserialize on a ContentHandler returns a Content?!! Something looks wrong here... + * + * @abstract + * @param $blob String + * @param null $format + * @return Content + */ + public abstract function unserialize( $blob, $format = null ); + + /** + * FIXME: bad method name: suggests it empties the content of an instance rather then creating a new empty one + */ + public abstract function emptyContent(); + ++ public static function getContentText( Content $content = null ) { global $wgContentHandlerTextFallback; @@@ -54,22 -64,9 +88,23 @@@ return null; } + /** + * Conveniance function for creating a Content object from a given textual representation. + * + * $text will be deserialized into a Content object of the model specified by $modelName (or, + * if that is not given, $title->getContentModelName()) using the given format. + * + * @static + * @param $text the textual represenation, will be unserialized to create the Content object + * @param Title $title the title of the page this text belongs to, required as a context for deserialization + * @param null|String $modelName the model to deserialize to. If not provided, $title->getContentModelName() is used. + * @param null|String $format the format to use for deserialization. If not given, the model's default format is used. + * + * @return Content a Content object representing $text + */ public static function makeContent( $text, Title $title, $modelName = null, $format = null ) { - if ( !$modelName ) { + + if ( is_null( $modelName ) ) { $modelName = $title->getContentModelName(); } @@@ -220,27 -175,15 +262,27 @@@ return $wgContentHandlers[$modelName]; } - # ---------------------------------------------------------------------------------------------------------- + // ---------------------------------------------------------------------------------------------------------- + + /** + * Constructor, initializing the ContentHandler instance with it's model name and a list of supported formats. + * Values for the parameters are typically provided as literals by subclasses' constructors. + * + * @param String $modelName (use CONTENT_MODEL_XXX constants). + * @param array $formats list for supported serialization formats (typically as MIME types) + */ public function __construct( $modelName, $formats ) { $this->mModelName = $modelName; $this->mSupportedFormats = $formats; } + /** + * + * @return String the model name + */ public function getModelName() { - # for wikitext: wikitext; in the future: wikiast, wikidom? - # for wikidata: wikidata + // for wikitext: wikitext; in the future: wikiast, wikidom? + // for wikidata: wikidata return $this->mModelName; }