Update documentation and styling
authorSiebrand Mazeland <s.mazeland@xs4all.nl>
Mon, 8 Apr 2013 12:09:48 +0000 (14:09 +0200)
committerSiebrand Mazeland <s.mazeland@xs4all.nl>
Thu, 11 Apr 2013 15:01:18 +0000 (17:01 +0200)
Remove some trailing whitespace, break long lines, make PHPDoc consistent
and update it in places.

Change-Id: I340b43a47e121a44ebd4aaa2a45dff12e945e645

includes/cache/MessageCache.php

index 8c1a068..6cc2a7e 100644 (file)
@@ -75,12 +75,16 @@ class MessageCache {
         * Get the signleton instance of this class
         *
         * @since 1.18
-        * @return MessageCache object
+        * @return MessageCache
         */
        public static function singleton() {
                if ( is_null( self::$instance ) ) {
                        global $wgUseDatabaseMessages, $wgMsgCacheExpiry;
-                       self::$instance = new self( wfGetMessageCacheStorage(), $wgUseDatabaseMessages, $wgMsgCacheExpiry );
+                       self::$instance = new self(
+                               wfGetMessageCacheStorage(),
+                               $wgUseDatabaseMessages,
+                               $wgMsgCacheExpiry
+                       );
                }
                return self::$instance;
        }
@@ -121,8 +125,8 @@ class MessageCache {
         * Try to load the cache from a local file.
         *
         * @param string $hash the hash of contents, to check validity.
-        * @param $code Mixed: Optional language code, see documenation of load().
-        * @return The cache array
+        * @param Mixed $code Optional language code, see documenation of load().
+        * @return array The cache array
         */
        function getLocalCache( $hash, $code ) {
                global $wgCacheDirectory;
@@ -194,7 +198,7 @@ class MessageCache {
         * or false if populating empty cache fails. Also returns true if MessageCache
         * is disabled.
         *
-        * @param bool|String $code String: language to which load messages
+        * @param bool|String $code Language to which load messages
         * @throws MWException
         * @return bool
         */
@@ -287,7 +291,7 @@ class MessageCache {
                                if ( $acquired ) {
                                        # Unlock the status key if there is an exception
                                        $that = $this;
-                                       $statusUnlocker = new ScopedCallback( function() use ( $that, $statusKey ) {
+                                       $statusUnlocker = new ScopedCallback( function () use ( $that, $statusKey ) {
                                                $that->mMemc->delete( $statusKey );
                                        } );
 
@@ -299,7 +303,7 @@ class MessageCache {
                                        # write is potentially non-atomic, e.g. the results of a replace()
                                        # may be discarded.
                                        if ( $this->lock( $cacheKey ) ) {
-                                               $mainUnlocker = new ScopedCallback( function() use ( $that, $cacheKey ) {
+                                               $mainUnlocker = new ScopedCallback( function () use ( $that, $cacheKey ) {
                                                        $that->unlock( $cacheKey );
                                                } );
                                        } else {
@@ -390,8 +394,8 @@ class MessageCache {
         * $wgMaxMsgCacheEntrySize are assigned a special value, and are loaded
         * on-demand from the database later.
         *
-        * @param string $code language code.
-        * @return Array: loaded messages for storing in caches.
+        * @param string $code Language code.
+        * @return array Loaded messages for storing in caches.
         */
        function loadFromDB( $code ) {
                wfProfileIn( __METHOD__ );
@@ -451,11 +455,15 @@ class MessageCache {
 
                foreach ( $res as $row ) {
                        $text = Revision::getRevisionText( $row );
-                       if( $text === false ) {
+                       if ( $text === false ) {
                                // Failed to fetch data; possible ES errors?
                                // Store a marker to fetch on-demand as a workaround...
                                $entry = '!TOO BIG';
-                               wfDebugLog( 'MessageCache', __METHOD__ . ": failed to load message page text for {$row->page_title} ($code)" );
+                               wfDebugLog(
+                                       'MessageCache',
+                                       __METHOD__
+                                               . ": failed to load message page text for {$row->page_title} ($code)"
+                               );
                        } else {
                                $entry = ' ' . $text;
                        }
@@ -471,8 +479,8 @@ class MessageCache {
        /**
         * Updates cache as necessary when message page is changed
         *
-        * @param string $title name of the page changed.
-        * @param $text Mixed: new contents of the page.
+        * @param string $title Name of the page changed.
+        * @param mixed $text New contents of the page.
         */
        public function replace( $title, $text ) {
                global $wgMaxMsgCacheEntrySize;
@@ -533,6 +541,9 @@ class MessageCache {
 
        /**
         * Is the given cache array expired due to time passing or a version change?
+        *
+        * @param $cache
+        * @return bool
         */
        protected function isCacheExpired( $cache ) {
                if ( !isset( $cache['VERSION'] ) || !isset( $cache['EXPIRY'] ) ) {
@@ -547,15 +558,14 @@ class MessageCache {
                return false;
        }
 
-
        /**
         * Shortcut to update caches.
         *
-        * @param $cache array: cached messages with a version.
-        * @param $dest string: Either "local-only" to save to local caches only
+        * @param array $cache Cached messages with a version.
+        * @param string $dest Either "local-only" to save to local caches only
         *   or "all" to save to all caches.
-        * @param $code string: Language code.
-        * @return bool on somekind of error.
+        * @param string|bool $code Language code (default: false)
+        * @return bool
         */
        protected function saveToCaches( $cache, $dest, $code = false ) {
                wfProfileIn( __METHOD__ );
@@ -584,8 +594,7 @@ class MessageCache {
        /**
         * Represents a write lock on the messages key
         *
-        * @param $key string
-        *
+        * @param string $key
         * @return Boolean: success
         */
        function lock( $key ) {
@@ -619,8 +628,8 @@ class MessageCache {
        /**
         * Get a message from either the content language or the user language.
         *
-        * @param $key String: the message cache key
-        * @param $useDB Boolean: get the message from the DB, false to use only
+        * @param string $key The message cache key
+        * @param bool $useDB Get the message from the DB, false to use only
         *               the localisation
         * @param bool|string $langcode Code of the language to get the message for, if
         *                  it is a valid code create a language for that language,
@@ -630,8 +639,7 @@ class MessageCache {
         *                  parameter functionality), or if it is a true boolean
         *                  then use the wikis content language (also as a
         *                  fallback).
-        * @param $isFullKey Boolean: specifies whether $key is a two part key
-        *                   "msg/lang".
+        * @param bool $isFullKey Specifies whether $key is a two part key "msg/lang".
         *
         * @throws MWException
         * @return string|bool
@@ -640,7 +648,8 @@ class MessageCache {
                global $wgLanguageCode, $wgContLang;
 
                if ( is_int( $key ) ) {
-                       // "Non-string key given" exception sometimes happens for numerical strings that become ints somewhere on their way here
+                       // "Non-string key given" exception sometimes happens for numerical
+                       // strings that become ints somewhere on their way here
                        $key = strval( $key );
                }
 
@@ -673,9 +682,9 @@ class MessageCache {
                }
 
                # Try the MediaWiki namespace
-               if( !$this->mDisable && $useDB ) {
+               if ( !$this->mDisable && $useDB ) {
                        $title = $uckey;
-                       if( !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
+                       if ( !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
                                $title .= '/' . $langcode;
                        }
                        $message = $this->getMsgFromNamespace( $title, $langcode );
@@ -690,7 +699,7 @@ class MessageCache {
                }
 
                # Try the array of another language
-               if( $message === false ) {
+               if ( $message === false ) {
                        $parts = explode( '/', $lckey );
                        # We may get calls for things that are http-urls from sidebar
                        # Let's not load nonexistent languages for those
@@ -704,14 +713,15 @@ class MessageCache {
                }
 
                # Is this a custom message? Try the default language in the db...
-               if( ( $message === false || $message === '-' ) &&
+               if ( ( $message === false || $message === '-' ) &&
                        !$this->mDisable && $useDB &&
-                       !$isFullKey && ( $langcode != $wgLanguageCode ) ) {
+                       !$isFullKey && ( $langcode != $wgLanguageCode )
+               ) {
                        $message = $this->getMsgFromNamespace( $uckey, $wgLanguageCode );
                }
 
                # Final fallback
-               if( $message === false ) {
+               if ( $message === false ) {
                        return false;
                }
 
@@ -737,8 +747,7 @@ class MessageCache {
         * and self::get() are some examples in core.
         *
         * @param string $title Message cache key with initial uppercase letter.
-        * @param string $code code denoting the language to try.
-        *
+        * @param string $code Code denoting the language to try.
         * @return string|bool False on failure
         */
        function getMsgFromNamespace( $title, $code ) {
@@ -749,7 +758,7 @@ class MessageCache {
                                return substr( $entry, 1 );
                        } elseif ( $entry === '!NONEXISTENT' ) {
                                return false;
-                       } elseif( $entry === '!TOO BIG' ) {
+                       } elseif ( $entry === '!TOO BIG' ) {
                                // Fall through and try invididual message cache below
                        }
                } else {
@@ -787,17 +796,24 @@ class MessageCache {
                        $content = $revision->getContent();
                        if ( !$content ) {
                                // A possibly temporary loading failure.
-                               wfDebugLog( 'MessageCache', __METHOD__ . ": failed to load message page text for {$title} ($code)" );
+                               wfDebugLog(
+                                       'MessageCache',
+                                       __METHOD__ . ": failed to load message page text for {$title} ($code)"
+                               );
                                $message = null; // no negative caching
                        } else {
                                // XXX: Is this the right way to turn a Content object into a message?
-                               // NOTE: $content is typically either WikitextContent, JavaScriptContent or CssContent.
-                               //       MessageContent is *not* used for storing messages, it's only used for wrapping them when needed.
+                               // NOTE: $content is typically either WikitextContent, JavaScriptContent or
+                               //       CssContent. MessageContent is *not* used for storing messages, it's
+                               //       only used for wrapping them when needed.
                                $message = $content->getWikitextForTransclusion();
 
                                if ( $message === false || $message === null ) {
-                                       wfDebugLog( 'MessageCache', __METHOD__ . ": message content doesn't provide wikitext "
-                                                               . "(content model: " . $content->getContentHandler() . ")" );
+                                       wfDebugLog(
+                                               'MessageCache',
+                                               __METHOD__ . ": message content doesn't provide wikitext "
+                                                       . "(content model: " . $content->getContentHandler() . ")"
+                                       );
 
                                        $message = false; // negative caching
                                } else {
@@ -818,15 +834,15 @@ class MessageCache {
        }
 
        /**
-        * @param $message string
-        * @param $interface bool
-        * @param $language
-        * @param $title Title
+        * @param string $message
+        * @param bool $interface
+        * @param string $language Language code
+        * @param Title $title
         * @return string
         */
        function transform( $message, $interface = false, $language = null, $title = null ) {
                // Avoid creating parser if nothing to transform
-               if( strpos( $message, '{{' ) === false ) {
+               if ( strpos( $message, '{{' ) === false ) {
                        return $message;
                }
 
@@ -870,14 +886,16 @@ class MessageCache {
        }
 
        /**
-        * @param $text string
-        * @param $title Title
-        * @param $linestart bool
-        * @param $interface bool
-        * @param $language
+        * @param string $text
+        * @param Title $title
+        * @param bool $linestart Whether or not this is at the start of a line
+        * @param bool $interface Whether this is an interface message
+        * @param string $language Language code
         * @return ParserOutput|string
         */
-       public function parse( $text, $title = null, $linestart = true, $interface = false, $language = null  ) {
+       public function parse( $text, $title = null, $linestart = true,
+               $interface = false, $language = null
+       ) {
                if ( $this->mInParser ) {
                        return htmlspecialchars( $text );
                }
@@ -936,12 +954,12 @@ class MessageCache {
        public function figureMessage( $key ) {
                global $wgLanguageCode;
                $pieces = explode( '/', $key );
-               if( count( $pieces ) < 2 ) {
+               if ( count( $pieces ) < 2 ) {
                        return array( $key, $wgLanguageCode );
                }
 
                $lang = array_pop( $pieces );
-               if( !Language::fetchLanguageName( $lang, null, 'mw' ) ) {
+               if ( !Language::fetchLanguageName( $lang, null, 'mw' ) ) {
                        return array( $key, $wgLanguageCode );
                }
 
@@ -954,7 +972,7 @@ class MessageCache {
         * If $code is the content language code, this will return all message keys
         * for which MediaWiki:msgkey exists. If $code is another language code, this
         * will ONLY return message keys for which MediaWiki:msgkey/$code exists.
-        * @param $code string
+        * @param string $code Language code
         * @return array of message keys (strings)
         */
        public function getAllMessageKeys( $code ) {