Index: trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.php |
— | — | @@ -28,10 +28,12 @@ |
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 |
Index: trunk/extensions/FundraiserLandingPage/FundraiserRedirector.body.php |
— | — | @@ -0,0 +1,50 @@ |
| 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 | + $wgOut->setSquidMaxage( 0 ); // Never cache on server side |
| 19 | + $this->setHeaders(); |
| 20 | + |
| 21 | + // Set the country parameter |
| 22 | + $country = $wgRequest->getVal( 'country' ); |
| 23 | + // If no country was passed do a GeoIP lookup |
| 24 | + if ( !$country ) { |
| 25 | + if ( function_exists( 'geoip_country_code_by_name' ) ) { |
| 26 | + $ip = wfGetIP(); |
| 27 | + if ( IP::isValid( $ip ) ) { |
| 28 | + $country = geoip_country_code_by_name( $ip ); |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + // If country still isn't set, set it to the default |
| 33 | + if ( !$country ) { |
| 34 | + $country = $wgFundraiserLPDefaults[ 'country' ]; |
| 35 | + } |
| 36 | + |
| 37 | + $params = "country=$country"; |
| 38 | + |
| 39 | + // Pass any other params that are set |
| 40 | + $excludeKeys = array( 'country', 'title' ); |
| 41 | + foreach ( $wgRequest->getValues() as $key => $value ) { |
| 42 | + // Skip the required variables |
| 43 | + if ( !in_array( $key, $excludeKeys ) ) { |
| 44 | + $params .= '&'."$key=$value"; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // Redirect to FundraiserLandingPage |
| 49 | + $wgOut->redirect( $this->getTitleFor( 'FundraiserLandingPage' )->getLocalUrl( $params ) ); |
| 50 | + } |
| 51 | +} |
Index: trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php |
— | — | @@ -12,24 +12,23 @@ |
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 = ''; |
28 | 27 | |
29 | 28 | # 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' ); |
| 29 | + $template = $this->make_safe( $wgRequest->getText( 'template', $wgFundraiserLPDefaults[ 'template' ] ) ); |
| 30 | + $appeal = $this->make_safe( $wgRequest->getText( 'appeal', $wgFundraiserLPDefaults[ 'appeal' ] ) ); |
| 31 | + $form = $this->make_safe( $wgRequest->getText( 'form', $wgFundraiserLPDefaults[ 'form' ] ) ); |
| 32 | + $country = $wgRequest->getVal( 'country' ); |
34 | 33 | // If no country was passed do a GeoIP lookup |
35 | 34 | if ( !$country ) { |
36 | 35 | if ( function_exists( 'geoip_country_code_by_name' ) ) { |
— | — | @@ -49,7 +48,7 @@ |
50 | 49 | $output .= "{{ $template\n| appeal = $appeal\n| form = $form\n| country = $country\n"; |
51 | 50 | |
52 | 51 | # add any parameters passed in the querystring |
53 | | - foreach ( $request->getValues() as $k_unsafe => $v_unsafe ) { |
| 52 | + foreach ( $wgRequest->getValues() as $k_unsafe => $v_unsafe ) { |
54 | 53 | # skip the required variables |
55 | 54 | if ( $k_unsafe == "template" || $k_unsafe == "appeal" || $k_unsafe == "form" || $k_unsafe == "country" ) { |
56 | 55 | continue; |
— | — | @@ -64,7 +63,7 @@ |
65 | 64 | $output .= "}}"; |
66 | 65 | |
67 | 66 | # print the output to the page |
68 | | - $this->getOutput()->addWikiText( $output ); |
| 67 | + $wgOut->addWikiText( $output ); |
69 | 68 | } |
70 | 69 | |
71 | 70 | |