jenkins-bot has submitted this change and it was merged.

Change subject: Allow to enable OOUI via a parser tag extension
......................................................................


Allow to enable OOUI via a parser tag extension

This change adds the possibility to enable OOUI out of the parser,
which enabled parser tag functions to easily enable OOUI, if they
need it, for every page view out of the function that handles the
parser tag.

Bug: T106949
Change-Id: If1e139d4f07be98e418e11470794ea42e8a9b2eb
---
M includes/OutputPage.php
M includes/parser/Parser.php
M includes/parser/ParserOutput.php
3 files changed, 55 insertions(+), 10 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index a551fe1..bbf3993 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -1817,6 +1817,11 @@
                        }
                }
 
+               // 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();
@@ -3946,21 +3951,34 @@
        }
 
        /**
+        * Helper function to setup the PHP implementation of OOUI to use in 
this request.
+        *
+        * @since 1.26
+        * @param String $skinName The Skin name to determine the correct OOUI 
theme
+        * @param String $dir Language direction
+        */
+       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 );
+               $theme = isset( $themes[ $skinName ] ) ? $themes[ $skinName ] : 
'MediaWiki';
+               // For example, 'OOUI\MediaWikiTheme'.
+               $themeClass = "OOUI\\{$theme}Theme";
+               OOUI\Theme::setSingleton( new $themeClass() );
+               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() {
-               $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() );
+               self::setupOOUI(
+                       strtolower( $this->getSkin()->getSkinName() ),
+                       $this->getLanguage()->getDir()
+               );
                $this->addModuleStyles( array(
                        'oojs-ui.styles',
                        'oojs-ui.styles.icons',
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 65d8182..0b6ab6e 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -6435,4 +6435,15 @@
                        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 );
+       }
 }
diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php
index 7068bd7..15321c2 100644
--- a/includes/parser/ParserOutput.php
+++ b/includes/parser/ParserOutput.php
@@ -49,7 +49,8 @@
                $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 @@
                return $this->mTOCEnabled;
        }
 
+       public function getEnableOOUI() {
+               return $this->mEnableOOUI;
+       }
+
        public function setText( $text ) {
                return wfSetVar( $this->mText, $text );
        }
@@ -283,6 +288,17 @@
                $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;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/226981
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If1e139d4f07be98e418e11470794ea42e8a9b2eb
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to