Index: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | $wgExtensionCredits[ 'specialpage' ][ ] = array( |
21 | 21 | 'path' => __FILE__, |
22 | 22 | 'name' => 'FundraiserLandingPage', |
23 | | - 'author' => 'Peter Gehres', |
| 23 | + 'author' => array( 'Peter Gehres', 'Ryan Kaldari' ), |
24 | 24 | 'url' => 'http://www.mediawiki.org/wiki/Extension:FundraiserLandingPage', |
25 | 25 | 'descriptionmsg' => 'fundraiserlandingpage-desc', |
26 | 26 | 'version' => '1.0.0', |
— | — | @@ -28,19 +28,23 @@ |
29 | 29 | $dir = dirname( __FILE__ ) . '/'; |
30 | 30 | |
31 | 31 | $wgAutoloadClasses[ 'FundraiserLandingPage' ] = $dir . 'FundraiserLandingPage.body.php'; |
| 32 | +$wgAutoloadClasses[ 'FundraiserRedirector' ] = $dir . 'FundraiserRedirector.body.php'; |
32 | 33 | |
33 | 34 | $wgExtensionMessagesFiles[ 'FundraiserLandingPage' ] = $dir . 'FundraiserLandingPage.i18n.php'; |
34 | 35 | |
35 | 36 | $wgSpecialPages[ 'FundraiserLandingPage' ] = 'FundraiserLandingPage'; |
| 37 | +$wgSpecialPages[ 'FundraiserRedirector' ] = 'FundraiserRedirector'; |
36 | 38 | |
37 | 39 | /* |
38 | 40 | * Defaults for the required fields. These fields will be included whether |
39 | 41 | * or not they are passed through the querystring. |
40 | 42 | */ |
41 | 43 | $wgFundraiserLPDefaults = array( |
42 | | - 'template' => 'Lp-wrapper', |
| 44 | + 'template' => 'Lp-layout-default', |
43 | 45 | 'appeal' => 'Appeal-default', |
44 | | - 'form' => 'Form-default', |
| 46 | + 'appeal-template' => 'Appeal-template-default', |
| 47 | + 'form-template' => 'Form-template-default', |
| 48 | + 'form-countryspecific' => 'Form-countryspecific-control', |
45 | 49 | 'country' => 'XX' // per Charles Barr |
46 | 50 | ); |
47 | 51 | |
Index: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserRedirector.body.php |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +<?php |
| 3 | +/* |
| 4 | + * Provides redirect service for donors coming from external sites (so that they get |
| 5 | + * directed to the proper form for their country). |
| 6 | + * |
| 7 | + * @author Ryan Kaldari <rkaldari@wikimedia.org> |
| 8 | + */ |
| 9 | +class FundraiserRedirector extends UnlistedSpecialPage { |
| 10 | + |
| 11 | + function __construct() { |
| 12 | + parent::__construct( 'FundraiserRedirector' ); |
| 13 | + } |
| 14 | + |
| 15 | + function execute( $par ) { |
| 16 | + global $wgRequest, $wgOut, $wgFundraiserLPDefaults; |
| 17 | + |
| 18 | + // Set the country parameter |
| 19 | + $country = $wgRequest->getVal( 'country' ); |
| 20 | + // If no country was passed do a GeoIP lookup |
| 21 | + if ( !$country ) { |
| 22 | + if ( function_exists( 'geoip_country_code_by_name' ) ) { |
| 23 | + $ip = wfGetIP(); |
| 24 | + if ( IP::isValid( $ip ) ) { |
| 25 | + $country = geoip_country_code_by_name( $ip ); |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + // If country still isn't set, set it to the default |
| 30 | + if ( !$country ) { |
| 31 | + $country = $wgFundraiserLPDefaults[ 'country' ]; |
| 32 | + } |
| 33 | + |
| 34 | + $params = array( 'country' => $country ); |
| 35 | + |
| 36 | + // Pass any other params that are set |
| 37 | + $excludeKeys = array( 'country', 'title' ); |
| 38 | + foreach ( $wgRequest->getValues() as $key => $value ) { |
| 39 | + // Skip the required variables |
| 40 | + if ( !in_array( $key, $excludeKeys ) ) { |
| 41 | + $params[$key] = $value; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + // Redirect to FundraiserLandingPage |
| 46 | + $wgOut->redirect( $this->getTitleFor( 'FundraiserLandingPage' )->getLocalUrl( $params ) ); |
| 47 | + } |
| 48 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserRedirector.body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 49 | + native |
Index: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php |
— | — | @@ -12,24 +12,39 @@ |
13 | 13 | } |
14 | 14 | |
15 | 15 | function execute( $par ) { |
16 | | - global $wgFundraiserLPDefaults, $wgOut, $wgFundraiserLandingPageMaxAge; |
| 16 | + global $wgFundraiserLPDefaults, $wgRequest, $wgOut, $wgFundraiserLandingPageMaxAge; |
17 | 17 | |
18 | 18 | #Set squid age |
19 | 19 | $wgOut->setSquidMaxage( $wgFundraiserLandingPageMaxAge ); |
20 | | - $request = $this->getRequest(); |
21 | 20 | $this->setHeaders(); |
22 | 21 | |
23 | 22 | # set the page title to something useful |
24 | | - $this->getOutput()->setPagetitle( wfMsg( 'donate_interface-make-your-donation' ) ); |
| 23 | + $wgOut->setPagetitle( wfMsg( 'donate_interface-make-your-donation' ) ); |
25 | 24 | |
26 | 25 | # clear output variable to be safe |
27 | 26 | $output = ''; |
| 27 | + |
| 28 | + # begin generating the template call |
| 29 | + $template = $this->make_safe( $wgRequest->getText( 'template', $wgFundraiserLPDefaults[ 'template' ] ) ); |
| 30 | + $output .= "{{ $template\n"; |
| 31 | + |
| 32 | + # get the required variables (except template and country) to use for the landing page |
| 33 | + $requiredParams = array( |
| 34 | + 'appeal', |
| 35 | + 'appeal-template', |
| 36 | + 'form-template', |
| 37 | + 'form-countryspecific' |
| 38 | + ); |
| 39 | + foreach( $requiredParams as $requiredParam ) { |
| 40 | + $param = $this->make_safe( |
| 41 | + $wgRequest->getText( $requiredParam, $wgFundraiserLPDefaults[$requiredParam] ) |
| 42 | + ); |
| 43 | + // Add them to the template call |
| 44 | + $output .= "| $requiredParam = $param\n"; |
| 45 | + } |
28 | 46 | |
29 | | - # get the required variables to use for the landing page |
30 | | - $template = $this->make_safe( $request->getText( 'template', $wgFundraiserLPDefaults[ 'template' ] ) ); |
31 | | - $appeal = $this->make_safe( $request->getText( 'appeal', $wgFundraiserLPDefaults[ 'appeal' ] ) ); |
32 | | - $form = $this->make_safe( $request->getText( 'form', $wgFundraiserLPDefaults[ 'form' ] ) ); |
33 | | - $country = $request->getVal( 'country' ); |
| 47 | + # get the country code |
| 48 | + $country = $wgRequest->getVal( 'country' ); |
34 | 49 | // If no country was passed do a GeoIP lookup |
35 | 50 | if ( !$country ) { |
36 | 51 | if ( function_exists( 'geoip_country_code_by_name' ) ) { |
— | — | @@ -44,17 +59,17 @@ |
45 | 60 | $country = $wgFundraiserLPDefaults[ 'country' ]; |
46 | 61 | } |
47 | 62 | $country = $this->make_safe( $country ); |
| 63 | + $output .= "| country = $country\n"; |
48 | 64 | |
49 | | - # begin generating the template call |
50 | | - $output .= "{{ $template\n| appeal = $appeal\n| form = $form\n| country = $country\n"; |
51 | | - |
52 | | - # add any parameters passed in the querystring |
53 | | - foreach ( $request->getValues() as $k_unsafe => $v_unsafe ) { |
| 65 | + $excludeKeys = $requiredParams + array( 'template', 'country', 'title' ); |
| 66 | + |
| 67 | + # add any other parameters passed in the querystring |
| 68 | + foreach ( $wgRequest->getValues() as $k_unsafe => $v_unsafe ) { |
54 | 69 | # skip the required variables |
55 | | - if ( $k_unsafe == "template" || $k_unsafe == "appeal" || $k_unsafe == "form" || $k_unsafe == "country" ) { |
| 70 | + if ( in_array( $k_unsafe, $excludeKeys ) ) { |
56 | 71 | continue; |
57 | 72 | } |
58 | | - # get the variables name and value |
| 73 | + # get the variable's name and value |
59 | 74 | $key = $this->make_safe( $k_unsafe ); |
60 | 75 | $val = $this->make_safe( $v_unsafe ); |
61 | 76 | # print to the template in wiki-syntax |
— | — | @@ -64,7 +79,7 @@ |
65 | 80 | $output .= "}}"; |
66 | 81 | |
67 | 82 | # print the output to the page |
68 | | - $this->getOutput()->addWikiText( $output ); |
| 83 | + $wgOut->addWikiText( $output ); |
69 | 84 | } |
70 | 85 | |
71 | 86 | |
Property changes on: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
72 | 87 | Merged /trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php:r104829,104886,104942,104984,105001,105124,105237 |
Property changes on: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage |
___________________________________________________________________ |
Modified: svn:mergeinfo |
73 | 88 | Merged /trunk/extensions/FundraiserLandingPage:r104829,104886,104942,104984,105001,105124,105237 |