r105248 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105247‎ | r105248 | r105249 >
Date:23:36, 5 December 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/FundraiserLandingPage (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserRedirector.body.php (added) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.php
@@ -19,7 +19,7 @@
2020 $wgExtensionCredits[ 'specialpage' ][ ] = array(
2121 'path' => __FILE__,
2222 'name' => 'FundraiserLandingPage',
23 - 'author' => 'Peter Gehres',
 23+ 'author' => array( 'Peter Gehres', 'Ryan Kaldari' ),
2424 'url' => 'http://www.mediawiki.org/wiki/Extension:FundraiserLandingPage',
2525 'descriptionmsg' => 'fundraiserlandingpage-desc',
2626 'version' => '1.0.0',
@@ -28,19 +28,23 @@
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
3941 * or not they are passed through the querystring.
4042 */
4143 $wgFundraiserLPDefaults = array(
42 - 'template' => 'Lp-wrapper',
 44+ 'template' => 'Lp-layout-default',
4345 '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',
4549 'country' => 'XX' // per Charles Barr
4650 );
4751
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
149 + native
Index: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php
@@ -12,24 +12,39 @@
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 = '';
 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+ }
2846
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' );
3449 // If no country was passed do a GeoIP lookup
3550 if ( !$country ) {
3651 if ( function_exists( 'geoip_country_code_by_name' ) ) {
@@ -44,17 +59,17 @@
4560 $country = $wgFundraiserLPDefaults[ 'country' ];
4661 }
4762 $country = $this->make_safe( $country );
 63+ $output .= "| country = $country\n";
4864
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 ) {
5469 # 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 ) ) {
5671 continue;
5772 }
58 - # get the variables name and value
 73+ # get the variable's name and value
5974 $key = $this->make_safe( $k_unsafe );
6075 $val = $this->make_safe( $v_unsafe );
6176 # print to the template in wiki-syntax
@@ -64,7 +79,7 @@
6580 $output .= "}}";
6681
6782 # print the output to the page
68 - $this->getOutput()->addWikiText( $output );
 83+ $wgOut->addWikiText( $output );
6984 }
7085
7186
Property changes on: branches/wmf/1.18wmf1/extensions/FundraiserLandingPage/FundraiserLandingPage.body.php
___________________________________________________________________
Modified: svn:mergeinfo
7287 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
7388 Merged /trunk/extensions/FundraiserLandingPage:r104829,104886,104942,104984,105001,105124,105237

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r104829adding a redirector and fixing old code to use globalskaldari02:51, 1 December 2011
r104886dont need this since Special pages arent server-cached anywaykaldari19:09, 1 December 2011
r104942new defaults and better template constructionkaldari02:09, 2 December 2011
r104984follow-up to r104829 - better way to build URLkaldari18:10, 2 December 2011
r105001Giving credit where credit is duepgehres20:59, 2 December 2011
r105124svn:eol-style nativejohnduhart19:01, 4 December 2011
r105237follow-up to r104886, dont need headers since were redirecting anywaykaldari22:21, 5 December 2011

Status & tagging log