Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / OutputPage.php
index bea8de8..35b2f38 100644 (file)
@@ -1,7 +1,24 @@
 <?php
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( 1 );
-}
+/**
+ * Preparation for the final page rendering.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
 
 /**
  * This class should be covered by a general architecture document which does
@@ -1661,18 +1678,6 @@ class OutputPage extends ContextSource {
                return $cookies;
        }
 
-       /**
-        * Return whether this page is not cacheable because "useskin" or "uselang"
-        * URL parameters were passed.
-        *
-        * @return Boolean
-        */
-       function uncacheableBecauseRequestVars() {
-               $request = $this->getRequest();
-               return $request->getText( 'useskin', false ) === false
-                       && $request->getText( 'uselang', false ) === false;
-       }
-
        /**
         * Check if the request has a cache-varying cookie header
         * If it does, it's very important that we don't allow public caching
@@ -1734,7 +1739,7 @@ class OutputPage extends ContextSource {
                $headers = array();
                foreach( $this->mVaryHeader as $header => $option ) {
                        $newheader = $header;
-                       if( is_array( $option ) ) {
+                       if ( is_array( $option ) && count( $option ) > 0 ) {
                                $newheader .= ';' . implode( ';', $option );
                        }
                        $headers[] = $newheader;
@@ -1840,7 +1845,7 @@ class OutputPage extends ContextSource {
                        $response->header( $this->getXVO() );
                }
 
-               if( !$this->uncacheableBecauseRequestVars() && $this->mEnableClientCache ) {
+               if( $this->mEnableClientCache ) {
                        if(
                                $wgUseSquid && session_id() == '' && !$this->isPrintable() &&
                                $this->mSquidMaxage != 0 && !$this->haveCacheVaryCookies()
@@ -2584,10 +2589,14 @@ $templates
                        // Inline empty modules: since they're empty, just mark them as 'ready'
                        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(\r
-                                               ResourceLoader::makeLoaderConditionalScript(\r
-                                                               ResourceLoader::makeLoaderStateScript( $emptyModules )\r
-                                               )\r
+                               $links .= Html::inlineScript(
+
+                                               ResourceLoader::makeLoaderConditionalScript(
+
+                                                               ResourceLoader::makeLoaderStateScript( $emptyModules )
+
+                                               )
+
                                ) . "\n";
                        }
 
@@ -2803,7 +2812,7 @@ $templates
                                $defaultModules['user'] = 'ready';
                        }
                } else {
-                       // User JS diabled
+                       // User JS disabled
                        $defaultModules['user'] = 'missing';
                }
 
@@ -2995,12 +3004,11 @@ $templates
        }
 
        /**
-        * @param $unused
-        * @param $addContentType bool
+        * @param $addContentType bool: Whether <meta> specifying content type should be returned
         *
-        * @return string HTML tag links to be put in the header.
+        * @return array in format "link name or number => 'link html'".
         */
