jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/372232 )
Change subject: Add feature to hide deeper levels of hierarchy in Drilldown to show maximum of \$wgCargoMaxVisibleHierarchyDrilldownValues values in the filter line ...................................................................... Add feature to hide deeper levels of hierarchy in Drilldown to show maximum of \$wgCargoMaxVisibleHierarchyDrilldownValues values in the filter line Change-Id: Iabed8a2d18d3a34cc07f43ecfdcbaf9569272d1e --- M Cargo.php M drilldown/CargoDrilldownHierarchy.php M drilldown/CargoSpecialDrilldown.php M extension.json 4 files changed, 63 insertions(+), 15 deletions(-) Approvals: Yaron Koren: Looks good to me, approved jenkins-bot: Verified diff --git a/Cargo.php b/Cargo.php index f99caea..75ca3fd 100644 --- a/Cargo.php +++ b/Cargo.php @@ -339,6 +339,7 @@ $wgCargoDrilldownLargestFontSize = -1; $wgCargoDrilldownMinValuesForComboBox = 40; $wgCargoDrilldownNumRangesForNumbers = 5; +$wgCargoMaxVisibleHierarchyDrilldownValues = 30; $wgCargoPageDataColumns = array(); $wgCargoFileDataColumns = array(); diff --git a/drilldown/CargoDrilldownHierarchy.php b/drilldown/CargoDrilldownHierarchy.php index 9eba211..c91a02a 100644 --- a/drilldown/CargoDrilldownHierarchy.php +++ b/drilldown/CargoDrilldownHierarchy.php @@ -70,9 +70,9 @@ $stack->push( $node ); while ( !$stack->isEmpty() ) { $node = $stack->pop(); + CargoDrilldownHierarchy::computeNodeCountByFilter( $node, $f, $fullTextSearchTerm, $appliedFilters ); if ( $node->mLeft !== 1 ) { // check if its not __pseudo_root__ node, then only add count - CargoDrilldownHierarchy::computeNodeCountByFilter( $node, $f, $fullTextSearchTerm, $appliedFilters ); $filter_values[$node->mRootValue] = $node->mWithinTreeMatchCount; } if ( count( $node->mChildren ) > 0 ) { @@ -86,4 +86,44 @@ } return $filter_values; } + + /* + * Finds maximum permissible depth for listing values in Drilldown filter line such that total values appearing on the Filter line + * is less than or equal to $wgCargoMaxVisibleHierarchyDrilldownValues + */ + static function findMaxDrilldownDepth( $node ) { + global $wgCargoMaxVisibleHierarchyDrilldownValues; + if ( !isset( $wgCargoMaxVisibleHierarchyDrilldownValues ) || !is_int( $wgCargoMaxVisibleHierarchyDrilldownValues ) || $wgCargoMaxVisibleHierarchyDrilldownValues < 0 ) { + return PHP_INT_MAX; + } + $maxDepth = 0; + $nodeCount = 0; + $queue = new SplQueue(); + $queue->enqueue( $node ); + $queue->enqueue( null ); + while ( !$queue->isEmpty() ) { + $node = $queue->dequeue(); + if ( $node === null ) { + if ( !$queue->isEmpty() ) { + $maxDepth++; + $queue->enqueue( null ); + } + } else { + if ( count( $node->mChildren ) > 0 && $node->mExactRootMatchCount > 0 ) { + // we will go one level deeper and print "nodevalue_only (x)" in filter line - so count it + $nodeCount++; + } + foreach ( $node->mChildren as $child ) { + if ( $child->mWithinTreeMatchCount > 0 ) { + if ( $nodeCount >= $wgCargoMaxVisibleHierarchyDrilldownValues ) { + break(2); + } + $queue->enqueue( $child ); + $nodeCount++; + } + } + } + } + return max(1, $maxDepth); + } } \ No newline at end of file diff --git a/drilldown/CargoSpecialDrilldown.php b/drilldown/CargoSpecialDrilldown.php index 414c940..1887990 100644 --- a/drilldown/CargoSpecialDrilldown.php +++ b/drilldown/CargoSpecialDrilldown.php @@ -553,20 +553,22 @@ } function printFilterValuesForHierarchy( $cur_url, $f, $fullTextSearchTerm, $applied_filters, $drilldownHierarchyRoot ) { + $results_line = ""; // compute counts $filter_values = CargoDrilldownHierarchy::computeNodeCountForTreeByFilter( $drilldownHierarchyRoot, $f, $fullTextSearchTerm, $applied_filters ); - $results_line = ""; - $num_printed_values = 0; + $maxDepth = CargoDrilldownHierarchy::findMaxDrilldownDepth( $drilldownHierarchyRoot ); + $depth = 0; + $num_printed_values_level = 0; $stack = new SplStack(); // preorder traversal of the tree $stack->push( $drilldownHierarchyRoot ); while ( !$stack->isEmpty() ) { $node = $stack->pop(); if ( $node != ")" ) { - if ( $node->mLeft !== 1 ) { + if ( $node->mLeft !== 1 && $node->mWithinTreeMatchCount > 0 ) { // check if its not __pseudo_root__ node, then only print - if ( $num_printed_values++ > 0 ) { + if ( $num_printed_values_level++ > 0 ) { $results_line .= " · "; } // generate a url to encode WITHIN search information by a "~within_" prefix in value_str @@ -576,24 +578,28 @@ $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 ( count( $node->mChildren ) > 0 && $node->mWithinTreeMatchCount > 0 && $depth < $maxDepth ) { + $depth++; if ( $node->mLeft !== 1 ) { - $filter_url = $cur_url . urlencode( str_replace( ' ', '_', $f->name ) ) . '=' . - urlencode( str_replace( ' ', '_', $node->mRootValue ) ); - $results_line .= " · "; - $results_line .= "(" . $this->printFilterValueLink( $f, - wfMessage( 'cargo-drilldown-hierarchy-only', $node->mRootValue )->parse() , - $node->mExactRootMatchCount, $filter_url, $filter_values ); + $results_line .= " · ("; + $num_printed_values_level = 0; + if ( $node->mExactRootMatchCount > 0 ) { + $filter_url = $cur_url . urlencode( str_replace( ' ', '_', $f->name ) ) . '=' . + urlencode( str_replace( ' ', '_', $node->mRootValue ) ); + $results_line .= $this->printFilterValueLink( $f, + wfMessage( 'cargo-drilldown-hierarchy-only', $node->mRootValue )->parse() , + $node->mExactRootMatchCount, $filter_url, $filter_values ); + $num_printed_values_level++; + } $stack->push( ")" ); } - $i = count( $node->mChildren ) - 1; - while ( $i >= 0 ) { + for( $i = count( $node->mChildren ) - 1; $i >= 0; $i--) { $stack->push( $node->mChildren[$i] ); - $i = $i - 1; } } } else { $results_line .= " ) "; + $depth--; } } return $results_line; diff --git a/extension.json b/extension.json index c20b440..5dfea12 100755 --- a/extension.json +++ b/extension.json @@ -305,6 +305,7 @@ "CargoDrilldownLargestFontSize": -1, "CargoDrilldownMinValuesForComboBox": 40, "CargoDrilldownNumRangesForNumbers": 5, + "CargoMaxVisibleHierarchyDrilldownValues": 30, "CargoPageDataColumns": [], "CargoFileDataColumns": [], "CargoHideNamespaceName": [6], -- To view, visit https://gerrit.wikimedia.org/r/372232 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iabed8a2d18d3a34cc07f43ecfdcbaf9569272d1e Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Cargo Gerrit-Branch: master Gerrit-Owner: Fz-29 <f29ah...@gmail.com> Gerrit-Reviewer: Fz-29 <f29ah...@gmail.com> Gerrit-Reviewer: Nischayn22 <nischay...@gmail.com> Gerrit-Reviewer: Oetterer <oette...@uni-paderborn.de> Gerrit-Reviewer: Yaron Koren <yaro...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits