Merge "Make sure that SQLite uses no prefix"
[lhc/web/wiklou.git] / includes / content / ContentHandler.php
index 33c803e..b61dc34 100644 (file)
@@ -80,7 +80,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @static
         * @param $content Content|null
         * @return null|string the textual form of $content, if available
         * @throws MWException if $content is not an instance of TextContent and
@@ -123,8 +122,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @static
-        *
         * @param $text string the textual representation, will be
         *    unserialized to create the Content object
         * @param $title null|Title the title of the page this text belongs to.
@@ -184,7 +181,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @static
         * @param $title Title
         * @return null|string default model name for the page given by $title
         */
@@ -256,7 +252,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @static
         * @param $title Title
         * @return ContentHandler
         */
@@ -271,7 +266,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @static
         * @param $content Content
         * @return ContentHandler
         */
@@ -304,7 +298,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @static
         * @param $modelId String The ID of the content model for which to get a
         *    handler. Use CONTENT_MODEL_XXX constants.
         * @return ContentHandler The ContentHandler singleton for handling the
@@ -352,7 +345,6 @@ abstract class ContentHandler {
         * Model names are localized using system messages. Message keys
         * have the form content-model-$name, where $name is getContentModelName( $id ).
         *
-        * @static
         * @param $name String The content model ID, as given by a CONTENT_MODEL_XXX
         *    constant or returned by Revision::getContentModel().
         *
@@ -415,7 +407,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @abstract
         * @param $content Content The Content object to serialize
         * @param $format null|String The desired serialization format
         * @return string Serialized form of the content
@@ -427,7 +418,6 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @abstract
         * @param $blob string serialized form of the content
         * @param $format null|String the format used for serialization
         * @return Content the Content object created by deserializing $blob
@@ -592,8 +582,6 @@ abstract class ContentHandler {
                $rcid = 0, # FIXME: use everywhere!
                $refreshCache = false, $unhide = false
        ) {
-               $this->checkModelID( $context->getTitle()->getContentModel() );
-
                $diffEngineClass = $this->getDiffEngineClass();
 
                return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
@@ -617,15 +605,17 @@ abstract class ContentHandler {
         * @return Language the page's language
         */
        public function getPageLanguage( Title $title, Content $content = null ) {
-               global $wgContLang;
+               global $wgContLang, $wgLang;
+               $pageLang = $wgContLang;
 
                if ( $title->getNamespace() == NS_MEDIAWIKI ) {
                        // Parse mediawiki messages with correct target language
                        list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
-                       return wfGetLangObj( $lang );
+                       $pageLang = wfGetLangObj( $lang );
                }
 
-               return $wgContLang;
+               wfRunHooks( 'PageContentLanguage', array( $title, &$pageLang, $wgLang ) );
+               return wfGetLangObj( $pageLang );
        }
 
        /**
@@ -812,20 +802,21 @@ abstract class ContentHandler {
                $content = $rev->getContent();
                $blank = false;
 
-               $this->checkModelID( $content->getModel() );
-
                // If the page is blank, use the text from the previous revision,
                // which can only be blank if there's a move/import/protect dummy
                // revision involved
-               if ( $content->getSize() == 0 ) {
+               if ( !$content || $content->isEmpty() ) {
                        $prev = $rev->getPrevious();
 
-                       if ( $prev )    {
-                               $content = $prev->getContent();
+                       if ( $prev ) {
+                               $rev = $prev;
+                               $content = $rev->getContent();
                                $blank = true;
                        }
                }
 
+               $this->checkModelID( $rev->getContentModel() );
+
                // Find out if there was only one contributor
                // Only scan the last 20 revisions
                $res = $dbw->select( 'revision', 'rev_user_text',
@@ -881,7 +872,7 @@ abstract class ContentHandler {
                }
 
                // Max content length = max comment length - length of the comment (excl. $1)
-               $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) );
+               $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) : '';
 
                // Now replace the '$1' placeholder
                $reason = str_replace( '$1', $text, $reason );