Sumit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/214672

Change subject: WikidataPageBanner allow named parameters
......................................................................

WikidataPageBanner allow named parameters

Allow the use of parameters of the form name=value, as arguments to the parser
function {{PAGEBANNER}}, for customizing. Required for
https://phabricator.wikimedia.org/T100486

Change-Id: I1e67311e76c66c26bd8b1f2dc22856dffd98c99a
---
M includes/WikidataPageBanner.hooks.php
1 file changed, 26 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner 
refs/changes/72/214672/1

diff --git a/includes/WikidataPageBanner.hooks.php 
b/includes/WikidataPageBanner.hooks.php
index 522cc0e..3cb656d 100644
--- a/includes/WikidataPageBanner.hooks.php
+++ b/includes/WikidataPageBanner.hooks.php
@@ -64,6 +64,12 @@
         */
        public static function addCustomBanner( $parser, $bannername ) {
                global $wgBannerNamespaces;
+               // @var options array
+               $opts = array();
+               for ( $i = 1; $i < func_num_args(); $i++ ) {
+                       $opts[] = func_get_arg( $i );
+               }
+               $params = self::extractOptions( $opts );
                $fileurl = self::getBannerUrl( $bannername );
                // if given banner does not exist, return
                if ( $fileurl === null ) {
@@ -143,4 +149,24 @@
                $parser->setFunctionHook( 'PAGEBANNER', 
'WikidataPageBanner::addCustomBanner', SFH_NO_HASH );
                return true;
        }
+
+       /**
+        * Converts an array of values in form [0] => "name=value" into a real
+        * associative array in form [name] => value
+        *
+        * @param array string $options
+        * @return array $results
+        */
+       public static function extractOptions( array $options ) {
+               $results = array();
+               foreach ( $options as $option ) {
+                       $pair = explode( '=', $option, 2 );
+                       if ( count( $pair ) == 2 ) {
+                               $name = trim( $pair[0] );
+                               $value = trim( $pair[1] );
+                               $results[$name] = $value;
+                       }
+               }
+               return $results;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e67311e76c66c26bd8b1f2dc22856dffd98c99a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Sumit <asthana.sumi...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to