r43012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43011‎ | r43012 | r43013 >
Date:18:51, 1 November 2008
Author:siebrand
Status:old
Tags:
Comment:
* delay message loading
* use $wgExtensionAliasesFiles for special page aliases
* merge 2 i18n files to one
* fix indentation, remove trailing whitespace and stylize.php
Modified paths:
  • /trunk/extensions/ContributionReporting/ContributionHistory.i18n.php (deleted) (history)
  • /trunk/extensions/ContributionReporting/ContributionHistory_body.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionReporting.alias.php (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionReporting.i18n.php (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionReporting.php (modified) (history)
  • /trunk/extensions/ContributionReporting/ContributionTotal.i18n.php (deleted) (history)
  • /trunk/extensions/ContributionReporting/ContributionTotal_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/ContributionHistory.i18n.php
@@ -1,5 +0,0 @@
2 -<?php
3 -$messages = array();
4 -$messages['en'] = array(
5 - 'contributionhistory' => 'Contribution history',
6 - );
Index: trunk/extensions/ContributionReporting/ContributionTotal.i18n.php
@@ -1,5 +0,0 @@
2 -<?php
3 -$messages = array();
4 -$messages['en'] = array(
5 - 'contributiontotal' => 'Contribution total',
6 - );
Index: trunk/extensions/ContributionReporting/ContributionReporting.php
@@ -1,7 +1,7 @@
22 <?php
33
44 # Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
5 -if (!defined('MEDIAWIKI')) {
 5+if ( !defined( 'MEDIAWIKI' ) ) {
66 echo <<<EOT
77 To install my extension, put the following line in LocalSettings.php:
88 require_once( "\$IP/extensions/ContributionReporting/ContributionReporting.php" );
@@ -15,49 +15,28 @@
1616 $wgContributionReportingDBpassword = $wgDBpassword;
1717 $wgContributionReportingDBname = $wgDBname;
1818
19 -$dir = dirname(__FILE__) . '/';
 19+$dir = dirname( __FILE__ ) . '/';
2020
21 -// Add any aliases for the special page.
22 -$wgHooks['LanguageGetSpecialPageAliases'][] = 'contributionReportingLocalizedPageName';
23 -
24 -$wgExtensionMessagesFiles['ContributionHistory'] = $dir . 'ContributionHistory.i18n.php';
 21+$wgExtensionMessagesFiles['ContributionReporting'] = $dir . 'ContributionReporting.i18n.php';
 22+$wgExtensionAliasesFiles['ContributionReporting'] = $dir . 'ContributionReporting.alias.php';
2523 $wgAutoloadClasses['ContributionHistory'] = $dir . 'ContributionHistory_body.php';
26 -$wgSpecialPages['ContributionHistory'] = 'ContributionHistory';
27 -
28 -$wgExtensionMessagesFiles['ContributionTotal'] = $dir . 'ContributionTotal.i18n.php';
2924 $wgAutoloadClasses['ContributionTotal'] = $dir . 'ContributionTotal_body.php';
 25+$wgSpecialPages['ContributionHistory'] = 'ContributionHistory';
3026 $wgSpecialPages['ContributionTotal'] = 'ContributionTotal';
3127
32 -function contributionReportingLocalizedPageName(&$specialPageArray, $code) {
33 - # The localized title of the special page is among the messages of the extension:
34 - wfLoadExtensionMessages('ContributionHistory');
35 - $text = wfMsg('contributionhistory');
36 -
37 - # Convert from title in text form to DBKey and put it into the alias array:
38 - $title = Title::newFromText($text);
39 - $specialPageArray['ContributionHistory'][] = $title->getDBKey();
40 -
41 - wfLoadExtensionMessages('ContributionTotal');
42 - $text = wfMsg('contributiontotal');
43 - $title = Title::newFromText($text);
44 - $specialPageArray['ContributionTotal'][] = $title->getDBKey();
45 -
46 - return true;
47 -}
48 -
4928 function contributionReportingConnection() {
5029 global $wgContributionReportingDBserver, $wgContributionReportingDBname;
5130 global $wgContributionReportingDBuser, $wgContributionReportingDBpassword;
52 -
 31+
5332 static $db;
54 -
55 - if (!$db) {
 33+
 34+ if ( !$db ) {
5635 $db = new DatabaseMysql(
5736 $wgContributionReportingDBserver,
5837 $wgContributionReportingDBuser,
5938 $wgContributionReportingDBpassword,
6039 $wgContributionReportingDBname );
6140 }
62 -
 41+
6342 return $db;
6443 }
Index: trunk/extensions/ContributionReporting/ContributionHistory_body.php
@@ -1,91 +1,91 @@
22 <?php
33 class ContributionHistory extends SpecialPage {
4 - function ContributionHistory() {
5 - SpecialPage::SpecialPage('ContributionHistory');
6 - wfLoadExtensionMessages('ContributionHistory');
7 - }
8 -
9 - function execute( $language = NULL ) {
10 - global $wgRequest, $wgOut;
11 -
12 - if (!$language) {
13 - $language = 'en';
14 - }
15 -
16 - // Get request data
17 - $dir = $wgRequest->getText('dir', '');
18 - $offset = $wgRequest->getText('offset');
19 - $limit = $wgRequest->getText('limit', 50);
20 -
21 - $this->setHeaders();
22 -
23 - $db = contributionReportingConnection();
 4+ function ContributionHistory() {
 5+ SpecialPage::SpecialPage( 'ContributionHistory' );
 6+ }
247
25 - $sql = 'SELECT * FROM public_reporting ORDER BY received DESC LIMIT ' . intval($limit);
26 -
27 - $res = $db->query($sql);
28 -
29 - $output = '<style type="text/css">';
30 - $output .= 'td {vertical-align: top; padding: 5px;}';
31 - $output .= 'td.left {padding-right: 10px;}';
32 - $output .= 'td.right {padding-left: 10px; text-align: right;}';
33 - $output .= 'td.alt {background-color: #DDDDDD;}';
34 - $output .= '</style>';
35 -
36 - $output .= '<table style="width: 100%">';
37 - $output .= '<tr><th style="width: 200px;">Name</th><th>Date</th><th style="text-align: right;">Amount</th></tr>';
38 -
39 - $alt = TRUE;
40 - while ($row = $res->fetchRow()) {
41 - $name = htmlspecialchars($row['name']);
42 - if (!$name) {
43 - $name = 'Anonymous';
44 - }
45 -
46 - $name = '<strong>' . $name . '</strong>';
47 -
48 - if ($row['note']) {
49 - $name .= '<br />' . htmlspecialchars($row['note']);
50 - }
51 -
52 - $amount = $this->formatAmount( $row );
53 -
54 - $class = '';
55 - if ($alt) {
56 - $class = ' alt';
57 - }
58 -
59 - $output .= '<tr><td class="left' . $class . '">' . $name . '</td><td class="left' . $class . '" style="width: 50px;">' . date('Y-m-j', $row['received']) . '</td><td class="right' . $class . '" style="width: 75px;">' . $amount . '</td></tr>';
60 -
61 - $alt = !$alt;
62 - }
63 -
64 - $output .= '</table>';
65 -
66 - header('Cache-Control: max-age=300,s-maxage=300');
67 - $wgOut->addWikiText('{{Template:Donate-header/' . $language . '}}');
68 - $wgOut->addWikiText('<skin>Tomas</skin>');
69 - $wgOut->addHTML('<h1>Real-time donor comments from around the world</h1>');
70 - $wgOut->addWikiText('<strong>{{Template:Contribution history introduction/' . $language . '}}</strong>');
71 - $wgOut->addHTML( $output );
72 - $wgOut->addWikiText('{{Template:Donate-footer/' . $language . '}}');
73 - }
 8+ function execute( $language = NULL ) {
 9+ global $wgRequest, $wgOut;
7410
75 - function formatAmount( $row ) {
76 - if( $row['original_currency'] ) {
77 - $currency = $row['original_currency'];
78 - $amount = $row['original_amount'];
79 - } else {
80 - $currency = 'USD';
81 - $amount = $row['converted_amount'];
82 - }
83 -
84 - if( $currency == 'JPY' ) {
85 - // No decimals for yen
86 - $amount = intval( $amount );
87 - }
88 -
89 - return htmlspecialchars( "$currency $amount" );
90 - }
 11+ if ( !$language ) {
 12+ $language = 'en';
 13+ }
9114
 15+ // Get request data
 16+ $dir = $wgRequest->getText( 'dir', '' );
 17+ $offset = $wgRequest->getText( 'offset' );
 18+ $limit = $wgRequest->getText( 'limit', 50 );
 19+
 20+ wfLoadExtensionMessages( 'ContributionReporting' );
 21+
 22+ $this->setHeaders();
 23+
 24+ $db = contributionReportingConnection();
 25+
 26+ $sql = 'SELECT * FROM public_reporting ORDER BY received DESC LIMIT ' . intval( $limit );
 27+
 28+ $res = $db->query( $sql );
 29+
 30+ $output = '<style type="text/css">';
 31+ $output .= 'td {vertical-align: top; padding: 5px;}';
 32+ $output .= 'td.left {padding-right: 10px;}';
 33+ $output .= 'td.right {padding-left: 10px; text-align: right;}';
 34+ $output .= 'td.alt {background-color: #DDDDDD;}';
 35+ $output .= '</style>';
 36+
 37+ $output .= '<table style="width: 100%">';
 38+ $output .= '<tr><th style="width: 200px;">Name</th><th>Date</th><th style="text-align: right;">Amount</th></tr>';
 39+
 40+ $alt = TRUE;
 41+ while ( $row = $res->fetchRow() ) {
 42+ $name = htmlspecialchars( $row['name'] );
 43+ if ( !$name ) {
 44+ $name = 'Anonymous';
 45+ }
 46+
 47+ $name = '<strong>' . $name . '</strong>';
 48+
 49+ if ( $row['note'] ) {
 50+ $name .= '<br />' . htmlspecialchars( $row['note'] );
 51+ }
 52+
 53+ $amount = $this->formatAmount( $row );
 54+
 55+ $class = '';
 56+ if ( $alt ) {
 57+ $class = ' alt';
 58+ }
 59+
 60+ $output .= '<tr><td class="left' . $class . '">' . $name . '</td><td class="left' . $class . '" style="width: 50px;">' . date( 'Y-m-j', $row['received'] ) . '</td><td class="right' . $class . '" style="width: 75px;">' . $amount . '</td></tr>';
 61+
 62+ $alt = !$alt;
 63+ }
 64+
 65+ $output .= '</table>';
 66+
 67+ header( 'Cache-Control: max-age=300,s-maxage=300' );
 68+ $wgOut->addWikiText( '{{Template:Donate-header/' . $language . '}}' );
 69+ $wgOut->addWikiText( '<skin>Tomas</skin>' );
 70+ $wgOut->addHTML( '<h1>Real-time donor comments from around the world</h1>' );
 71+ $wgOut->addWikiText( '<strong>{{Template:Contribution history introduction/' . $language . '}}</strong>' );
 72+ $wgOut->addHTML( $output );
 73+ $wgOut->addWikiText( '{{Template:Donate-footer/' . $language . '}}' );
 74+ }
 75+
 76+ function formatAmount( $row ) {
 77+ if ( $row['original_currency'] ) {
 78+ $currency = $row['original_currency'];
 79+ $amount = $row['original_amount'];
 80+ } else {
 81+ $currency = 'USD';
 82+ $amount = $row['converted_amount'];
 83+ }
 84+
 85+ if ( $currency == 'JPY' ) {
 86+ // No decimals for yen
 87+ $amount = intval( $amount );
 88+ }
 89+
 90+ return htmlspecialchars( "$currency $amount" );
 91+ }
9292 }
Index: trunk/extensions/ContributionReporting/ContributionTotal_body.php
@@ -1,43 +1,44 @@
22 <?php
33
44 class ContributionTotal extends SpecialPage {
5 - function ContributionTotal() {
6 - SpecialPage::SpecialPage('ContributionTotal');
7 - wfLoadExtensionMessages('ContributionTotal');
8 - }
9 -
10 - function execute( $par ) {
11 - global $wgRequest, $wgOut;
12 -
13 - $this->setHeaders();
14 -
15 - # Get request data from, e.g.
16 - $start = $wgRequest->getText('start');
17 - $action = $wgRequest->getText('action');
18 -
19 - $db = contributionReportingConnection();
 5+ function ContributionTotal() {
 6+ SpecialPage::SpecialPage( 'ContributionTotal' );
 7+ }
208
21 - $sql = 'SELECT SUM(converted_amount) AS ttl FROM public_reporting';
22 -
23 - if ($start) {
24 - $sql .= ' WHERE received >= ' . $db->addQuotes($start);
25 - }
26 -
27 - $res = $db->query($sql);
28 -
29 - $row = $res->fetchRow();
30 -
31 - # Output
32 - $output = $row['ttl'] ? $row['ttl'] : '0';
33 -
34 - header('Cache-Control: max-age=300,s-maxage=300');
35 - if ($action == 'raw') {
36 - $wgOut->disable();
37 - echo $output;
38 - }
39 - else {
40 - $wgOut->setRobotpolicy( 'noindex,nofollow' );
41 - $wgOut->addHTML( $output );
42 - }
43 - }
 9+ function execute( $par ) {
 10+ global $wgRequest, $wgOut;
 11+
 12+ wfLoadExtensionMessages( 'ContributionReporting' );
 13+
 14+ $this->setHeaders();
 15+
 16+ # Get request data from, e.g.
 17+ $start = $wgRequest->getText( 'start' );
 18+ $action = $wgRequest->getText( 'action' );
 19+
 20+ $db = contributionReportingConnection();
 21+
 22+ $sql = 'SELECT SUM(converted_amount) AS ttl FROM public_reporting';
 23+
 24+ if ( $start ) {
 25+ $sql .= ' WHERE received >= ' . $db->addQuotes( $start );
 26+ }
 27+
 28+ $res = $db->query( $sql );
 29+
 30+ $row = $res->fetchRow();
 31+
 32+ # Output
 33+ $output = $row['ttl'] ? $row['ttl'] : '0';
 34+
 35+ header( 'Cache-Control: max-age=300,s-maxage=300' );
 36+ if ( $action == 'raw' ) {
 37+ $wgOut->disable();
 38+ echo $output;
 39+ }
 40+ else {
 41+ $wgOut->setRobotpolicy( 'noindex,nofollow' );
 42+ $wgOut->addHTML( $output );
 43+ }
 44+ }
4445 }
Property changes on: trunk/extensions/ContributionReporting/ContributionTotal_body.php
___________________________________________________________________
Added: svn:keywords
4546 + Id
Index: trunk/extensions/ContributionReporting/ContributionReporting.alias.php
@@ -0,0 +1,15 @@
 2+<?php
 3+/**
 4+ * Aliases for ContributionReporting extension special pages
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$aliases = array();
 11+
 12+/** English */
 13+$aliases['en'] = array(
 14+ 'ContributionHistory' => array( 'ContributionHistory' ),
 15+ 'ContributionTotal' => array( 'ContributionTotal' ),
 16+);
Property changes on: trunk/extensions/ContributionReporting/ContributionReporting.alias.php
___________________________________________________________________
Added: svn:eol-style
117 + native
Added: svn:keywords
218 + Id
Index: trunk/extensions/ContributionReporting/ContributionReporting.i18n.php
@@ -0,0 +1,17 @@
 2+<?php
 3+/**
 4+ * Internationalisation for ContributionReporting extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English
 13+ * @author Trevor Parscal
 14+ */
 15+$messages['en'] = array(
 16+ 'contributiontotal' => 'Contribution total',
 17+ 'contributionhistory' => 'Contribution history',
 18+);
Property changes on: trunk/extensions/ContributionReporting/ContributionReporting.i18n.php
___________________________________________________________________
Added: svn:mergeinfo
Added: svn:eol-style
119 + native
Added: svn:keywords
220 + Id

Status & tagging log