jenkins-bot has submitted this change and it was merged.

Change subject: Use TUX elements to build tabs.
......................................................................


Use TUX elements to build tabs.

Make a switch between translated, untranslated and outdated translations
through tabs. Used ellipsis options to swap between the last two tabs
since the tab header would overflow, thereby misaligning the tabs.

Bug: T100175
Change-Id: I85f691b6fed96434ef0b5e80cefa1e0d59dba2ff
---
M i18n/search/en.json
M i18n/search/qqq.json
M resources/css/ext.translate.special.searchtranslations.css
M specials/SpecialSearchTranslations.php
M ttmserver/CrossLanguageTranslationSearchQuery.php
5 files changed, 155 insertions(+), 5 deletions(-)

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



diff --git a/i18n/search/en.json b/i18n/search/en.json
index 8677188..6338ce0 100644
--- a/i18n/search/en.json
+++ b/i18n/search/en.json
@@ -18,5 +18,11 @@
        "tux-sst-solr-offline-title": "Search unavailable",
        "tux-sst-solr-offline-body": "The search service is temporarily 
unavailable.",
        "tux-sst-next": "Next ›",
-       "tux-sst-prev": "‹ Previous"
+       "tux-sst-prev": "‹ Previous",
+       "tux-sst-default": "Translations",
+       "tux-sst-translated": "Translations from $1",
+       "tux-sst-untranslated": "No translation from $1",
+       "tux-sst-outdated": "Outdated translations from $1",
+       "tux-sst-ellipsis-untranslated": "No translation",
+       "tux-sst-ellipsis-outdated": "Outdated translations"
 }
diff --git a/i18n/search/qqq.json b/i18n/search/qqq.json
index 6b1c8f8..1a5d303 100644
--- a/i18n/search/qqq.json
+++ b/i18n/search/qqq.json
@@ -20,5 +20,11 @@
        "tux-sst-solr-offline-title": "Used as title of error page.\n\nThe body 
of error message is {{msg-mw|Tux-sst-solr-offline-body}}.\n{{Identical|Search 
unavailable}}",
        "tux-sst-solr-offline-body": "Used as error message.\n\nThe page title 
for this message is {{msg-mw|tux-sst-solr-offline-title}}.",
        "tux-sst-next": "Link to browser more search results.\n\nSee also:\n* 
{{msg-mw|Tux-sst-prev}}",
-       "tux-sst-prev": "Link to browser more search results.\n\nSee also:\n* 
{{msg-mw|Tux-sst-next}}"
+       "tux-sst-prev": "Link to browser more search results.\n\nSee also:\n* 
{{msg-mw|Tux-sst-next}}",
+       "tux-sst-default": "Label for a tab to show translations for the 
language.",
+       "tux-sst-translated": "Label for a tab to show translated messages 
matching the query in the source language. Parameters:\n* $1 - the language 
code of the source text.",
+       "tux-sst-untranslated": "Label for a tab to show untranslated messages 
matching the query in the source language. Parameters:\n* $1 - the language 
code of the source text.",
+       "tux-sst-outdated": "Label for a tab to show outdated messages matching 
the query in the source language. Parameters:\n* $1 - the language code of the 
source text.",
+       "tux-sst-ellipsis-untranslated": "Used as label for an ellipsis to hide 
untranslated messages.",
+       "tux-sst-ellipsis-outdated": "Used as label for an ellipsis to hide 
outdated messages."
 }
diff --git a/resources/css/ext.translate.special.searchtranslations.css 
b/resources/css/ext.translate.special.searchtranslations.css
index 5a7b8c6..7ab43a1 100644
--- a/resources/css/ext.translate.special.searchtranslations.css
+++ b/resources/css/ext.translate.special.searchtranslations.css
@@ -167,3 +167,16 @@
        font-size: 14px;
        padding: 0 8px;
 }
