Merge "Add top help link to MediaWiki.org in several pages via indicator"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 07fa94b..33483eb 100644 (file)
@@ -196,12 +196,6 @@ class OutputPage extends ContextSource {
 
        // Parser related.
 
-       /**
-        * @var int
-        * @todo Unused?
-        */
-       private $mContainsOldMagic = 0;
-
        /** @var int */
        protected $mContainsNewMagic = 0;
 
@@ -1379,7 +1373,8 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add an array of indicators, with their identifiers as array keys and HTML contents as values.
+        * Add an array of indicators, with their identifiers as array
+        * keys and HTML contents as values.
         *
         * In case of duplicate keys, existing values are overwritten.
         *
@@ -1404,6 +1399,34 @@ class OutputPage extends ContextSource {
                return $this->mIndicators;
        }
 
+       /**
+        * Adds help link with an icon via page indicators.
+        * @param string $to
+        * @param bool $overrideBaseUrl
+        * @since 1.25
+        */
+       public function addHelpLink( $to, $overrideBaseUrl = false ) {
+               $this->addModules( 'mediawiki.helplink' );
+               $text = wfMessage( 'helppage-top-gethelp' )->escaped();
+
+               if ( $overrideBaseUrl ) {
+                       $helpUrl = $to;
+               } else {
+                       $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$to";
+               }
+               $link = Html::rawElement(
+                       'a',
+                       array(
+                               'href' => $helpUrl,
+                               'target' => '_blank',
+                               'class' => 'mw-helplink',
+                       ),
+                       $text
+               );
+
+               $this->setIndicators( array( 'mw-helplink' => $link ) );
+       }
+
        /**
         * Do not allow scripts which can be modified by wiki users to load on this page;
         * only allow scripts bundled with, or generated by, the software.
@@ -1685,8 +1708,6 @@ class OutputPage extends ContextSource {
        ) {
                global $wgParser;
 
-               wfProfileIn( __METHOD__ );
-
                $popts = $this->parserOptions();
                $oldTidy = $popts->setTidy( $tidy );
                $popts->setInterfaceMessage( (bool)$interface );
@@ -1700,7 +1721,6 @@ class OutputPage extends ContextSource {
 
                $this->addParserOutput( $parserOutput );
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -2173,8 +2193,6 @@ class OutputPage extends ContextSource {
                        return;
                }
 
-               wfProfileIn( __METHOD__ );
-
                $response = $this->getRequest()->response();
                $config = $this->getConfig();
 
@@ -2209,7 +2227,6 @@ class OutputPage extends ContextSource {
                                }
                        }
 
-                       wfProfileOut( __METHOD__ );
                        return;
                } elseif ( $this->mStatusCode ) {
                        $message = HttpStatus::getMessage( $this->mStatusCode );
@@ -2264,9 +2281,7 @@ class OutputPage extends ContextSource {
                        // adding of CSS or Javascript by extensions.
                        Hooks::run( 'BeforePageDisplay', array( &$this, &$sk ) );
 
-                       wfProfileIn( 'Output-skin' );
                        $sk->outputPage();
-                       wfProfileOut( 'Output-skin' );
                }
 
                // This hook allows last minute changes to final overall output by modifying output buffer
@@ -2276,7 +2291,6 @@ class OutputPage extends ContextSource {
 
                ob_end_flush();
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -2626,8 +2640,6 @@ class OutputPage extends ContextSource {
        public function headElement( Skin $sk, $includeStyle = true ) {
                global $wgContLang;
 
-               $section = new ProfileSection( __METHOD__ );
-
                $userdir = $this->getLanguage()->getDir();
                $sitedir = $wgContLang->getDir();
 
@@ -2729,7 +2741,7 @@ class OutputPage extends ContextSource {
         *   call rather than a "<script src='...'>" tag.
         * @return string The html "<script>", "<link>" and "<style>" tags
         */
-       protected function makeResourceLoaderLink( $modules, $only, $useESI = false,
+       public function makeResourceLoaderLink( $modules, $only, $useESI = false,
                array $extraQuery = array(), $loadCall = false
        ) {
                $modules = (array)$modules;
@@ -3138,7 +3150,7 @@ class OutputPage extends ContextSource {
         * have to be purged on configuration changes.
         * @return array
         */
-       private function getJSVars() {
+       public function getJSVars() {
                global $wgContLang;
 
                $curRevisionId = 0;
@@ -3295,6 +3307,13 @@ class OutputPage extends ContextSource {
                        'content' => "MediaWiki $wgVersion",
                ) );
 
+               if ( $config->get( 'ReferrerPolicy' ) !== false ) {
+                       $tags['meta-referrer'] = Html::element( 'meta', array(
+                               'name' => 'referrer',
+                               'content' => $config->get( 'ReferrerPolicy' )
+                       ) );
+               }
+
                $p = "{$this->mIndexPolicy},{$this->mFollowPolicy}";
                if ( $p !== 'index,follow' ) {
                        // http://www.robotstxt.org/wc/meta-user.html
@@ -3797,12 +3816,13 @@ class OutputPage extends ContextSource {
         * This function takes a number of message/argument specifications, wraps them in
         * some overall structure, and then parses the result and adds it to the output.
         *
-        * In the $wrap, $1 is replaced with the first message, $2 with the second, and so
-        * on. The subsequent arguments may either be strings, in which case they are the
-        * message names, or arrays, in which case the first element is the message name,
-        * and subsequent elements are the parameters to that message.
+        * In the $wrap, $1 is replaced with the first message, $2 with the second,
+        * and so on. The subsequent arguments may be either
+        * 1) strings, in which case they are message names, or
+        * 2) arrays, in which case, within each array, the first element is the message
+        *    name, and subsequent elements are the parameters to that message.
         *
-        * Don't use this for messages that are not in users interface language.
+        * Don't use this for messages that are not in the user's interface language.
         *
         * For example:
         *
@@ -3813,7 +3833,7 @@ class OutputPage extends ContextSource {
         *    $wgOut->addWikiText( "<div class='error'>\n"
         *        . wfMessage( 'some-error' )->plain() . "\n</div>" );
         *
-        * The newline after opening div is needed in some wikitext. See bug 19226.
+        * The newline after the opening div is needed in some wikitext. See bug 19226.
         *
         * @param string $wrap
         */
@@ -3888,4 +3908,16 @@ class OutputPage extends ContextSource {
        public function sectionEditLinksEnabled() {
                return $this->mEnableSectionEditLinks;
        }
+
+       /**
+        * Add ResourceLoader module styles for OOUI and set up the PHP implementation of it for use with
+        * MediaWiki and this OutputPage instance.
+        *
+        * @since 1.25
+        */
+       public function enableOOUI() {
+               OOUI\Theme::setSingleton( new OOUI\MediaWikiTheme() );
+               OOUI\Element::setDefaultDir( $this->getLanguage()->getDir() );
+               $this->addModuleStyles( 'oojs-ui.styles' );
+       }
 }