r75671 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75670‎ | r75671 | r75672 >
Date:20:45, 29 October 2010
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
Whiles to foreach

Remove unused globals and variables
Modified paths:
  • /trunk/extensions/ContactPageFundraiser/SpecialContact.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionHistory_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionStatistics_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionTotal_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/FundraiserStatistics_body.php (modified) (history)
  • /trunk/extensions/ContributionTracking/ContributionTracking.php (modified) (history)
  • /trunk/extensions/ContributionTracking/ContributionTracking_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionTracking/ContributionTracking_body.php
@@ -29,14 +29,11 @@
3030
3131 function execute( $language ) {
3232 global $wgRequest, $wgOut;
33 - wfLoadExtensionMessages( 'ContributionTracking' );
3433
3534 if ( !preg_match( '/^[a-z-]+$/', $language ) ) {
3635 $language = 'en';
3736 }
3837 $this->lang = Language::factory( $language );
39 - wfLoadExtensionMessages( 'ContributionTracking' );
40 - wfLoadExtensionMessages( 'ContributionTracking', $language );
4138
4239 $this->setHeaders();
4340
Index: trunk/extensions/ContributionTracking/ContributionTracking.php
@@ -26,7 +26,6 @@
2727 //this only works if contribution tracking is inside a mediawiki DB, which typically it isn't.
2828 //$wgHooks['LoadExtensionSchemaUpdates'][] = 'efContributionTrackingLoadUpdates';
2929
30 -
3130 $wgContributionTrackingDBserver = $wgDBserver;
3231 $wgContributionTrackingDBname = $wgDBname;
3332 $wgContributionTrackingDBuser = $wgDBuser;
Index: trunk/extensions/ContactPageFundraiser/SpecialContact.php
@@ -27,7 +27,6 @@
2828 * Constructor
2929 */
3030 function __construct() {
31 - global $wgOut;
3231 parent::__construct( 'Contact', '', true );
3332 }
3433
@@ -38,7 +37,6 @@
3938 function execute( $par ) {
4039 global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgContactUser;
4140
42 - wfLoadExtensionMessages( 'ContactPageFundraiser' );
4341 $fname = "SpecialContact::execute";
4442
4543 if ( $wgRequest->wasPosted() ) {
@@ -56,7 +54,7 @@
5755 $form['url'] = $wgRequest->getVal('url');
5856 $form['country'] = $wgRequest->getVal('country');
5957 $form['citytown'] = $wgRequest->getVal('city-town');
60 - $form['provstat'] = $wgRequest->getVal('prov-state');
 58+ $form['provstat'] = $wgRequest->getVal('prov-state');
6159 $form['story'] = $wgRequest->getVal('story');
6260 $form['followup'] = $wgRequest->getVal('follow-up');
6361
@@ -67,57 +65,53 @@
6866 $f->setText( $text );
6967 $f->doSubmit();
7068 }
 69+ if( !$wgEnableEmail || !$wgContactUser ) {
 70+ $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
 71+ return;
 72+ }
7173
72 - else {
73 -
74 - }
75 - if( !$wgEnableEmail || !$wgContactUser ) {
76 - $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
77 - return;
78 - }
 74+ $action = $wgRequest->getVal( 'action' );
7975
80 - $action = $wgRequest->getVal( 'action' );
 76+ $nu = User::newFromName( $wgContactUser );
 77+ if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
 78+ wfDebug( "Target is invalid user or can't receive.\n" );
 79+ $wgOut->showErrorPage( "noemailtitle", "noemailtext" );
 80+ return;
 81+ }
8182
82 - $nu = User::newFromName( $wgContactUser );
83 - if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
84 - wfDebug( "Target is invalid user or can't receive.\n" );
85 - $wgOut->showErrorPage( "noemailtitle", "noemailtext" );
86 - return;
87 - }
 83+ $f = new EmailContactForm( $nu );
