jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/372563 )
Change subject: Perform true "drilldown" in the applied filter line for
hierarchy field
......................................................................
Perform true "drilldown" in the applied filter line for hierarchy field
Change-Id: I4eff3f1660538cb75930123543940192e62b24ba
---
M drilldown/CargoDrilldownHierarchy.php
M drilldown/CargoFilter.php
M drilldown/CargoSpecialDrilldown.php
3 files changed, 77 insertions(+), 13 deletions(-)
Approvals:
Yaron Koren: Looks good to me, approved
jenkins-bot: Verified
diff --git a/drilldown/CargoDrilldownHierarchy.php
b/drilldown/CargoDrilldownHierarchy.php
index 07f889b..9eba211 100644
--- a/drilldown/CargoDrilldownHierarchy.php
+++ b/drilldown/CargoDrilldownHierarchy.php
@@ -16,9 +16,13 @@
if ( $f->fieldDescription->mIsList ) {
$countArg = "_rowID";
$fieldTableName = $f->tableName . '__' . $f->name;
- $tableNames[] = $fieldTableName;
+ if ( !in_array( $fieldTableName, $tableNames ) ) {
+ $tableNames[] = $fieldTableName;
+ }
$fieldName = '_value';
- $joinConds[$fieldTableName] =
CargoUtils::joinOfMainAndFieldTable( $cdb, $f->tableName, $fieldTableName );
+ if ( !array_key_exists( $fieldTableName, $joinConds ) )
{
+ $joinConds[$fieldTableName] =
CargoUtils::joinOfMainAndFieldTable( $cdb, $f->tableName, $fieldTableName );
+ }
} else {
$countArg = "_ID";
$fieldName = $f->name;
@@ -28,17 +32,19 @@
$countClause = "COUNT(DISTINCT($countArg)) AS total";
$hierarchyTableName = $f->tableName . '__' . $f->name .
'__hierarchy';
- $tableNames[] = $hierarchyTableName;
+ if ( !in_array( $hierarchyTableName, $tableNames ) ) {
+ $tableNames[] = $hierarchyTableName;
+ }
- $joinConds[$hierarchyTableName] =
CargoUtils::joinOfSingleFieldAndHierarchyTable( $cdb,
- $fieldTableName, $fieldName, $hierarchyTableName );
-
+ if ( !array_key_exists( $hierarchyTableName, $joinConds ) ) {
+ $joinConds[$hierarchyTableName] =
CargoUtils::joinOfSingleFieldAndHierarchyTable( $cdb,
+ $fieldTableName, $fieldName,
$hierarchyTableName );
+ }
$withinTreeHierarchyConds = array();
$exactRootHierarchyConds = array();
$withinTreeHierarchyConds[] = "_left >= $node->mLeft";
$withinTreeHierarchyConds[] = "_right <= $node->mRight";
$exactRootHierarchyConds[] = "_left = $node->mLeft";
-
// within hierarchy tree value count
$res = $cdb->select( $tableNames, array( $countClause ),
array_merge( $conds, $withinTreeHierarchyConds ),
null, null, $joinConds );
diff --git a/drilldown/CargoFilter.php b/drilldown/CargoFilter.php
index 14cf062..760dc89 100644
--- a/drilldown/CargoFilter.php
+++ b/drilldown/CargoFilter.php
@@ -113,10 +113,19 @@
foreach ( $appliedFilters as $af ) {
$conds[] = $af->checkSQL();
+ $fieldTableName = $this->tableName;
+ $columnName = $af->filter->name;
if ( $af->filter->fieldDescription->mIsList ) {
$fieldTableName = $this->tableName . '__' .
$af->filter->name;
$tableNames[] = $fieldTableName;
$joinConds[$fieldTableName] =
CargoUtils::joinOfMainAndFieldTable( $cdb, $this->tableName, $fieldTableName );
+ $columnName = '_value';
+ }
+ if ( $af->filter->fieldDescription->mIsHierarchy ) {
+ $hierarchyTableName = $this->tableName . '__' .
$af->filter->name . '__hierarchy';
+ $tableNames[] = $hierarchyTableName;
+ $joinConds[$hierarchyTableName] =
CargoUtils::joinOfSingleFieldAndHierarchyTable( $cdb,
+ $fieldTableName, $columnName,
$hierarchyTableName );
}
}
return array( $tableNames, $conds, $joinConds );
diff --git a/drilldown/CargoSpecialDrilldown.php
b/drilldown/CargoSpecialDrilldown.php
index f7ff850..414c940 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -413,6 +413,9 @@
* at least one value set
*/
function printAppliedFilterLine( $af ) {
+ if ( $af->filter->fieldDescription->mIsHierarchy ) {
+ return $this->printAppliedFilterLineForHierarchy( $af );
+ }
$results_line = "";
$current_filter_values = array();
foreach ( $this->applied_filters as $af2 ) {
@@ -486,6 +489,48 @@
return $this->printFilterLine( $af->filter->name, true, true,
$results_line );
}
+ function printAppliedFilterLineForHierarchy( $af ) {
+ $applied_filters = $this->applied_filters;
+ $cur_url = $this->makeBrowseURL( $this->tableName,
$this->fullTextSearchTerm, array() );
+ $cur_url .= ( strpos( $cur_url, '?' ) ) ? '&' : '?';
+ // Drilldown for hierarchy is designed for literal 'drilldown'
+ // Therefore it has single filter value applied at anytime
+ $filter_value = "";
+ $isFilterValueNotWithin = false;
+ if ( count ( $af->values ) > 0 ) {
+ $filter_value = $af->values[0]->text;
+ $matches = array();
+ preg_match( "/^~within (.+)/", $filter_value, $matches
);
+ if ( count( $matches ) > 0 ) {
+ $filter_value = $matches[1];
+ } else {
+ $isFilterValueNotWithin = true;
+ }
+ }
+ $drilldownHierarchyRoot =
CargoDrilldownHierarchy::newFromWikiText(
$af->filter->fieldDescription->mHierarchyStructure );
+ $stack = new SplStack();
+ // preorder traversal of the tree
+ $stack->push( $drilldownHierarchyRoot );
+ while ( !$stack->isEmpty() ) {
+ $node = $stack->pop();
+ if ( $node->mRootValue === $filter_value ) {
+ $drilldownHierarchyRoot = $node;
+ break;
+ }
+ for( $i = count( $node->mChildren ) - 1; $i >= 0; $i--
) {
+ $stack->push( $node->mChildren[$i] );
+ }
+ }
+ if ( $isFilterValueNotWithin === true ) {
+
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter( $node,
+ $af->filter, null, $applied_filters );
+ $results_line = wfMessage(
'cargo-drilldown-hierarchy-only', $node->mRootValue )->parse() . "
($node->mExactRootMatchCount)";
+ } else {
+ $results_line = $this->printFilterValuesForHierarchy(
$cur_url, $af->filter, null, $applied_filters, $drilldownHierarchyRoot );
+ }
+ return $this->printFilterLine( $af->filter->name, false, true,
$results_line );
+ }
+
function printUnappliedFilterValues( $cur_url, $f, $filter_values ) {
$results_line = "";
// now print the values
@@ -502,16 +547,20 @@
}
function printUnappliedFilterValuesForHierarchy( $cur_url, $f,
$fullTextSearchTerm, $applied_filters ) {
- $results_line = "";
// construct the tree of CargoDrilldownHierarchy
- $drilldownHierarchyTreeRoot =
CargoDrilldownHierarchy::newFromWikiText(
$f->fieldDescription->mHierarchyStructure );
+ $drilldownHierarchyRoot =
CargoDrilldownHierarchy::newFromWikiText(
$f->fieldDescription->mHierarchyStructure );
+ return $this->printFilterValuesForHierarchy( $cur_url, $f,
$fullTextSearchTerm, $applied_filters, $drilldownHierarchyRoot );
+ }
+
+ function printFilterValuesForHierarchy( $cur_url, $f,
$fullTextSearchTerm, $applied_filters, $drilldownHierarchyRoot ) {
// compute counts
- $filter_values =
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter(
$drilldownHierarchyTreeRoot,
+ $filter_values =
CargoDrilldownHierarchy::computeNodeCountForTreeByFilter(
$drilldownHierarchyRoot,
$f, $fullTextSearchTerm, $applied_filters );
+ $results_line = "";
$num_printed_values = 0;
$stack = new SplStack();
// preorder traversal of the tree
- $stack->push( $drilldownHierarchyTreeRoot );
+ $stack->push( $drilldownHierarchyRoot );
while ( !$stack->isEmpty() ) {
$node = $stack->pop();
if ( $node != ")" ) {
@@ -524,8 +573,8 @@
$filter_url = $cur_url . urlencode(
str_replace( ' ', '_', $f->name ) ) . '=' .
urlencode( str_replace( ' ',
'_', "~within_" . $node->mRootValue ) );
// generate respective <a> tag with
value and its count
- $results_line .=
$this->printFilterValueLink( $f, $node->mRootValue,
- $node->mWithinTreeMatchCount,
$filter_url, $filter_values );
+ $results_line .= ( $node ===
$drilldownHierarchyRoot )?$node->mRootValue . " ($node->mWithinTreeMatchCount)":
+ $this->printFilterValueLink(
$f, $node->mRootValue, $node->mWithinTreeMatchCount, $filter_url,
$filter_values );
}
if ( count( $node->mChildren ) > 0 ) {
if ( $node->mLeft !== 1 ) {
--
To view, visit https://gerrit.wikimedia.org/r/372563
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4eff3f1660538cb75930123543940192e62b24ba
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Fz-29 <[email protected]>
Gerrit-Reviewer: Fz-29 <[email protected]>
Gerrit-Reviewer: Nischayn22 <[email protected]>
Gerrit-Reviewer: Oetterer <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits