r36246 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36245‎ | r36246 | r36247 >
Date:19:22, 12 June 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Added $wgTranslateAuthorBlacklist
Modified paths:
  • /trunk/extensions/Translate/README (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/ffs/Simple.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -11,7 +11,7 @@
1212 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1313 */
1414
15 -define( 'TRANSLATE_VERSION', '8.45' );
 15+define( 'TRANSLATE_VERSION', '8.46' );
1616
1717 $wgExtensionCredits['specialpage'][] = array(
1818 'name' => 'Translate',
@@ -85,6 +85,21 @@
8686
8787 $wgTranslateBlacklist = array();
8888
 89+/**
 90+ * Two-dimensional array of rules that blacklists certain authors from appearing
 91+ * in the exports. This is useful for keeping bots and people doing maintenance
 92+ * work in translations not to appear besides real translators everywhere.
 93+ *
 94+ * Rules are arrays, where first element is type: white or black. Whitelisting
 95+ * always overrules blacklisting. Second element should be a valid pattern that
 96+ * can be given a preg_match(). It will be matched against string of format
 97+ * "group-id;language;author name", without quotes.
 98+ * As an example by default we have rule that ignores all authors whose name
 99+ * ends in a bot for all languages and all groups.
 100+ */
 101+$wgTranslateAuthorBlacklist = array();
 102+$wgTranslateAuthorBlacklist[] = array( 'black', '/^.*;.*;.*Bot$/Ui' );
 103+
89104 $wgTranslateMessageNamespaces = array( NS_MEDIAWIKI );
90105
91106 /** AC = Available classes */
Index: trunk/extensions/Translate/README
@@ -47,6 +47,7 @@
4848 * changed the way of adding MediaWiki extensions
4949 * support for having messages in namespaces other than NS_MEDIAWIKi
5050 * try to load qqq from files if not found from the database
 51+* added $wgTranslateAuthorBlacklist
5152
5253 == Changes in version 8 ==
5354 * Released 2008-02-06
Index: trunk/extensions/Translate/ffs/Simple.php
@@ -197,10 +197,45 @@
198198 fwrite( $handle, self::SEPARATOR . "\n");
199199 }
200200
 201+
 202+ public function filterAuthors( array $authors, $code, $groupId ) {
 203+ global $wgTranslateAuthorBlacklist;
 204+ foreach ( $authors as $i => $v ) {
 205+ $hash = "$groupId;$code;$v";
 206+
 207+ $blacklisted = false;
 208+ foreach ( $wgTranslateAuthorBlacklist as $rule ) {
 209+ list( $type, $regex ) = $rule;
 210+ if ( preg_match($regex, $hash) ) {
 211+ if ( $type === 'white' ) {
 212+ $blacklisted = false;
 213+ break;
 214+ } else {
 215+ $blacklisted = true;
 216+ }
 217+ }
 218+ }
 219+
 220+ if ( $blacklisted ) {
 221+ unset($authors[$i]);
 222+ }
 223+
 224+ }
 225+
 226+ return $authors;
 227+
 228+ }
 229+
201230 protected function formatAuthors( $prefix, $code ) {
 231+ // Check if there is any authors at all
202232 if ( empty($this->authors[$code]) ) return '';
 233+
 234+ $groupId = $this->group->getId();
 235+ $authors = $this->authors[$code];
 236+ $authors = $this->filterAuthors( $authors, $code, $groupId );
 237+
203238 $s = array();
204 - foreach ( $this->authors[$code] as $a ) {
 239+ foreach ( $authors as $a ) {
205240 $s[] = $prefix . $a;
206241 }
207242 return implode( "\n", $s ) . "\n";

Status & tagging log