r44019 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44018‎ | r44019 | r44020 >
Date:17:57, 28 November 2008
Author:siebrand
Status:deferred
Tags:
Comment:
* move error class span outside message
* ran stylize.php
Modified paths:
  • /trunk/extensions/AmazonPlus/AmazonPlus.i18n.php (modified) (history)
  • /trunk/extensions/AmazonPlus/AmazonPlus.js (modified) (history)
  • /trunk/extensions/AmazonPlus/AmazonPlus.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AmazonPlus/AmazonPlus.php
@@ -24,35 +24,35 @@
2525
2626 # make sure that everything that needs to be set/loaded is that way
2727 $err = '';
28 -if(!ini_get('allow_url_fopen')) {
 28+if ( !ini_get( 'allow_url_fopen' ) ) {
2929 # we need allow_url_fopen to be on in order for the file_get_contents() call to work on the amazon url
30 - if(ini_set('allow_url_fopen', 1) === false) {
 30+ if ( ini_set( 'allow_url_fopen', 1 ) === false ) {
3131 $err .= "\n<li>allow_url_fopen must be enabled in php.ini</li>";
3232 }
3333 }
34 -if(!extension_loaded('simplexml')) {
 34+if ( !extension_loaded( 'simplexml' ) ) {
3535 # we need the simplexml extension loaded to parse the xml string
3636 $err .= "\n<li>The SimpleXML extension for PHP must be loaded</li>";
3737 }
3838 # if there were errors found, die with the messages
39 -if($err) {
 39+if ( $err ) {
4040 $html = '<html><head><title>Error</title></head><body>
4141 The following errors were discovered with the AmazonPlus extension for MediaWiki:
4242 <ul>' . $err . '</ul></body></html>';
4343 echo $html;
44 - die(1);
 44+ die( 1 );
4545 }
4646
4747 $wgExtensionCredits['other'][] = array(
4848 'name' => 'AmazonPlus',
4949 'description' => 'A highly customizable extension to display Amazon information',
5050 'descriptionmsg' => 'amazonplus-desc',
51 - 'version' => '0.1',
 51+ 'version' => '0.2',
5252 'url' => 'http://www.mediawiki.org/wiki/Extension:AmazonPlus',
5353 'author' => 'Ryan Schmidt',
5454 );
5555
56 -$wgExtensionMessagesFiles['AmazonPlus'] = dirname(__FILE__) . '/AmazonPlus.i18n.php';
 56+$wgExtensionMessagesFiles['AmazonPlus'] = dirname( __FILE__ ) . '/AmazonPlus.i18n.php';
5757
5858 if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
5959 $wgHooks['ParserFirstCallInit'][] = 'efAmazonPlusSetup';
@@ -62,59 +62,59 @@
6363
6464 $wgHooks['BeforePageDisplay'][] = 'efAmazonPlusJavascript';
6565
66 -$wgAmazonPlusAWS = ''; #Amazon AWS Id. Required
67 -$wgAmazonPlusAssociates = array(); #Amazon Associates IDs, per locale.Example: array( 'us' => 'myamazonid', 'fr' => 'myfrenchid' ); Required
68 -$wgAmazonPlusDefaultSearch = 'Books'; #Default search type, can be Books, DVDs, etc.
69 -$wgAmazonPlusDecimal = '.'; #What to seperate the decimals with in currency. e.g. 15.43 or 12,72
 66+$wgAmazonPlusAWS = ''; # Amazon AWS Id. Required
 67+$wgAmazonPlusAssociates = array(); # Amazon Associates IDs, per locale.Example: array( 'us' => 'myamazonid', 'fr' => 'myfrenchid' ); Required
 68+$wgAmazonPlusDefaultSearch = 'Books'; # Default search type, can be Books, DVDs, etc.
 69+$wgAmazonPlusDecimal = '.'; # What to seperate the decimals with in currency. e.g. 15.43 or 12,72
7070
71 -#defines
72 -define('AMAZONPLUS_ALL', 0);
73 -define('AMAZONPLUS_AMAZON', 1);
74 -define('AMAZONPLUS_NEW', 2);
75 -define('AMAZONPLUS_USED', 3);
 71+# defines
 72+define( 'AMAZONPLUS_ALL', 0 );
 73+define( 'AMAZONPLUS_AMAZON', 1 );
 74+define( 'AMAZONPLUS_NEW', 2 );
 75+define( 'AMAZONPLUS_USED', 3 );
7676
7777 # Set up the tag extension
7878 function efAmazonPlusSetup() {
7979 global $wgParser;
8080 $wgParser->setHook( 'amazon', 'efAmazonPlusRender' );
81 - wfLoadExtensionMessages('AmazonPlus');
 81+ wfLoadExtensionMessages( 'AmazonPlus' );
8282 return true;
8383 }
8484
8585 # Set up the javascript
86 -function efAmazonPlusJavascript(&$out, $sk) {
 86+function efAmazonPlusJavascript( &$out, $sk ) {
8787 global $wgScriptPath;
8888 $src = $wgScriptPath . '/extensions/AmazonPlus/AmazonPlus.js';
89 - $out->addScript('<script type="text/javascript" src="'.$src.'"></script>');
 89+ $out->addScript( '<script type="text/javascript" src="' . $src . '"></script>' );
9090 return true;
9191 }
9292
9393 # Render the tag extension
94 -function efAmazonPlusRender($input, $args, $parser) {
 94+function efAmazonPlusRender( $input, $args, $parser ) {
9595 $title = $parser->getTitle();
96 - #If we can, disable the time limit so queries don't time out
97 - @set_time_limit(0);
98 -
99 - #Parse out template parameters only before getting setting up the class so {{{1}}} and the like work
100 - $input = $parser->replaceVariables($input, false, true);
101 -
102 - $am = new AmazonPlus($title, $args, $input);
103 - if(!$am instanceOf AmazonPlus) {
104 - return wfMsg($am);
 96+ # If we can, disable the time limit so queries don't time out
 97+ @set_time_limit( 0 );
 98+
 99+ # Parse out template parameters only before getting setting up the class so {{{1}}} and the like work
 100+ $input = $parser->replaceVariables( $input, false, true );
 101+
 102+ $am = new AmazonPlus( $title, $args, $input );
 103+ if ( !$am instanceOf AmazonPlus ) {
 104+ return wfMsg( $am );
105105 }
106106 wfSuppressWarnings();
107107 $s = $am->doRequest();
108 - if($s === false) {
109 - return wfMsg('amazonplus-nores');
110 - } elseif($s !== true) {
111 - return wfMsg($s);
 108+ if ( $s === false ) {
 109+ return '<span class="error">' . wfMsg( 'amazonplus-nores' ) . '</span>';
 110+ } elseif ( $s !== true ) {
 111+ return wfMsg( $s );
112112 }
113113
114114 $ret = $am->getResult();
115 - $temp = $parser->mOptions->setAllowExternalImages(true);
116 - $ret = $parser->recursiveTagParse($ret);
117 - $ret = str_replace('%' . $am->getToken() . '%', $am->priceSelect(), $ret);
118 - $parser->mOptions->setAllowExternalImages($temp);
 115+ $temp = $parser->mOptions->setAllowExternalImages( true );
 116+ $ret = $parser->recursiveTagParse( $ret );
 117+ $ret = str_replace( '%' . $am->getToken() . '%', $am->priceSelect(), $ret );
 118+ $parser->mOptions->setAllowExternalImages( $temp );
119119 wfRestoreWarnings();
120120 return $ret;
121121 }
@@ -122,20 +122,20 @@
123123 # Class for holding/parsing information from the Amazon REST interface
124124 class AmazonPlus {
125125 var $locale, $request, $response, $xml, $input, $error, $valid, $token, $title;
126 -
127 - function __construct($title, $args, $input) {
 126+
 127+ function __construct( $title, $args, $input ) {
128128 global $wgAmazonPlusAWS, $wgAmazonPlusAssociates;
129 - $this->valid = array('us', 'gb', 'ca', 'de', 'fr', 'jp');
 129+ $this->valid = array( 'us', 'gb', 'ca', 'de', 'fr', 'jp' );
130130 $this->currencies = array();
131131 $this->token = rand();
132 - if(isset($args['locale'])) {
133 - $this->locale = ($this->validLocale($args['locale'])) ? $args['locale'] : 'us';
 132+ if ( isset( $args['locale'] ) ) {
 133+ $this->locale = ( $this->validLocale( $args['locale'] ) ) ? $args['locale'] : 'us';
134134 } else {
135135 $this->locale = 'us';
136136 }
137 - $id = (isset($args['id'])) ? $args['id'] : $this->getId($title, $args);
138 - if(!$id) {
139 - return 'amazonplus-noidres';
 137+ $id = ( isset( $args['id'] ) ) ? $args['id'] : $this->getId( $title, $args );
 138+ if ( !$id ) {
 139+ return '<span class="error">' . 'amazonplus-noidres' . '</span>';
140140 }
141141 $this->title = $title;
142142 $this->input = $input;
@@ -149,68 +149,68 @@
150150 'ResponseGroup' => 'Large',
151151 );
152152 }
153 -
154 - function validLocale($loc) {
 153+
 154+ function validLocale( $loc ) {
155155 global $wgAmazonPlusAssociates;
156 - return (in_array($loc, $this->valid) && array_key_exists($loc, $wgAmazonPlusAssociates));
 156+ return ( in_array( $loc, $this->valid ) && array_key_exists( $loc, $wgAmazonPlusAssociates ) );
157157 }
158 -
159 - function setValue($key, $value) { $this->request[$key] = $value; }
160 - function getValue($key) { return $this->request[$key]; }
 158+
 159+ function setValue( $key, $value ) { $this->request[$key] = $value; }
 160+ function getValue( $key ) { return $this->request[$key]; }
161161 function getToken() { return $this->token; }
162162 function getLocale() { return $this->locale; }
163 -
164 - function getId($title, $args) {
 163+
 164+ function getId( $title, $args ) {
165165 global $wgAmazonPlusAWS, $wgAmazonPlusAssociates, $wgAmazonPlusDefaultSearch;
166 - $kw = (isset($args['keywords'])) ? $args['keywords'] : $title->getText();
167 - $si = (isset($args['search'])) ? $args['search'] : $wgAmazonPlusDefaultSearch;
 166+ $kw = ( isset( $args['keywords'] ) ) ? $args['keywords'] : $title->getText();
 167+ $si = ( isset( $args['search'] ) ) ? $args['search'] : $wgAmazonPlusDefaultSearch;
168168 $this->request = array(
169169 'Service' => 'AWSECommerceService',
170170 'Operation' => 'ItemSearch',
171171 'ResponseGroup' => 'ItemIds',
172 - 'Version' => '2008-08-19',
 172+ 'Version' => '2008-08-19',
173173 'Keywords' => $kw,
174 - 'AWSAccessKeyId'=> $wgAmazonPlusAWS,
 174+ 'AWSAccessKeyId' => $wgAmazonPlusAWS,
175175 'SearchIndex' => $si,
176176 'AssociateTag' => $wgAmazonPlusAssociates[$this->locale],
177177 );
178178 $this->doRequest();
179 - if(!$this->xml->Items->TotalResults) {
 179+ if ( !$this->xml->Items->TotalResults ) {
180180 return false;
181181 }
182182 return $this->xml->Items->Item[0]->ASIN;
183183 }
184 -
 184+
185185 function doRequest() {
186186 $tld = $this->localeString();
187187 $str = "http://ecs.amazonaws.{$tld}/onca/xml";
188188 $i = false;
189 - foreach($this->request as $key => $value) {
190 - if($i) {
 189+ foreach ( $this->request as $key => $value ) {
 190+ if ( $i ) {
191191 $str .= '&';
192192 } else {
193193 $str .= '?';
194194 $i = true;
195195 }
196 - $str .= wfUrlencode($key) . '=' . wfUrlencode($value);
 196+ $str .= wfUrlencode( $key ) . '=' . wfUrlencode( $value );
197197 }
198 -
199 - $this->response = file_get_contents($str);
200 - if($this->response === false) {
201 - return 'amazonplus-fgcerr';
 198+
 199+ $this->response = file_get_contents( $str );
 200+ if ( $this->response === false ) {
 201+ return '<span class="error">' . 'amazonplus-fgcerr' . '</span>';
202202 }
203 -
204 - $this->xml = simplexml_load_string($this->response);
205 - if($this->xml === false) {
206 - return 'amazonplus-slserr';
 203+
 204+ $this->xml = simplexml_load_string( $this->response );
 205+ if ( $this->xml === false ) {
 206+ return '<span class="error">' . 'amazonplus-slserr' . '</span>';
207207 }
208208
209 - if($this->xml->Items->TotalResults == '0') {
 209+ if ( $this->xml->Items->TotalResults == '0' ) {
210210 return false;
211211 }
212212 return true;
213213 }
214 -
 214+
215215 function getResult() {
216216 $item = $this->xml->Items->Item;
217217 $imageset = $item->ImageSets->ImageSet;
@@ -218,8 +218,8 @@
219219 $editorials = $item->EditorialReviews->EditorialReview;
220220 $reviews = $item->CustomerReviews;
221221 $links = array();
222 - foreach($item->ItemLinks->ItemLink as $link) {
223 - $links[str_replace(' ', '', $link->Description)] = $link->URL;
 222+ foreach ( $item->ItemLinks->ItemLink as $link ) {
 223+ $links[str_replace( ' ', '', $link->Description )] = $link->URL;
224224 }
225225 $replace = array(
226226 /* IMAGES */
@@ -234,37 +234,37 @@
235235 'reviewlink' => $links['AllCustomerReviews'],
236236 'source' => $editorials->Source,
237237 'rating' => $reviews->AverageRating,
238 - 'stars' => $this->starsImage($reviews->AverageRating),
 238+ 'stars' => $this->starsImage( $reviews->AverageRating ),
239239 'total' => $reviews->TotalReviews,
240240 /* PRICES */
241 - 'price' => $this->formatPrice($item, AMAZONPLUS_ALL),
242 - 'price-amazon' => $this->formatPrice($item, AMAZONPLUS_AMAZON),
243 - 'price-new' => $this->formatPrice($item, AMAZONPLUS_NEW),
244 - 'price-used' => $this->formatPrice($item, AMAZONPLUS_USED),
245 - 'price-us' => $this->getPrice('us', $item->ASIN, AMAZONPLUS_ALL),
246 - 'price-gb' => $this->getPrice('gb', $item->ASIN, AMAZONPLUS_ALL),
247 - 'price-ca' => $this->getPrice('ca', $item->ASIN, AMAZONPLUS_ALL),
248 - 'price-de' => $this->getPrice('de', $item->ASIN, AMAZONPLUS_ALL),
249 - 'price-jp' => $this->getPrice('jp', $item->ASIN, AMAZONPLUS_ALL),
250 - 'price-fr' => $this->getPrice('fr', $item->ASIN, AMAZONPLUS_ALL),
251 - 'price-us-amazon' => $this->getPrice('us', $item->ASIN, AMAZONPLUS_AMAZON),
252 - 'price-gb-amazon' => $this->getPrice('gb', $item->ASIN, AMAZONPLUS_AMAZON),
253 - 'price-ca-amazon' => $this->getPrice('ca', $item->ASIN, AMAZONPLUS_AMAZON),
254 - 'price-de-amazon' => $this->getPrice('de', $item->ASIN, AMAZONPLUS_AMAZON),
255 - 'price-jp-amazon' => $this->getPrice('jp', $item->ASIN, AMAZONPLUS_AMAZON),
256 - 'price-fr-amazon' => $this->getPrice('fr', $item->ASIN, AMAZONPLUS_AMAZON),
257 - 'price-us-new' => $this->getPrice('us', $item->ASIN, AMAZONPLUS_NEW),
258 - 'price-gb-new' => $this->getPrice('gb', $item->ASIN, AMAZONPLUS_NEW),
259 - 'price-ca-new' => $this->getPrice('ca', $item->ASIN, AMAZONPLUS_NEW),
260 - 'price-de-new' => $this->getPrice('de', $item->ASIN, AMAZONPLUS_NEW),
261 - 'price-jp-new' => $this->getPrice('jp', $item->ASIN, AMAZONPLUS_NEW),
262 - 'price-fr-new' => $this->getPrice('fr', $item->ASIN, AMAZONPLUS_NEW),
263 - 'price-us-used' => $this->getPrice('us', $item->ASIN, AMAZONPLUS_USED),
264 - 'price-gb-used' => $this->getPrice('gb', $item->ASIN, AMAZONPLUS_USED),
265 - 'price-ca-used' => $this->getPrice('ca', $item->ASIN, AMAZONPLUS_USED),
266 - 'price-de-used' => $this->getPrice('de', $item->ASIN, AMAZONPLUS_USED),
267 - 'price-jp-used' => $this->getPrice('jp', $item->ASIN, AMAZONPLUS_USED),
268 - 'price-fr-used' => $this->getPrice('fr', $item->ASIN, AMAZONPLUS_USED),
 241+ 'price' => $this->formatPrice( $item, AMAZONPLUS_ALL ),
 242+ 'price-amazon' => $this->formatPrice( $item, AMAZONPLUS_AMAZON ),
 243+ 'price-new' => $this->formatPrice( $item, AMAZONPLUS_NEW ),
 244+ 'price-used' => $this->formatPrice( $item, AMAZONPLUS_USED ),
 245+ 'price-us' => $this->getPrice( 'us', $item->ASIN, AMAZONPLUS_ALL ),
 246+ 'price-gb' => $this->getPrice( 'gb', $item->ASIN, AMAZONPLUS_ALL ),
 247+ 'price-ca' => $this->getPrice( 'ca', $item->ASIN, AMAZONPLUS_ALL ),
 248+ 'price-de' => $this->getPrice( 'de', $item->ASIN, AMAZONPLUS_ALL ),
 249+ 'price-jp' => $this->getPrice( 'jp', $item->ASIN, AMAZONPLUS_ALL ),
 250+ 'price-fr' => $this->getPrice( 'fr', $item->ASIN, AMAZONPLUS_ALL ),
 251+ 'price-us-amazon' => $this->getPrice( 'us', $item->ASIN, AMAZONPLUS_AMAZON ),
 252+ 'price-gb-amazon' => $this->getPrice( 'gb', $item->ASIN, AMAZONPLUS_AMAZON ),
 253+ 'price-ca-amazon' => $this->getPrice( 'ca', $item->ASIN, AMAZONPLUS_AMAZON ),
 254+ 'price-de-amazon' => $this->getPrice( 'de', $item->ASIN, AMAZONPLUS_AMAZON ),
 255+ 'price-jp-amazon' => $this->getPrice( 'jp', $item->ASIN, AMAZONPLUS_AMAZON ),
 256+ 'price-fr-amazon' => $this->getPrice( 'fr', $item->ASIN, AMAZONPLUS_AMAZON ),
 257+ 'price-us-new' => $this->getPrice( 'us', $item->ASIN, AMAZONPLUS_NEW ),
 258+ 'price-gb-new' => $this->getPrice( 'gb', $item->ASIN, AMAZONPLUS_NEW ),
 259+ 'price-ca-new' => $this->getPrice( 'ca', $item->ASIN, AMAZONPLUS_NEW ),
 260+ 'price-de-new' => $this->getPrice( 'de', $item->ASIN, AMAZONPLUS_NEW ),
 261+ 'price-jp-new' => $this->getPrice( 'jp', $item->ASIN, AMAZONPLUS_NEW ),
 262+ 'price-fr-new' => $this->getPrice( 'fr', $item->ASIN, AMAZONPLUS_NEW ),
 263+ 'price-us-used' => $this->getPrice( 'us', $item->ASIN, AMAZONPLUS_USED ),
 264+ 'price-gb-used' => $this->getPrice( 'gb', $item->ASIN, AMAZONPLUS_USED ),
 265+ 'price-ca-used' => $this->getPrice( 'ca', $item->ASIN, AMAZONPLUS_USED ),
 266+ 'price-de-used' => $this->getPrice( 'de', $item->ASIN, AMAZONPLUS_USED ),
 267+ 'price-jp-used' => $this->getPrice( 'jp', $item->ASIN, AMAZONPLUS_USED ),
 268+ 'price-fr-used' => $this->getPrice( 'fr', $item->ASIN, AMAZONPLUS_USED ),
269269 'compare' => '%' . $this->token . '%',
270270 'offers' => $links['AllOffers'],
271271 /* DETAILS */
@@ -275,12 +275,12 @@
276276 'binding' => $attr->Binding,
277277 'pages' => $attr->NumberOfPages,
278278 'edition' => $attr->Edition,
279 - 'releaseyear' => $this->parseDate($attr->ReleaseDate, 0),
280 - 'releasemonth' => $this->parseDate($attr->ReleaseDate, 1),
281 - 'releaseday' => $this->parseDate($attr->ReleaseDate, 2),
282 - 'publishedyear' => $this->parseDate($attr->PublicationDate, 0),
283 - 'publishedmonth' => $this->parseDate($attr->PublicationDate, 1),
284 - 'publishedday' => $this->parseDate($attr->PublicationDate, 2),
 279+ 'releaseyear' => $this->parseDate( $attr->ReleaseDate, 0 ),
 280+ 'releasemonth' => $this->parseDate( $attr->ReleaseDate, 1 ),
 281+ 'releaseday' => $this->parseDate( $attr->ReleaseDate, 2 ),
 282+ 'publishedyear' => $this->parseDate( $attr->PublicationDate, 0 ),
 283+ 'publishedmonth' => $this->parseDate( $attr->PublicationDate, 1 ),
 284+ 'publishedday' => $this->parseDate( $attr->PublicationDate, 2 ),
285285 'detailslink' => $links['Technical Details'],
286286 /* IDENTIFICATION */
287287 'isbn' => $attr->ISBN,
@@ -288,33 +288,33 @@
289289 'ean' => $item->EAN,
290290 /* PURCHASING URLS */
291291 'buy' => $item->DetailPageURL,
292 - 'buy-us' => $this->getUrl('us', $item->ASIN),
293 - 'buy-gb' => $this->getUrl('gb', $item->ASIN),
294 - 'buy-ca' => $this->getUrl('ca', $item->ASIN),
295 - 'buy-de' => $this->getUrl('de', $item->ASIN),
296 - 'buy-jp' => $this->getUrl('jp', $item->ASIN),
297 - 'buy-fr' => $this->getUrl('fr', $item->ASIN),
 292+ 'buy-us' => $this->getUrl( 'us', $item->ASIN ),
 293+ 'buy-gb' => $this->getUrl( 'gb', $item->ASIN ),
 294+ 'buy-ca' => $this->getUrl( 'ca', $item->ASIN ),
 295+ 'buy-de' => $this->getUrl( 'de', $item->ASIN ),
 296+ 'buy-jp' => $this->getUrl( 'jp', $item->ASIN ),
 297+ 'buy-fr' => $this->getUrl( 'fr', $item->ASIN ),
298298 );
299 -
300 - foreach($replace as $find => $rep) {
301 - $this->input = str_replace('%'.$find.'%', $rep, $this->input);
 299+
 300+ foreach ( $replace as $find => $rep ) {
 301+ $this->input = str_replace( '%' . $find . '%', $rep, $this->input );
302302 }
303303 return $this->input;
304304 }
305 -
306 - function starsImage($rating) {
307 - $rating = str_replace('.', '-', $rating);
308 - return 'http://g-ecx.images-amazon.com/images/G/01/x-locale/common/customer-reviews/ratings/stars-'.$rating.'._V25749327_.gif';
 305+
 306+ function starsImage( $rating ) {
 307+ $rating = str_replace( '.', '-', $rating );
 308+ return 'http://g-ecx.images-amazon.com/images/G/01/x-locale/common/customer-reviews/ratings/stars-' . $rating . '._V25749327_.gif';
309309 }
310 -
311 - function parseDate($date, $segment) {
312 - $pieces = explode('-', $date);
 310+
 311+ function parseDate( $date, $segment ) {
 312+ $pieces = explode( '-', $date );
313313 return $pieces[$segment];
314314 }
315 -
316 - function getPrice($loc, $asin, $type) {
317 - #if it isn't in the input, then don't do the query to save time
318 - switch($type) {
 315+
 316+ function getPrice( $loc, $asin, $type ) {
 317+ # if it isn't in the input, then don't do the query to save time
 318+ switch( $type ) {
319319 case AMAZONPLUS_ALL:
320320 $app = '';
321321 break;
@@ -328,59 +328,59 @@
329329 $app = '-used';
330330 break;
331331 }
332 - if(strpos($this->input, "%price-{$loc}{$app}%") === false)
 332+ if ( strpos( $this->input, "%price-{$loc}{$app}%" ) === false )
333333 return '';
334 - #do we already have this info?
335 - if($loc == $this->locale)
336 - return $this->formatPrice($this->xml->Items->Item, $type);
337 - $ap = new AmazonPlus($this->title, array('locale' => $loc, 'id' => $asin), "%price{$app}%");
338 - #if we can't get the right locale, stop early
339 - if($ap->getLocale() != $loc)
340 - return ''; #Perhaps this should be an error message?
 334+ # do we already have this info?
 335+ if ( $loc == $this->locale )
 336+ return $this->formatPrice( $this->xml->Items->Item, $type );
 337+ $ap = new AmazonPlus( $this->title, array( 'locale' => $loc, 'id' => $asin ), "%price{$app}%" );
 338+ # if we can't get the right locale, stop early
 339+ if ( $ap->getLocale() != $loc )
 340+ return ''; # Perhaps this should be an error message?
341341 $ap->doRequest();
342342 return $ap->getResult();
343343 }
344 -
345 - function getUrl($loc, $asin) {
346 - #if it isn't in the input, then don't do the query to save time
347 - if(strpos($this->input, "%buy-{$loc}%") === false)
 344+
 345+ function getUrl( $loc, $asin ) {
 346+ # if it isn't in the input, then don't do the query to save time
 347+ if ( strpos( $this->input, "%buy-{$loc}%" ) === false )
348348 return '';
349 - #do we already have this info?
350 - if($loc == $this->locale)
 349+ # do we already have this info?
 350+ if ( $loc == $this->locale )
351351 return $this->xml->Items->Item->DetailPageURL;
352 - $ap = new AmazonPlus($this->title, array('locale' => $loc, 'id' => $asin), '%buy%');
353 - #if we can't get the right locale, stop early
354 - if($ap->getLocale() != $loc)
355 - return ''; #Perhaps this should be an error message?
 352+ $ap = new AmazonPlus( $this->title, array( 'locale' => $loc, 'id' => $asin ), '%buy%' );
 353+ # if we can't get the right locale, stop early
 354+ if ( $ap->getLocale() != $loc )
 355+ return ''; # Perhaps this should be an error message?
356356 $ap->doRequest();
357 - return $ap->getResult();
 357+ return $ap->getResult();
358358 }
359 -
 359+
360360 function priceSelect() {
361361 $html = '<select onchange="javascript:convertPrices();">
362 -<option id="cp-none" value="cp-none">' . wfMsgHtml('amazonplus-cp-none') . '</option>
363 -<option id="cp-usd" value="cp-usd">' . wfMsgHtml('amazonplus-cp-usd') . '</option>
364 -<option id="cp-cad" value="cp-cad">' . wfMsgHtml('amazonplus-cp-cad') . '</option>
365 -<option id="cp-gbp" value="cp-gbp">' . wfMsgHtml('amazonplus-cp-gbp') . '</option>
366 -<option id="cp-eur" value="cp-eur">' . wfMsgHtml('amazonplus-cp-eur') . '</option>
367 -<option id="cp-jpy" value="cp-jpy">' . wfMsgHtml('amazonplus-cp-jpy') . '</option>
 362+<option id="cp-none" value="cp-none">' . wfMsgHtml( 'amazonplus-cp-none' ) . '</option>
 363+<option id="cp-usd" value="cp-usd">' . wfMsgHtml( 'amazonplus-cp-usd' ) . '</option>
 364+<option id="cp-cad" value="cp-cad">' . wfMsgHtml( 'amazonplus-cp-cad' ) . '</option>
 365+<option id="cp-gbp" value="cp-gbp">' . wfMsgHtml( 'amazonplus-cp-gbp' ) . '</option>
 366+<option id="cp-eur" value="cp-eur">' . wfMsgHtml( 'amazonplus-cp-eur' ) . '</option>
 367+<option id="cp-jpy" value="cp-jpy">' . wfMsgHtml( 'amazonplus-cp-jpy' ) . '</option>
368368 </select>';
369369 return $html;
370370 }
371 -
372 - function formatPrice($offer, $type) {
 371+
 372+ function formatPrice( $offer, $type ) {
373373 global $wgAmazonPlusDecimal;
374 - if($offer->Offers->TotalOffers != '0' && ($type == AMAZONPLUS_ALL || $type == AMAZONPLUS_AMAZON)) {
 374+ if ( $offer->Offers->TotalOffers != '0' && ( $type == AMAZONPLUS_ALL || $type == AMAZONPLUS_AMAZON ) ) {
375375 $amount = $offer->Offers->Offer->OfferListing->Price->Amount;
376376 $code = $offer->Offers->Offer->OfferListing->Price->CurrencyCode;
377377 $extra[] = 'amazonplus-amazon';
378 - $err = false;
379 - } elseif($offer->OfferSummary->TotalNew != '0' && ($type == AMAZONPLUS_ALL || $type == AMAZONPLUS_NEW)) {
 378+ $err = false;
 379+ } elseif ( $offer->OfferSummary->TotalNew != '0' && ( $type == AMAZONPLUS_ALL || $type == AMAZONPLUS_NEW ) ) {
380380 $amount = $offer->OfferSummary->LowestNewPrice->Amount;
381381 $code = $offer->OfferSummary->LowestNewPrice->CurrencyCode;
382382 $extra[] = 'amazonplus-new';
383383 $err = false;
384 - } elseif($offer->TotalUsed != '0' && ($type == AMAZONPLUS_ALL || $type == AMAZONPLUS_USED)) {
 384+ } elseif ( $offer->TotalUsed != '0' && ( $type == AMAZONPLUS_ALL || $type == AMAZONPLUS_USED ) ) {
385385 $amount = $offer->OfferSummary->LowestUsedPrice->Amount;
386386 $code = $offer->OfferSummary->LowestUsedPrice->CurrencyCode;
387387 $extra[] = 'amazonplus-used';
@@ -388,27 +388,27 @@
389389 } else {
390390 $err = 'amazonplus-none';
391391 }
392 - if($err) {
393 - return wfMsg($err);
 392+ if ( $err ) {
 393+ return wfMsg( $err );
394394 }
395 - foreach($offer->ItemAttributes->Languages as $lang) {
396 - if($lang->Type != 'Published') continue;
397 - $extra[] = 'amazonplus-' . strtolower($lang->Name);
 395+ foreach ( $offer->ItemAttributes->Languages as $lang ) {
 396+ if ( $lang->Type != 'Published' ) continue;
 397+ $extra[] = 'amazonplus-' . strtolower( $lang->Name );
398398 break;
399399 }
400400 $app = '';
401401 $params = '';
402402 $i = 0;
403 - foreach($extra as $val) {
404 - $msg = wfMsg($val);
405 - if($msg == '') continue;
406 - if($i++ != 0) $params .= wfMsg('amazonplus-status-sep');
 403+ foreach ( $extra as $val ) {
 404+ $msg = wfMsg( $val );
 405+ if ( $msg == '' ) continue;
 406+ if ( $i++ != 0 ) $params .= wfMsg( 'amazonplus-status-sep' );
407407 $params .= $msg;
408408 }
409 - if($params) $app = ' '.wfMsg('amazonplus-status', $params);
410 - $begin = substr($amount, 0, strlen($amount)-2);
411 - $end = substr($amount, -2);
412 - switch($this->locale) {
 409+ if ( $params ) $app = ' ' . wfMsg( 'amazonplus-status', $params );
 410+ $begin = substr( $amount, 0, strlen( $amount ) - 2 );
 411+ $end = substr( $amount, - 2 );
 412+ switch( $this->locale ) {
413413 case 'us': $sign = '&#36;'; break;
414414 case 'ca': $sign = '&#36;'; break;
415415 case 'de': $sign = '&euro;'; break;
@@ -416,11 +416,11 @@
417417 case 'jp': $sign = '&yen;'; break;
418418 case 'gb': $sign = '&pound;'; break;
419419 }
420 - return wfMsg('amazonplus-currency', array($begin . $wgAmazonPlusDecimal . $end, $code, $sign, $app));
 420+ return wfMsg( 'amazonplus-currency', array( $begin . $wgAmazonPlusDecimal . $end, $code, $sign, $app ) );
421421 }
422 -
 422+
423423 function localeString() {
424 - switch($this->locale) {
 424+ switch( $this->locale ) {
425425 case 'us': return 'com';
426426 case 'gb': return 'co.uk';
427427 case 'ca': return 'ca';
Index: trunk/extensions/AmazonPlus/AmazonPlus.js
@@ -1,3 +1,3 @@
22 function convertPrices() {
33 return;
4 -}
\ No newline at end of file
 4+}
Index: trunk/extensions/AmazonPlus/AmazonPlus.i18n.php
@@ -4,10 +4,10 @@
55
66 $messages['en'] = array(
77 'amazonplus-desc' => 'A highly customizable extension to display Amazon information',
8 - 'amazonplus-nores' => '<span class="error">Error: No results found!</span>',
9 - 'amazonplus-noidres' => '<span class="error">Error: Could not find a product ID!</span>',
10 - 'amazonplus-fgcerr' => '<span class="error">Error: Could not retrieve data from Amazon!</span>',
11 - 'amazonplus-slserr' => '<span class="error">Error: Could not parse data from Amazon!</span>',
 8+ 'amazonplus-nores' => 'Error: No results found!',
 9+ 'amazonplus-noidres' => 'Error: Could not find a product ID!',
 10+ 'amazonplus-fgcerr' => 'Error: Could not retrieve data from Amazon!',
 11+ 'amazonplus-slserr' => 'Error: Could not parse data from Amazon!',
1212 'amazonplus-used' => 'used',
1313 'amazonplus-german' => 'german',
1414 'amazonplus-french' => 'french',

Status & tagging log