Merge "Allow to enable OOUI via a parser tag extension"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 6 Aug 2015 08:39:41 +0000 (08:39 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 6 Aug 2015 08:39:41 +0000 (08:39 +0000)
includes/OutputPage.php
includes/parser/Parser.php
includes/parser/ParserOutput.php

index 0f0b2f5..dd7b90a 100644 (file)
@@ -1818,6 +1818,11 @@ class OutputPage extends ContextSource {
                        }
                }
 
+               // enable OOUI if requested via ParserOutput
+               if ( $parserOutput->getEnableOOUI() ) {
+                       $this->enableOOUI();
+               }
+
                // Link flags are ignored for now, but may in the future be
                // used to mark individual language links.
                $linkFlags = array();
@@ -3942,21 +3947,34 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add ResourceLoader module styles for OOUI and set up the PHP implementation of it for use with
-        * MediaWiki and this OutputPage instance.
+        * Helper function to setup the PHP implementation of OOUI to use in this request.
         *
-        * @since 1.25
+        * @since 1.26
+        * @param String $skinName The Skin name to determine the correct OOUI theme
+        * @param String $dir Language direction
         */
-       public function enableOOUI() {
+       public static function setupOOUI( $skinName = '', $dir = 'ltr' ) {
                $themes = ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
                // Make keys (skin names) lowercase for case-insensitive matching.
                $themes = array_change_key_case( $themes, CASE_LOWER );
-               $skinName = strtolower( $this->getSkin()->getSkinName() );
                $theme = isset( $themes[ $skinName ] ) ? $themes[ $skinName ] : 'MediaWiki';
                // For example, 'OOUI\MediaWikiTheme'.
                $themeClass = "OOUI\\{$theme}Theme";
                OOUI\Theme::setSingleton( new $themeClass() );
-               OOUI\Element::setDefaultDir( $this->getLanguage()->getDir() );
+               OOUI\Element::setDefaultDir( $dir );
+       }
+
+       /**
+        * 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() {
+               self::setupOOUI(
+                       strtolower( $this->getSkin()->getSkinName() ),
+                       $this->getLanguage()->getDir()
+               );
                $this->addModuleStyles( array(
                        'oojs-ui.styles',
                        'oojs-ui.styles.icons',
index 7dab564..6189997 100644 (file)
@@ -6444,4 +6444,15 @@ class Parser {
                        return $this;
                }
        }
+
+       /**
+        * Set's up the PHP implementation of OOUI for use in this request
+        * and instructs OutputPage to enable OOUI for itself.
+        *
+        * @since 1.26
+        */
+       public function enableOOUI() {
+               OutputPage::setupOOUI();
+               $this->mOutput->setEnableOOUI( true );
+       }
 }
index 7068bd7..15321c2 100644 (file)
@@ -49,7 +49,8 @@ class ParserOutput extends CacheTime {
                $mProperties = array(),       # Name/value pairs to be cached in the DB
                $mTOCHTML = '',               # HTML of the TOC
                $mTimestamp,                  # Timestamp of the revision
-               $mTOCEnabled = true;          # Whether TOC should be shown, can't override __NOTOC__
+               $mTOCEnabled = true,          # Whether TOC should be shown, can't override __NOTOC__
+               $mEnableOOUI = false;         # Whether OOUI should be enabled
        private $mIndexPolicy = '';       # 'index' or 'noindex'?  Any other value will result in no change.
        private $mAccessedOptions = array(); # List of ParserOptions (stored in the keys)
        private $mExtensionData = array(); # extra data used by extensions
@@ -232,6 +233,10 @@ class ParserOutput extends CacheTime {
                return $this->mTOCEnabled;
        }
 
+       public function getEnableOOUI() {
+               return $this->mEnableOOUI;
+       }
+
        public function setText( $text ) {
                return wfSetVar( $this->mText, $text );
        }
@@ -283,6 +288,17 @@ class ParserOutput extends CacheTime {
                $this->mIndicators[$id] = $content;
        }
 
+       /**
+        * Enables OOUI, if true, in any OutputPage instance this ParserOutput
+        * object is added to.
+        *
+        * @since 1.26
+        * @param bool $enable If OOUI should be enabled or not
+        */
+       public function setEnableOOUI( $enable = false ) {
+               $this->mEnableOOUI = $enable;
+       }
+
        public function addLanguageLink( $t ) {
                $this->mLanguageLinks[] = $t;
        }