r109023 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109022‎ | r109023 | r109024 >
Date:10:12, 16 January 2012
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
initial skelton for CongressLookup extension
Modified paths:
  • /trunk/extensions/CongressLookup (added) (history)
  • /trunk/extensions/CongressLookup/CongressLookup.alias.php (added) (history)
  • /trunk/extensions/CongressLookup/CongressLookup.i18n.php (added) (history)
  • /trunk/extensions/CongressLookup/CongressLookup.php (added) (history)
  • /trunk/extensions/CongressLookup/SpecialCongressLookup.php (added) (history)
  • /trunk/extensions/CongressLookup/patches (added) (history)
  • /trunk/extensions/CongressLookup/patches/CongressLookup.sql (added) (history)

Diff [purge]

Index: trunk/extensions/CongressLookup/CongressLookup.i18n.php
@@ -0,0 +1,25 @@
 2+<?php
 3+/**
 4+ * Internationalisation for CongressLookup extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+/** English
 13+ * @author Ryan Kaldari
 14+ */
 15+$messages['en'] = array(
 16+ 'congresslookup-desc' => 'Look up congressional representatives based on a U.S. zip code',
 17+ 'congresslookup' => 'CongressLookup',
 18+);
 19+
 20+/** Message documentation (Message documentation)
 21+ * @author Ryan Kaldari
 22+ */
 23+$messages['qqq'] = array(
 24+ 'congresslookup-desc' => '{{desc}}',
 25+ 'congresslookup' => 'The name of the extension CongressLookup.',
 26+);
Property changes on: trunk/extensions/CongressLookup/CongressLookup.i18n.php
___________________________________________________________________
Added: svn:eol-style
127 + native
Index: trunk/extensions/CongressLookup/CongressLookup.php
@@ -0,0 +1,71 @@
 2+<?php
 3+/**
 4+ * MediaWiki CongressLookup extension
 5+ * http://www.mediawiki.org/wiki/Extension:CongressLookup
 6+ *
 7+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 8+ * of this software and associated documentation files (the "Software"), to deal
 9+ * in the Software without restriction, including without limitation the rights
 10+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11+ * copies of the Software, and to permit persons to whom the Software is
 12+ * furnished to do so, subject to the following conditions:
 13+ *
 14+ * The above copyright notice and this permission notice shall be included in
 15+ * all copies or substantial portions of the Software.
 16+ *
 17+ * This program is distributed WITHOUT ANY WARRANTY.
 18+ */
 19+
 20+/**
 21+ * @file
 22+ * @ingroup Extensions
 23+ * @author Ryan Kaldari
 24+ */
 25+
 26+# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
 27+if ( !defined( 'MEDIAWIKI' ) ) {
 28+ echo <<<EOT
 29+To install this extension, put the following line in LocalSettings.php:
 30+require_once( "\$IP/extensions/CongressLookup/CongressLookup.php" );
 31+EOT;
 32+ exit( 1 );
 33+}
 34+
 35+// Extension credits that will show up on Special:Version
 36+$wgExtensionCredits['specialpage'][] = array(
 37+ 'path' => __FILE__,
 38+ 'name' => 'CongressLookup',
 39+ 'version' => '1.0',
 40+ 'url' => 'https://www.mediawiki.org/wiki/Extension:CongressLookup',
 41+ 'author' => array( 'Ryan Kaldari' ),
 42+ 'descriptionmsg' => 'congresslookup-desc',
 43+);
 44+
 45+// Configurrable variable for caching time
 46+$wgCongressLookupMaxAge = 900; // 15 minutes
 47+
 48+$dir = dirname( __FILE__ ) . '/';
 49+
 50+$wgAutoloadClasses['SpecialCongressLookup'] = $dir . 'SpecialCongressLookup.php';
 51+$wgExtensionMessagesFiles['CongressLookup'] = $dir . 'CongressLookup.i18n.php';
 52+$wgExtensionMessagesFiles['CongressLookupAlias'] = $dir . 'CongressLookup.alias.php';
 53+$wgSpecialPages['CongressLookup'] = 'SpecialCongressLookup';
 54+
 55+$wgHooks['LoadExtensionSchemaUpdates'][] = 'congressLookupSchemaUpdate';
 56+
 57+/**
 58+ * LoadExtensionSchemaUpdates hook handler
 59+ * This function makes sure that the database schema is up to date.
 60+ * @param $updater DatabaseUpdater|null
 61+ * @return true
 62+ */
 63+function congressLookupSchemaUpdate( $updater = null ) {
 64+ if ( $updater === null ) {
 65+ global $wgExtNewTables;
 66+ $wgExtNewTables[] = array( 'cl_senate', dirname( __FILE__ ) . '/patches/CongressLookup.sql' );
 67+ } else {
 68+ $updater->addExtensionUpdate( array( 'addTable', 'cl_senate',
 69+ dirname( __FILE__ ) . '/patches/CongressLookup.sql', true ) );
 70+ }
 71+ return true;
 72+}
