[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Removed duplicate retrieval of filters in drilldown

2016-10-13 Thread Yaron Koren (Code Review)
Yaron Koren has uploaded a new change for review.

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

Change subject: Removed duplicate retrieval of filters in drilldown
..

Removed duplicate retrieval of filters in drilldown

Change-Id: Id6d9cc640aacd8ce83241046b85c1a54a628
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 14 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/20/315720/2

diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 42930a6..c766e50 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -62,15 +62,15 @@
}
 
$tableSchemas = CargoUtils::getTableSchemas( array( $tableName 
) );
-   $filters = array();
+   $all_filters = array();
foreach ( $tableSchemas[$tableName]->mFieldDescriptions as 
$fieldName => $fieldDescription ) {
// Skip "hidden" fields.
if ( $fieldDescription->mIsHidden ) {
continue;
}
 
-   // Skip coordinate fields.
-   if ( $fieldDescription->mType == 'Coordinates' ) {
+   // Some field types shouldn't get a filter at all.
+   if ( in_array( $fieldDescription->mType, array( 'Text', 
'File', 'Coordinates', 'URL', 'Email', 'Wikitext', 'Searchtext' ) ) ) {
continue;
}
 
@@ -78,16 +78,16 @@
$curFilter->setName( $fieldName );
$curFilter->setTableName( $tableName );
$curFilter->setFieldDescription( $fieldDescription );
-   $filters[] = $curFilter;
+   $all_filters[] = $curFilter;
}
 
$filter_used = array();
-   foreach ( $filters as $i => $filter ) {
+   foreach ( $all_filters as $i => $filter ) {
$filter_used[] = false;
}
$applied_filters = array();
$remaining_filters = array();
-   foreach ( $filters as $i => $filter ) {
+   foreach ( $all_filters as $i => $filter ) {
$filter_name = str_replace( array( ' ', "'" ), array( 
'_', "\'" ), $filter->name );
$search_terms = $request->getArray( '_search_' . 
$filter_name );
$lower_date = $request->getArray( '_lower_' . 
$filter_name );
@@ -107,9 +107,9 @@
$filter_used[$i] = true;
}
}
-   // add every unused filter to the $remaining_filters array,
-   // unless it requires some other filter that hasn't been applied
-   foreach ( $filters as $i => $filter ) {
+   // Add every unused filter to the $remaining_filters array,
+   // unless it requires some other filter that hasn't been 
applied.
+   foreach ( $all_filters as $i => $filter ) {
$matched_all_required_filters = true;
foreach ( $filter->required_filters as $required_filter 
) {
$found_match = false;
@@ -130,7 +130,7 @@
 
$out->addHTML( "\n\t\t\t\t\n" 
);
$rep = new CargoDrilldownPage(
-   $tableName, $applied_filters, $remaining_filters, 
$offset, $limit );
+   $tableName, $all_filters, $applied_filters, 
$remaining_filters, $offset, $limit );
$num = $rep->execute( $query );
$out->addHTML( "\n\t\t\t \n" );
 
@@ -148,6 +148,7 @@
 
 class CargoDrilldownPage extends QueryPage {
public $tableName = "";
+   public $all_filters = array();
public $applied_filters = array();
public $remaining_filters = array();
public $showSingleTable = false;
@@ -161,10 +162,11 @@
 * @param int $offset
 * @param int $limit
 */
-   function __construct( $tableName, $applied_filters, $remaining_filters, 
$offset, $limit ) {
+   function __construct( $tableName, $all_filters, $applied_filters, 
$remaining_filters, $offset, $limit ) {
parent::__construct( 'Drilldown' );
 
$this->tableName = $tableName;
+   $this->all_filters = $all_filters;
$this->applied_filters = $applied_filters;
$this->remaining_filters = $remaining_filters;
$this->offset = $offset;
@@ -977,20 +979,8 @@
$filtersHTML = "\n";
$cur_url = $this->makeBrowseURL( $this->tableName, 
$this->applied_filters );
$cur_url .= ( strpos( 

[MediaWiki-commits] [Gerrit] mediawiki...Cargo[master]: Removed duplicate retrieval of filters in drilldown

2016-10-13 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Removed duplicate retrieval of filters in drilldown
..


Removed duplicate retrieval of filters in drilldown

Change-Id: Id6d9cc640aacd8ce83241046b85c1a54a628
---
M drilldown/CargoSpecialDrilldown.php
1 file changed, 14 insertions(+), 24 deletions(-)

Approvals:
  Yaron Koren: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/drilldown/CargoSpecialDrilldown.php 
b/drilldown/CargoSpecialDrilldown.php
index 42930a6..c766e50 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -62,15 +62,15 @@
}
 
$tableSchemas = CargoUtils::getTableSchemas( array( $tableName 
) );
-   $filters = array();
+   $all_filters = array();
foreach ( $tableSchemas[$tableName]->mFieldDescriptions as 
$fieldName => $fieldDescription ) {
// Skip "hidden" fields.
if ( $fieldDescription->mIsHidden ) {
continue;
}
 
-   // Skip coordinate fields.
-   if ( $fieldDescription->mType == 'Coordinates' ) {
+   // Some field types shouldn't get a filter at all.
+   if ( in_array( $fieldDescription->mType, array( 'Text', 
'File', 'Coordinates', 'URL', 'Email', 'Wikitext', 'Searchtext' ) ) ) {
continue;
}
 
@@ -78,16 +78,16 @@
$curFilter->setName( $fieldName );
$curFilter->setTableName( $tableName );
$curFilter->setFieldDescription( $fieldDescription );
-   $filters[] = $curFilter;
+   $all_filters[] = $curFilter;
}
 
$filter_used = array();
-   foreach ( $filters as $i => $filter ) {
+   foreach ( $all_filters as $i => $filter ) {
$filter_used[] = false;
}
$applied_filters = array();
$remaining_filters = array();
-   foreach ( $filters as $i => $filter ) {
+   foreach ( $all_filters as $i => $filter ) {
$filter_name = str_replace( array( ' ', "'" ), array( 
'_', "\'" ), $filter->name );
$search_terms = $request->getArray( '_search_' . 
$filter_name );
$lower_date = $request->getArray( '_lower_' . 
$filter_name );
@@ -107,9 +107,9 @@
$filter_used[$i] = true;
}
}
-   // add every unused filter to the $remaining_filters array,
-   // unless it requires some other filter that hasn't been applied
-   foreach ( $filters as $i => $filter ) {
+   // Add every unused filter to the $remaining_filters array,
+   // unless it requires some other filter that hasn't been 
applied.
+   foreach ( $all_filters as $i => $filter ) {
$matched_all_required_filters = true;
foreach ( $filter->required_filters as $required_filter 
) {
$found_match = false;
@@ -130,7 +130,7 @@
 
$out->addHTML( "\n\t\t\t\t\n" 
);
$rep = new CargoDrilldownPage(
-   $tableName, $applied_filters, $remaining_filters, 
$offset, $limit );
+   $tableName, $all_filters, $applied_filters, 
$remaining_filters, $offset, $limit );
$num = $rep->execute( $query );
$out->addHTML( "\n\t\t\t \n" );
 
@@ -148,6 +148,7 @@
 
 class CargoDrilldownPage extends QueryPage {
public $tableName = "";
+   public $all_filters = array();
public $applied_filters = array();
public $remaining_filters = array();
public $showSingleTable = false;
@@ -161,10 +162,11 @@
 * @param int $offset
 * @param int $limit
 */
-   function __construct( $tableName, $applied_filters, $remaining_filters, 
$offset, $limit ) {
+   function __construct( $tableName, $all_filters, $applied_filters, 
$remaining_filters, $offset, $limit ) {
parent::__construct( 'Drilldown' );
 
$this->tableName = $tableName;
+   $this->all_filters = $all_filters;
$this->applied_filters = $applied_filters;
$this->remaining_filters = $remaining_filters;
$this->offset = $offset;
@@ -977,20 +979,8 @@
$filtersHTML = "\n";
$cur_url = $this->makeBrowseURL( $this->tableName, 
$this->applied_filters );
$cur_url .= ( strpos( $cur_url, '?' ) ) ? '&' : '?';
-