Petar.petkovic has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/383986 )

Change subject: [WIP] Port Translate filters to new RC filters UI
......................................................................

[WIP] Port Translate filters to new RC filters UI

Bug: T159795
Change-Id: Id47e57487e13f90354e1cdfbb1e2f19fb869ac11
---
M Translate.php
M i18n/core/en.json
M i18n/core/qqq.json
M utils/RcFilter.php
4 files changed, 152 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate 
refs/changes/86/383986/1

diff --git a/Translate.php b/Translate.php
index 19b90b8..2d825b8 100644
--- a/Translate.php
+++ b/Translate.php
@@ -131,6 +131,8 @@
 // Recent changes filters
 $wgHooks['ChangesListSpecialPageQuery'][] = 
'TranslateRcFilter::translationFilter';
 $wgHooks['SpecialRecentChangesPanel'][] = 
'TranslateRcFilter::translationFilterForm';
+$wgHooks['ChangesListSpecialPageStructuredFilters'][] =
+'TranslateRcFilter::onChangesListSpecialPageStructuredFilters';
 $wgHooks['SkinTemplateToolboxEnd'][] = 
'TranslateToolbox::toolboxAllTranslations';
 $wgHooks['AbortEmailNotification'][] = 
'TranslateHooks::onAbortEmailNotificationReview';
 
diff --git a/i18n/core/en.json b/i18n/core/en.json
index c7fcaaf..5194287 100644
--- a/i18n/core/en.json
+++ b/i18n/core/en.json
@@ -114,6 +114,13 @@
        "action-translate-messagereview": "review translations",
        "right-translate-groupreview": "Change workflow state of message 
groups",
        "action-translate-groupreview": "change workflow state of message 
groups",
+       "translate-rcfilters-translations": "Translations",
+       "translate-rcfilters-translations-only-label": "Translations",
+       "translate-rcfilters-translations-only-desc": "Changes to translated 
pages.",
+       "translate-rcfilters-translations-filter-label": "Not translations",
+       "translate-rcfilters-translations-filter-desc": "All changes that are 
not translations.",
+       "translate-rcfilters-translations-site-label": "Site Messages",
+       "translate-rcfilters-translations-site-desc": "Customizations of site 
messages.",
        "translate-rc-translation-filter": "Filter translations:",
        "translate-rc-translation-filter-no": "Do nothing",
        "translate-rc-translation-filter-only": "Show translations only",
diff --git a/i18n/core/qqq.json b/i18n/core/qqq.json
index 9358dbf..ad959f0 100644
--- a/i18n/core/qqq.json
+++ b/i18n/core/qqq.json
@@ -147,6 +147,13 @@
        "right-translate-groupreview": "{{doc-right|translate-groupreview}}",
        "action-translate-groupreview": "{{doc-action|translate-groupreview}}",
        "translate-rc-translation-filter": "Name of filter in 
[[Special:RecentChanges]]. Gives a user the option to filter out translations, 
show translations only, or do nothing (default).",
+       "translate-rcfilters-translations": "Title for the filter group for 
translations. Only available on [[Special:RecentChanges]].",
+       "translate-rcfilters-translations-only-label": "Label for the filter 
for showing changes to translated pages only.",
+       "translate-rcfilters-translations-only-desc": "Description for the 
filter for showing changes to translated pages only.",
+       "translate-rcfilters-translations-filter-label": "Label for the filter 
for showing changes to pages that aren't translations.",
+       "translate-rcfilters-translations-filter-desc": "Description for the 
filter for showing changes to pages that aren't translations.",
+       "translate-rcfilters-translations-site-label": "Label for the filter 
for showing customizations of site messages.",
+       "translate-rcfilters-translations-site-desc": "Description for the 
filter for showing customizations of site messages.",
        "translate-rc-translation-filter-no": "Option for filter in 
[[Special:RecentChanges]]. Selecting this option results in the filter not 
doing anything. It is the default value.",
        "translate-rc-translation-filter-only": "Option for filter in 
[[Special:RecentChanges]]. Selecting this option results in the filter only 
showing recent changes that are translations.",
        "translate-rc-translation-filter-filter": "Option for filter in 
[[Special:RecentChanges]]. Selecting this option results in the filter not 
showing any recent changes that are translations.",
diff --git a/utils/RcFilter.php b/utils/RcFilter.php
index 82ce523..2b865b9 100644
--- a/utils/RcFilter.php
+++ b/utils/RcFilter.php
@@ -28,12 +28,12 @@
         * @param FormOptions $opts
         * @return bool true
         */
-       public static function translationFilter( $pageName, &$tables, 
&$fields, &$conds, &$query_options,
-               &$join_conds, FormOptions $opts
+       public static function translationFilter( $pageName, &$tables, 
&$fields, &$conds,
+               &$query_options, &$join_conds, FormOptions $opts
        ) {
-               global $wgTranslateMessageNamespaces, 
$wgTranslateRcFilterDefault;
+               global $wgTranslateRcFilterDefault;
 
-               if ( $pageName !== 'Recentchanges' ) {
+               if ( $pageName !== 'Recentchanges' || 
self::isStructuredFilterUiEnabled() ) {
                        return true;
                }
 
@@ -44,12 +44,7 @@
 
                $dbr = wfGetDB( DB_REPLICA );
 
-               $namespaces = [];
-
-               foreach ( $wgTranslateMessageNamespaces as $index ) {
-                       $namespaces[] = $index;
-                       $namespaces[] = $index + 1; // Talk too
-               }
+               $namespaces = self::getTranslateNamespaces();
 
                if ( $translations === 'only' ) {
                        $conds[] = 'rc_namespace IN (' . $dbr->makeList( 
$namespaces ) . ')';
@@ -64,6 +59,18 @@
                return true;
        }
 
+       private static function getTranslateNamespaces() {
+               global $wgTranslateMessageNamespaces;
+               $namespaces = [];
+
+               foreach ( $wgTranslateMessageNamespaces as $index ) {
+                       $namespaces[] = $index;
+                       $namespaces[] = $index + 1; // Include Talk namespaces
+               }
+
+               return $namespaces;
+       }
+
        /**
         * Hooks SpecialRecentChangesPanel. See the hook documentation for
         * documentation of the function parameters.
@@ -74,6 +81,10 @@
         * @return bool true
         */
        public static function translationFilterForm( &$items, $opts ) {
+               if ( self::isStructuredFilterUiEnabled() ) {
+                       return true;
+               }
+
                $opts->consumeValue( 'translations' );
                $default = $opts->getValue( 'translations' );
 
@@ -97,4 +108,119 @@
 
                return true;
        }
+
+       private static function isStructuredFilterUiEnabled() {
+               $context = RequestContext::getMain();
+
+               // This assumes usage only on RC page
+               $page = new SpecialRecentChanges();
+               $page->setContext( $context );
+
+               return $page->isStructuredFilterUiEnabled();
+       }
+
+       /**
+        * Hooks ChangesListSpecialPageStructuredFilters. See the hook 
documentation for
+        * documentation of the function parameters.
+        *
+        * Adds translations filters to structured UI
+        * @param ChangesListSpecialPage $special
+        * @return bool true
+       */
+       public static function onChangesListSpecialPageStructuredFilters(
+               ChangesListSpecialPage $special
+       ) {
+               global $wgTranslateRcFilterDefault;
+               $defaultFilter = $wgTranslateRcFilterDefault !== 'noaction' ?
+                       $wgTranslateRcFilterDefault :
+                       ChangesListStringOptionsFilterGroup::NONE;
+
+               $translationsGroup = new ChangesListStringOptionsFilterGroup(
+                       [
+                               'name' => 'translations',
+                               'title' => 'translate-rcfilters-translations',
+                               'priority' => -7,
+                               'default' => $defaultFilter,
+                               'isFullCoverage' => true,
+                               'filters' => [
+                                       [
+                                               'name' => 'only',
+                                               'label' => 
'translate-rcfilters-translations-only-label',
+                                               'description' => 
'translate-rcfilters-translations-only-desc',
+                                               'cssClassSuffix' => 'only',
+                                               'isRowApplicableCallable' => 
function ( $ctx, $rc ) {
+                                                       $namespaces = 
self::getTranslateNamespaces();
+
+                                                       return in_array( 
$rc->getAttribute( 'rc_namespace' ), $namespaces ) &&
+                                                               strpos( 
$rc->getAttribute( 'rc_title' ), '/' ) !== false;
+                                               }
+                                       ],
+                                       [
+                                               'name' => 'filter',
+                                               'label' => 
'translate-rcfilters-translations-filter-label',
+                                               'description' => 
'translate-rcfilters-translations-filter-desc',
+                                               'cssClassSuffix' => 'filter',
+                                               'isRowApplicableCallable' => 
function ( $ctx, $rc ) {
+                                                       $namespaces = 
self::getTranslateNamespaces();
+
+                                                       return !in_array( 
$rc->getAttribute( 'rc_namespace' ), $namespaces );
+                                               }
+                                       ],
+                                       [
+                                               'name' => 'site',
+                                               'label' => 
'translate-rcfilters-translations-site-label',
+                                               'description' => 
'translate-rcfilters-translations-site-desc',
+                                               'cssClassSuffix' => 'site',
+                                               'isRowApplicableCallable' => 
function ( $ctx, $rc ) {
+                                                       $namespaces = 
self::getTranslateNamespaces();
+
+                                                       return in_array( 
$rc->getAttribute( 'rc_namespace' ), $namespaces ) &&
+                                                               strpos( 
$rc->getAttribute( 'rc_title' ), '/' ) === false;
+                                               }
+                                       ],
+                               ],
+                               'queryCallable' => function ( 
$specialClassName, $ctx, $dbr, &$tables,
+                                       &$fields, &$conds, &$query_options, 
&$join_conds, $selectedValues
+                               ) {
+                                       $fields[] = 'rc_title';
+                                       $fields[] = 'rc_namespace';
+
+                                       $namespaces = 
self::getTranslateNamespaces();
+                                       $inNamespaceCond = 'rc_namespace IN (' .
+                                               $dbr->makeList( $namespaces ) . 
')';
+                                       $notInNamespaceCond = 'rc_namespace NOT 
IN (' .
+                                               $dbr->makeList( $namespaces ) . 
')';
+                                       $hasSlashCond = 'rc_title ' .
+                                               $dbr->buildLike( 
$dbr->anyString(), '/', $dbr->anyString() );
+                                       $noSlashCond = 'rc_title NOT' .
+                                               $dbr->buildLike( 
$dbr->anyString(), '/', $dbr->anyString() );
+
+                                       if ( count( $selectedValues ) !== 1 ) {
+                                               // All filters are exclusive
+                                               return;
+                                       }
+
+                                       if ( $selectedValues === [ 'only' ] ) {
+                                               $conds[] = $inNamespaceCond;
+                                               $conds[] = $hasSlashCond;
+                                               return;
+                                       }
+
+                                       if ( $selectedValues === [ 'filter' ] ) 
{
+                                               $conds[] = $notInNamespaceCond;
+                                               return;
+                                       }
+
+                                       if ( $selectedValues === [ 'site' ] ) {
+                                               $conds[] = $inNamespaceCond;
+                                               $conds[] = $noSlashCond;
+                                               return;
+                                       }
+                               }
+                       ]
+               );
+
+               $special->registerFilterGroup( $translationsGroup );
+               return true;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id47e57487e13f90354e1cdfbb1e2f19fb869ac11
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Petar.petkovic <ppetko...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to