r104829 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104828‎ | r104829 | r104830 >
Date:02:51, 1 December 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
adding a redirector and fixing old code to use globals
Modified paths:
  • /trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php (modified) (history)
  • /trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.php (modified) (history)
  • /trunk/extensions/FundraiserLandingPage/FundraiserRedirector.body.php (added) (history)

Diff [purge]

Index: trunk/extensions/FundraiserLandingPage/FundraiserLandingPage.php
@@ -28,10 +28,12 @@
2929 $dir = dirname( __FILE__ ) . '/';
3030
3131 $wgAutoloadClasses[ 'FundraiserLandingPage' ] = $dir . 'FundraiserLandingPage.body.php';
 32+$wgAutoloadClasses[ 'FundraiserRedirector' ] = $dir . 'FundraiserRedirector.body.php';
3233
3334 $wgExtensionMessagesFiles[ 'FundraiserLandingPage' ] = $dir . 'FundraiserLandingPage.i18n.php';
3435
3536 $wgSpecialPages[ 'FundraiserLandingPage' ] = 'FundraiserLandingPage';
 37+$wgSpecialPages[ 'FundraiserRedirector' ] = 'FundraiserRedirector';
3638
3739 /*
3840 * 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 @@
1313 }
1414
1515 function execute( $par ) {
16 - global $wgFundraiserLPDefaults, $wgOut, $wgFundraiserLandingPageMaxAge;
 16+ global $wgFundraiserLPDefaults, $wgRequest, $wgOut, $wgFundraiserLandingPageMaxAge;
1717
1818 #Set squid age
1919 $wgOut->setSquidMaxage( $wgFundraiserLandingPageMaxAge );
20 - $request = $this->getRequest();
2120 $this->setHeaders();
2221
2322 # 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' ) );
2524
2625 # clear output variable to be safe
2726 $output = '';
2827
2928 # 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' );
3433 // If no country was passed do a GeoIP lookup
3534 if ( !$country ) {
3635 if ( function_exists( 'geoip_country_code_by_name' ) ) {
@@ -49,7 +48,7 @@
5049 $output .= "{{ $template\n| appeal = $appeal\n| form = $form\n| country = $country\n";
5150
5251 # 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 ) {
5453 # skip the required variables
5554 if ( $k_unsafe == "template" || $k_unsafe == "appeal" || $k_unsafe == "form" || $k_unsafe == "country" ) {
5655 continue;
@@ -64,7 +63,7 @@
6564 $output .= "}}";
6665
6766 # print the output to the page
68 - $this->getOutput()->addWikiText( $output );
 67+ $wgOut->addWikiText( $output );
6968 }
7069
7170

Follow-up revisions

RevisionCommit summaryAuthorDate
r104886dont need this since Special pages arent server-cached anywaykaldari19:09, 1 December 2011
r104984follow-up to r104829 - better way to build URLkaldari18:10, 2 December 2011
r105248MFT r104829, r104886, r104942, r104984, r105001, r105124, r105237awjrichards23:36, 5 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   09:05, 2 December 2011

Why are you building the url manually? getLocalUrl takes an array too.

#Comment by Kaldari (talk | contribs)   18:11, 2 December 2011

Fixed in r104984.

Status & tagging log