tosfos has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/183775

Change subject: some bug fixes, documentation and whitespace fixes
......................................................................

some bug fixes, documentation and whitespace fixes

Change-Id: Iaa017464648fff1c94a454977bc61a1ed93dd2b3
---
M Cargo.hooks.php
M Cargo.php
M CargoFieldDescription.php
M CargoPageValuesAction.php
M CargoPopulateTableJob.php
M CargoQueryAPI.php
M CargoQueryDisplayer.php
M CargoRecreateDataAction.php
M CargoRecreateTablesJob.php
M CargoSQLQuery.php
M CargoUtils.php
M README
M drilldown/CargoAppliedFilter.php
13 files changed, 303 insertions(+), 137 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/75/183775/1

diff --git a/Cargo.hooks.php b/Cargo.hooks.php
index c28eb81..c220fb2 100644
--- a/Cargo.hooks.php
+++ b/Cargo.hooks.php
@@ -1,14 +1,22 @@
 <?php
+
 /**
  * CargoHooks class
  *
  * @author Yaron Koren
  * @ingroup Cargo
  */
-
 class CargoHooks {
 
-       static function setGlobalJSVariables( &$vars ) {
+       /**
+        * Add date-related messages to Global JS vars in user language
+        *
+        * @global int $wgCargoMapClusteringMinimum
+        * @param array $vars Global JS vars
+        * @param OutputPage $out
+        * @return boolean
+        */
+       static function setGlobalJSVariables( array &$vars, OutputPage $out ) {
                global $wgCargoMapClusteringMinimum;
 
                $vars['wgCargoMapClusteringMinimum'] = 
$wgCargoMapClusteringMinimum;
@@ -18,13 +26,35 @@
                // Built-in arrays already exist for month names, but those
                // unfortunately are based on the language of the wiki, not
                // the language of the user.
-               $vars['wgCargoMonthNames'] = array( wfMessage( 'january' 
)->text(), wfMessage( 'february' )->text(), wfMessage( 'march' )->text(), 
wfMessage( 'april' )->text(), wfMessage( 'may-long' )->text(), wfMessage( 
'june' )->text(), wfMessage( 'july' )->text(), wfMessage( 'august' )->text(), 
wfMessage( 'september' )->text(), wfMessage( 'october' )->text(), wfMessage( 
'november' )->text(), wfMessage( 'december' )->text() );
-               $vars['wgCargoMonthNamesShort'] = array( wfMessage( 'jan' 
)->text(), wfMessage( 'feb' )->text(), wfMessage( 'mar' )->text(), wfMessage( 
'apr' )->text(), wfMessage( 'may' )->text(), wfMessage( 'jun' )->text(), 
wfMessage( 'jul' )->text(), wfMessage( 'aug' )->text(), wfMessage( 'sep' 
)->text(), wfMessage( 'oct' )->text(), wfMessage( 'nov' )->text(), wfMessage( 
'dec' )->text() );
-               $vars['wgCargoWeekDays'] = array( wfMessage( 'sunday' 
)->text(), wfMessage( 'monday' )->text(), wfMessage( 'tuesday' )->text(), 
wfMessage( 'wednesday' )->text(), wfMessage( 'thursday' )->text(), wfMessage( 
'friday' )->text(), wfMessage( 'saturday' )->text() );
-               $vars['wgCargoWeekDaysShort'] = array( wfMessage( 'sun' 
)->text(), wfMessage( 'mon' )->text(), wfMessage( 'tue' )->text(), wfMessage( 
'wed' )->text(), wfMessage( 'thu' )->text(), wfMessage( 'fri' )->text(), 
wfMessage( 'sat' )->text() );
+               $monthNames = array( 'january', 'february', 'march', 'april', 
'may', 'june', 'july', 'august',
+                       'september', 'october', 'november', 'december' );
+               $vars['wgCargoMonthNames'] = array();
+               foreach ( $monthNames as $monthName ) {
+                       $vars['wgCargoMonthNames'][] = $out->msg( $monthName 
)->text();
+               }
+
+               $weekDays = array( 'sunday', 'monday', 'tuesday', 'wednesday', 
'thursday', 'friday', 'saturday' );
+               $vars['wgCargoWeekDays'] = array();
+               foreach ( $weekDays as $weekDay ) {
+                       $vars['wgCargoWeekDays'][] = $out->msg( $weekDay 
)->text();
+               }
+
+               $weekDaysShort = array( 'sun', 'mon', 'tue', 'wed', 'thu', 
'fri', 'sat' );
+               $vars['wgCargoWeekDaysShort'] = array();
+               foreach ( $weekDaysShort as $weekDayShort ) {
+                       $vars['wgCargoWeekDaysShort'][] = $out->msg( 
$weekDayShort )->text();
+               }
+
                return true;
        }
 
+       /**
+        * Add the "purge cache" tab to actions
+        *
+        * @param SkinTemplate $skinTemplate
+        * @param array $links
+        * @return boolean
+        */
        public static function addPurgeCacheTab( SkinTemplate &$skinTemplate, 
array &$links ) {
                // Only add this tab if Semantic MediaWiki (which has its
                // identical "refresh" tab) is not installed.
@@ -44,6 +74,9 @@
        }
 
        /**
+        * Delete a page
+        *
+        * @param int $pageID
         * @TODO - move this to a different class, like CargoUtils?
         */
        public static function deletePageFromSystem( $pageID ) {
@@ -85,8 +118,21 @@
         *
         * We use that hook, instead of 'PageContentSave', because we need
         * the page ID to have been set already for newly-created pages.
+        *
+        * @global Parser $wgParser
+        * @param WikiPage $article
+        * @param User $user Unused
+        * @param Content $content
+        * @param string $summary Unused
+        * @param boolean $isMinor Unused
+        * @param null $isWatch Unused
+        * @param null $section Unused
+        * @param int $flags Unused
+        * @param Status $status Unused
+        * @return boolean
         */
-       public static function onPageContentSaveComplete( $article, $user, 
$content, $summary, $isMinor, $isWatch, $section, $flags, $status ) {
+       public static function onPageContentSaveComplete( $article, $user, 
$content, $summary, $isMinor,
+               $isWatch, $section, $flags, $status ) {
                // First, delete the existing data.
                $pageID = $article->getID();
                self::deletePageFromSystem( $pageID );
@@ -141,7 +187,18 @@
                return true;
        }
 
-       public static function onTitleMoveComplete( Title &$title, Title 
&$newtitle, User &$user, $oldid, $newid, $reason ) {
+       /**
+        *
+        * @param Title $title Unused
+        * @param Title $newtitle
+        * @param User $user Unused
+        * @param int $oldid
+        * @param int $newid Unused
+        * @param string $reason Unused
+        * @return boolean
+        */
+       public static function onTitleMoveComplete( Title &$title, Title 
&$newtitle, User &$user, $oldid,
+               $newid, $reason ) {
                // For each main data table to which this page belongs, change
                // the page name.
                $newPageName = $newtitle->getPrefixedText();
@@ -162,7 +219,8 @@
        /**
         * Deletes all Cargo data about a page, if the page has been deleted.
         */
-       public static function onArticleDeleteComplete( &$article, User &$user, 
$reason, $id, $content, $logEntry ) {
+       public static function onArticleDeleteComplete( &$article, User &$user, 
$reason, $id, $content,
+               $logEntry ) {
                self::deletePageFromSystem( $id );
                return true;
        }
@@ -175,18 +233,24 @@
                if ( $updater === null ) {
                        global $wgExtNewTables, $wgDBtype;
                        //if ( $wgDBtype == 'mysql' ) {
-                               $wgExtNewTables[] = array( 'cargo_tables', 
"$dir/Cargo.sql" );
-                               $wgExtNewTables[] = array( 'cargo_pages', 
"$dir/Cargo.sql" );
+                       $wgExtNewTables[] = array( 'cargo_tables', 
"$dir/Cargo.sql" );
+                       $wgExtNewTables[] = array( 'cargo_pages', 
"$dir/Cargo.sql" );
                        //}
                } else {
                        //if ( $updater->getDB()->getType() == 'mysql' ) {
-                               $updater->addExtensionUpdate( array( 
'addTable', 'cargo_tables', "$dir/Cargo.sql", true ) );
-                               $updater->addExtensionUpdate( array( 
'addTable', 'cargo_pages', "$dir/Cargo.sql", true ) );
+                       $updater->addExtensionUpdate( array( 'addTable', 
'cargo_tables', "$dir/Cargo.sql", true ) );
+                       $updater->addExtensionUpdate( array( 'addTable', 
'cargo_pages', "$dir/Cargo.sql", true ) );
                        //}
                }
                return true;
        }
 
+       /**
+        * Called by a hook in the Admin Links extension.
+        *
+        * @param ALTree $adminLinksTree
+        * @return boolean
+        */
        public static function addToAdminLinks( &$adminLinksTree ) {
                $browseSearchSection = $adminLinksTree->getSection( wfMessage( 
'adminlinks_browsesearch' )->text() );
                $cargoRow = new ALRow( 'cargo' );
diff --git a/Cargo.php b/Cargo.php
index 4c93bf7..ed7ffee 100644
--- a/Cargo.php
+++ b/Cargo.php
@@ -8,11 +8,11 @@
 
 if ( !defined( 'MEDIAWIKI' ) ) die();
 
-define( 'CARGO_VERSION', '0.5' );
+define( 'CARGO_VERSION', '0.5.1' );
 
 $wgExtensionCredits['parserhook'][] = array(
        'path' => __FILE__,
-       'name'  => 'Cargo',
+       'name' => 'Cargo',
        'version' => CARGO_VERSION,
        'author' => 'Yaron Koren',
        'url' => '',
diff --git a/CargoFieldDescription.php b/CargoFieldDescription.php
index 3a40363..1ededed 100644
--- a/CargoFieldDescription.php
+++ b/CargoFieldDescription.php
@@ -18,14 +18,17 @@
 
        /**
         * Initializes from a string within the #cargo_declare function.
+        *
+        * @param string $fieldDescriptionStr
+        * @return \CargoFieldDescription
         */
        static function newFromString( $fieldDescriptionStr ) {
                $fieldDescription = new CargoFieldDescription();
 
-               if ( strpos( $fieldDescriptionStr, 'List') === 0 ) {
+               if ( strpos( $fieldDescriptionStr, 'List' ) === 0 ) {
                        $matches = array();
-                       $foundMatch = preg_match( '/List \((.*)\) of (.*)/', 
$fieldDescriptionStr, $matches);
-                       if (! $foundMatch) {
+                       $foundMatch = preg_match( '/List \((.*)\) of (.*)/', 
$fieldDescriptionStr, $matches );
+                       if ( !$foundMatch ) {
                                // Return a true error message here?
                                return null;
                        }
@@ -36,7 +39,7 @@
 
                // There may be additional parameters, in/ parentheses.
                $matches = array();
-               $foundMatch2 = preg_match( '/(.*)\s*\((.*)\)/', 
$fieldDescriptionStr, $matches);
+               $foundMatch2 = preg_match( '/(.*)\s*\((.*)\)/', 
$fieldDescriptionStr, $matches );
                if ( $foundMatch2 ) {
                        $fieldDescriptionStr = trim( $matches[1] );
                        $extraParamsString = $matches[2];
@@ -66,6 +69,11 @@
                return $fieldDescription;
        }
 
+       /**
+        *
+        * @param array $descriptionData
+        * @return \CargoFieldDescription
+        */
        static function newFromDBArray( $descriptionData ) {
                $fieldDescription = new CargoFieldDescription();
                foreach ( $descriptionData as $param => $value ) {
@@ -86,6 +94,10 @@
                return $fieldDescription;
        }
 
+       /**
+        *
+        * @return array
+        */
        function toDBArray() {
                $descriptionData = array();
                $descriptionData['type'] = $this->mType;
diff --git a/CargoPageValuesAction.php b/CargoPageValuesAction.php
index ea4b2b8..c899519 100644
--- a/CargoPageValuesAction.php
+++ b/CargoPageValuesAction.php
@@ -11,7 +11,7 @@
         * Return the name of the action this object responds to
         * @return String lowercase
         */
-       public function getName(){
+       public function getName() {
                return 'pagevalues';
        }
 
@@ -32,9 +32,16 @@
                return true;
        }
 
-       public static function addLink( $skinTemplate, &$toolbox) {
+       /**
+        * Add the "Page values" link to the toolbox
+        *
+        * @param BaseTemplate $skinTemplate
+        * @param array $toolbox
+        * @return boolean
+        */
+       public static function addLink( BaseTemplate $skinTemplate, array 
&$toolbox ) {
                $toolbox['cargo-pagevalues'] = array(
-                       'text' => $skinTemplate->getSkin()->getContext()->msg( 
'pagevalues' )->text(),
+                       'msg' => 'pagevalues',
                        'href' => 
$skinTemplate->getSkin()->getTitle()->getLocalUrl( array( 'action' => 
'pagevalues' ) ),
                        'id' => 't-cargopagevalueslink',
                        'rel' => 'cargo-pagevalues'
diff --git a/CargoPopulateTableJob.php b/CargoPopulateTableJob.php
index ff6fc1b..5c813cd 100644
--- a/CargoPopulateTableJob.php
+++ b/CargoPopulateTableJob.php
@@ -8,8 +8,14 @@
  */
 
 class CargoPopulateTableJob extends Job {
-       function __construct( $title, $params = '', $id = 0 ) {
-               parent::__construct( 'cargoPopulateTable', $title, $params, $id 
);
+
+       /**
+        *
+        * @param Title $title
+        * @param array|bool $params
+        */
+       function __construct( $title, $params = false ) {
+               parent::__construct( 'cargoPopulateTable', $title, $params );
        }
 
        /**
diff --git a/CargoQueryAPI.php b/CargoQueryAPI.php
index 04518c3..fe02f55 100644
--- a/CargoQueryAPI.php
+++ b/CargoQueryAPI.php
@@ -26,7 +26,8 @@
                        $this->dieUsage( 'The tables must be specified', 
'param_substr' );
                }
 
-               $sqlQuery = CargoSQLQuery::newFromValues( $tablesStr, 
$fieldsStr, $whereStr, $joinOnStr, $groupByStr, $orderByStr, $limitStr );
+               $sqlQuery = CargoSQLQuery::newFromValues( $tablesStr, 
$fieldsStr, $whereStr, $joinOnStr,
+                               $groupByStr, $orderByStr, $limitStr );
                try {
                        $queryResults = $sqlQuery->run();
                } catch ( Exception $e ) {
@@ -46,8 +47,8 @@
        }
 
        protected function getAllowedParams() {
-               return array (
-                       'limit' => array (
+               return array(
+                       'limit' => array(
                                ApiBase::PARAM_TYPE => 'limit',
                                ApiBase::PARAM_DFLT => 50,
                                ApiBase::PARAM_MIN => 1,
@@ -64,7 +65,7 @@
        }
 
        protected function getParamDescription() {
-               return array (
+               return array(
                        'tables' => 'The Cargo database table or tables on 
which to search',
                        'fields' => 'The table field(s) to retrieve',
                        'where' => 'The conditions for the query, corresponding 
to an SQL WHERE clause',
@@ -76,12 +77,14 @@
        }
 
        protected function getDescription() {
-               return 'An SQL-style query used for data tables, provided by 
the Cargo extension (http://www.mediawiki.org/Extension:Cargo)';
+               return 'An SQL-style query used for data tables, provided by 
the Cargo extension '
+                       . '(http://www.mediawiki.org/Extension:Cargo)';
        }
 
        protected function getExamples() {
-               return array (
-                       
'api.php?action=cargoquery&tables=Items&fields=_pageName=Item,Source,Date=Publication_date&where=Source+LIKE+\'%New%\'&order_by=Date&limit=100'
+               return array(
+                       
'api.php?action=cargoquery&tables=Items&fields=_pageName=Item,Source,Date=Publication_date'
+                       . '&where=Source+LIKE+\'%New%\'&order_by=Date&limit=100'
                );
        }
 
diff --git a/CargoQueryDisplayer.php b/CargoQueryDisplayer.php
index e7f20e0..d068272 100644
--- a/CargoQueryDisplayer.php
+++ b/CargoQueryDisplayer.php
@@ -96,9 +96,13 @@
                                        // this, using array_map().
                                        $delimiter = 
$fieldDescription->mDelimiter;
                                        $fieldValues = explode( $delimiter, 
$value );
-                                       foreach( $fieldValues as $i => 
$fieldValue ) {
-                                               if ( trim( $fieldValue ) == '' 
) continue;
-                                               if ( $i > 0 ) $text .= 
"$delimiter ";
+                                       foreach ( $fieldValues as $i => 
$fieldValue ) {
+                                               if ( trim( $fieldValue ) == '' 
) {
+                                                       continue;
+                                               }
+                                               if ( $i > 0 ) {
+                                                       $text .= "$delimiter ";
+                                               }
                                                $text .= 
self::formatFieldValue( $fieldValue, $fieldType, $fieldDescription, 
$this->mParser );
                                        }
                                } elseif ( $fieldType == 'Date' || $fieldType 
== 'Datetime' ) {
@@ -137,7 +141,8 @@
                        global $wgCargoDecimalMark, 
$wgCargoDigitGroupingCharacter;
                        // Can we assume that the decimal mark will be a '.' in 
the database?
                        $numDecimalPlaces = strlen( $value ) - strrpos( $value, 
'.' ) - 1;
-                       return number_format( $value, $numDecimalPlaces, 
$wgCargoDecimalMark, $wgCargoDigitGroupingCharacter );
+                       return number_format( $value, $numDecimalPlaces, 
$wgCargoDecimalMark,
+                               $wgCargoDigitGroupingCharacter );
                } elseif ( $type == 'Page' ) {
                        $title = Title::newFromText( $value );
                        return Linker::link( $title );
@@ -149,7 +154,8 @@
                        return Linker::makeThumbLinkObj( $title, wfLocalFile( 
$title ), $value, '' );
                } elseif ( $type == 'URL' ) {
                        if ( array_key_exists( 'link text', 
$fieldDescription->mOtherParams ) ) {
-                               return Html::element( 'a', array( 'href' => 
$value ), $fieldDescription->mOtherParams['link text'] );
+                               return Html::element( 'a', array( 'href' => 
$value ),
+                                               
$fieldDescription->mOtherParams['link text'] );
                        } else {
                                // Otherwise, do nothing.
                                return $value;
@@ -170,7 +176,7 @@
                if ( $datePrecision == CargoStore::YEAR_ONLY ) {
                        $seconds = strtotime( $dateValue );
                        // 'o' is better than 'Y' because it does not add
-                       // leading zeroes to years with less than four digits.
+                       // leading zeroes to years with fewer than four digits.
                        return date( 'o', $seconds );
                } else { // CargoStore::FULL_PRECISION
                        global $wgAmericanDates;
@@ -209,7 +215,8 @@
                if ( array_key_exists( 'intro', $this->mDisplayParams ) ) {
                        $text .= $this->mDisplayParams['intro'];
                }
-               $text .= $formatter->display( $queryResults, 
$formattedQueryResults, $this->mFieldDescriptions, $this->mDisplayParams );
+               $text .= $formatter->display( $queryResults, 
$formattedQueryResults, $this->mFieldDescriptions,
+                       $this->mDisplayParams );
                if ( array_key_exists( 'outro', $this->mDisplayParams ) ) {
                        $text .= $this->mDisplayParams['outro'];
                }
@@ -248,7 +255,8 @@
                        $queryStringParams[$key] = $value;
                }
 
-               return Html::rawElement( 'p', null, Linker::link( $vd, 
wfMessage( 'moredotdotdot' )->parse(), array(), $queryStringParams ) );
+               return Html::rawElement( 'p', null,
+                               Linker::link( $vd, wfMessage( 'moredotdotdot' 
)->parse(), array(), $queryStringParams ) );
        }
 
 }
diff --git a/CargoRecreateDataAction.php b/CargoRecreateDataAction.php
index 57f1de1..bc08cb7 100644
--- a/CargoRecreateDataAction.php
+++ b/CargoRecreateDataAction.php
@@ -11,7 +11,7 @@
         * Return the name of the action this object responds to
         * @return String lowercase
         */
-       public function getName(){
+       public function getName() {
                return 'recreatedata';
        }
 
@@ -19,6 +19,10 @@
         * The main action entry point. Do all output for display and send it 
to the context
         * output.
         * $this->getOutput(), etc.
+        *
+        * @param string $action
+        * @param Article $article
+        * @return boolean
         */
        public static function show( $action, Article $article ) {
                $title = $article->getTitle();
@@ -42,16 +46,18 @@
        }
 
        /**
-        * Adds an "action" (i.e., a tab) to edit the current article with
-        * a form
+        * Adds an "action" (i.e., a tab) to recreate the current article's data
+        *
+        * @param SkinTemplate $obj
+        * @param array $content_actions
+        * @return boolean
         */
-       static function displayTab( $obj, &$content_actions ) {
-               global $wgRequest;
-
+       static function displayTab( SkinTemplate $obj, array &$content_actions 
) {
                $title = $obj->getTitle();
-               if ( !$title ) {
+               if ( !$title || $title->getNamespace() !== NS_TEMPLATE || 
!$title->userCan( 'recreatecargodata' ) ) {
                        return true;
                }
+               $request = $obj->getRequest();
 
                // Make sure that this is a template page, that it either
                // has (or had) a #cargo_declare call or has a #cargo_attach
@@ -61,40 +67,39 @@
                        return true;
                }
 
-               if ( !$title->userCan( 'recreatecargodata' ) ) {
-                       return true;
-               }
-
                // Check if table already exists, and set tab accordingly.
                if ( CargoUtils::tableExists( $tableName ) ) {
-                       $recreateDataTabText = wfMessage( 'recreatedata' 
)->parse();
+                       $recreateDataTabMsg = 'recreatedata';
                } else {
-                       $recreateDataTabText = wfMessage( 
'cargo-createdatatable' )->parse();
+                       $recreateDataTabMsg = 'cargo-createdatatable';
                }
 
                $recreateDataTab = array(
-                       'class' => ( $wgRequest->getVal( 'action' ) == 
'recreatdata' ) ? 'selected' : '',
-                       'text' => $recreateDataTabText,
+                       'class' => ( $request->getVal( 'action' ) == 
'recreatedata' ) ? 'selected' : '',
+                       'text' => $obj->msg( $recreateDataTabMsg )->parse(),
                        'href' => $title->getLocalURL( 'action=recreatedata' )
                );
 
                $content_actions['recreatedata'] = $recreateDataTab;
 
-               return true; // always return true, in order not to stop MW's 
hook processing!
+               return true;
        }
 
        /**
         * Like displayTab(), but called with a different hook - this one is
         * called for the 'Vector' skin, and others.
+        *
+        * @param SkinTemplate $obj
+        * @param array $links
+        * @return boolean
         */
-       static function displayTab2( $obj, &$links ) {
+       static function displayTab2( SkinTemplate $obj, array &$links ) {
                // The old '$content_actions' array is thankfully just a
                // sub-array of this one.
                $views_links = $links['actions'];
                self::displayTab( $obj, $views_links );
                $links['actions'] = $views_links;
                return true;
-
        }
 
 }
diff --git a/CargoRecreateTablesJob.php b/CargoRecreateTablesJob.php
index 760f877..6c82223 100644
--- a/CargoRecreateTablesJob.php
+++ b/CargoRecreateTablesJob.php
@@ -8,8 +8,14 @@
  */
 
 class CargoRecreateTablesJob extends Job {
-       function __construct( $title, $params = '', $id = 0 ) {
-               parent::__construct( 'cargoRecreateTables', $title, $params, 
$id );
+
+       /**
+        *
+        * @param Title $title
+        * @param array|bool $params
+        */
+       function __construct( $title, $params = false ) {
+               parent::__construct( 'cargoRecreateTables', $title, $params );
        }
 
        /**
@@ -27,15 +33,21 @@
                }
 
                $templatePageID = $this->title->getArticleID();
-               self::recreateDBTablesForTemplate( $templatePageID );
+               $success = self::recreateDBTablesForTemplate( $templatePageID );
+               wfProfileOut( __METHOD__ );
+               return $success;
        }
-
 
        /**
         * Drop, and then create again, the database table(s) holding the
         * data for this template.
         * Why "tables"? Because every field that holds a list of values gets
         * its own helper table.
+        *
+        * @global string $wgDBtype
+        * @param int $templatePageID
+        * @return boolean
+        * @throws MWException
         */
        public static function recreateDBTablesForTemplate( $templatePageID ) {
                global $wgDBtype;
@@ -57,7 +69,8 @@
                        try {
                                $cdb->dropTable( $curTable );
                        } catch ( Exception $e ) {
-                               throw new MWException( "Caught exception ($e) 
while trying to drop Cargo table. Please make sure that your database user 
account has the DROP permission." );
+                               throw new MWException( "Caught exception ($e) 
while trying to drop Cargo table. "
+                               . "Please make sure that your database user 
account has the DROP permission." );
                        }
                        $dbr->delete( 'cargo_pages', array( 'table_name' => 
$curTable ) );
                }
@@ -121,7 +134,8 @@
                $cdb->query( $createIndexSQL2 );
                $createIndexSQL3 = "CREATE INDEX page_title_$tableName ON " . 
$cdb->tableName( $tableName ) . " (_pageTitle)";
                $cdb->query( $createIndexSQL3 );
-               $createIndexSQL4 = "CREATE INDEX page_namespace_$tableName ON " 
. $cdb->tableName( $tableName ) . " (_pageNamespace)";
+               $createIndexSQL4 = "CREATE INDEX page_namespace_$tableName ON " 
. $cdb->tableName( $tableName )
+                       . " (_pageNamespace)";
                $cdb->query( $createIndexSQL4 );
                $createIndexSQL5 = "CREATE UNIQUE INDEX id_$tableName ON " . 
$cdb->tableName( $tableName ) . " (_ID)";
                $cdb->query( $createIndexSQL5 );
@@ -158,7 +172,9 @@
                }
 
                // Finally, store all the info in the cargo_tables table.
-               $dbr->insert( 'cargo_tables', array( 'template_id' => 
$templatePageID, 'main_table' => $tableName, 'field_tables' => serialize( 
$fieldTableNames ), 'table_schema' => $tableSchemaString ) );
+               $dbr->insert( 'cargo_tables',
+                       array( 'template_id' => $templatePageID, 'main_table' 
=> $tableName,
+                       'field_tables' => serialize( $fieldTableNames ), 
'table_schema' => $tableSchemaString ) );
                return true;
        }
 
@@ -230,7 +246,6 @@
                                        // Should really be 'REAL', with
                                        // accompanying handling.
                                        return 'TEXT';
-
                        }
                } else { // 'Text', 'Page', etc.
                        if ( $size == null ) {
diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 027c5b7..96f4b46 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -29,7 +29,8 @@
         * This is newFromValues() instead of __construct() so that an
         * object can be created without any values.
         */
-       public static function newFromValues( $tablesStr, $fieldsStr, 
$whereStr, $joinOnStr, $groupByStr, $orderByStr, $limitStr ) {
+       public static function newFromValues( $tablesStr, $fieldsStr, 
$whereStr, $joinOnStr, $groupByStr,
+               $orderByStr, $limitStr ) {
                global $wgCargoDefaultQueryLimit, $wgCargoMaxQueryLimit;
 
                $sqlQuery = new CargoSQLQuery();
@@ -65,7 +66,8 @@
         * Lightweight constructor that just sets the fields, with (essentially)
         * no processing.
         */
-       public static function newFromValues2( $tablesStr, $fieldsStr, 
$whereStr, $joinOnStr, $groupByStr, $orderByStr, $limitStr ) {
+       public static function newFromValues2( $tablesStr, $fieldsStr, 
$whereStr, $joinOnStr, $groupByStr,
+               $orderByStr, $limitStr ) {
                $sqlQuery = new CargoSQLQuery();
                $sqlQuery->mTablesStr = $tablesStr;
                $sqlQuery->mTableNames = explode( ',', $tablesStr );
@@ -83,7 +85,7 @@
         * Gets an array of field names and their aliases from the passed-in
         * SQL fragment.
         */
-       function setAliasedFieldNames( ) {
+       function setAliasedFieldNames() {
                $this->mAliasedFieldNames = array();
                $fieldNames = CargoUtils::smartSplit( ',', $this->mFieldsStr );
                // Default is "_pageName".
@@ -95,7 +97,8 @@
                // and require "GROUP BY" instead.
                foreach ( $fieldNames as $i => $fieldName ) {
                        if ( strtolower( substr( $fieldName, 0, 9 ) ) == 
'distinct ' ) {
-                               throw new MWException( "Error: The DISTINCT 
keyword is not allowed by Cargo; please use \"group by=\" instead." );
+                               throw new MWException( "Error: The DISTINCT 
keyword is not allowed by Cargo; "
+                               . "please use \"group by=\" instead." );
                        }
                }
 
@@ -199,7 +202,7 @@
                $matchedTables = array( $firstTableInJoins );
                do {
                        $previousNumUnmatchedTables = $numUnmatchedTables;
-                       foreach( $this->mCargoJoinConds as $joinCond ) {
+                       foreach ( $this->mCargoJoinConds as $joinCond ) {
                                $table1 = $joinCond['table1'];
                                $table2 = $joinCond['table2'];
                                if ( !in_array( $table1, $this->mTableNames ) ) 
{
@@ -245,9 +248,9 @@
                        $this->mJoinConds[$table2] = array(
                                $cargoJoinCond['joinType'],
                                'cargo__' . $cargoJoinCond['table1'] . '.' .
-                                       $cargoJoinCond['field1'] . '=' .
-                                       'cargo__' . $cargoJoinCond['table2'] .
-                                       '.' . $cargoJoinCond['field2']
+                               $cargoJoinCond['field1'] . '=' .
+                               'cargo__' . $cargoJoinCond['table2'] .
+                               '.' . $cargoJoinCond['field2']
                        );
                }
        }
@@ -297,7 +300,8 @@
                                        $description->mType = 'Integer';
                                } elseif ( in_array( $probableFunction, array( 
'concat', 'lower', 'lcase', 'upper', 'ucase' ) ) ) {
                                        // Do nothing.
-                               } elseif ( in_array( $probableFunction, array( 
'date', 'date_format', 'date_add', 'date_sub', 'date_diff' ) ) ) {
+                               } elseif ( in_array( $probableFunction,
+                                               array( 'date', 'date_format', 
'date_add', 'date_sub', 'date_diff' ) ) ) {
                                        $description->mType = 'Date';
                                }
                        } else {
@@ -321,7 +325,8 @@
                                                        }
                                                }
                                        }
-                               } elseif ( strlen( $fieldName ) > 6 && strpos( 
$fieldName, '__full', strlen( $fieldName ) - 6 ) !== false ) {
+                               } elseif ( strlen( $fieldName ) > 6 &&
+                                       strpos( $fieldName, '__full', strlen( 
$fieldName ) - 6 ) !== false ) {
                                        $fieldName = substr( $fieldName, 0, 
strlen( $fieldName ) - 6 );
                                }
                                if ( $tableName != null ) {
@@ -434,19 +439,19 @@
                        $tableName = $virtualField['tableName'];
 
                        $likePattern1 = "/\b$tableName\.$fieldName(\s*HOLDS 
LIKE\s*)/";
-                       $foundLikeMatch1 = preg_match( $likePattern1, 
$this->mWhereStr, $matches);
+                       $foundLikeMatch1 = preg_match( $likePattern1, 
$this->mWhereStr, $matches );
                        $foundLikeMatch2 = $foundMatch1 = $foundMatch2 = false;
                        if ( !$foundLikeMatch1 ) {
                                $likePattern2 = "/\b$fieldName(\s*HOLDS 
LIKE\s*)/";
-                               $foundLikeMatch2 = preg_match( $likePattern2, 
$this->mWhereStr, $matches);
+                               $foundLikeMatch2 = preg_match( $likePattern2, 
$this->mWhereStr, $matches );
                        }
 
                        if ( !$foundLikeMatch1 && !$foundLikeMatch2 ) {
                                $pattern1 = 
"/\b$tableName\.$fieldName(\s*HOLDS\s*)?/";
-                               $foundMatch1 = preg_match( $pattern1, 
$this->mWhereStr, $matches);
+                               $foundMatch1 = preg_match( $pattern1, 
$this->mWhereStr, $matches );
                                if ( !$foundMatch1 ) {
                                        $pattern2 = 
"/\b$fieldName(\s*HOLDS\s*)?/";
-                                       $foundMatch2 = preg_match( $pattern2, 
$this->mWhereStr, $matches);
+                                       $foundMatch2 = preg_match( $pattern2, 
$this->mWhereStr, $matches );
                                }
                        }
 
@@ -465,9 +470,11 @@
                                        'field2' => '_rowID'
                                );
                                if ( $foundLikeMatch1 ) {
-                                       $this->mWhereStr = preg_replace( 
$likePattern1, "$fieldTableName._value LIKE ", $this->mWhereStr );
+                                       $this->mWhereStr = preg_replace( 
$likePattern1, "$fieldTableName._value LIKE ",
+                                               $this->mWhereStr );
                                } elseif ( $foundLikeMatch2 ) {
-                                       $this->mWhereStr = preg_replace( 
$likePattern2, "$fieldTableName._value LIKE ", $this->mWhereStr );
+                                       $this->mWhereStr = preg_replace( 
$likePattern2, "$fieldTableName._value LIKE ",
+                                               $this->mWhereStr );
                                } elseif ( $foundMatch1 ) {
                                        $this->mWhereStr = preg_replace( 
$pattern1, "$fieldTableName._value=", $this->mWhereStr );
                                } elseif ( $foundMatch2 ) {
@@ -481,7 +488,7 @@
                foreach ( $this->mCargoJoinConds as $i => $joinCond ) {
                        // We only handle 'HOLDS' here - no joining on
                        // 'HOLDS LIKE'.
-                       if ( ! array_key_exists( 'holds', $joinCond ) ) {
+                       if ( !array_key_exists( 'holds', $joinCond ) ) {
                                continue;
                        }
 
@@ -526,12 +533,12 @@
                        $fieldName = $virtualField['fieldName'];
                        $tableName = $virtualField['tableName'];
                        $pattern1 = "/\b$tableName\.$fieldName\b/";
-                       $foundMatch1 = preg_match( $pattern1, 
$this->mGroupByStr, $matches);
+                       $foundMatch1 = preg_match( $pattern1, 
$this->mGroupByStr, $matches );
                        $pattern2 = "/\b$fieldName\b/";
                        $foundMatch2 = false;
 
                        if ( !$foundMatch1 ) {
-                               $foundMatch2 = preg_match( $pattern2, 
$this->mGroupByStr, $matches);
+                               $foundMatch2 = preg_match( $pattern2, 
$this->mGroupByStr, $matches );
                        }
                        if ( $foundMatch1 || $foundMatch2 ) {
                                $fieldTableName = $tableName . '__' . 
$fieldName;
@@ -598,12 +605,12 @@
                        $fieldName = $virtualField['fieldName'];
                        $tableName = $virtualField['tableName'];
                        $pattern1 = "/\b$tableName\.$fieldName\b/";
-                       $foundMatch1 = preg_match( $pattern1, 
$this->mOrderByStr, $matches);
+                       $foundMatch1 = preg_match( $pattern1, 
$this->mOrderByStr, $matches );
                        $pattern2 = "/\b$fieldName\b/";
                        $foundMatch2 = false;
 
                        if ( !$foundMatch1 ) {
-                               $foundMatch2 = preg_match( $pattern2, 
$this->mOrderByStr, $matches);
+                               $foundMatch2 = preg_match( $pattern2, 
$this->mOrderByStr, $matches );
                        }
                        if ( $foundMatch1 || $foundMatch2 ) {
                                $fieldTableName = $tableName . '__' . 
$fieldName;
@@ -693,29 +700,33 @@
                        $fieldName = $coordinateField['fieldName'];
                        $tableName = $coordinateField['tableName'];
                        $pattern1 = 
"/\b$tableName\.$fieldName(\s*NEAR\s*)\(([^)]*)\)/";
-                       $foundMatch1 = preg_match( $pattern1, $this->mWhereStr, 
$matches);
+                       $foundMatch1 = preg_match( $pattern1, $this->mWhereStr, 
$matches );
                        if ( !$foundMatch1 ) {
                                $pattern2 = 
"/\b$fieldName(\s*NEAR\s*)\(([^)]*)\)/";
-                               $foundMatch2 = preg_match( $pattern2, 
$this->mWhereStr, $matches);
+                               $foundMatch2 = preg_match( $pattern2, 
$this->mWhereStr, $matches );
                        }
                        if ( $foundMatch1 || $foundMatch2 ) {
                                // If no "NEAR", throw an error.
                                if ( count( $matches ) != 3 ) {
-                                       throw new MWException( "Error: operator 
for the virtual coordinates field '$tableName.$fieldName' must be 'NEAR'." );
+                                       throw new MWException( "Error: operator 
for the virtual coordinates field "
+                                       . "'$tableName.$fieldName' must be 
'NEAR'." );
                                }
                                $coordinatesAndDistance = explode( ',', 
$matches[2] );
                                if ( count( $coordinatesAndDistance ) != 3 ) {
-                                       throw new MWException( "Error: value 
for the 'NEAR' operator must be of the form \"(latitude, longitude, 
distance)\"." );
+                                       throw new MWException( "Error: value 
for the 'NEAR' operator must be of the form "
+                                       . "\"(latitude, longitude, 
distance)\"." );
                                }
                                list( $latitude, $longitude, $distance ) = 
$coordinatesAndDistance;
                                $distanceComponents = explode( ' ', trim( 
$distance ) );
                                if ( count( $distanceComponents ) != 2 ) {
-                                       throw new MWException( "Error: the 
third argument for the 'NEAR' operator, representing the distance, must be of 
the form \"number unit\"." );
+                                       throw new MWException( "Error: the 
third argument for the 'NEAR' operator, "
+                                       . "representing the distance, must be 
of the form \"number unit\"." );
                                }
                                list( $distanceNumber, $distanceUnit ) = 
$distanceComponents;
                                $distanceNumber = trim( $distanceNumber );
                                $distanceUnit = trim( $distanceUnit );
-                               list( $latDistance, $longDistance ) = 
self::distanceToDegrees( $distanceNumber, $distanceUnit, $latitude );
+                               list( $latDistance, $longDistance ) = 
self::distanceToDegrees( $distanceNumber, $distanceUnit,
+                                               $latitude );
                                // There are much better ways to do this, but
                                // for now, just make a "bounding box" instead
                                // of a bounding circle.
@@ -745,7 +756,8 @@
                } elseif ( in_array( $distanceUnit, array( 'miles', 'mi' ) ) ) {
                        $distanceInKM = $distanceNumber * 1.60934;
                } else {
-                       throw new MWException( "Error: distance for 'NEAR' 
operator must be in either miles or kilometers (\"$distanceUnit\" specified)." 
);
+                       throw new MWException( "Error: distance for 'NEAR' 
operator must be in either miles or "
+                       . "kilometers (\"$distanceUnit\" specified)." );
                }
                // The calculation of distance to degrees latitude is
                // essentially the same wherever you are on the globe, although
@@ -764,7 +776,9 @@
                } else {
                        $latNum = CargoStore::coordinatePartToNumber( 
$latString );
                }
-               if ( $latIsNegative ) $latNum *= -1;
+               if ( $latIsNegative ) {
+                       $latNum *= -1;
+               }
 
                $lengthOfOneDegreeLongitude = cos( deg2rad( $latNum ) ) * 
111.321;
                $longDistance = $distanceInKM / $lengthOfOneDegreeLongitude;
@@ -782,11 +796,11 @@
                foreach ( $this->mAliasedFieldNames as $alias => $fieldName ) {
                        $fieldDescription = $this->mFieldDescriptions[$alias];
                        if ( ( $fieldDescription->mType == 'Date' || 
$fieldDescription->mType == 'Datetime' ) &&
-                       // Make sure this is an actual field and not a call
-                       // to a function, like DATE_FORMAT(), by checking for
-                       // the presence of '(' and ')' - there's probably a
-                       // more elegant way to do this.
-                       ( strpos( $fieldName, '(' ) == false ) && ( strpos( 
$fieldName, ')' ) == false ) ) {
+                               // Make sure this is an actual field and not a 
call
+                               // to a function, like DATE_FORMAT(), by 
checking for
+                               // the presence of '(' and ')' - there's 
probably a
+                               // more elegant way to do this.
+                               ( strpos( $fieldName, '(' ) == false ) && ( 
strpos( $fieldName, ')' ) == false ) ) {
                                $dateFields[] = $fieldName;
                        }
                }
@@ -821,7 +835,7 @@
                $cdb = CargoUtils::getDB();
 
                foreach ( $this->mTableNames as $tableName ) {
-                       if ( ! $cdb->tableExists( $tableName ) ) {
+                       if ( !$cdb->tableExists( $tableName ) ) {
                                throw new MWException( "Error: no database 
table exists for \"$tableName\"." );
                        }
                }
@@ -841,14 +855,15 @@
                        $realAliasedFieldNames['"' . $alias . '"'] = $fieldName;
                }
 
-               $res = $cdb->select( $this->mTableNames, 
$realAliasedFieldNames, $this->mWhereStr, __METHOD__, $selectOptions, 
$this->mJoinConds );
+               $res = $cdb->select( $this->mTableNames, 
$realAliasedFieldNames, $this->mWhereStr, __METHOD__,
+                       $selectOptions, $this->mJoinConds );
 
                // Is there a more straightforward way of turning query
                // results into an array?
                $resultArray = array();
                while ( $row = $cdb->fetchRow( $res ) ) {
                        $resultsRow = array();
-                       foreach( $this->mAliasedFieldNames as $alias => 
$fieldName ) {
+                       foreach ( $this->mAliasedFieldNames as $alias => 
$fieldName ) {
                                // Escape any HTML, to avoid JavaScript
                                // injections and the like.
                                $resultsRow[$alias] = htmlspecialchars( 
$row[$alias] );
diff --git a/CargoUtils.php b/CargoUtils.php
index e178293..8c94303 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -8,27 +8,42 @@
 
 class CargoUtils {
 
+       /**
+        *
+        * @global string $wgDBuser
+        * @global string $wgDBpassword
+        * @global string $wgCargoDBserver
+        * @global string $wgCargoDBname
+        * @global string $wgCargoDBuser
+        * @global string $wgCargoDBpassword
+        * @global string $wgCargoDBtype
+        * @return DatabaseBase
+        */
        public static function getDB() {
-               global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, 
$wgDBtype;
+               global $wgDBuser, $wgDBpassword;
                global $wgCargoDBserver, $wgCargoDBname, $wgCargoDBuser, 
$wgCargoDBpassword, $wgCargoDBtype;
+               $dbr = wfGetDB( DB_SLAVE );
+               $server = $dbr->getServer();
+               $name = $dbr->getDBname();
+               $type = $dbr->getType();
 
-               $dbType = is_null( $wgCargoDBtype ) ? $wgDBtype : 
$wgCargoDBtype;
-               $dbServer = is_null( $wgCargoDBserver ) ? $wgDBserver : 
$wgCargoDBserver;
+               $dbType = is_null( $wgCargoDBtype ) ? $type : $wgCargoDBtype;
+               $dbServer = is_null( $wgCargoDBserver ) ? $server : 
$wgCargoDBserver;
                $dbUsername = is_null( $wgCargoDBuser ) ? $wgDBuser : 
$wgCargoDBuser;
                $dbPassword = is_null( $wgCargoDBpassword ) ? $wgDBpassword : 
$wgCargoDBpassword;
-               $dbName = is_null( $wgCargoDBname ) ? $wgDBname : 
$wgCargoDBname;
+               $dbName = is_null( $wgCargoDBname ) ? $name : $wgCargoDBname;
                $dbFlags = DBO_DEFAULT;
                $dbTablePrefix = 'cargo__';
 
                $db = DatabaseBase::factory( $dbType,
-                       array(
+                               array(
                                'host' => $dbServer,
                                'user' => $dbUsername,
                                'password' => $dbPassword,
                                'dbname' => $dbName,
                                'flags' => $dbFlags,
                                'tablePrefix' => $dbTablePrefix,
-                       )
+                               )
                );
                return $db;
        }
@@ -38,17 +53,15 @@
         */
        public static function getPageProp( $pageID, $pageProp ) {
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'page_props',
-                       array(
-                               'pp_value'
-                       ),
-                       array(
-                               'pp_page' => $pageID,
-                               'pp_propname' => $pageProp,
+               $res = $dbr->select( 'page_props', array(
+                       'pp_value'
+                       ), array(
+                       'pp_page' => $pageID,
+                       'pp_propname' => $pageProp,
                        )
                );
 
-               if ( ! $row = $dbr->fetchRow( $res ) ) {
+               if ( !$row = $dbr->fetchRow( $res ) ) {
                        return null;
                }
 
@@ -71,7 +84,7 @@
 
        static function getTableSchemas( $tableNames ) {
                $mainTableNames = array();
-               foreach( $tableNames as $tableName ) {
+               foreach ( $tableNames as $tableName ) {
                        if ( strpos( $tableName, '__' ) !== false ) {
                                // We just want the first part of it.
                                $tableNameParts = explode( '__', $tableName );
@@ -83,7 +96,8 @@
                }
                $tableSchemas = array();
                $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( 'cargo_tables', array( 'main_table', 
'table_schema' ), array( 'main_table' => $mainTableNames ) );
+               $res = $dbr->select( 'cargo_tables', array( 'main_table', 
'table_schema' ),
+                       array( 'main_table' => $mainTableNames ) );
                while ( $row = $dbr->fetchRow( $res ) ) {
                        $tableName = $row['main_table'];
                        $tableSchemaString = $row['table_schema'];
@@ -121,7 +135,7 @@
         * Splits a string by the delimiter, but ignores delimiters contained
         * within parentheses.
         */
-       static function smartSplit( $delimiter, $string) {
+       static function smartSplit( $delimiter, $string ) {
                if ( $string == '' ) {
                        return array();
                }
@@ -146,13 +160,19 @@
                        }
                }
                $returnValues[] = $curReturnValue;
-               
+
                return $returnValues;
        }
 
        /**
         * Parse a piece of wikitext differently depending on whether
         * we're in a special or regular page.
+        *
+        * @global WebRequest $wgRequest
+        * @global Parser $wgParser
+        * @param string $value
+        * @param Parser $parser
+        * @return string
         */
        public static function smartParse( $value, $parser ) {
                // This decode() call is here in case the value was
@@ -164,21 +184,22 @@
                $value = htmlspecialchars_decode( $value );
                // Parse it as if it's wikitext. The exact call
                // depends on whether we're in a special page or not.
-               global $wgTitle, $wgRequest;
+               global $wgRequest;
                if ( is_null( $parser ) ) {
                        global $wgParser;
                        $parser = $wgParser;
                }
-               if ( $wgTitle != null && $wgTitle->isSpecialPage() && 
$wgTitle->getText() == 'RunJobs' ) {
+               $title = $parser->getTitle();
+               if ( $title != null && $title->isSpecial( 'RunJobs' ) ) {
                        // Conveniently, if this is called from within a job
                        // being run, the name of the page will be
                        // Special:RunJobs.
                        // If that's the case, do nothing - we don't need to
                        // parse the value.
-               } elseif ( ( $wgTitle != null && $wgTitle->isSpecialPage() ) ||
+               } elseif ( ( $title != null && $title->isSpecialPage() ) ||
                        // The 'pagevalues' action is also a Cargo special page.
                        $wgRequest->getVal( 'action' ) == 'pagevalues' ) {
-                       $parserOutput = $parser->parse( $value, $wgTitle, new 
ParserOptions(), false );
+                       $parserOutput = $parser->parse( $value, $title, new 
ParserOptions(), false );
                        $value = $parserOutput->getText();
                } else {
                        $value = $parser->internalParse( $value );
diff --git a/README b/README
index 0312537..dcfce33 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 Cargo extension
 
-        Version 0.6
+        Version 0.5.1
         Yaron Koren
 
 This is free software licensed under the GNU General Public License. Please
diff --git a/drilldown/CargoAppliedFilter.php b/drilldown/CargoAppliedFilter.php
index 709fb91..9f4e201 100644
--- a/drilldown/CargoAppliedFilter.php
+++ b/drilldown/CargoAppliedFilter.php
@@ -18,24 +18,27 @@
        var $lower_date_string;
        var $upper_date_string;
 
-       static function create( $filter, $values, $search_terms = null, 
$lower_date = null, $upper_date = null ) {
+       static function create( $filter, $values, $search_terms = null, 
$lower_date = null,
+               $upper_date = null ) {
                $af = new CargoAppliedFilter();
                $af->filter = $filter;
                if ( $search_terms != null ) {
                        $af->search_terms = array();
-                       foreach( $search_terms as $search_term ) {
+                       foreach ( $search_terms as $search_term ) {
                                $af->search_terms[] = htmlspecialchars( 
str_replace( '_', ' ', $search_term ) );
                        }
                }
                if ( $lower_date != null ) {
                        $af->lower_date = $lower_date;
-                       $af->lower_date_string = 
CargoDrilldownUtils::monthToString( $lower_date['month'] ) . " " . 
$lower_date['day'] . ", " . $lower_date['year'];
+                       $af->lower_date_string = 
CargoDrilldownUtils::monthToString( $lower_date['month'] ) .
+                               " " . $lower_date['day'] . ", " . 
$lower_date['year'];
                }
                if ( $upper_date != null ) {
                        $af->upper_date = $upper_date;
-                       $af->upper_date_string = 
CargoDrilldownUtils::monthToString( $upper_date['month'] ) . " " . 
$upper_date['day'] . ", " . $upper_date['year'];
+                       $af->upper_date_string = 
CargoDrilldownUtils::monthToString( $upper_date['month'] ) .
+                               " " . $upper_date['day'] . ", " . 
$upper_date['year'];
                }
-               if ( ! is_array( $values ) ) {
+               if ( !is_array( $values ) ) {
                        $values = array( $values );
                }
                foreach ( $values as $val ) {
@@ -80,20 +83,25 @@
                        }
                }
                if ( $this->lower_date != null ) {
-                       $date_string = $this->lower_date['year'] . "-" . 
$this->lower_date['month'] . "-" . $this->lower_date['day'];
+                       $date_string = $this->lower_date['year'] . "-" . 
$this->lower_date['month'] . "-" .
+                               $this->lower_date['day'];
                        $sql .= "date($value_field) >= date('$date_string') ";
                }
                if ( $this->upper_date != null ) {
                        if ( $this->lower_date != null ) {
                                $sql .= " AND ";
                        }
-                       $date_string = $this->upper_date['year'] . "-" . 
$this->upper_date['month'] . "-" . $this->upper_date['day'];
+                       $date_string = $this->upper_date['year'] . "-" . 
$this->upper_date['month'] . "-" .
+                               $this->upper_date['day'];
                        $sql .= "date($value_field) <= date('$date_string') ";
                }
                foreach ( $this->values as $i => $fv ) {
-                       if ( $i > 0 ) { $sql .= " OR "; }
+                       if ( $i > 0 ) {
+                               $sql .= " OR ";
+                       }
                        if ( $fv->is_other ) {
-                               $checkNullOrEmptySql = "$value_field IS NULL " 
. ( $wgDBtype == 'postgres' ? '' : "OR $value_field = '' ");
+                               $checkNullOrEmptySql = "$value_field IS NULL " 
. ( $wgDBtype == 'postgres' ? '' :
+                                               "OR $value_field = '' ");
                                $notOperatorSql = ( $wgDBtype == 'postgres' ? 
"not" : "!" );
                                $sql .= "($notOperatorSql ($checkNullOrEmptySql 
";
                                foreach ( 
$this->filter->possible_applied_filters as $paf ) {
@@ -101,7 +109,8 @@
                                }
                                $sql .= "))";
                        } elseif ( $fv->is_none ) {
-                               $checkNullOrEmptySql = ( $wgDBtype == 
'postgres' ? '' : "$value_field = '' OR ") . "$value_field IS NULL";
+                               $checkNullOrEmptySql = ( $wgDBtype == 
'postgres' ? '' : "$value_field = '' OR ") .
+                                       "$value_field IS NULL";
                                $sql .= "($checkNullOrEmptySql) ";
                        } elseif ( $fv->is_numeric ) {
                                if ( $fv->lower_limit && $fv->upper_limit ) {
@@ -114,7 +123,8 @@
                        } elseif ( $this->filter->fieldDescription->mType == 
'Date' ) {
                                $date_field = $this->filter->name;
                                if ( $fv->time_period == 'day' ) {
-                                       $sql .= "YEAR($date_field) = 
{$fv->year} AND MONTH($date_field) = {$fv->month} AND DAYOFMONTH($date_field) = 
{$fv->day} ";
+                                       $sql .= "YEAR($date_field) = 
{$fv->year} AND MONTH($date_field) = {$fv->month} "
+                                               . "AND DAYOFMONTH($date_field) 
= {$fv->day} ";
                                } elseif ( $fv->time_period == 'month' ) {
                                        $sql .= "YEAR($date_field) = 
{$fv->year} AND MONTH($date_field) = {$fv->month} ";
                                } elseif ( $fv->time_period == 'year' ) {
@@ -125,7 +135,7 @@
                                }
                        } else {
                                $value = $fv->text;
-                               $sql .= "$value_field = 
'{$cdb->strencode($value)}'";
+                               $sql .= "$value_field = '{$cdb->strencode( 
$value )}'";
                        }
                }
                $sql .= ")";

-- 
To view, visit https://gerrit.wikimedia.org/r/183775
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa017464648fff1c94a454977bc61a1ed93dd2b3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: tosfos <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to