Page MenuHomePhabricator

Support for i18n int strings (throug int option)
Open, Needs TriagePublic

Description

Support MediaWiki Messages ({{int: strings) in SemanticDrilldown. They will be used for rending the labels

Example:

{{#drilldowninfo:filters=
  Tag (property=Tag,int=SA Tag Tags),
  |display parameters=?Sort Key;?Short Description;?Tag;format=broadtable;mainlabel={{int:SA Subject Area Subject Area}};
  |header=Template:S Subject Area Drilldown Header
}}

Patch:

Index: includes/SD_ParserFunctions.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- includes/SD_ParserFunctions.php	(revision 78c5fe9b5a9eb1a12a9eb97d1ad73495a388cb93)
+++ includes/SD_ParserFunctions.php	(revision )
@@ -82,7 +82,7 @@
 					continue;
 				}
 				$key = trim( $filterSetting[0] );
-				if ( $key != 'property' && $key != 'category' && $key != 'requires' ) {
+				if ( $key != 'property' && $key != 'category' && $key != 'requires' && $key != 'int') {
 					return "<div class=\"error\">Error: unknown setting, \"$key\".</div>";
 					// Display an error message?
 					continue;
Index: includes/SD_Filter.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- includes/SD_Filter.php	(revision 78c5fe9b5a9eb1a12a9eb97d1ad73495a388cb93)
+++ includes/SD_Filter.php	(revision )
@@ -39,7 +39,11 @@
 	public function addRequiredFilter( $filterName ) {
 		$this->required_filters[] = $filterName;
 	}
-	
+
+	public function addInt( $int ) {
+		$this->int = $int;
+	}
+	
 	static function loadAllFromPageSchema( $psSchemaObj ){
 		$filters_ps = array();		
 		$template_all = $psSchemaObj->getTemplates();						
Index: includes/SD_Utils.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- includes/SD_Utils.php	(revision 78c5fe9b5a9eb1a12a9eb97d1ad73495a388cb93)
+++ includes/SD_Utils.php	(revision )
@@ -200,6 +200,8 @@
 						$curFilter->setCategory( $value );
 					} elseif ( $key == 'requires' ) {
 						$curFilter->addRequiredFilter( $value );
+					} elseif ( $key == 'int' ) {
+						$curFilter->addInt( $value );
 					}
 				}
 				$filters[] = $curFilter;
Index: specials/SD_BrowseData.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- specials/SD_BrowseData.php	(revision 78c5fe9b5a9eb1a12a9eb97d1ad73495a388cb93)
+++ specials/SD_BrowseData.php	(revision )
@@ -473,15 +473,20 @@
 	 * Create the full display of the filter line, once the text for
 	 * the "results" (values) for this filter has been created.
 	 */
-	function printFilterLine( $filterName, $isApplied, $isNormalFilter, $resultsLine ) {
+	function printFilterLine( $filterName, $isApplied, $isNormalFilter, $resultsLine, $filter ) {
 		global $sdgScriptPath;
 		global $sdgDisableFilterCollapsible;
 
 		$filterLabel = $this->printFilterLabel( $filterName );
 
+		$label = $filterLabel;
+		if ( isset( $filter->int ) ) {
+			$label = wfMessage( $filter->int )->text();
+		}
+
 		if ($sdgDisableFilterCollapsible) {
 			$text  = '<div class="drilldown-filter">';
-			$text .= '	<div class="drilldown-filter-label">' . $filterLabel . '</div>';
+			$text .= '	<div class="drilldown-filter-label">' . $label . '</div>';
 			$text .= '	<div class="drilldown-filter-values">' . $resultsLine . '</div>';
 			$text .= '</div>';
 
@@ -568,7 +573,7 @@
 			}
 			$curSearchTermNum = count( $af->search_terms );
 			$results_line = $this->printComboBoxInput( $af->filter->name, $curSearchTermNum, $filter_values );
-			return $this->printFilterLine( $af->filter->name, true, true, $results_line );
+			return $this->printFilterLine( $af->filter->name, true, true, $results_line, $af->filter );
 		/*
 		} elseif ( $af->lower_date != null || $af->upper_date != null ) {
 			// With the current interface, this code will never get
@@ -615,7 +620,8 @@
 				}
 			}
 		}
-		return $this->printFilterLine( $af->filter->name, true, true, $results_line );
+
+		return $this->printFilterLine( $af->filter->name, true, true, $results_line, $af->filter);
 	}
 
 	function printUnappliedFilterValues( $cur_url, $f, $filter_values ) {
@@ -985,7 +991,7 @@
 			}
 			if ( !is_array( $filter_values ) ) {
 				$f->dropTempTable();
-				return $this->printFilterLine( $f->name, false, false, $filter_values );
+				return $this->printFilterLine( $f->name, false, false, $filter_values, $f );
 			}
 			if ( count( $filter_values ) > 0 ) {
 				$found_results_for_filter = true;
@@ -1039,7 +1045,7 @@
 			$results_line = $this->printUnappliedFilterValues( $cur_url, $f, $filter_values );
 		}
 
-		$text = $this->printFilterLine( $f->name, false, $normal_filter, $results_line );
+		$text = $this->printFilterLine( $f->name, false, $normal_filter, $results_line, $f );
 		$f->dropTempTable();
 
 		if ( $sdgHideFiltersWithoutValues && count( $filter_values ) == 0 ) {
@@ -1202,11 +1208,17 @@
 					} else {
 						$header .= $this->printAppliedFilterLine( $af );
 					}
+					if (isset($f->int)) {
+						$af->int = $f->int;
-				}
-			}
+					}
+				}
+			}
 			foreach ( $this->remaining_filters as $rf ) {
 				if ( $rf->name == $f->name ) {
 					$header .= $this->printUnappliedFilterLine( $rf, $cur_url );
+				}
+				if (isset($f->int)) {
+					$rf->int = $f->int;
 				}
 			}
 		}

Event Timeline

Fannon created this task.May 19 2016, 10:58 AM
Restricted Application added subscribers: Zppix, Aklapper. · View Herald TranscriptMay 19 2016, 10:58 AM

When testing, I found a bug where some int labels were assigned to the wrong filter:

Index: specials/SD_BrowseData.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- specials/SD_BrowseData.php	(revision 040570f230c85e8b8fce610f39a63c8ef00bbfa4)
+++ specials/SD_BrowseData.php	(revision )
@@ -1217,17 +1217,11 @@
 					} else {
 						$header .= $this->printAppliedFilterLine( $af );
 					}
-					if (isset($f->int)) {
-						$af->int = $f->int;
-					}
-				}
+				}
+			}
-			}
 			foreach ( $this->remaining_filters as $rf ) {
 				if ( $rf->name == $f->name ) {
 					$header .= $this->printUnappliedFilterLine( $rf, $cur_url );
-				}
-				if (isset($f->int)) {
-					$rf->int = $f->int;
 				}
 			}
 		}
Aklapper renamed this task from NEW FEATURE: Support for i18n int strings (throug int option) to Support for i18n int strings (throug int option).May 19 2016, 12:57 PM

Is this "ready to merge"?

​Yes, this should be ready to merge, but the second patch needs to be
included as well. It removes a few lines of code that were unnecessary and
messed something up in one case.

Thanks Yaron!
Simon​

Oh, okay.

By the way, what's the point of the addInt() method? You're not treating $int as a private field anywhere else.

Oh, that's a leftover - sorry!

Alright. Actually, looking at the code, I see what you did there - you copied from the other setter methods in class. (Though it should be setInt(), not addInt()).

Another question: why did you add another variable, $label, instead of just using the $filterLabel variable?

Oh no, $label shouldn't be there,either :(

I tried to get this working by labels, but the int-strings will be replaced
and stored as page properties when the page containing #drilldowninfo is
saved. So I had to revert this and use "int" instead, which is translated
dynamically on display of Semantic Drilldown.

Aklapper removed Yaron_Koren as the assignee of this task.Jun 19 2020, 4:15 PM
Aklapper added a subscriber: Yaron_Koren.

This task has been assigned to the same task owner for more than two years. Resetting task assignee due to inactivity, to decrease task cookie-licking and to get a slightly more realistic overview of plans. Please feel free to assign this task to yourself again if you still realistically work or plan to work on this task - it would be welcome!

For tips how to manage individual work in Phabricator (noisy notifications, lists of task, etc.), see https://phabricator.wikimedia.org/T228575#6237124 for available options.
(For the records, two emails were sent to assignee addresses before resetting assignees. See T228575 for more info and for potential feedback. Thanks!)

Restricted Application added a subscriber: Liuxinyu970226. · View Herald TranscriptJun 19 2020, 4:15 PM