Property changes on: trunk/extensions/CongressLookup/CongressLookup.php
___________________________________________________________________
Added: svn:eol-style
173 + native
Index: trunk/extensions/CongressLookup/SpecialCongressLookup.php
@@ -0,0 +1,39 @@
 2+<?php
 3+if ( !defined( 'MEDIAWIKI' ) ) {
 4+ echo "CongressLookup extension\n";
 5+ exit( 1 );
 6+}
 7+
 8+/**
 9+ * This class creates a page which asks the user for their zip code. It then uses the zip code to
 10+ * look up information about the user's congressional representatives and presents that information
 11+ * to the user.
 12+ */
 13+class SpecialCongressLookup extends UnlistedSpecialPage {
 14+
 15+ protected $sharedMaxAge = 600; // Cache for 10 minutes on the server side
 16+ protected $maxAge = 600; // Cache for 10 minutes on the client side
 17+
 18+ public function __construct() {
 19+ // Register special page
 20+ parent::__construct( 'CongressLookup' );
 21+ }
 22+
 23+ /**
 24+ * Handle different types of page requests
 25+ */
 26+ public function execute( $sub ) {
 27+ global $wgRequest, $wgOut, $wgCongressLookupMaxAge;
 28+
 29+ // Pull in query string parameters
 30+ $zip = $wgRequest->getVal( 'zip' );
 31+
 32+ /* Setup */
 33+ $wgOut->setSquidMaxage( $wgCongressLookupMaxAge );
 34+ $this->setHeaders();
 35+
 36+ /* Display */
 37+ // TODO: Do some work here.
 38+ }
 39+
 40+}
Property changes on: trunk/extensions/CongressLookup/SpecialCongressLookup.php
___________________________________________________________________
Added: svn:eol-style
141 + native
Index: trunk/extensions/CongressLookup/patches/CongressLookup.sql
@@ -0,0 +1,39 @@
 2+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cl_senate (
 3+ `ss_id` int(10) unsigned NOT NULL,
 4+ `ss_bioguideid` varchar(32) NOT NULL,
 5+ `ss_gender` varchar(1) NOT NULL,
 6+ `ss_name` varchar(255) NOT NULL,
 7+ `ss_title` varchar(8) NOT NULL,
 8+ `ss_state` varchar(2) NOT NULL,
 9+ `ss_phone` varchar(32) NOT NULL,
 10+ `ss_fax` varchar(32) NOT NULL,
 11+ `ss_contactform` varchar(255) NOT NULL,
 12+ PRIMARY KEY (`ss_id`)
 13+) /*$wgDBTableOptions*/;
 14+CREATE INDEX /*i*/ss_state ON /*$wgDBprefix*/sopa_senate (ss_state);
 15+
 16+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cl_house (
 17+ `sh_id` int(10) unsigned NOT NULL,
 18+ `sh_bioguideid` varchar(32) NOT NULL,
 19+ `sh_gender` varchar(1) NOT NULL,
 20+ `sh_name` varchar(255) NOT NULL,
 21+ `sh_title` varchar(8) NOT NULL,
 22+ `sh_state` varchar(2) NOT NULL,
 23+ `sh_district` varchar(32) NOT NULL,
 24+ `sh_phone` varchar(32) NOT NULL,
 25+ `sh_fax` varchar(32) NOT NULL,
 26+ `sh_contactform` varchar(255) NOT NULL,
 27+ PRIMARY KEY (`sh_id`)
 28+) /*$wgDBTableOptions*/;
 29+
 30+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cl_zip3 (
 31+ `sz3_zip` int(3) unsigned DEFAULT NULL,
 32+ `sz3_state` varchar(2) DEFAULT NULL,
 33+ PRIMARY KEY (`sz3_zip`)
 34+) /*$wgDBTableOptions*/;
 35+
 36+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cl_zip5 (
 37+ `sz5_zip` int(5) unsigned NOT NULL,
 38+ `sz5_rep_id` int(10) unsigned DEFAULT NULL,
 39+ PRIMARY KEY (`sz5_zip`)
 40+) /*$wgDBTableOptions*/;
Index: trunk/extensions/CongressLookup/CongressLookup.alias.php
@@ -0,0 +1,14 @@
 2+<?php
 3+/**
 4+ * Aliases for Special:CongressLookup
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$specialPageAliases = array();
 11+
 12+/** English (English) */
 13+$specialPageAliases['en'] = array(
 14+ 'CongressLookup' => array( 'CongressLookup' ),
 15+);
Property changes on: trunk/extensions/CongressLookup/CongressLookup.alias.php
___________________________________________________________________
Added: svn:eol-style
116 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r109035Fixed mixed spaces/tabs from r109023 in CongressLookup.sqlreedy14:21, 16 January 2012
r109055follow-up to r109023 - sqlite support, and removing unnecessary MediaWiki checkkaldari19:45, 16 January 2012
r109068followup r109023, r109055...khorn22:24, 16 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   12:00, 16 January 2012

Mixed tabs and spaces in the sql file.

#Comment by 😂 (talk | contribs)   17:48, 16 January 2012
  • Should put the PRIMARY KEY on the column definition to support Sqlite.
  • Don't need the MEDIAWIKI check on SpecialCongressLookup.php since it's only a class.
#Comment by Khorn (WMF) (talk | contribs)   22:03, 16 January 2012

Got an error running this script, here:

CREATE INDEX /*i*/ss_state ON /*$wgDBprefix*/sopa_senate (ss_state);

The error:

Database returned error "1146: Table 'mediawiki.sopa_senate' doesn't exist (localhost)"
#Comment by Khorn (WMF) (talk | contribs)   22:31, 16 January 2012

resolved in r109068.

#Comment by Khorn (WMF) (talk | contribs)   22:19, 16 January 2012

And another error (can't have a null primary key), on:

 `sz3_zip` int(3) unsigned DEFAULT NULL PRIMARY KEY,
Database returned error "1067: Invalid default value for 'sz3_zip' (localhost)"
#Comment by Khorn (WMF) (talk | contribs)   22:21, 16 January 2012

Oops, actually that comment should go with r109055. Adding it over there.

Status & tagging log