Nemo bis has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/345784 )
Change subject: [WIP] Allow to filter Special:SupportedLanguages by message
group
......................................................................
[WIP] Allow to filter Special:SupportedLanguages by message group
Bug: T64196
Change-Id: I6e607b752227a40d920f97a0a7fdec19f440a262
---
M specials/SpecialMessageGroupStats.php
M specials/SpecialSupportedLanguages.php
2 files changed, 73 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Translate
refs/changes/84/345784/1
diff --git a/specials/SpecialMessageGroupStats.php
b/specials/SpecialMessageGroupStats.php
index 3af184e..53cfba3 100644
--- a/specials/SpecialMessageGroupStats.php
+++ b/specials/SpecialMessageGroupStats.php
@@ -306,7 +306,7 @@
* @param string|bool $default Group id of the group chosen by default.
Optional.
* @return XmlSelect
*/
- protected function getGroupSelector( $default = false ) {
+ static function getGroupSelector( $default = false ) {
$groups = MessageGroups::getAllGroups();
$selector = new XmlSelect( 'group', 'group', $default );
diff --git a/specials/SpecialSupportedLanguages.php
b/specials/SpecialSupportedLanguages.php
index f337101..7d77a26 100644
--- a/specials/SpecialSupportedLanguages.php
+++ b/specials/SpecialSupportedLanguages.php
@@ -41,7 +41,7 @@
$out = $this->getOutput();
$lang = $this->getLanguage();
- // Only for manual debugging nowdays
+ // Only for manual debugging nowadays
$this->purge = false;
$this->setHeaders();
@@ -69,31 +69,58 @@
$this->outputLanguageCloud( $languages, $names );
$out->addWikiMsg( 'supportedlanguages-count', $lang->formatNum(
count( $languages ) ) );
+ $out .= Html::openElement( 'div' );
+ $out .= Html::openElement( 'form', [ 'method' => 'get',
'action' => $wgScript ] );
+ $out .= Html::hidden( 'title',
$this->getPageTitle()->getPrefixedText() );
+ $out->addHTML( SpecialMessageGroupStats::getGroupSelector() );
+ $out .= Xml::submitButton( $this->msg( 'translate-mgs-submit'
)->text() );
+ $out .= Html::closeElement( 'form' );
+ $out .= Html::closeElement( 'div' );
+
if ( $par && Language::isKnownLanguageTag( $par ) ) {
$code = $par;
+ $request = $this->getRequest();
+ $group = $request->getText( 'group' );
$out->addWikiMsg( 'supportedlanguages-colorlegend',
$this->getColorLegend() );
- $users = $this->fetchTranslators( $code );
- if ( $users === false ) {
- // generic-pool-error is from MW core
- $out->wrapWikiMsg( '<div
class="warningbox">$1</div>', 'generic-pool-error' );
- return;
- }
+ if ( $group === '' ) {
+ $users = $this->fetchTranslators( $code );
+ if ( $users === false ) {
+ // generic-pool-error is from MW core
+ $out->wrapWikiMsg( '<div
class="warningbox">$1</div>', 'generic-pool-error' );
+ return;
+ }
- global $wgTranslateAuthorBlacklist;
- $users = $this->filterUsers( $users, $code,
$wgTranslateAuthorBlacklist );
- $this->preQueryUsers( $users );
- $this->showLanguage( $code, $users );
+ $this->showLanguage( $code, $users );
+ } else {
+ foreach ( $languages as $code ) {
+ $users = $this->fetchTranslators(
$code, $group );
+ if ( $users === false ) {
+ // generic-pool-error is from
MW core
+ $out->wrapWikiMsg( '<div
class="warningbox">$1</div>', 'generic-pool-error' );
+ return;
+ }
+ $this->showLanguage( $code, $users,
$group );
+ }
+ }
}
}
- protected function showLanguage( $code, $users ) {
+ protected function showLanguage( $code, $users, $group = '' ) {
$out = $this->getOutput();
$lang = $this->getLanguage();
+ global $wgTranslateAuthorBlacklist;
+ $users = $this->filterUsers( $users, $code,
$wgTranslateAuthorBlacklist );
+ $this->preQueryUsers( $users );
$usernames = array_keys( $users );
- $userStats = $this->getUserStats( $usernames );
+ if ( $group === '' ) {
+ $userStats = $this->getUserStats( $usernames );
+ } else {
+ // Use the numbers from fetchTranslators() for this group
+ $userStats = $users;
+ }
// Information to be used inside the foreach loop.
$linkInfo = [];
@@ -186,11 +213,12 @@
* Fetch the translators for a language with caching
*
* @param string $code
+ * @param string $group
* @return array|bool Map of (user name => page count) or false on
failure
*/
- public function fetchTranslators( $code ) {
+ public function fetchTranslators( $code = '', $group = '' ) {
$cache = wfGetCache( CACHE_ANYTHING );
- $cachekey = wfMemcKey(
'translate-supportedlanguages-translator-list-v1', $code );
+ $cachekey = wfMemcKey(
'translate-supportedlanguages-translator-list-v1', $code, $group );
if ( $this->purge ) {
$cache->delete( $cachekey );
@@ -208,8 +236,8 @@
'TranslateFetchTranslators',
"TranslateFetchTranslators-$code",
[
- 'doWork' => function () use ( $that, $code,
$cache, $cachekey ) {
- $users = $that->loadTranslators( $code
);
+ 'doWork' => function () use ( $that, $code,
$group, $cache, $cachekey ) {
+ $users = $that->loadTranslators( $code,
$group );
$newData = [ 'users' => $users,
'asOfTime' => time() ];
$cache->set( $cachekey, $newData, 86400
);
return $users;
@@ -230,25 +258,46 @@
}
/**
- * Fetch the translators for a language
+ * Fetch the translators for a language and/or group
*
* @param string $code
+ * @param string $group
* @return array Map of (user name => page count)
*/
- public function loadTranslators( $code ) {
+ public function loadTranslators( $code = '', $group = '' ) {
global $wgTranslateMessageNamespaces;
$dbr = wfGetDB( DB_SLAVE, 'vslow' );
+ if ( $code == '' ) {
+ $suffix = '/' . $dbr->anyString();
+ } else {
+ $suffix = '/' . $code;
+ }
+ if ( $group == '' ) {
+ $condsTitle = [ 'page_title' . $dbr->buildLike(
$dbr->anyString(), $suffix ) ];
+ } else {
+ $groupObj = MessageGroups::getGroup( $group );
+ $keys = $groupObj->getKeys();
+ $namespace = $wgContLang->getNsText(
$groupObj->getNamespace() );
+ $condsTitle = [];
+ foreach ( $keys as $title ) {
+ $condsTitle[] = 'OR page_title' .
$dbr->buildLike(
+ $namespace . $title . $suffix
+ );
+ }
+ $condsTitle[0] = substr_replace( $condsTitle[0], '(',
0, 2 );
+ }
+
+
$tables = [ 'page', 'revision' ];
$fields = [
'rev_user_text',
- 'count(page_id) as count'
+ 'count(rev_id) as count'
];
- $conds = [
- 'page_title' . $dbr->buildLike( $dbr->anyString(), '/',
$code ),
+ $conds = array_merge( [
'page_namespace' => $wgTranslateMessageNamespaces,
'page_id=rev_page',
- ];
+ ], $condsTitle );
$options = [ 'GROUP BY' => 'rev_user_text', 'ORDER BY' =>
'NULL' ];
$res = $dbr->select( $tables, $fields, $conds, __METHOD__,
$options );
--
To view, visit https://gerrit.wikimedia.org/r/345784
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e607b752227a40d920f97a0a7fdec19f440a262
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Nemo bis <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits