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

Change subject: Convert FundraiserLandingPage to use extension registration
......................................................................


Convert FundraiserLandingPage to use extension registration

Bug: T87917
Change-Id: I9315e19e139d79e946f2e0e5017939caafcaf5e8
---
M FundraiserLandingPage.body.php
A FundraiserLandingPage.hooks.php
D FundraiserLandingPage.i18n.php
M FundraiserLandingPage.php
M FundraiserRedirector.body.php
A extension.json
6 files changed, 193 insertions(+), 235 deletions(-)

Approvals:
  Florianschmidtwelzow: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/FundraiserLandingPage.body.php b/FundraiserLandingPage.body.php
index 6bd9e8a..b1c8bff 100644
--- a/FundraiserLandingPage.body.php
+++ b/FundraiserLandingPage.body.php
@@ -5,8 +5,7 @@
  *
  * @author Peter Gehres <[email protected]>
  */
-class FundraiserLandingPage extends UnlistedSpecialPage
-{
+class FundraiserLandingPage extends UnlistedSpecialPage  {
        function __construct() {
                parent::__construct( 'FundraiserLandingPage' );
        }
@@ -37,9 +36,11 @@
                $output = '';
                
                # begin generating the template call
-               $template = fundraiserLandingPageMakeSafe( $request->getText( 
'template', $wgFundraiserLPDefaults[ 'template' ] ) );
+               $template = self::fundraiserLandingPageMakeSafe(
+                       $request->getText( 'template', $wgFundraiserLPDefaults[ 
'template' ] )
+               );
                $output .= "{{ $template\n";
-               
+
                # get the required variables (except template and country) to 
use for the landing page
                $requiredParams = array(
                        'appeal',
@@ -48,7 +49,7 @@
                        'form-countryspecific'
                );
                foreach( $requiredParams as $requiredParam ) {
-                       $param = fundraiserLandingPageMakeSafe(
+                       $param = self::fundraiserLandingPageMakeSafe(
                                $request->getText( $requiredParam, 
$wgFundraiserLPDefaults[$requiredParam] )
                        );
                        // Add them to the template call
@@ -61,11 +62,11 @@
                if ( !$country ) {
                        $country = $wgFundraiserLPDefaults[ 'country' ];
                }
-               $country = fundraiserLandingPageMakeSafe( $country );
+               $country = self::fundraiserLandingPageMakeSafe( $country );
                $output .= "| country = $country\n";
 
                $excludeKeys = $requiredParams + array( 'template', 'country', 
'title' );
-               
+
                # add any other parameters passed in the querystring
                foreach ( $request->getValues() as $k_unsafe => $v_unsafe ) {
                        # skip the required variables
@@ -73,8 +74,8 @@
                                continue;
                        }
                        # get the variable's name and value
-                       $key = fundraiserLandingPageMakeSafe( $k_unsafe );
-                       $val = fundraiserLandingPageMakeSafe( $v_unsafe );
+                       $key = self::fundraiserLandingPageMakeSafe( $k_unsafe );
+                       $val = self::fundraiserLandingPageMakeSafe( $v_unsafe );
                        # print to the template in wiki-syntax
                        $output .= "| $key = $val\n";
                }
@@ -84,4 +85,95 @@
                # print the output to the page
                $out->addWikiText( $output );
        }
+
+       /**
+        * This function limits the possible characters passed as template keys 
and
+        * values to letters, numbers, hypens, underscores, and the forward 
slash.
+        * The function also performs standard escaping of the passed values.
+        *
+        * @param $string  string The unsafe string to escape and check for 
invalid characters
+        * @param $default string A default value to return if when making the 
$string safe no
+        *                 results are returned.
+        *
+        * @return mixed|String A string matching the regex or an empty string
+        */
+       private static function fundraiserLandingPageMakeSafe( $string, 
$default = '' ) {
+               if ( $default != '' ) {
+                       $default = self::fundraiserLandingPageMakeSafe( 
$default );
+               }
+
+               $num = preg_match( '([a-zA-Z0-9_\-/]+)', $string, $matches );
+
+               if ( $num == 1 ) {
+                       # theoretically this is overkill, but better safe than 
sorry
+                       return wfEscapeWikiText( htmlspecialchars( $matches[ 0 
] ) );
+               }
+               return $default;
+       }
+
+       /**
+        * Attempts to load a language localized template. Precedence is 
Language,
+        * Country, Root. It is assumed that all parts of the title are 
separated
+        * with '/'.
+        *
+        * @param Parser $parser   Reference to the WM parser object
+        * @param string $page     The template page root to load
+        * @param string $language The language to attempt to localize onto
+        * @param string $country  The country to attempt to localize onto
+        *
+        * @return string The wikitext template
+        */
+       public static function fundraiserLandingPageSwitchLanguage( $parser, 
$page = '', $language = 'en', $country = 'XX' ) {
+               $page = self::fundraiserLandingPageMakeSafe( $page );
+               $country = self::fundraiserLandingPageMakeSafe( $country, 'XX' 
);
+               $language = self::fundraiserLandingPageMakeSafe( $language, 
'en' );
+
+               if ( Title::newFromText( "Template:$page/$language/$country" 
)->exists() ) {
+                       $tpltext = "$page/$language/$country";
+               } elseif ( Title::newFromText( "Template:$page/$language" 
)->exists() ) {
+                       $tpltext = "$page/$language";
+               } else {
+                       // If all the variants don't exist, then merely return 
the base. If
+                       // something really screwy happened and the base 
doesn't exist either
+                       // we will let the WM error handler sort it out.
+
+                       $tpltext = $page;
+               }
+
+               return array( "{{Template:$tpltext}}", 'noparse' => false );
+       }
+
+       /**
+        * Attempts to load a language localized template. Precedence is 
Country,
+        * Language, Root. It is assumed that all parts of the title are 
separated
+        * with '/'.
+        *
+        * @param Parser $parser   Reference to the WM parser object
+        * @param string $page     The template page root to load
+        * @param string $country  The country to attempt to localize onto
+        * @param string $language The language to attempt to localize onto
+        *
+        * @return string The wikitext template
+        */
+       public static function fundraiserLandingPageSwitchCountry( $parser, 
$page = '', $country = 'XX', $language = 'en' ) {
+               $page = self::fundraiserLandingPageMakeSafe( $page );
+               $country = self::fundraiserLandingPageMakeSafe( $country, 'XX' 
);
+               $language = self::fundraiserLandingPageMakeSafe( $language, 
'en' );
+
+               if ( Title::newFromText( "Template:$page/$country/$language" 
)->exists() ) {
+                       $tpltext = "$page/$country/$language";
+
+               } elseif ( Title::newFromText( "Template:$page/$country" 
)->exists() ) {
+                       $tpltext = "$page/$country";
+
+               } else {
+                       // If all the variants don't exist, then merely return 
the base. If
+                       // something really screwy happened and the base 
doesn't exist either
+                       // we will let the WM error handler sort it out.
+
+                       $tpltext = $page;
+               }
+
+               return array( "{{Template:$tpltext}}", 'noparse' => false );
+       }
 }
diff --git a/FundraiserLandingPage.hooks.php b/FundraiserLandingPage.hooks.php
new file mode 100644
index 0000000..dee6a63
--- /dev/null
+++ b/FundraiserLandingPage.hooks.php
@@ -0,0 +1,24 @@
+<?php
+class FundraiserLandingPageHooks {
+       /**
+        * Register the parser function hooks 'switchlanguage' and 
'switchcountry'
+        * with the MW backend.
+        *
+        * @param $parser Parser The MW parser object to hook into.
+        *
+        * @return bool Always true
+        */
+       public static function onParserFirstCallInit( &$parser ) {
+               $parser->setFunctionHook(
+                       'switchlanguage',
+                       
'FundraiserLandingPage::fundraiserLandingPageSwitchLanguage'
+               );
+               $parser->setFunctionHook(
+                       'switchcountry',
+                       
'FundraiserLandingPage::fundraiserLandingPageSwitchCountry'
+               );
+
+               // Return true so that MediaWiki continues to load extensions.
+               return true;
+       }
+}
diff --git a/FundraiserLandingPage.i18n.php b/FundraiserLandingPage.i18n.php
deleted file mode 100644
index ceb6e56..0000000
--- a/FundraiserLandingPage.i18n.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-/**
- * This is a backwards-compatibility shim, generated by:
- * 
https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php
- *
- * Beginning with MediaWiki 1.23, translation strings are stored in json files,
- * and the EXTENSION.i18n.php file only exists to provide compatibility with
- * older releases of MediaWiki. For more information about this migration, see:
- * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format
- *
- * This shim maintains compatibility back to MediaWiki 1.17.
- */
-$messages = array();
-if ( !function_exists( 'wfJsonI18nShimefe325500d3ceedc' ) ) {
-       function wfJsonI18nShimefe325500d3ceedc( $cache, $code, &$cachedData ) {
-               $codeSequence = array_merge( array( $code ), 
$cachedData['fallbackSequence'] );
-               foreach ( $codeSequence as $csCode ) {
-                       $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json";
-                       if ( is_readable( $fileName ) ) {
-                               $data = FormatJson::decode( file_get_contents( 
$fileName ), true );
-                               foreach ( array_keys( $data ) as $key ) {
-                                       if ( $key === '' || $key[0] === '@' ) {
-                                               unset( $data[$key] );
-                                       }
-                               }
-                               $cachedData['messages'] = array_merge( $data, 
$cachedData['messages'] );
-                       }
-
-                       $cachedData['deps'][] = new FileDependency( $fileName );
-               }
-               return true;
-       }
-
-       $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 
'wfJsonI18nShimefe325500d3ceedc';
-}
diff --git a/FundraiserLandingPage.php b/FundraiserLandingPage.php
index 735577d..a9faa05 100644
--- a/FundraiserLandingPage.php
+++ b/FundraiserLandingPage.php
@@ -4,194 +4,20 @@
  * QueryString and passes them to the specified template as template variables.
  *
  * @author Peter Gehres <[email protected]>
+ * To install the FundraiserLandingPage extension, put the following line in 
LocalSettings.php:
+ * require_once( 
"\$IP/extensions/FundraiserLandingPage/FundraiserLandingPage.php" );
  */
-
-if ( !defined( 'MEDIAWIKI' ) ) {
-       echo <<<EOT
-To install the FundraiserLandingPage extension, put the following line in 
LocalSettings.php:
-require_once( 
"\$IP/extensions/FundraiserLandingPage/FundraiserLandingPage.php" );
-EOT;
-       exit( 1 );
+if ( function_exists( 'wfLoadExtension' ) ) {
+       wfLoadExtension( 'FundraiserLandingPage' );
+       // Keep i18n globals so mergeMessageFileList.php doesn't break
+       $wgMessagesDirs['FundraiserLandingPage'] = __DIR__ . '/i18n';
+       $wgExtensionMessagesFiles['FundraiserLandingPageAlias'] = __DIR__ . 
'/FundraiserLandingPage.alias.php';
+       $wgExtensionMessagesFiles['FundraiserLandingPageMagic'] = __DIR__ . 
'/FundraiserLandingPage.i18n.magic.php';
+       /*wfWarn(
+               'Deprecated PHP entry point used for FundraiserLandingPage 
extension. Please use wfLoadExtension instead, ' .
+               'see https://www.mediawiki.org/wiki/Extension_registration for 
more details.'
+       );*/
+       return;
+} else {
+       die( 'This version of the FundraiserLandingPage extension requires 
MediaWiki 1.25+' );
 }
-
-$wgExtensionCredits[ 'specialpage' ][ ] = array(
-       'path'           => __FILE__,
-       'name'           => 'FundraiserLandingPage',
-       'author'         => array( 'Peter Gehres', 'Ryan Kaldari' ),
-       'url'            => 
'https://www.mediawiki.org/wiki/Extension:FundraiserLandingPage',
-       'descriptionmsg' => 'fundraiserlandingpage-desc',
-       'version'        => '1.1.0',
-);
-
-$dir = __DIR__ . '/';
-
-$wgAutoloadClasses[ 'FundraiserLandingPage' ] = $dir . 
'FundraiserLandingPage.body.php';
-$wgAutoloadClasses[ 'FundraiserRedirector' ] = $dir . 
'FundraiserRedirector.body.php';
-
-$wgMessagesDirs['FundraiserLandingPage'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles[ 'FundraiserLandingPage' ] = $dir . 
'FundraiserLandingPage.i18n.php';
-
-$wgSpecialPages[ 'FundraiserLandingPage' ] = 'FundraiserLandingPage';
-$wgSpecialPages[ 'FundraiserRedirector' ] = 'FundraiserRedirector';
-
-// Specify the function that will initialize the parser function hooks.
-$wgHooks[ 'ParserFirstCallInit' ][ ] = 
'fundraiserLandingPageSetupParserFunction';
-$wgExtensionMessagesFiles[ 'FundraiserLandingPageMagic' ] = $dir . 
'FundraiserLandingPage.i18n.magic.php';
-
-/*
- * Defaults for the required fields.  These fields will be included whether
- * or not they are passed through the querystring.
- */
-$wgFundraiserLPDefaults = array(
-       'template'             => 'Lp-layout-default',
-       'appeal'               => 'Appeal-default',
-       'appeal-template'      => 'Appeal-template-default',
-       'form-template'        => 'Form-template-default',
-       'form-countryspecific' => 'Form-countryspecific-control',
-       'country'              => 'XX'
-);
-
-// Adding configurrable variable for caching time
-$wgFundraiserLandingPageMaxAge = 600; // 10 minutes
-
-// Array of chapter countries and the MediaWiki message that contains
-// the redirect URL.
-$wgFundraiserLandingPageChapters = array(
-       'CH' => "fundraiserlandingpage-wmch-landing-page",
-       'DE' => "fundraiserlandingpage-wmde-landing-page",
-//     'FR' => "fundraiserlandingpage-wmfr-landing-page", // disabled May 2013 
per WMFr request
-//     'GB' => "fundraiserlandingpage-wmuk-landing-page", // disabled for 2012 
per agreement with WMUK
-
-/*
- *     All French Territories disabled May 2013 per WMFr request
-       // French Territories per WMFr email 2012-06-13
-       'GP' => "fundraiserlandingpage-wmfr-landing-page", // Guadeloupe
-       'MQ' => "fundraiserlandingpage-wmfr-landing-page", // Martinique
-       'GF' => "fundraiserlandingpage-wmfr-landing-page", // French Guiana
-       'RE' => "fundraiserlandingpage-wmfr-landing-page", // Réunion
-       'YT' => "fundraiserlandingpage-wmfr-landing-page", // Mayotte
-       'PM' => "fundraiserlandingpage-wmfr-landing-page", // Saint Pierre and 
Miquelon
-       'NC' => "fundraiserlandingpage-wmfr-landing-page", // New Caledonia
-       'PF' => "fundraiserlandingpage-wmfr-landing-page", // French Polynesia
-       'WF' => "fundraiserlandingpage-wmfr-landing-page", // Wallis and Futuna
-       'BL' => "fundraiserlandingpage-wmfr-landing-page", // Saint Barthélemy
-       'MF' => "fundraiserlandingpage-wmfr-landing-page", // Collectivity of 
San Martin
-       'TF' => "fundraiserlandingpage-wmfr-landing-page", // French Southern 
and Antarctic Lands
-*/
-
-);
-
-/**
- * This function limits the possible characters passed as template keys and
- * values to letters, numbers, hypens, underscores, and the forward slash.
- * The function also performs standard escaping of the passed values.
- *
- * @param $string  string The unsafe string to escape and check for invalid 
characters
- * @param $default string A default value to return if when making the $string 
safe no
- *                 results are returned.
- *
- * @return mixed|String A string matching the regex or an empty string
- */
-function fundraiserLandingPageMakeSafe( $string, $default = '' ) {
-       if ( $default != '' ) {
-               $default = fundraiserLandingPageMakeSafe( $default );
-       }
-
-       $num = preg_match( '([a-zA-Z0-9_\-/]+)', $string, $matches );
-
-       if ( $num == 1 ) {
-               # theoretically this is overkill, but better safe than sorry
-               return wfEscapeWikiText( htmlspecialchars( $matches[ 0 ] ) );
-       }
-       return $default;
-}
-
-/**
- * Register the parser function hooks 'switchlanguage' and 'switchcountry'
- * with the MW backend.
- *
- * @see FundraiserLandingPageSwitchLanguage
- * @see FundraiserLandingPageSwitchCountry
- *
- * @param $parser Parser The WM parser object to hook into.
- *
- * @return bool Always true
- */
-function fundraiserLandingPageSetupParserFunction( &$parser ) {
-       $parser->setFunctionHook( 'switchlanguage', 
'fundraiserLandingPageSwitchLanguage' );
-       $parser->setFunctionHook( 'switchcountry', 
'fundraiserLandingPageSwitchCountry' );
-
-       // Return true so that MediaWiki continues to load extensions.
-       return true;
-}
-
-/**
- * Attempts to load a language localized template. Precedence is Language,
- * Country, Root. It is assumed that all parts of the title are separated
- * with '/'.
- *
- * @param Parser $parser   Reference to the WM parser object
- * @param string $page     The template page root to load
- * @param string $language The language to attempt to localize onto
- * @param string $country  The country to attempt to localize onto
- *
- * @return string The wikitext template
- */
-function fundraiserLandingPageSwitchLanguage( $parser, $page = '', $language = 
'en', $country = 'XX' ) {
-       $page = fundraiserLandingPageMakeSafe( $page );
-       $country = fundraiserLandingPageMakeSafe( $country, 'XX' );
-       $language = fundraiserLandingPageMakeSafe( $language, 'en' );
-
-       if ( Title::newFromText( "Template:$page/$language/$country" 
)->exists() ) {
-               $tpltext = "$page/$language/$country";
-       } elseif ( Title::newFromText( "Template:$page/$language" )->exists() ) 
{
-               $tpltext = "$page/$language";
-       } else {
-               // If all the variants don't exist, then merely return the 
base. If
-               // something really screwy happened and the base doesn't exist 
either
-               // we will let the WM error handler sort it out.
-
-               $tpltext = $page;
-       }
-
-       return array( "{{Template:$tpltext}}", 'noparse' => false );
-}
-
-/**
- * Attempts to load a language localized template. Precedence is Country,
- * Language, Root. It is assumed that all parts of the title are separated
- * with '/'.
- *
- * @param Parser $parser   Reference to the WM parser object
- * @param string $page     The template page root to load
- * @param string $country  The country to attempt to localize onto
- * @param string $language The language to attempt to localize onto
- *
- * @return string The wikitext template
- */
-function fundraiserLandingPageSwitchCountry( $parser, $page = '', $country = 
'XX', $language = 'en' ) {
-       $page = fundraiserLandingPageMakeSafe( $page );
-       $country = fundraiserLandingPageMakeSafe( $country, 'XX' );
-       $language = fundraiserLandingPageMakeSafe( $language, 'en' );
-
-       if ( Title::newFromText( "Template:$page/$country/$language" 
)->exists() ) {
-               $tpltext = "$page/$country/$language";
-
-       } elseif ( Title::newFromText( "Template:$page/$country" )->exists() ) {
-               $tpltext = "$page/$country";
-
-       } else {
-               // If all the variants don't exist, then merely return the 
base. If
-               // something really screwy happened and the base doesn't exist 
either
-               // we will let the WM error handler sort it out.
-
-               $tpltext = $page;
-       }
-
-       return array( "{{Template:$tpltext}}", 'noparse' => false );
-}
-
-// These variables are theoretically in ContributionTracking,
-// but setting a default here for safety
-$wgContributionTrackingFundraiserMaintenance = false;
-$wgContributionTrackingFundraiserMaintenanceUnsched = false;
diff --git a/FundraiserRedirector.body.php b/FundraiserRedirector.body.php
index 45c6469..f142355 100644
--- a/FundraiserRedirector.body.php
+++ b/FundraiserRedirector.body.php
@@ -93,8 +93,7 @@
 
                                        if( strpos( $redirectURL, "?" ) === 
false ){
                                                $redirectURL .= "?" . 
$querystring;
-                                       }
-                                       else{
+                                       } else{
                                                $redirectURL .= "&" . 
$querystring;
                                        }
                                }
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..6cac7e9
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,52 @@
+{
+       "name": "FundraiserLandingPage",
+       "author": [
+               "Peter Gehres",
+               "Ryan Kaldari"
+       ],
+       "url": "https://www.mediawiki.org/wiki/Extension:FundraiserLandingPage";,
+       "descriptionmsg": "fundraiserlandingpage-desc",
+       "version": "1.1.0",
+       "type": "specialpage",
+       "AutoloadClasses": {
+               "FundraiserLandingPage": "FundraiserLandingPage.body.php",
+               "FundraiserRedirector": "FundraiserRedirector.body.php",
+               "FundraiserLandingPageHooks": "FundraiserLandingPage.hooks.php"
+       },
+       "MessagesDirs": {
+               "FundraiserLandingPage": [
+                       "i18n"
+               ]
+       },
+       "Hooks": {
+               "ParserFirstCallInit": 
"FundraiserLandingPageHooks::onParserFirstCallInit"
+       },
+       "ExtensionMessagesFiles": {
+               "FundraiserLandingPageAlias": "FundraiserLandingPage.alias.php",
+               "FundraiserLandingPageMagic": 
"FundraiserLandingPage.i18n.magic.php"
+       },
+       "SpecialPages": {
+               "FundraiserLandingPage": "FundraiserLandingPage",
+               "FundraiserRedirector": "FundraiserRedirector"
+       },
+       "config": {
+               "FundraiserLPDefaults": {
+                       "template": "Lp-layout-default",
+                       "appeal": "Appeal-default",
+                       "appeal-template": "Appeal-template-default",
+                       "form-template": "Form-template-default",
+                       "form-countryspecific": "Form-countryspecific-control",
+                       "country": "XX",
+                       "_merge_strategy": "array_plus"
+               },
+               "FundraiserLandingPageChapters": {
+                       "CH": "fundraiserlandingpage-wmch-landing-page",
+                       "DE": "fundraiserlandingpage-wmde-landing-page",
+                       "_merge_strategy": "array_plus"
+               },
+               "FundraiserLandingPageMaxAge": 600,
+               "ContributionTrackingFundraiserMaintenance": false,
+               "ContributionTrackingFundraiserMaintenanceUnsched": false
+       },
+       "manifest_version": 1
+}
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9315e19e139d79e946f2e0e5017939caafcaf5e8
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/FundraiserLandingPage
Gerrit-Branch: master
Gerrit-Owner: MtDu <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: MtDu <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to