Merge "Watch user page and user talk page by default"
[lhc/web/wiklou.git] / includes / content / ContentHandler.php
index ede4306..1abe1fa 100644 (file)
@@ -31,7 +31,6 @@
  * @ingroup Content
  */
 class MWContentSerializationException extends MWException {
-
 }
 
 /**
@@ -54,7 +53,6 @@ class MWContentSerializationException extends MWException {
  * @ingroup Content
  */
 abstract class ContentHandler {
-
        /**
         * Switch for enabling deprecation warnings. Used by ContentHandler::deprecated()
         * and ContentHandler::runLegacyHooks().
@@ -145,8 +143,8 @@ abstract class ContentHandler {
         *    not be unserialized using $format.
         */
        public static function makeContent( $text, Title $title = null,
-               $modelId = null, $format = null )
-       {
+               $modelId = null, $format = null
+       {
                if ( is_null( $modelId ) ) {
                        if ( is_null( $title ) ) {
                                throw new MWException( "Must provide a Title object or a content model ID." );
@@ -156,6 +154,7 @@ abstract class ContentHandler {
                }
 
                $handler = ContentHandler::getForModelID( $modelId );
+
                return $handler->unserializeContent( $text, $format );
        }
 
@@ -259,6 +258,7 @@ abstract class ContentHandler {
         */
        public static function getForTitle( Title $title ) {
                $modelId = $title->getContentModel();
+
                return ContentHandler::getForModelID( $modelId );
        }
 
@@ -273,13 +273,14 @@ abstract class ContentHandler {
         */
        public static function getForContent( Content $content ) {
                $modelId = $content->getModel();
+
                return ContentHandler::getForModelID( $modelId );
        }
 
        /**
-        * @var Array A Cache of ContentHandler instances by model id
+        * @var array A Cache of ContentHandler instances by model id
         */
-       static $handlers;
+       protected static $handlers;
 
        /**
         * Returns the ContentHandler singleton for the given model ID. Use the
@@ -330,14 +331,16 @@ abstract class ContentHandler {
                        $handler = new $class( $modelId );
 
                        if ( !( $handler instanceof ContentHandler ) ) {
-                               throw new MWException( "$class from \$wgContentHandlers is not compatible with ContentHandler" );
+                               throw new MWException( "$class from \$wgContentHandlers is not " .
+                                       "compatible with ContentHandler" );
                        }
                }
 
                wfDebugLog( 'ContentHandler', 'Created handler for ' . $modelId
-                                       . ': ' . get_class( $handler ) );
+                       . ': ' . get_class( $handler ) );
 
                ContentHandler::$handlers[$modelId] = $handler;
+
                return ContentHandler::$handlers[$modelId];
        }
 
@@ -380,6 +383,7 @@ abstract class ContentHandler {
                }
 
                $formats = array_unique( $formats );
+
                return $formats;
        }
 
@@ -598,16 +602,18 @@ abstract class ContentHandler {
        /**
         * Get the language in which the content of the given page is written.
         *
-        * This default implementation just returns $wgContLang (except for pages in the MediaWiki namespace)
+        * This default implementation just returns $wgContLang (except for pages
+        * in the MediaWiki namespace)
         *
-        * Note that the pages language is not cacheable, since it may in some cases depend on user settings.
+        * Note that the pages language is not cacheable, since it may in some
+        * cases depend on user settings.
         *
         * Also note that the page language may or may not depend on the actual content of the page,
         * that is, this method may load the content in order to determine the language.
         *
         * @since 1.21
         *
-        * @param Title        $title the page to determine the language for.
+        * @param Title $title the page to determine the language for.
         * @param Content|null $content the page's content, if you have it handy, to avoid reloading it.
         *
         * @return Language the page's language
@@ -623,6 +629,7 @@ abstract class ContentHandler {
                }
 
                wfRunHooks( 'PageContentLanguage', array( $title, &$pageLang, $wgLang ) );
+
                return wfGetLangObj( $pageLang );
        }
 
@@ -641,7 +648,7 @@ abstract class ContentHandler {
         *
         * @since 1.21
         *
-        * @param Title        $title the page to determine the language for.
+        * @param Title $title the page to determine the language for.
         * @param Content|null $content the page's content, if you have it handy, to avoid reloading it.
         *
         * @return Language the page's language for viewing
@@ -735,15 +742,15 @@ abstract class ContentHandler {
                if ( is_object( $rt ) ) {
                        if ( !is_object( $ot )
                                || !$rt->equals( $ot )
-                               || $ot->getFragment() != $rt->getFragment() )
-                       {
+                               || $ot->getFragment() != $rt->getFragment()
+                       {
                                $truncatedtext = $newContent->getTextForSummary(
                                        250
-                                               - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
-                                               - strlen( $rt->getFullText() ) );
+                                       - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
+                                       - strlen( $rt->getFullText() ) );
 
                                return wfMessage( 'autoredircomment', $rt->getFullText() )
-                                               ->rawParams( $truncatedtext )->inContentLanguage()->text();
+                                       ->rawParams( $truncatedtext )->inContentLanguage()->text();
                        }
                }
 
@@ -756,7 +763,7 @@ abstract class ContentHandler {
                                200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
 
                        return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
-                                       ->inContentLanguage()->text();
+                               ->inContentLanguage()->text();
                }
 
                // Blanking auto-summaries
@@ -764,15 +771,15 @@ abstract class ContentHandler {
                        return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
                } elseif ( !empty( $oldContent )
                        && $oldContent->getSize() > 10 * $newContent->getSize()
-                       && $newContent->getSize() < 500 )
-               {
+                       && $newContent->getSize() < 500
+               {
                        // Removing more than 90% of the article
 
                        $truncatedtext = $newContent->getTextForSummary(
                                200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
 
                        return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
-                                       ->inContentLanguage()->text();
+                               ->inContentLanguage()->text();
                }
 
                // If we reach this point, there's no applicable auto-summary for our
@@ -1004,11 +1011,11 @@ abstract class ContentHandler {
         * Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if
         * self::$enableDeprecationWarnings is set to true.
         *
-        * @param string      $func The name of the deprecated function
-        * @param string      $version The version since the method is deprecated. Usually 1.21
-        *                    for ContentHandler related stuff.
-        * @param string|bool $component: Component to which the function belongs.
-        *                                If false, it is assumed the function is in MediaWiki core.
+        * @param string $func The name of the deprecated function
+        * @param string $version The version since the method is deprecated. Usually 1.21
+        *   for ContentHandler related stuff.
+        * @param string|bool $component : Component to which the function belongs.
+        *   If false, it is assumed the function is in MediaWiki core.
         *
         * @see ContentHandler::$enableDeprecationWarnings
         * @see wfDeprecated
@@ -1037,7 +1044,8 @@ abstract class ContentHandler {
         * @see ContentHandler::$enableDeprecationWarnings
         */
        public static function runLegacyHooks( $event, $args = array(),
-                       $warn = null ) {
+               $warn = null
+       ) {
 
                if ( $warn === null ) {
                        $warn = self::$enableDeprecationWarnings;
@@ -1079,7 +1087,8 @@ abstract class ContentHandler {
 
                        wfRestoreWarnings();
 
-                       wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " . implode( ', ', $handlerInfo ), 2 );
+                       wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " .
+                               implode( ', ', $handlerInfo ), 2 );
                }
 
                // convert Content objects to text