8884
89 - $f = new EmailContactForm( $nu );
 85+ if ( "success" == $action ) {
 86+ wfDebug( "$fname: success.\n" );
 87+ $f->showSuccess( );
 88+ } else if ( "submit" == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
 89+ $token = $wgRequest->getVal( 'wpEditToken' );
9090
91 - if ( "success" == $action ) {
92 - wfDebug( "$fname: success.\n" );
93 - $f->showSuccess( );
94 - } else if ( "submit" == $action && $wgRequest->wasPosted() && $f->hasAllInfo() ) {
95 - $token = $wgRequest->getVal( 'wpEditToken' );
96 -
97 - if( $wgUser->isAnon() ) {
98 - # Anonymous users may not have a session
99 - # open. Check for suffix anyway.
100 - $tokenOk = ( EDIT_TOKEN_SUFFIX == $token );
101 - } else {
102 - $tokenOk = $wgUser->matchEditToken( $token );
103 - }
104 -
105 - if ( !$tokenOk ) {
106 - wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" );
107 - $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
108 - $f->showForm();
109 - } else if ( !$f->passCaptcha() ) {
110 - wfDebug( "$fname: captcha failed" );
111 - $wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this!
112 - $f->showForm();
113 - } else {
114 - wfDebug( "$fname: submit\n" );
115 - $f->doSubmit();
116 - }
 91+ if( $wgUser->isAnon() ) {
 92+ # Anonymous users may not have a session
 93+ # open. Check for suffix anyway.
 94+ $tokenOk = ( EDIT_TOKEN_SUFFIX == $token );
11795 } else {
118 - wfDebug( "$fname: form\n" );
 96+ $tokenOk = $wgUser->matchEditToken( $token );
 97+ }
 98+
 99+ if ( !$tokenOk ) {
 100+ wfDebug( "$fname: bad token (".($wgUser->isAnon()?'anon':'user')."): $token\n" );
 101+ $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
119102 $f->showForm();
 103+ } else if ( !$f->passCaptcha() ) {
 104+ wfDebug( "$fname: captcha failed" );
 105+ $wgOut->addWikiText( wfMsg( 'contactpage-captcha-failed' ) ); //TODO: provide a message for this!
 106+ $f->showForm();
 107+ } else {
 108+ wfDebug( "$fname: submit\n" );
 109+ $f->doSubmit();
120110 }
 111+ } else {
 112+ wfDebug( "$fname: form\n" );
 113+ $f->showForm();
121114 }
 115+ }
