jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/383986 )
Change subject: Port Translate filters to new RC filters UI
......................................................................
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, 177 insertions(+), 10 deletions(-)
Approvals:
jenkins-bot: Verified
Nikerabbit: Checked; Looks good to me, approved
diff --git a/Translate.php b/Translate.php
index 93579ec..b9edc9d 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..547e4ff 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 in MediaWiki namespace.",
"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..de9197b 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,144 @@
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' => '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' => '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' => '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 ) .
')';
+
+ $onlyCond = $dbr->makeList( [
+ $inNamespaceCond,
+ 'rc_title ' .
+ $dbr->buildLike(
$dbr->anyString(), '/', $dbr->anyString() )
+ ], LIST_AND );
+ $siteCond = $dbr->makeList( [
+ $inNamespaceCond,
+ 'rc_title NOT' .
+ $dbr->buildLike(
$dbr->anyString(), '/', $dbr->anyString() )
+ ], LIST_AND );
+
+ if ( count( $selectedValues ) === 3 ) {
+ // no filters
+ return;
+ }
+
+ if ( $selectedValues === [ 'filter',
'only' ] ) {
+ $conds[] = $dbr->makeList( [
+ $notInNamespaceCond,
+ $onlyCond
+ ], LIST_OR );
+ return;
+ }
+
+ if ( $selectedValues === [ 'filter',
'site' ] ) {
+ $conds[] = $dbr->makeList( [
+ $notInNamespaceCond,
+ $siteCond
+ ], LIST_OR );
+ return;
+ }
+
+ if ( $selectedValues === [ 'only',
'site' ] ) {
+ $conds[] = $inNamespaceCond;
+ return;
+ }
+
+ if ( $selectedValues === [ 'filter' ] )
{
+ $conds[] = $notInNamespaceCond;
+ return;
+ }
+
+ if ( $selectedValues === [ 'only' ] ) {
+ $conds[] = $onlyCond;
+ return;
+ }
+
+ if ( $selectedValues === [ 'site' ] ) {
+ $conds[] = $siteCond;
+ }
+ }
+ ]
+ );
+
+ $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: merged
Gerrit-Change-Id: Id47e57487e13f90354e1cdfbb1e2f19fb869ac11
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Petar.petkovic <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Petar.petkovic <[email protected]>
Gerrit-Reviewer: Sbisson <[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