-       public function getHeadLinks( $unused = null, $addContentType = false ) {
+       public function getHeadLinksArray( $addContentType = false ) {
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
                        $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
                        $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
@@ -3013,20 +3021,20 @@ $templates
                        if ( $wgHtml5 ) {
                                # More succinct than <meta http-equiv=Content-Type>, has the
                                # same effect
-                               $tags[] = Html::element( 'meta', array( 'charset' => 'UTF-8' ) );
+                               $tags['meta-charset'] = Html::element( 'meta', array( 'charset' => 'UTF-8' ) );
                        } else {
-                               $tags[] = Html::element( 'meta', array(
+                               $tags['meta-content-type'] = Html::element( 'meta', array(
                                        'http-equiv' => 'Content-Type',
                                        'content' => "$wgMimeType; charset=UTF-8"
                                ) );
-                               $tags[] = Html::element( 'meta', array(  // bug 15835
+                               $tags['meta-content-style-type'] = Html::element( 'meta', array(  // bug 15835
                                        'http-equiv' => 'Content-Style-Type',
                                        'content' => 'text/css'
                                ) );
                        }
                }
 
-               $tags[] = Html::element( 'meta', array(
+               $tags['meta-generator'] = Html::element( 'meta', array(
                        'name' => 'generator',
                        'content' => "MediaWiki $wgVersion",
                ) );
@@ -3035,7 +3043,7 @@ $templates
                if( $p !== 'index,follow' ) {
                        // http://www.robotstxt.org/wc/meta-user.html
                        // Only show if it's different from the default robots policy
-                       $tags[] = Html::element( 'meta', array(
+                       $tags['meta-robots'] = Html::element( 'meta', array(
                                'name' => 'robots',
                                'content' => $p,
                        ) );
@@ -3046,7 +3054,7 @@ $templates
                                "/<.*?" . ">/" => '',
                                "/_/" => ' '
                        );
-                       $tags[] = Html::element( 'meta', array(
+                       $tags['meta-keywords'] = Html::element( 'meta', array(
                                'name' => 'keywords',
                                'content' =>  preg_replace(
                                        array_keys( $strip ),
@@ -3063,7 +3071,11 @@ $templates
                        } else {
                                $a = 'name';
                        }
-                       $tags[] = Html::element( 'meta',
+                       $tagName = "meta-{$tag[0]}";
+                       if ( isset( $tags[$tagName] ) ) {
+                               $tagName .= $tag[1];
+                       }
+                       $tags[$tagName] = Html::element( 'meta',
                                array(
                                        $a => $tag[0],
                                        'content' => $tag[1]
@@ -3082,14 +3094,14 @@ $templates
                                && ( $this->getTitle()->exists() || $this->getTitle()->quickUserCan( 'create', $user ) ) ) {
                                // Original UniversalEditButton
                                $msg = $this->msg( 'edit' )->text();
-                               $tags[] = Html::element( 'link', array(
+                               $tags['universal-edit-button'] = Html::element( 'link', array(
                                        'rel' => 'alternate',
                                        'type' => 'application/x-wiki',
                                        'title' => $msg,
                                        'href' => $this->getTitle()->getLocalURL( 'action=edit' )
                                ) );
                                // Alternate edit link
-                               $tags[] = Html::element( 'link', array(
+                               $tags['alternative-edit'] = Html::element( 'link', array(
                                        'rel' => 'edit',
                                        'title' => $msg,
                                        'href' => $this->getTitle()->getLocalURL( 'action=edit' )
@@ -3102,15 +3114,15 @@ $templates
                # uses whichever one appears later in the HTML source. Make sure
                # apple-touch-icon is specified first to avoid this.
                if ( $wgAppleTouchIcon !== false ) {
-                       $tags[] = Html::element( 'link', array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
+                       $tags['apple-touch-icon'] = Html::element( 'link', array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
                }
 
                if ( $wgFavicon !== false ) {
-                       $tags[] = Html::element( 'link', array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
+                       $tags['favicon'] = Html::element( 'link', array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
                }
 
                # OpenSearch description link
-               $tags[] = Html::element( 'link', array(
+               $tags['opensearch'] = Html::element( 'link', array(
                        'rel' => 'search',
                        'type' => 'application/opensearchdescription+xml',
                        'href' => wfScript( 'opensearch_desc' ),
@@ -3122,7 +3134,7 @@ $templates
                        # for the MediaWiki API (and potentially additional custom API
                        # support such as WordPress or Twitter-compatible APIs for a
                        # blogging extension, etc)
-                       $tags[] = Html::element( 'link', array(
+                       $tags['rsd'] = Html::element( 'link', array(
                                'rel' => 'EditURI',
                                'type' => 'application/rsd+xml',
                                // Output a protocol-relative URL here if $wgServer is protocol-relative
@@ -3142,14 +3154,14 @@ $templates
                                if ( !$urlvar ) {
                                        $variants = $lang->getVariants();
                                        foreach ( $variants as $_v ) {
-                                               $tags[] = Html::element( 'link', array(
+                                               $tags["variant-$_v"] = Html::element( 'link', array(
                                                        'rel' => 'alternate',
                                                        'hreflang' => $_v,
                                                        'href' => $this->getTitle()->getLocalURL( array( 'variant' => $_v ) ) )
                                                );
                                        }
                                } else {
-                                       $tags[] = Html::element( 'link', array(
+                                       $tags['canonical'] = Html::element( 'link', array(
                                                'rel' => 'canonical',
                                                'href' => $this->getTitle()->getCanonicalUrl()
                                        ) );
@@ -3172,7 +3184,7 @@ $templates
                }
 
                if ( $copyright ) {
-                       $tags[] = Html::element( 'link', array(
+                       $tags['copyright'] = Html::element( 'link', array(
                                'rel' => 'copyright',
                                'href' => $copyright )
                        );
@@ -3221,7 +3233,17 @@ $templates
                                }
                        }
                }
-               return implode( "\n", $tags );
+               return $tags;
+       }
+
+       /**
+        * @param $unused
+        * @param $addContentType bool: Whether <meta> specifying content type should be returned
+        *
+        * @return string HTML tag links to be put in the header.
+        */
+       public function getHeadLinks( $unused = null, $addContentType = false ) {
+               return implode( "\n", $this->getHeadLinksArray( $addContentType ) );
        }
 
        /**