+
+/* Override tabs */
+.tux-searchpage .tux-messagetable-header .seven {
+       width: 100%;
+}
+
+.tux-searchpage .tux-message-selector .more ul {
+       width: auto;
+}
+
+.tux-searchpage .tux-message-selector .more ul a {
+       white-space: pre-wrap;
+}
diff --git a/specials/SpecialSearchTranslations.php 
b/specials/SpecialSearchTranslations.php
index e83ccab..273505a 100644
--- a/specials/SpecialSearchTranslations.php
+++ b/specials/SpecialSearchTranslations.php
@@ -62,6 +62,7 @@
 
                $out = $this->getOutput();
                $out->addModules( 'ext.translate.special.searchtranslations' );
+               $out->addModuleStyles( 'ext.translate.special.translate' );
 
                $this->opts = $opts = new FormOptions();
                $opts->add( 'query', '' );
@@ -87,6 +88,10 @@
                $filter = $opts->getValue( 'filter' );
                try {
                        if ( $filter !== '' ) {
+                               if ( $opts->getValue( 'language' ) === '' ) {
+                                       $params['language'] = 
$this->getLanguage()->getCode();
+                                       $opts->setValue( 'language', 
$params['language'] );
+                               }
                                $translationSearch = new 
CrossLanguageTranslationSearchQuery( $params, $server );
                                $documents = $translationSearch->getDocuments();
                                $total = $translationSearch->getTotalHits();
@@ -106,6 +111,12 @@
                $facetHtml = '';
 
                if ( count( $facets['language'] ) > 0 ) {
+                       if ( $filter !== '' ) {
+                               $facets['language'] = array_merge(
+                                       $facets['language'],
+                                       array( $opts->getValue( 'language' ) => 
$total )
+                               );
+                       }
                        $facetHtml = Html::element( 'div',
                                array( 'class' => 'row facet languages',
                                        'data-facets' => FormatJson::encode( 
$this->getLanguages( $facets['language'] ) ),
@@ -236,9 +247,16 @@
 
                $nondefaults = $this->opts->getChangedValues();
                $selected = $this->opts->getValue( 'language' );
+               $filter = $this->opts->getValue( 'filter' );
 
                foreach ( $facet as $key => $value ) {
-                       if ( $key === $selected ) {
+                       if ( $filter !== '' && $key === $selected ) {
+                               unset( $nondefaults['language'] );
+                               unset( $nondefaults['filter'] );
+                       } elseif ( $filter !== '' ) {
+                               $nondefaults['language'] = $key;
+                               $nondefaults['filter'] = $filter;
+                       } elseif ( $key === $selected ) {
                                unset( $nondefaults['language'] );
                        } else {
                                $nondefaults['language'] = $key;
@@ -313,10 +331,11 @@
        }
 
        protected function showSearch( $search, $count, $facets, $results ) {
+               $messageSelector = $this->messageSelector();
                $this->getOutput()->addHtml( <<<HTML
 <div class="grid tux-searchpage">
        <div class="row searchinput">
-               <div class="nine columns offset-by-three">$search</div>
+               <div class="nine columns offset-by-three">$messageSelector 
$search</div>
        </div>
        <div class="row count">
                <div class="nine columns offset-by-three">$count</div>
@@ -342,6 +361,112 @@
                );
        }
 
+       // Build ellipsis to select options
+       protected function ellipsisSelector( $key, $value ) {
+               $nondefaults = $this->opts->getChangedValues();
+               $taskParams = array( 'filter' => $value ) + $nondefaults;
+               ksort( $taskParams );
+               $href = $this->getTitle()->getLocalUrl( $taskParams );
+               $link = Html::element( 'a',
+                       array( 'href' => $href ),
+                       // Messages for grepping:
+                       // tux-sst-ellipsis-untranslated
+                       // tux-sst-ellipsis-outdated
+                       $this->msg( 'tux-sst-ellipsis-' . $key )->text()
+               );
+
+               $container = Html::rawElement( 'li', array(
+                       'class' => 'column',
+                       'data-filter' => $value,
+                       'data-title' => $key,
+               ), $link );
+
+               return $container;
+       }
+
+       /*
+        * Design the tabs
+        */
+       protected function messageSelector() {
+               $nondefaults = $this->opts->getChangedValues();
+               $output = Html::openElement( 'div', array( 'class' => 'row 
tux-messagetable-header' ) );
+               $output .= Html::openElement( 'div', array( 'class' => 'seven 
columns' ) );
+               $output .= Html::openElement( 'ul', array( 'class' => 'row 
tux-message-selector' ) );
+               $tabs = array(
+                       'default' => '',
+                       'translated' => 'translated',
+                       'untranslated' => 'untranslated'
+               );
+
+               $ellipsisOptions = array(
+                       'outdated' => 'fuzzy'
+               );
+
+               $selected = $this->opts->getValue( 'filter' );
+               $keys = array_keys( $tabs );
+               if ( !in_array( $selected, array_values( $tabs ) ) ) {
+                       $key = $keys[count( $keys ) - 1];
+                       $ellipsisOptions = array( $key => $tabs[$key] );
+
+                       // Remove the last tab
+                       unset( $tabs[$key] );
+                       $tabs = array_merge( $tabs, array( 'outdated' => 
$selected ) );
+               }
+
+               $container = Html::openElement( 'ul', array( 'class' => 'column 
tux-message-selector' ) );
+               foreach ( $ellipsisOptions as $optKey => $optValue ) {
+                       $container .= $this->ellipsisSelector( $optKey, 
$optValue );
+               }
+
+               $sourcelanguage = $this->opts->getValue( 'sourcelanguage' );
+               $sourcelanguage = TranslateUtils::getLanguageName( 
$sourcelanguage );
+               foreach ( $tabs as $tab => $filter ) {
+                       // Messages for grepping:
+                       // tux-sst-default
+                       // tux-sst-translated
+                       // tux-sst-untranslated
+                       // tux-sst-outdated
+                       $tabClass = "tux-sst-$tab";
+                       $taskParams = array( 'filter' => $filter ) + 
$nondefaults;
+                       ksort( $taskParams );
+                       $href = $this->getTitle()->getLocalUrl( $taskParams );
+                       if ( $tab === 'default' ) {
+                               $link = Html::element(
+                                       'a',
+                                       array( 'href' => $href ),
+                                       $this->msg( $tabClass )->text()
+                               );
+                       } else {
+                               $link = Html::element(
+                                       'a',
+                                       array( 'href' => $href ),
+                                       $this->msg( $tabClass, $sourcelanguage 
)->text()
+                               );
+                       }
+
+                       if ( $selected === $filter ) {
+                               $tabClass = $tabClass . ' selected';
+                       }
+                       $output .= Html::rawElement( 'li', array(
+                               'class' => array( 'column', $tabClass ),
+                               'data-filter' => $filter,
+                               'data-title' => $tab,
+                       ), $link );
+               }
+
+               // More column
+               $output .= Html::openElement( 'li', array( 'class' => 'column 
more' ) ) .
+                       '...' .
+                       $container .
+                       Html::closeElement( 'li' );
+
+               $output .= Html::closeElement( 'ul' );
+               $output .= Html::closeElement( 'div' );
+               $output .= Html::closeElement( 'div' );
+
+               return $output;
+       }
+
        protected function getSearchInput( $query ) {
                $attribs = array(
                        'placeholder' => $this->msg( 'tux-sst-search-ph' ),
diff --git a/ttmserver/CrossLanguageTranslationSearchQuery.php 
b/ttmserver/CrossLanguageTranslationSearchQuery.php
index 72f0c7c..0ba0e1c 100644
--- a/ttmserver/CrossLanguageTranslationSearchQuery.php
+++ b/ttmserver/CrossLanguageTranslationSearchQuery.php
@@ -67,7 +67,7 @@
        protected function extractMessages( $resultset, $offset, $limit ) {
                $messages = $documents = $ret = array();
 
-               $language = RequestContext::getMain()->getLanguage()->getCode();
+               $language = $this->params['language'];
                foreach ( $resultset->getResults() as $document ) {
                        $data = $document->getData();
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I85f691b6fed96434ef0b5e80cefa1e0d59dba2ff
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Phoenix303 <[email protected]>
Gerrit-Reviewer: Nemo bis <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Phoenix303 <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to