Pass array to Title::getLocalURL instead of an urlencoded string
[lhc/web/wiklou.git] / includes / OutputPage.php
index 6349de8..08eb3ae 100644 (file)
@@ -123,7 +123,7 @@ class OutputPage extends ContextSource {
        var $mScripts = '';
 
        /**
-        * Inline CSS styles. Use addInlineStyle() sparsingly
+        * Inline CSS styles. Use addInlineStyle() sparingly
         */
        var $mInlineStyles = '';
 
@@ -253,6 +253,11 @@ class OutputPage extends ContextSource {
         */
        private $mProperties = array();
 
+       /**
+        * @var string|null: ResourceLoader target for load.php links. If null, will be omitted
+        */
+       private $mTarget = null;
+
        /**
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will implicitly create
@@ -314,7 +319,7 @@ class OutputPage extends ContextSource {
         * @param string $text or array of strings
         */
        function addKeyword( $text ) {
-               if( is_array( $text ) ) {
+               if ( is_array( $text ) ) {
                        $this->mKeywords = array_merge( $this->mKeywords, $text );
                } else {
                        array_push( $this->mKeywords, $text );
@@ -408,13 +413,14 @@ class OutputPage extends ContextSource {
        public function addScriptFile( $file, $version = null ) {
                global $wgStylePath, $wgStyleVersion;
                // See if $file parameter is an absolute URL or begins with a slash
-               if( substr( $file, 0, 1 ) == '/' || preg_match( '#^[a-z]*://#i', $file ) ) {
+               if ( substr( $file, 0, 1 ) == '/' || preg_match( '#^[a-z]*://#i', $file ) ) {
                        $path = $file;
                } else {
                        $path = "{$wgStylePath}/common/{$file}";
                }
-               if ( is_null( $version ) )
+               if ( is_null( $version ) ) {
                        $version = $wgStyleVersion;
+               }
                $this->addScript( Html::linkedScript( wfAppendQuery( $path, $version ) ) );
        }
 
@@ -447,11 +453,12 @@ class OutputPage extends ContextSource {
        protected function filterModules( $modules, $position = null, $type = ResourceLoaderModule::TYPE_COMBINED ) {
                $resourceLoader = $this->getResourceLoader();
                $filteredModules = array();
-               foreach( $modules as $val ) {
+               foreach ( $modules as $val ) {
                        $module = $resourceLoader->getModule( $val );
-                       if( $module instanceof ResourceLoaderModule
+                       if ( $module instanceof ResourceLoaderModule
                                && $module->getOrigin() <= $this->getAllowedModules( $type )
-                               && ( is_null( $position ) || $module->getPosition() == $position ) )
+                               && ( is_null( $position ) || $module->getPosition() == $position )
+                               && ( !$this->mTarget || in_array( $this->mTarget, $module->getTargets() ) ) )
                        {
                                $filteredModules[] = $val;
                        }
@@ -556,6 +563,22 @@ class OutputPage extends ContextSource {
                $this->mModuleMessages = array_merge( $this->mModuleMessages, (array)$modules );
        }
 
+       /**
+        * @return null|string: ResourceLoader target
+        */
+       public function getTarget() {
+               return $this->mTarget;
+       }
+
+       /**
+        * Sets ResourceLoader target for load.php links. If null, will be omitted
+        *
+        * @param $target string|null
+        */
+       public function setTarget( $target ) {
+               $this->mTarget = $target;
+       }
+
        /**
         * Get an array of head items
         *
@@ -665,17 +688,17 @@ class OutputPage extends ContextSource {
         * @return Boolean: true iff cache-ok headers was sent.
         */
        public function checkLastModified( $timestamp ) {
-               global $wgCachePages, $wgCacheEpoch;
+               global $wgCachePages, $wgCacheEpoch, $wgUseSquid, $wgSquidMaxage;
 
                if ( !$timestamp || $timestamp == '19700101000000' ) {
                        wfDebug( __METHOD__ . ": CACHE DISABLED, NO TIMESTAMP\n" );
                        return false;
                }
-               if( !$wgCachePages ) {
+               if ( !$wgCachePages ) {
                        wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
                        return false;
                }
-               if( $this->getUser()->getOption( 'nocache' ) ) {
+               if ( $this->getUser()->getOption( 'nocache' ) ) {
                        wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false );
                        return false;
                }
@@ -686,6 +709,10 @@ class OutputPage extends ContextSource {
                        'user' => $this->getUser()->getTouched(),
                        'epoch' => $wgCacheEpoch
                );
+               if ( $wgUseSquid ) {
+                       // bug 44570: the core page itself may not change, but resources might
+                       $modifiedTimes['sepoch'] = wfTimestamp( TS_MW, time() - $wgSquidMaxage );
+               }
                wfRunHooks( 'OutputPageCheckLastModified', array( &$modifiedTimes ) );
 
                $maxModified = max( $modifiedTimes );
@@ -724,7 +751,7 @@ class OutputPage extends ContextSource {
                        wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n", false );
                wfDebug( __METHOD__ . ": effective Last-Modified: " .
                        wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", false );
-               if( $clientHeaderTime < $maxModified ) {
+               if ( $clientHeaderTime < $maxModified ) {
                        wfDebug( __METHOD__ . ": STALE, $info\n", false );
                        return false;
                }
@@ -766,10 +793,10 @@ class OutputPage extends ContextSource {
        public function setRobotPolicy( $policy ) {
                $policy = Article::formatRobotPolicy( $policy );
 
-               if( isset( $policy['index'] ) ) {
+               if ( isset( $policy['index'] ) ) {
                        $this->setIndexPolicy( $policy['index'] );
                }
-               if( isset( $policy['follow'] ) ) {
+               if ( isset( $policy['follow'] ) ) {
                        $this->setFollowPolicy( $policy['follow'] );
                }
        }
@@ -783,7 +810,7 @@ class OutputPage extends ContextSource {
         */
        public function setIndexPolicy( $policy ) {
                $policy = trim( $policy );
-               if( in_array( $policy, array( 'index', 'noindex' ) ) ) {
+               if ( in_array( $policy, array( 'index', 'noindex' ) ) ) {
                        $this->mIndexPolicy = $policy;
                }
        }
@@ -797,7 +824,7 @@ class OutputPage extends ContextSource {
         */
        public function setFollowPolicy( $policy ) {
                $policy = trim( $policy );
-               if( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
+               if ( in_array( $policy, array( 'follow', 'nofollow' ) ) ) {
                        $this->mFollowPolicy = $policy;
                }
        }
@@ -897,7 +924,7 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Replace the subtile with $str
+        * Replace the subtitle with $str
         *
         * @param string|Message $str new value of the subtitle. String should be safe HTML.
         */
@@ -1284,7 +1311,7 @@ class OutputPage extends ContextSource {
         * @return Int ResourceLoaderModule ORIGIN_ class constant
         */
        public function getAllowedModules( $type ) {
-               if( $type == ResourceLoaderModule::TYPE_COMBINED ) {
+               if ( $type == ResourceLoaderModule::TYPE_COMBINED ) {
                        return min( array_values( $this->mAllowedModules ) );
                } else {
                        return isset( $this->mAllowedModules[$type] )
@@ -1303,7 +1330,7 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * As for setAllowedModules(), but don't inadvertantly make the page more accessible
+        * As for setAllowedModules(), but don't inadvertently make the page more accessible
         * @param  $type String
         * @param  $level Int ResourceLoaderModule class constant
         */
@@ -1401,7 +1428,7 @@ class OutputPage extends ContextSource {
         * @param $timestamp Mixed: string, or null
         * @return Mixed: previous value
         */
-       public function setRevisionTimestamp( $timestamp) {
+       public function setRevisionTimestamp( $timestamp ) {
                return wfSetVar( $this->mRevisionTimestamp, $timestamp );
        }
 
@@ -1467,7 +1494,7 @@ class OutputPage extends ContextSource {
         * @param $interface Boolean: is this text in the user interface language?
         */
        public function addWikiText( $text, $linestart = true, $interface = true ) {
-               $title = $this->getTitle(); // Work arround E_STRICT
+               $title = $this->getTitle(); // Work around E_STRICT
                if ( !$title ) {
                        throw new MWException( 'Title is null' );
                }
@@ -1626,7 +1653,7 @@ class OutputPage extends ContextSource {
        public function parse( $text, $linestart = true, $interface = false, $language = null ) {
                global $wgParser;
 
-               if( is_null( $this->getTitle() ) ) {
+               if ( is_null( $this->getTitle() ) ) {
                        throw new MWException( 'Empty $mTitle in ' . __METHOD__ );
                }
 
@@ -1750,8 +1777,8 @@ class OutputPage extends ContextSource {
        public function addVaryHeader( $header, $option = null ) {
                if ( !array_key_exists( $header, $this->mVaryHeader ) ) {
                        $this->mVaryHeader[$header] = (array)$option;
-               } elseif( is_array( $option ) ) {
-                       if( is_array( $this->mVaryHeader[$header] ) ) {
+               } elseif ( is_array( $option ) ) {
+                       if ( is_array( $this->mVaryHeader[$header] ) ) {
                                $this->mVaryHeader[$header] = array_merge( $this->mVaryHeader[$header], $option );
                        } else {
                                $this->mVaryHeader[$header] = $option;
@@ -1785,7 +1812,7 @@ class OutputPage extends ContextSource {
                $this->addVaryHeader( 'Cookie', $cookiesOption );
 
                $headers = array();
-               foreach( $this->mVaryHeader as $header => $option ) {
+               foreach ( $this->mVaryHeader as $header => $option ) {
                        $newheader = $header;
                        if ( is_array( $option ) && count( $option ) > 0 ) {
                                $newheader .= ';' . implode( ';', $option );
@@ -1807,11 +1834,11 @@ class OutputPage extends ContextSource {
         */
        function addAcceptLanguage() {
                $lang = $this->getTitle()->getPageLanguage();
-               if( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
+               if ( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
                        $variants = $lang->getVariants();
                        $aloption = array();
                        foreach ( $variants as $variant ) {
-                               if( $variant === $lang->getCode() ) {
+                               if ( $variant === $lang->getCode() ) {
                                        continue;
                                } else {
                                        $aloption[] = 'string-contains=' . $variant;
@@ -1892,12 +1919,11 @@ class OutputPage extends ContextSource {
                        $response->header( $this->getXVO() );
                }
 
-               if( $this->mEnableClientCache ) {
-                       if(
+               if ( $this->mEnableClientCache ) {
+                       if (
                                $wgUseSquid && session_id() == '' && !$this->isPrintable() &&
                                $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies()
-                       )
-                       {
+                       ) {
                                if ( $wgUseESI ) {
                                        # We'll purge the proxy cache explicitly, but require end user agents
                                        # to revalidate against the proxy on each visit.
@@ -1924,7 +1950,7 @@ class OutputPage extends ContextSource {
                                $response->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
                                $response->header( "Cache-Control: private, must-revalidate, max-age=0" );
                        }
-                       if( $this->mLastModified ) {
+                       if ( $this->mLastModified ) {
                                $response->header( "Last-Modified: {$this->mLastModified}" );
                        }
                } else {
@@ -1939,7 +1965,7 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Get the message associed with the HTTP response code $code
+        * Get the message associated with the HTTP response code $code
         *
         * @param $code Integer: status code
         * @return String or null: message or null if $code is not in the list of
@@ -1959,7 +1985,7 @@ class OutputPage extends ContextSource {
        public function output() {
                global $wgLanguageCode, $wgDebugRedirects, $wgMimeType, $wgVaryOnXFP;
 
-               if( $this->mDoNothing ) {
+               if ( $this->mDoNothing ) {
                        return;
                }
 
@@ -1974,9 +2000,9 @@ class OutputPage extends ContextSource {
                        $redirect = $this->mRedirect;
                        $code = $this->mRedirectCode;
 
-                       if( wfRunHooks( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) {
-                               if( $code == '301' || $code == '303' ) {
-                                       if( !$wgDebugRedirects ) {
+                       if ( wfRunHooks( "BeforePageRedirect", array( $this, &$redirect, &$code ) ) ) {
+                               if ( $code == '301' || $code == '303' ) {
+                                       if ( !$wgDebugRedirects ) {
                                                $message = HttpStatus::getMessage( $code );
                                                $response->header( "HTTP/1.1 $code $message" );
                                        }
@@ -1988,7 +2014,7 @@ class OutputPage extends ContextSource {
                                $this->sendCacheControl();
 
                                $response->header( "Content-Type: text/html; charset=utf-8" );
-                               if( $wgDebugRedirects ) {
+                               if ( $wgDebugRedirects ) {
                                        $url = htmlspecialchars( $redirect );
                                        print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
                                        print "<p>Location: <a href=\"$url\">$url</a></p>\n";
@@ -2097,7 +2123,7 @@ class OutputPage extends ContextSource {
         * @param array $params message parameters; ignored if $msg is a Message object
         */
        public function showErrorPage( $title, $msg, $params = array() ) {
-               if( !$title instanceof Message ) {
+               if ( !$title instanceof Message ) {
                        $title = $this->msg( $title );
                }
 
@@ -2238,7 +2264,7 @@ class OutputPage extends ContextSource {
                if ( count( $errors ) > 1 ) {
                        $text .= '<ul class="permissions-errors">' . "\n";
 
-                       foreach( $errors as $error ) {
+                       foreach ( $errors as $error ) {
                                $text .= '<li>';
                                $text .= call_user_func_array( array( $this, 'msg' ), $error )->plain();
                                $text .= "</li>\n";
@@ -2286,7 +2312,7 @@ class OutputPage extends ContextSource {
 
                if ( !empty( $reasons ) ) {
                        // Permissions error
-                       if( $source ) {
+                       if ( $source ) {
                                $this->setPageTitle( $this->msg( 'viewsource-title', $this->getTitle()->getPrefixedText() ) );
                                $this->addBacklinkSubtitle( $this->getTitle() );
                        } else {
@@ -2299,7 +2325,7 @@ class OutputPage extends ContextSource {
                }
 
                // Show source, if supplied
-               if( is_string( $source ) ) {
+               if ( is_string( $source ) ) {
                        $this->addWikiMsg( 'viewsourcetext' );
 
                        $pageLang = $this->getTitle()->getPageLanguage();
@@ -2325,13 +2351,13 @@ $templates
                # If the title doesn't exist, it's fairly pointless to print a return
                # link to it.  After all, you just tried editing it and couldn't, so
                # what's there to do there?
-               if( $this->getTitle()->exists() ) {
+               if ( $this->getTitle()->exists() ) {
                        $this->returnToMain( null, $this->getTitle() );
                }
        }
 
        /**
-        * Turn off regular page output and return an error reponse
+        * Turn off regular page output and return an error response
         * for when rate limiting has triggered.
         */
        public function rateLimited() {
@@ -2349,7 +2375,7 @@ $templates
         */
        public function showLagWarning( $lag ) {
                global $wgSlaveLagWarning, $wgSlaveLagCritical;
-               if( $lag >= $wgSlaveLagWarning ) {
+               if ( $lag >= $wgSlaveLagWarning ) {
                        $message = $lag < $wgSlaveLagCritical
                                ? 'lag-warn-normal'
                                : 'lag-warn-high';
@@ -2393,15 +2419,14 @@ $templates
         * @param $options Options array to pass to Linker
         */
        public function addReturnTo( $title, $query = array(), $text = null, $options = array() ) {
-               if( in_array( 'http', $options ) ) {
+               if ( in_array( 'http', $options ) ) {
                        $proto = PROTO_HTTP;
-               } elseif( in_array( 'https', $options ) ) {
+               } elseif ( in_array( 'https', $options ) ) {
                        $proto = PROTO_HTTPS;
                } else {
                        $proto = PROTO_RELATIVE;
                }
 
-               $this->addLink( array( 'rel' => 'next', 'href' => $title->getFullURL( '', false, $proto ) ) );
                $link = $this->msg( 'returnto' )->rawParams(
                        Linker::link( $title, $text, array(), $query, $options ) )->escaped();
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
@@ -2531,7 +2556,7 @@ $templates
 
                        wfRunHooks( 'AjaxAddScript', array( &$this ) );
 
-                       if( $wgAjaxWatch && $this->getUser()->isLoggedIn() ) {
+                       if ( $wgAjaxWatch && $this->getUser()->isLoggedIn() ) {
                                $this->addModules( 'mediawiki.page.watch.ajax' );
                        }
 
@@ -2600,6 +2625,9 @@ $templates
                                return $links;
                        }
                }
+               if ( !is_null( $this->mTarget ) ) {
+                       $extraQuery['target'] = $this->mTarget;
+               }
 
                // Create keyed-by-group list of module objects from modules list
                $groups = array();
@@ -2612,8 +2640,8 @@ $templates
                                        && $only == ResourceLoaderModule::TYPE_SCRIPTS )
                                || ( $module->getOrigin() > $this->getAllowedModules( ResourceLoaderModule::TYPE_STYLES )
                                        && $only == ResourceLoaderModule::TYPE_STYLES )
-                               )
-                       {
+                               || ( $this->mTarget && !in_array( $this->mTarget, $module->getTargets() ) )
+                       {
                                continue;
                        }
 
@@ -2648,7 +2676,7 @@ $templates
                        );
                        $context = new ResourceLoaderContext( $resourceLoader, new FauxRequest( $query ) );
                        // Extract modules that know they're empty
-                       $emptyModules = array ();
+                       $emptyModules = array();
                        foreach ( $grpModules as $key => $module ) {
                                if ( $module->isKnownEmpty( $context ) ) {
                                        $emptyModules[$key] = 'ready';
@@ -2659,13 +2687,9 @@ $templates
                        if ( count( $emptyModules ) > 0 && $only !== ResourceLoaderModule::TYPE_STYLES ) {
                                // If we're only getting the styles, we don't need to do anything for empty modules.
                                $links .= Html::inlineScript(
-
                                                ResourceLoader::makeLoaderConditionalScript(
-
                                                                ResourceLoader::makeLoaderStateScript( $emptyModules )
-
                                                )
-
                                ) . "\n";
                        }
 
@@ -2695,7 +2719,7 @@ $templates
                        }
                        // Special handling for the user group; because users might change their stuff
                        // on-wiki like user pages, or user preferences; we need to find the highest
-                       // timestamp of these user-changable modules so we can ensure cache misses on change
+                       // timestamp of these user-changeable modules so we can ensure cache misses on change
                        // This should NOT be done for the site group (bug 27564) because anons get that too
                        // and we shouldn't be putting timestamps in Squid-cached HTML
                        $version = null;
@@ -2732,7 +2756,7 @@ $templates
                                // Automatically select style/script elements
                                if ( $only === ResourceLoaderModule::TYPE_STYLES ) {
                                        $link = Html::linkedStyle( $url );
-                               } else if ( $loadCall ) {
+                               } elseif ( $loadCall ) {
                                        $link = Html::inlineScript(
                                                ResourceLoader::makeLoaderConditionalScript(
                                                        Xml::encodeJsCall( 'mw.loader.load', array( $url, 'text/javascript', true ) )
@@ -2743,7 +2767,7 @@ $templates
                                }
                        }
 
-                       if( $group == 'noscript' ) {
+                       if ( $group == 'noscript' ) {
                                $links .= Html::rawElement( 'noscript', array(), $link ) . "\n";
                        } else {
                                $links .= $link . "\n";
@@ -2847,14 +2871,14 @@ $templates
                        );
                        $defaultModules['site'] = 'loading';
                } else {
-                       // The wiki is configured to not allow a site module.
-                       $defaultModules['site'] = 'missing';
+                       // Site module is empty, save request by marking ready in advance (bug 46857)
+                       $defaultModules['site'] = 'ready';
                }
 
                // Add user JS if enabled
                if ( $wgAllowUserJs ) {
                        if ( $this->getUser()->isLoggedIn() ) {
-                               if( $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview() ) {
+                               if ( $this->getTitle() && $this->getTitle()->isJsSubpage() && $this->userCanPreview() ) {
                                        # XXX: additional security check/prompt?
                                        // We're on a preview of a JS subpage
                                        // Exclude this page from the user module in case it's in there (bug 26283)
@@ -2874,15 +2898,14 @@ $templates
                                }
                                $defaultModules['user'] = 'loading';
                        } else {
-                               // Non-logged-in users have no user module. Treat it as empty and 'ready' to avoid
-                               // blocking default gadgets that might depend on it. Although arguably default-enabled
-                               // gadgets should not depend on the user module, it's harmless and less error-prone to
-                               // handle this case.
+                               // Non-logged-in users have an empty user module.
+                               // Save request by marking ready in advance (bug 46857)
                                $defaultModules['user'] = 'ready';
                        }
                } else {
-                       // User JS disabled
-                       $defaultModules['user'] = 'missing';
+                       // User modules are disabled on this wiki.
+                       // Save request by marking ready in advance (bug 46857)
+                       $defaultModules['user'] = 'ready';
                }
 
                // Group JS is only enabled if site JS is enabled.
@@ -2893,13 +2916,13 @@ $templates
                                );
                                $defaultModules['user.groups'] = 'loading';
                        } else {
-                               // Non-logged-in users have no user.groups module. Treat it as empty and 'ready' to
-                               // avoid blocking gadgets that might depend upon the module.
+                               // Non-logged-in users have no user.groups module.
+                               // Save request by marking ready in advance (bug 46857)
                                $defaultModules['user.groups'] = 'ready';
                        }
                } else {
                        // Site (and group JS) disabled
-                       $defaultModules['user.groups'] = 'missing';
+                       $defaultModules['user.groups'] = 'ready';
                }
 
                $loaderInit = '';
@@ -3118,7 +3141,7 @@ $templates
                ) );
 
                $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
-               if( $p !== 'index,follow' ) {
+               if ( $p !== 'index,follow' ) {
                        // http://www.robotstxt.org/wc/meta-user.html
                        // Only show if it's different from the default robots policy
                        $tags['meta-robots'] = Html::element( 'meta', array(
@@ -3266,7 +3289,7 @@ $templates
 
                # Feeds
                if ( $wgFeed ) {
-                       foreach( $this->getSyndicationLinks() as $format => $link ) {
+                       foreach ( $this->getSyndicationLinks() as $format => $link ) {
                                # Use the page name for the title.  In principle, this could
                                # lead to issues with having the same name for different feeds
                                # corresponding to the same page, but we can't avoid that at
@@ -3301,7 +3324,7 @@ $templates
                                foreach ( $wgAdvertisedFeedTypes as $format ) {
                                        $tags[] = $this->feedLink(
                                                $format,
-                                               $rctitle->getLocalURL( "feed={$format}" ),
+                                               $rctitle->getLocalURL( array( 'feed' => $format ) ),
                                                $this->msg( "site-{$format}-feed", $wgSitename )->text() # For grep: 'site-rss-feed', 'site-atom-feed'.
                                        );
                                }
@@ -3368,13 +3391,13 @@ $templates
                $options = array();
                // Even though we expect the media type to be lowercase, but here we
                // force it to lowercase to be safe.
-               if( $media ) {
+               if ( $media ) {
                        $options['media'] = $media;
                }
-               if( $condition ) {
+               if ( $condition ) {
                        $options['condition'] = $condition;
                }
-               if( $dir ) {
+               if ( $dir ) {
                        $options['dir'] = $dir;
                }
                $this->styles[$style] = $options;
@@ -3386,7 +3409,7 @@ $templates
         * @param string $flip Set to 'flip' to flip the CSS if needed
         */
        public function addInlineStyle( $style_css, $flip = 'noflip' ) {
-               if( $flip === 'flip' && $this->getLanguage()->isRTL() ) {
+               if ( $flip === 'flip' && $this->getLanguage()->isRTL() ) {
                        # If wanted, and the interface is right-to-left, flip the CSS
                        $style_css = CSSJanus::transform( $style_css, true, false );
                }
@@ -3416,7 +3439,7 @@ $templates
                if ( $wgUseSiteCss ) {
                        $moduleStyles[] = 'site';
                        $moduleStyles[] = 'noscript';
-                       if( $this->getUser()->isLoggedIn() ) {
+                       if ( $this->getUser()->isLoggedIn() ) {
                                $moduleStyles[] = 'user.groups';
                        }
                }
@@ -3497,9 +3520,9 @@ $templates
                }
                $this->mExtStyles = array();
 
-               foreach( $this->styles as $file => $options ) {
+               foreach ( $this->styles as $file => $options ) {
                        $link = $this->styleLink( $file, $options );
-                       if( $link ) {
+                       if ( $link ) {
                                $links[$file] = $link;
                        }
                }
@@ -3515,22 +3538,22 @@ $templates
         * @return String: HTML fragment
         */
        protected function styleLink( $style, $options ) {
-               if( isset( $options['dir'] ) ) {
-                       if( $this->getLanguage()->getDir() != $options['dir'] ) {
+               if ( isset( $options['dir'] ) ) {
+                       if ( $this->getLanguage()->getDir() != $options['dir'] ) {
                                return '';
                        }
                }
 
-               if( isset( $options['media'] ) ) {
+               if ( isset( $options['media'] ) ) {
                        $media = self::transformCssMedia( $options['media'] );
-                       if( is_null( $media ) ) {
+                       if ( is_null( $media ) ) {
                                return '';
                        }
                } else {
                        $media = 'all';
                }
 
-               if( substr( $style, 0, 1 ) == '/' ||
+               if ( substr( $style, 0, 1 ) == '/' ||
                        substr( $style, 0, 5 ) == 'http:' ||
                        substr( $style, 0, 6 ) == 'https:' ) {
                        $url = $style;
@@ -3541,7 +3564,7 @@ $templates
 
                $link = Html::linkedStyle( $url, $media );
 
-               if( isset( $options['condition'] ) ) {
+               if ( isset( $options['condition'] ) ) {
                        $condition = htmlspecialchars( $options['condition'] );
                        $link = "<!--[if $condition]>$link<![endif]-->";
                }
@@ -3566,22 +3589,22 @@ $templates
                        'printable' => 'print',
                        'handheld' => 'handheld',
                );
-               foreach( $switches as $switch => $targetMedia ) {
-                       if( $wgRequest->getBool( $switch ) ) {
-                               if( $media == $targetMedia ) {
+               foreach ( $switches as $switch => $targetMedia ) {
+                       if ( $wgRequest->getBool( $switch ) ) {
+                               if ( $media == $targetMedia ) {
                                        $media = '';
-                               } elseif( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
+                               } elseif ( preg_match( $screenMediaQueryRegex, $media ) === 1 ) {
                                        // This regex will not attempt to understand a comma-separated media_query_list
                                        //
                                        // Example supported values for $media: 'screen', 'only screen', 'screen and (min-width: 982px)' ),
                                        // Example NOT supported value for $media: '3d-glasses, screen, print and resolution > 90dpi'
                                        //
-                                       // If it's a print request, we never want any kind of screen styesheets
+                                       // If it's a print request, we never want any kind of screen stylesheets
                                        // If it's a handheld request (currently the only other choice with a switch),
                                        // we don't want simple 'screen' but we might want screen queries that
                                        // have a max-width or something, so we'll pass all others on and let the
                                        // client do the query.
-                                       if( $targetMedia == 'print' || $media == 'screen' ) {
+                                       if ( $targetMedia == 'print' || $media == 'screen' ) {
                                                return null;
                                        }
                                }
@@ -3589,13 +3612,13 @@ $templates
                }
 
                // Expand longer media queries as iPhone doesn't grok 'handheld'
-               if( $wgHandheldForIPhone ) {
+               if ( $wgHandheldForIPhone ) {
                        $mediaAliases = array(
                                'screen' => 'screen and (min-device-width: 481px)',
                                'handheld' => 'handheld, only screen and (max-device-width: 480px)',
                        );
 
-                       if( isset( $mediaAliases[$media] ) ) {
+                       if ( isset( $mediaAliases[$media] ) ) {
                                $media = $mediaAliases[$media];
                        }
                }