Amire80 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/54632


Change subject: (bug 43030) WIP: Filter unneeded messages from !additions
......................................................................

(bug 43030) WIP: Filter unneeded messages from !additions

Not thoroughly tested yet

Change-Id: Ib5e7c6c53cbe40f215232796d3e148a17d66ecdd
---
M messagegroups/RecentAdditionsMessageGroup.php
M messagegroups/RecentMessageGroup.php
2 files changed, 50 insertions(+), 1 deletion(-)


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

diff --git a/messagegroups/RecentAdditionsMessageGroup.php 
b/messagegroups/RecentAdditionsMessageGroup.php
index 4acd80e..68daf80 100644
--- a/messagegroups/RecentAdditionsMessageGroup.php
+++ b/messagegroups/RecentAdditionsMessageGroup.php
@@ -41,4 +41,39 @@
                );
                return $conds;
        }
+
+       /**
+        * Filters out messages that aren't useful.
+        * See bug 43030.
+        *
+        * @param $group MessageGroup
+        * @param $msg string message id
+        * @return boolean
+        */
+       protected function groupMatches( $group, $msg ) {
+               $groupId = $group->getId();
+
+               if ( !array_key_exists( $groupId, $this->groupInfoCache ) ) {
+                       $this->groupInfoCache[$groupId] = array(
+                               'tags' => $group->getTags(),
+                               'translatableLanguages' => 
$group->getTranslatableLanguages(),
+                               'discouraged' => ( MessageGroups::getPriority( 
$group ) === 'discouraged' ),
+                       );
+               }
+
+               foreach ( array( 'ignored', 'optional' ) as $tag ) {
+                       if ( in_array( $msg, 
$this->groupInfoCache[$groupId]['tags'][$tag] ) ) {
+                               return false;
+                       }
+               }
+
+               if ( $this->groupInfoCache[$groupId]['discouraged']
+                       || is_array( 
$this->groupInfoCache[$groupId]['translatableLanguages'] ) &&
+                               in_array( $msg, 
$this->groupInfoCache[$groupId]['translatableLanguages'] )
+               ) {
+                       return false;
+               }
+
+               return true;
+       }
 }
diff --git a/messagegroups/RecentMessageGroup.php 
b/messagegroups/RecentMessageGroup.php
index 53edb60..77d681d 100644
--- a/messagegroups/RecentMessageGroup.php
+++ b/messagegroups/RecentMessageGroup.php
@@ -18,6 +18,7 @@
        protected $namespace = false;
 
        protected $language;
+       protected $groupInfoCache;
 
        public function __construct() {}
 
@@ -63,6 +64,17 @@
                return $conds;
        }
 
+       /**
+        * Allows subclasses to filter out more unwanted groups.
+        *
+        * @param $group MessageGroup
+        * @param $msg string message id
+        * @return boolean
+        */
+       protected function groupMatches( $group, $msg ) {
+               return true;
+       }
+
        public function getDefinitions() {
                if ( !$this->language ) {
                        throw new MWException( "Language not set" );
@@ -79,6 +91,7 @@
                $res = $db->select( $tables, $fields, $conds, __METHOD__, 
$options );
 
                $defs = array();
+               $this->groupInfoCache = array();
                foreach ( $res as $row ) {
                        $title = Title::makeTitle( $row->rc_namespace, 
$row->rc_title );
                        $handle = new MessageHandle( $title );
@@ -94,7 +107,8 @@
                        if ( !isset( $defs[$mkey] ) ) {
                                $group = $handle->getGroup();
                                $msg = $group->getMessage( $handle->getKey(), 
$group->getSourceLanguage() );
-                               if ( $msg !== null ) {
+
+                               if ( $msg !== null && $this->groupMatches( 
$group, $msg )  ) {
                                        $defs[$mkey] = $msg;
                                }
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5e7c6c53cbe40f215232796d3e148a17d66ecdd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>

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

Reply via email to