122116 }
123117
124118 /**
@@ -135,7 +129,6 @@
136130 */
137131 function __construct( $target ) {
138132 global $wgRequest, $wgUser;
139 - global $wgCaptchaClass;
140133
141134 $this->target = $target;
142135 $this->text = $wgRequest->getText( 'wpText' );
@@ -284,8 +277,8 @@
285278
286279 function doSubmit( ) {
287280 global $wgOut, $wgRequest;
288 - global $wgEnableEmail, $wgUserEmailUseReplyTo, $wgEmergencyContact;
289 - global $wgContactUser, $wgContactSender, $wgContactSenderName;
 281+ global $wgUserEmailUseReplyTo, $wgEmergencyContact;
 282+ global $wgContactSender, $wgContactSenderName;
290283
291284 $csender = $wgContactSender ? $wgContactSender : $wgEmergencyContact;
292285 $cname = $wgContactSenderName;
Index: trunk/extensions/ContributionReporting/ContributionStatistics_body.php
@@ -20,13 +20,9 @@
2121 public function __construct() {
2222 // Initialize special page
2323 parent::__construct( 'ContributionStatistics' );
24 -
25 - // Internationalization
26 - wfLoadExtensionMessages( 'ContributionReporting' );
2724 }
2825
2926 public function execute( $sub ) {
30 - global $wgRequest, $wgOut, $wgUser;
3127 global $egContributionStatisticsViewDays;
3228
3329 $this->evalDateRange();
@@ -124,8 +120,7 @@
125121
126122 $months = $this->getMonthlyTotals();
127123 $total = $this->getTotalContributions();
128 -
129 - $msg = '';
 124+
130125 if ( $this->mMode == 'range' ) {
131126 $msg = wfMsgExt( 'contribstats-month-range-totals', array( 'parsemag' ), $wgLang->formatNum( count( $months ) ) );
132127 } else {
@@ -216,8 +211,7 @@
217212
218213 public function showContributionBreakdown() {
219214 global $wgOut, $wgLang;
220 -
221 - $msg = '';
 215+
222216 if ( $this->mMode == 'range' ) {
223217 $msg = wfMsg( 'contribstats-contribution-range-breakdown',
224218 $wgLang->date( wfTimestamp( TS_MW, $this->mStartDate ) ),
@@ -252,7 +246,6 @@
253247 wfMsg( 'contribstats-value-over', $wgLang->formatNum( 1000 ) ) => array( 1000, 999999999999.99 ),
254248 );
255249 foreach( $list as $label => $range ) {
256 - $data = array();
257250 if( isset( $range[1] ) ) {
258251 $data = $this->getNumContributionsWithin( $range[0], $range[1] );
259252 } else {
@@ -301,7 +294,7 @@
302295
303296 // Build day/value array
304297 $totals = array();
305 - while ( $row = $dbr->fetchRow( $res ) ) {
 298+ foreach ( $res as $row ) {
306299 /*
307300 $median = $dbr->selectField( 'public_reporting',
308301 array( 'converted_amount' ),
@@ -347,7 +340,7 @@
348341
349342 // Build day/value array
350343 $totals = array();
351 - while ( $row = $dbr->fetchRow( $res ) ) {
 344+ foreach ( $res as $row ) {
352345 $median = $dbr->selectField( 'public_reporting',
353346 array( 'converted_amount' ),
354347 array(
@@ -390,7 +383,7 @@
391384 );
392385
393386 $totals = array();
394 - while ( $row = $dbr->fetchRow( $res ) ) {
 387+ foreach ( $res as $row ) {
395388 $median = $dbr->selectField( 'public_reporting',
396389 array( 'converted_amount' ),
397390 array_merge(
Index: trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php
@@ -15,9 +15,6 @@
1616 public function __construct() {
1717 // Initialize special page
1818 parent::__construct( 'ContributionTrackingStatistics' );
19 -
20 - // Internationalization
21 - wfLoadExtensionMessages( 'ContributionReporting' );
2219 }
2320
2421 public function execute( $sub ) {
@@ -75,10 +72,6 @@
7673 // Generic Table Display for Totals
7774 // FORMAT: 1 daily, 2 weekly, 3 Monthly, 4 Combined
7875 public function showTotalsForRange( $range, $format ) {
79 - global $wgOut;
80 - global $wgAllowedTempaltes, $wgAllowedSupport,
81 - $wgAllowedPaymentMethod, $wgContributionReportingBaseURL;
82 -
8376 list( $start, $end ) = $range;
8477 $current = $end;
8578
@@ -121,7 +114,7 @@
122115
123116 public function createTable( $totals ) {
124117 // Table headers
125 - global $wgOut, $wgAllowedTemplates, $wgAllowedSupport;
 118+ global $wgAllowedTemplates, $wgAllowedSupport;
126119 global $wgAllowedPaymentMethod, $wgContributionReportingBaseURL;
127120
128121 $htmlOut = Xml::openElement( 'table',
@@ -145,11 +138,16 @@
146139 foreach( $totals as $template ) {
147140 //grab info from utm_src, 'unpack' template, landing page, donation page thus far
148141 $expanded_template = explode(".", $template[0]);
149 - if(!isset($expanded_template[1])){ $expanded_template[1] = "";}
150 - if(!isset($expanded_template[2])){ $expanded_template[2] = "";}
 142+ if(!isset($expanded_template[1])) {
 143+ $expanded_template[1] = "";
 144+ }
 145+ if(!isset($expanded_template[2])) {
 146+ $expanded_template[2] = "";
 147+ }
151148
152 - if ( ! in_array($expanded_template[0], $wgAllowedTemplates ) )
 149+ if ( ! in_array($expanded_template[0], $wgAllowedTemplates ) ) {
153150 continue;
 151+ }
154152 if( ($expanded_template[1] != "") && (! in_array($expanded_template[1], $wgAllowedSupport)) ){
155153 continue;
156154 }
@@ -250,7 +248,7 @@
251249
252250 );
253251
254 - while ( $row = $dbr->fetchRow( $res ) ) {
 252+ foreach ( $res as $row ) {
255253 $result[] = array(
256254 $row[0],
257255 $row[1],
Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
@@ -12,7 +12,6 @@
1313
1414 public function __construct() {
1515 parent::__construct( 'FundraiserStatistics' );
16 - wfLoadExtensionMessages( 'ContributionReporting' );
1716 }
1817
1918 public function execute( $sub ) {
@@ -88,7 +87,7 @@
8988 }
9089 // Scale factors
9190 foreach ( $charts as $name => $chart ) {
92 - $charts[$name]['factor'] = $factor = 300 / $chart['max'];
 91+ $charts[$name]['factor'] = 300 / $chart['max'];
9392 }
9493 // HTML-time!
9594 $view = 0;
Index: trunk/extensions/ContributionReporting/ContributionHistory_body.php
@@ -16,9 +16,6 @@
1717 $offset = $wgRequest->getIntOrNull( 'offset' );
1818 $show = 100;
1919
20 - wfLoadExtensionMessages( 'ContributionReporting' );
21 - wfLoadExtensionMessages( 'ContributionReporting', $language );
22 -
2320 $this->setHeaders();
2421
2522 $db = efContributionReportingConnection();
@@ -109,8 +106,8 @@
110107 'LIMIT' => $show
111108 )
112109 );
113 - $alt = TRUE;
114 - while ( $row = $res->fetchRow() ) {
 110+ $alt = true;
 111+ foreach ( $res as $row ) {
115112 if ( $this->isTiny( $row ) ) {
116113 continue; // Skip over micro payments generally < $1
117114 }
Index: trunk/extensions/ContributionReporting/ContributionTotal_body.php
@@ -8,8 +8,6 @@
99 function execute( $par ) {
1010 global $wgRequest, $wgOut;
1111
12 - wfLoadExtensionMessages( 'ContributionReporting' );
13 -
1412 $this->setHeaders();
1513
1614 # Get request data from, e.g.

Follow-up revisions

RevisionCommit summaryAuthorDate
r102697MFT r45856, r71558, r71962, r73304, r73309, r75671, r75680, r75726, r76542, r...awjrichards22:02, 10 November 2011

Comments

#Comment by Trevor Parscal (WMF) (talk | contribs)   20:53, 12 November 2010

The changes this rev introduces for FundraiserStatistics_body.php has been reverted. Lots of errors and mistakes were made.

Status & tagging log