Merge "Include the backtrace in the log for job exceptions"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 4a2b17a..3657ac3 100644 (file)
@@ -39,9 +39,6 @@ class OutputPage extends ContextSource {
        /// Should be private. Used with addMeta() which adds "<meta>"
        var $mMetatags = array();
 
-       /// "<meta keywords='stuff'>" most of the time the first 10 links to an article
-       var $mKeywords = array();
-
        var $mLinktags = array();
        var $mCanonicalUrl = false;
 
@@ -313,19 +310,6 @@ class OutputPage extends ContextSource {
                array_push( $this->mMetatags, array( $name, $val ) );
        }
 
-       /**
-        * Add a keyword or a list of keywords in the page header
-        *
-        * @param string $text or array of strings
-        */
-       function addKeyword( $text ) {
-               if ( is_array( $text ) ) {
-                       $this->mKeywords = array_merge( $this->mKeywords, $text );
-               } else {
-                       array_push( $this->mKeywords, $text );
-               }
-       }
-
        /**
         * Add a new \<link\> tag to the page header.
         *
@@ -1296,7 +1280,6 @@ class OutputPage extends ContextSource {
         * Return whether user JavaScript is allowed for this page
         * @deprecated since 1.18 Load modules with ResourceLoader, and origin and
         *     trustworthiness is identified and enforced automagically.
-        *     Will be removed in 1.20.
         * @return Boolean
         */
        public function isUserJsAllowed() {
@@ -1987,7 +1970,8 @@ class OutputPage extends ContextSource {
         * the object, let's actually output it:
         */
        public function output() {
-               global $wgLanguageCode, $wgDebugRedirects, $wgMimeType, $wgVaryOnXFP;
+               global $wgLanguageCode, $wgDebugRedirects, $wgMimeType, $wgVaryOnXFP,
+                       $wgUseAjax, $wgResponsiveImages;
 
                if ( $this->mDoNothing ) {
                        return;
@@ -2050,11 +2034,34 @@ class OutputPage extends ContextSource {
                }
 
                if ( $this->mArticleBodyOnly ) {
-                       $this->out( $this->mBodytext );
+                       echo $this->mBodytext;
                } else {
-                       $this->addDefaultModules();
 
                        $sk = $this->getSkin();
+                       // add skin specific modules
+                       $modules = $sk->getDefaultModules();
+
+                       // enforce various default modules for all skins
+                       $coreModules = array(
+                               // keep this list as small as possible
+                               'mediawiki.page.startup',
+                               'mediawiki.user',
+                       );
+
+                       // Support for high-density display images if enabled
+                       if ( $wgResponsiveImages ) {
+                               $coreModules[] = 'mediawiki.hidpi';
+                       }
+
+                       $this->addModules( $coreModules );
+                       foreach ( $modules as $group ) {
+                               $this->addModules( $group );
+                       }
+                       MWDebug::addModules( $this );
+                       if ( $wgUseAjax ) {
+                               // FIXME: deprecate? - not clear why this is useful
+                               wfRunHooks( 'AjaxAddScript', array( &$this ) );
+                       }
 
                        // Hook that allows last minute changes to the output page, e.g.
                        // adding of CSS or Javascript by extensions.
@@ -2076,11 +2083,13 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Actually output something with print().
+        * Actually output something with print.
         *
         * @param string $ins the string to output
+        * @deprecated since 1.22 Use echo yourself.
         */
        public function out( $ins ) {
+               wfDeprecated( __METHOD__, '1.22' );
                print $ins;
        }
 
@@ -2475,7 +2484,7 @@ $templates
         * @return String: The doctype, opening "<html>", and head element.
         */
        public function headElement( Skin $sk, $includeStyle = true ) {
-               global $wgContLang;
+               global $wgContLang, $wgMimeType;
 
                $userdir = $this->getLanguage()->getDir();
                $sitedir = $wgContLang->getDir();
@@ -2496,10 +2505,22 @@ $templates
                        $ret .= "$openHead\n";
                }
 
+               if ( !Html::isXmlMimeType( $wgMimeType ) ) {
+                       // Add <meta charset="UTF-8">
+                       // This should be before <title> since it defines the charset used by
+                       // text including the text inside <title>.
+                       // The spec recommends defining XHTML5's charset using the XML declaration
+                       // instead of meta.
+                       // Our XML declaration is output by Html::htmlHeader.
+                       // http://www.whatwg.org/html/semantics.html#attr-meta-http-equiv-content-type
+                       // http://www.whatwg.org/html/semantics.html#charset
+                       $ret .= Html::element( 'meta', array( 'charset' => 'UTF-8' ) );
+               }
+
                $ret .= Html::element( 'title', null, $this->getHTMLTitle() ) . "\n";
 
                $ret .= implode( "\n", array(
-                       $this->getHeadLinks( null, true ),
+                       $this->getHeadLinks(),
                        $this->buildCssLinks(),
                        $this->getHeadScripts(),
                        $this->getHeadItems()
@@ -2540,59 +2561,6 @@ $templates
                return $ret;
        }
 
-       /**
-        * Add the default ResourceLoader modules to this object
-        */
-       private function addDefaultModules() {
-               global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
-                       $wgAjaxWatch, $wgResponsiveImages;
-
-               // Add base resources
-               $this->addModules( array(
-                       'mediawiki.user',
-                       'mediawiki.page.startup',
-                       'mediawiki.page.ready',
-               ) );
-               if ( $wgIncludeLegacyJavaScript ) {
-                       $this->addModules( 'mediawiki.legacy.wikibits' );
-               }
-
-               if ( $wgPreloadJavaScriptMwUtil ) {
-                       $this->addModules( 'mediawiki.util' );
-               }
-
-               MWDebug::addModules( $this );
-
-               // Add various resources if required
-               if ( $wgUseAjax ) {
-                       $this->addModules( 'mediawiki.legacy.ajax' );
-
-                       wfRunHooks( 'AjaxAddScript', array( &$this ) );
-
-                       if ( $wgAjaxWatch && $this->getUser()->isLoggedIn() ) {
-                               $this->addModules( 'mediawiki.page.watch.ajax' );
-                       }
-
-                       if ( !$this->getUser()->getOption( 'disablesuggest', false ) ) {
-                               $this->addModules( 'mediawiki.searchSuggest' );
-                       }
-               }
-
-               if ( $this->getUser()->getBoolOption( 'editsectiononrightclick' ) ) {
-                       $this->addModules( 'mediawiki.action.view.rightClickEdit' );
-               }
-
-               # Crazy edit-on-double-click stuff
-               if ( $this->isArticle() && $this->getUser()->getOption( 'editondblclick' ) ) {
-                       $this->addModules( 'mediawiki.action.view.dblClickEdit' );
-               }
-
-               // Support for high-density display images
-               if ( $wgResponsiveImages ) {
-                       $this->addModules( 'mediawiki.hidpi' );
-               }
-       }
-
        /**
         * Get a ResourceLoader object associated with this OutputPage
         *
@@ -2968,7 +2936,7 @@ $templates
                // This also enforces $.isReady to be true at </body> which fixes the
                // mw.loader bug in Firefox with using document.write between </body>
                // and the DOMContentReady event (bug 47457).
-               $html = Html::inlineScript( 'jQuery.ready();' );
+               $html = Html::inlineScript( 'window.jQuery && jQuery.ready();' );
 
                if ( !$wgResourceLoaderExperimentalAsyncLoading ) {
                        $html .= $this->getScriptsForBottomQueue( false );
@@ -3128,13 +3096,11 @@ $templates
        }
 
        /**
-        * @param bool $addContentType Whether "<meta>" specifying content type should be returned
-        *
         * @return array in format "link name or number => 'link html'".
         */
-       public function getHeadLinksArray( $addContentType = false ) {
+       public function getHeadLinksArray() {
                global $wgUniversalEditButton, $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI,
-                       $wgSitename, $wgVersion, $wgHtml5, $wgMimeType,
+                       $wgSitename, $wgVersion,
                        $wgFeed, $wgOverrideSiteFeed, $wgAdvertisedFeedTypes,
                        $wgDisableLangConversion, $wgCanonicalLanguageLinks,
                        $wgRightsPage, $wgRightsUrl;
@@ -3143,23 +3109,6 @@ $templates
 
                $canonicalUrl = $this->mCanonicalUrl;
 
-               if ( $addContentType ) {
-                       if ( $wgHtml5 ) {
-                               # More succinct than <meta http-equiv=Content-Type>, has the
-                               # same effect
-                               $tags['meta-charset'] = Html::element( 'meta', array( 'charset' => 'UTF-8' ) );
-                       } else {
-                               $tags['meta-content-type'] = Html::element( 'meta', array(
-                                       'http-equiv' => 'Content-Type',
-                                       'content' => "$wgMimeType; charset=UTF-8"
-                               ) );
-                               $tags['meta-content-style-type'] = Html::element( 'meta', array( // bug 15835
-                                       'http-equiv' => 'Content-Style-Type',
-                                       'content' => 'text/css'
-                               ) );
-                       }
-               }
-
                $tags['meta-generator'] = Html::element( 'meta', array(
                        'name' => 'generator',
                        'content' => "MediaWiki $wgVersion",
@@ -3175,21 +3124,6 @@ $templates
                        ) );
                }
 
-               if ( count( $this->mKeywords ) > 0 ) {
-                       $strip = array(
-                               "/<.*?" . ">/" => '',
-                               "/_/" => ' '
-                       );
-                       $tags['meta-keywords'] = Html::element( 'meta', array(
-                               'name' => 'keywords',
-                               'content' => preg_replace(
-                                       array_keys( $strip ),
-                                       array_values( $strip ),
-                                       implode( ',', $this->mKeywords )
-                               )
-                       ) );
-               }
-
                foreach ( $this->mMetatags as $tag ) {
                        if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
                                $a = 'http-equiv';
@@ -3377,13 +3311,10 @@ $templates
        }
 
        /**
-        * @param $unused
-        * @param bool $addContentType 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 ) );
+       public function getHeadLinks() {
+               return implode( "\n", $this->getHeadLinksArray() );
        }
 
        /**
@@ -3604,7 +3535,7 @@ $templates
         * this stylesheet
         */
        public static function transformCssMedia( $media ) {
-               global $wgRequest, $wgHandheldForIPhone;
+               global $wgRequest;
 
                // http://www.w3.org/TR/css3-mediaqueries/#syntax
                $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i';
@@ -3636,18 +3567,6 @@ $templates
                        }
                }
 
-               // Expand longer media queries as iPhone doesn't grok 'handheld'
-               if ( $wgHandheldForIPhone ) {
-                       $mediaAliases = array(
-                               'screen' => 'screen and (min-device-width: 481px)',
-                               'handheld' => 'handheld, only screen and (max-device-width: 480px)',
-                       );
-
-                       if ( isset( $mediaAliases[$media] ) ) {
-                               $media = $mediaAliases[$media];
-                       }
-               }
-
                return $media;
        }