r43007 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43006‎ | r43007 | r43008 >
Date:18:17, 1 November 2008
Author:brion
Status:old
Tags:
Comment:
Initial checkin of David Strauss's in-progress extension for donation reporting for the fundraiser
Modified paths:
  • /trunk/extensions/ContributionReporting (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionHistory.i18n.php (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionHistory_body.php (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionReporting.php (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionTotal.i18n.php (added) (history)
  • /trunk/extensions/ContributionReporting/ContributionTotal_body.php (added) (history)
  • /trunk/extensions/ContributionReporting/README (added) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/ContributionReporting.php
@@ -0,0 +1,52 @@
 2+<?php
 3+
 4+# 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')) {
 6+ echo <<<EOT
 7+To install my extension, put the following line in LocalSettings.php:
 8+require_once( "\$IP/extensions/ContributionReporting/ContributionReporting.php" );
 9+EOT;
 10+ exit( 1 );
 11+}
 12+
 13+$dir = dirname(__FILE__) . '/';
 14+
 15+$wgHooks['LanguageGetSpecialPageAliases'][] = 'contributionReportingLocalizedPageName'; # Add any aliases for the special page.
 16+
 17+$wgExtensionMessagesFiles['ContributionHistory'] = $dir . 'ContributionHistory.i18n.php';
 18+$wgAutoloadClasses['ContributionHistory'] = $dir . 'ContributionHistory_body.php'; # Tell MediaWiki to load the extension body.
 19+$wgSpecialPages['ContributionHistory'] = 'ContributionHistory'; # Let MediaWiki know about your new special page.
 20+
 21+$wgExtensionMessagesFiles['ContributionTotal'] = $dir . 'ContributionTotal.i18n.php';
 22+$wgAutoloadClasses['ContributionTotal'] = $dir . 'ContributionTotal_body.php'; # Tell MediaWiki to load the extension body.
 23+$wgSpecialPages['ContributionTotal'] = 'ContributionTotal'; # Let MediaWiki know about your new special page.
 24+
 25+function contributionReportingLocalizedPageName(&$specialPageArray, $code) {
 26+ # The localized title of the special page is among the messages of the extension:
 27+ wfLoadExtensionMessages('ContributionHistory');
 28+ $text = wfMsg('contributionhistory');
 29+
 30+ # Convert from title in text form to DBKey and put it into the alias array:
 31+ $title = Title::newFromText($text);
 32+ $specialPageArray['ContributionHistory'][] = $title->getDBKey();
 33+
 34+ wfLoadExtensionMessages('ContributionTotal');
 35+ $text = wfMsg('contributiontotal');
 36+ $title = Title::newFromText($text);
 37+ $specialPageArray['ContributionTotal'][] = $title->getDBKey();
 38+
 39+ return true;
 40+}
 41+
 42+function contributionReportingConnection() {
 43+ global $wgContributionReportingDBserver, $wgContributionReportingDBname;
 44+ global $wgContributionReportingDBuser, $wgContributionReportingDBpassword;
 45+
 46+ static $db;
 47+
 48+ if (!$db) {
 49+ $db = new DatabaseMysql($wgContributionReportingDBserver, $wgContributionReportingDBuser, $wgContributionReportingDBpassword, $wgContributionReportingDBname);
 50+ }
 51+
 52+ return $db;
 53+}
Property changes on: trunk/extensions/ContributionReporting/ContributionReporting.php
___________________________________________________________________
Added: svn:eol-style
154 + native
Index: trunk/extensions/ContributionReporting/ContributionHistory_body.php
@@ -0,0 +1,76 @@
 2+<?php
 3+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();
 24+
 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 = htmlspecialchars($row['original_currency'] . ' ' . $row['original_amount']);
 53+ if (!$row['original_currency'] || !$row['original_amount']) {
 54+ $amount = 'USD ' . htmlspecialchars($row['converted_amount']);
 55+ }
 56+
 57+ $class = '';
 58+ if ($alt) {
 59+ $class = ' alt';
 60+ }
 61+
 62+ $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>';
 63+
 64+ $alt = !$alt;
 65+ }
 66+
 67+ $output .= '</table>';
 68+
 69+ header('Cache-Control: max-age=300,s-maxage=300');
 70+ $wgOut->addWikiText('{{Template:Donate-header/' . $language . '}}');
 71+ $wgOut->addWikiText('<skin>Tomas</skin>');
 72+ $wgOut->addHTML('<h1>Real-time donor comments from around the world</h1>');
 73+ $wgOut->addWikiText('<strong>{{Template:Contribution history introduction/' . $language . '}}</strong>');
 74+ $wgOut->addHTML( $output );
 75+ $wgOut->addWikiText('{{Template:Donate-footer/' . $language . '}}');
 76+ }
 77+}
Property changes on: trunk/extensions/ContributionReporting/ContributionHistory_body.php
___________________________________________________________________
Added: svn:eol-style
178 + native
Index: trunk/extensions/ContributionReporting/ContributionHistory.i18n.php
@@ -0,0 +1,5 @@
 2+<?php
 3+$messages = array();
 4+$messages['en'] = array(
 5+ 'contributionhistory' => 'Contribution history',
 6+ );
Property changes on: trunk/extensions/ContributionReporting/ContributionHistory.i18n.php
___________________________________________________________________
Added: svn:eol-style
17 + native
Index: trunk/extensions/ContributionReporting/ContributionTotal_body.php
@@ -0,0 +1,43 @@
 2+<?php
 3+
 4+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();
 20+
 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+ }
 44+}
Property changes on: trunk/extensions/ContributionReporting/ContributionTotal_body.php
___________________________________________________________________
Added: svn:eol-style
145 + native
Index: trunk/extensions/ContributionReporting/ContributionTotal.i18n.php
@@ -0,0 +1,5 @@
 2+<?php
 3+$messages = array();
 4+$messages['en'] = array(
 5+ 'contributiontotal' => 'Contribution total',
 6+ );
Property changes on: trunk/extensions/ContributionReporting/ContributionTotal.i18n.php
___________________________________________________________________
Added: svn:eol-style
17 + native
Index: trunk/extensions/ContributionReporting/README
@@ -0,0 +1,2 @@
 2+This is currently hardcoded for Wikimedia's 2008-09 fundraiser event,
 3+pulling from our customized CiviCRM tables.
Property changes on: trunk/extensions/ContributionReporting/README
___________________________________________________________________
Added: svn:eol-style
14 + native

Status & tagging log