r98645 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98644‎ | r98645 | r98646 >
Date:23:27, 1 October 2011
Author:reedy
Status:deferred
Tags:
Comment:
Moar documentations
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMagic.php (modified) (history)
  • /trunk/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /trunk/extensions/Translate/utils/Font.php (modified) (history)
  • /trunk/extensions/Translate/utils/RevTag.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslateYaml.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationMemoryUpdater.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -73,7 +73,12 @@
7474 * @ingroup FFS
7575 */
7676 class SimpleFFS implements FFS {
 77+
 78+ /**
 79+ * @var FileBasedMessageGroup
 80+ */
7781 protected $group;
 82+
7883 protected $writePath;
7984 protected $extra;
8085
@@ -83,12 +88,30 @@
8489 $this->extra = $conf['FILES'];
8590 }
8691
 92+ /**
 93+ * @param $group FileBasedMessageGroup
 94+ */
8795 public function setGroup( FileBasedMessageGroup $group ) { $this->group = $group; }
 96+
 97+ /**
 98+ * @return FileBasedMessageGroup
 99+ */
88100 public function getGroup() { return $this->group; }
89101
 102+ /**
 103+ * @param $writePath string
 104+ */
90105 public function setWritePath( $writePath ) { $this->writePath = $writePath; }
 106+
 107+ /**
 108+ * @return string
 109+ */
91110 public function getWritePath() { return $this->writePath; }
92111
 112+ /**
 113+ * @param $code string|bool
 114+ * @return bool
 115+ */
93116 public function exists( $code = false ) {
94117 if ( $code === false ) {
95118 $code = $this->group->getSourceLanguage();
@@ -106,6 +129,11 @@
107130 return true;
108131 }
109132
 133+ /**
 134+ * @param $code string
 135+ * @return array|bool
 136+ * @throws MWException
 137+ */
110138 public function read( $code ) {
111139 if ( !$this->exists( $code ) ) {
112140 return false;
@@ -120,6 +148,11 @@
121149 return $this->readFromVariable( $input );
122150 }
123151
 152+ /**
 153+ * @param $data array
 154+ * @return array
 155+ * @throws MWException
 156+ */
124157 public function readFromVariable( $data ) {
125158 $parts = explode( "\0\0\0\0", $data );
126159
@@ -155,6 +188,9 @@
156189 );
157190 }
158191
 192+ /**
 193+ * @param $collection MessageCollection
 194+ */
159195 public function write( MessageCollection $collection ) {
160196 $writePath = $this->writePath;
161197
@@ -186,6 +222,10 @@
187223 }
188224 }
189225
 226+ /**
 227+ * @param $collection MessageCollection
 228+ * @return
 229+ */
190230 public function writeIntoVariable( MessageCollection $collection ) {
191231 $sourceFile = $this->group->getSourceFilePath( $collection->code );
192232 $this->tryReadSource( $sourceFile, $collection );
@@ -193,6 +233,10 @@
194234 return $this->writeReal( $collection );
195235 }
196236
 237+ /**
 238+ * @param $collection MessageCollection
 239+ * @return string
 240+ */
197241 protected function writeReal( MessageCollection $collection ) {
198242 $output = '';
199243
@@ -212,6 +256,10 @@
213257 return $output;
214258 }
215259
 260+ /**
 261+ * @param $filename string
 262+ * @param $collection MessageCollection
 263+ */
216264 protected function tryReadSource( $filename, $collection ) {
217265 $sourceText = $this->tryReadFile( $filename );
218266
@@ -224,6 +272,11 @@
225273 }
226274 }
227275
 276+ /**
 277+ * @param $filename string
 278+ * @return bool|string
 279+ * @throws MWException
 280+ */
228281 protected function tryReadFile( $filename ) {
229282 if ( !$filename ) {
230283 return false;
@@ -245,6 +298,11 @@
246299 return $data;
247300 }
248301
 302+ /**
 303+ * @param $authors array
 304+ * @param $code string
 305+ * @return array
 306+ */
249307 protected function filterAuthors( array $authors, $code ) {
250308 global $wgTranslateAuthorBlacklist;
251309 $groupId = $this->group->getId();
@@ -274,6 +332,10 @@
275333 return $authors;
276334 }
277335
 336+ /**
 337+ * @param $data string
 338+ * @return string
 339+ */
278340 public static function fixNewLines( $data ) {
279341 $data = str_replace( "\r\n", "\n", $data );
280342 $data = str_replace( "\r", "\n", $data );
@@ -294,6 +356,9 @@
295357 class JavaFFS extends SimpleFFS {
296358 protected $keySeparator = '=';
297359
 360+ /**
 361+ * @param $group FileBasedMessageGroup
 362+ */
298363 public function __construct( FileBasedMessageGroup $group ) {
299364 parent::__construct( $group );
300365
@@ -304,12 +369,18 @@
305370
306371 // READ
307372
 373+ /**
 374+ * @param $data array
 375+ * @return array
 376+ * @throws MWException
 377+ */
308378 public function readFromVariable( $data ) {
309379 $data = self::fixNewLines( $data );
310380 $lines = array_map( 'ltrim', explode( "\n", $data ) );
311381 $authors = $messages = array();
312382 $linecontinuation = false;
313383
 384+ $value = '';
314385 foreach ( $lines as $line ) {
315386 if ( $linecontinuation ) {
316387 $linecontinuation = false;
@@ -364,6 +435,10 @@
365436
366437 // Write
367438
 439+ /**
 440+ * @param $collection MessageCollection
 441+ * @return string
 442+ */
368443 protected function writeReal( MessageCollection $collection ) {
369444 $header = $this->doHeader( $collection );
370445 $header .= $this->doAuthors( $collection );
@@ -397,6 +472,10 @@
398473 }
399474 }
400475
 476+ /**
 477+ * @param $collection MessageCollection
 478+ * @return string
 479+ */
401480 protected function doHeader( MessageCollection $collection ) {
402481 if ( isset( $this->extra['header'] ) ) {
403482 $output = $this->extra['header'];
@@ -413,6 +492,10 @@
414493 return $output;
415494 }
416495
 496+ /**
 497+ * @param $collection MessageCollection
 498+ * @return string
 499+ */
417500 protected function doAuthors( MessageCollection $collection ) {
418501 $output = '';
419502 $authors = $collection->getAuthors();
@@ -433,11 +516,18 @@
434517 abstract class JavaScriptFFS extends SimpleFFS {
435518 /**
436519 * Message keys format.
 520+ *
 521+ * @param $string
 522+ *
 523+ * @return string
437524 */
438525 abstract protected function transformKey( $key );
439526
440527 /**
441528 * Header of message file.
 529+ *
 530+ * @param $code string
 531+ * @param $authors array
442532 */
443533 abstract protected function header( $code, $authors );
444534
@@ -446,6 +536,10 @@
447537 */
448538 abstract protected function footer();
449539
 540+ /**
 541+ * @param $data array
 542+ * @return array
 543+ */
450544 public function readFromVariable( $data ) {
451545 /* Parse authors list */
452546 $authors = preg_replace( "#/\* Translators\:\n(.*?)\n \*/(.*)#s", '$1', $data );
@@ -543,6 +637,10 @@
544638 );
545639 }
546640
 641+ /**
 642+ * @param $collection MessageCollection
 643+ * @return string
 644+ */
547645 public function writeReal( MessageCollection $collection ) {
548646 $header = $this->header( $collection->code, $collection->getAuthors() );
549647
@@ -578,6 +676,10 @@
579677 return $header . $body . $this->footer();
580678 }
581679
 680+ /**
 681+ * @param $authors array
 682+ * @return string
 683+ */
582684 protected function authorsList( $authors ) {
583685 if ( count( $authors ) === 0 ) {
584686 return '';
@@ -594,6 +696,10 @@
595697 return substr( " * Translators:\n$authorsList", 0, -1 );
596698 }
597699
 700+ /**
 701+ * @param $string string
 702+ * @return string
 703+ */
598704 protected static function unescapeJsString( $string ) {
599705 // See ECMA 262 section 7.8.4 for string literal format
600706 $pairs = array(
@@ -631,10 +737,20 @@
632738 * @ingroup FFS
633739 */
634740 class OpenLayersFFS extends JavaScriptFFS {
 741+
 742+ /**
 743+ * @param $key string
 744+ * @return string
 745+ */
635746 protected function transformKey( $key ) {
636747 return "'$key'";
637748 }
638749
 750+ /**
 751+ * @param $code string
 752+ * @param $authors array
 753+ * @return string
 754+ */
639755 protected function header( $code, $authors ) {
640756 $names = Language::getLanguageNames();
641757 $name = $names[ $code ];
@@ -665,6 +781,9 @@
666782 /** @endcond */
667783 }
668784
 785+ /**
 786+ * @return string
 787+ */
669788 protected function footer() {
670789 return "});\n";
671790 }
@@ -675,10 +794,21 @@
676795 * @ingroup FFS
677796 */
678797 class ShapadoJsFFS extends JavaScriptFFS {
 798+
 799+ /**
 800+ * @param $key string
 801+ *
 802+ * @return string
 803+ */
679804 protected function transformKey( $key ) {
680805 return $key;
681806 }
682807
 808+ /**
 809+ * @param $code string
 810+ * @param $authors array
 811+ * @return string
 812+ */
683813 protected function header( $code, $authors ) {
684814 global $wgSitename;
685815
@@ -700,6 +830,9 @@
701831 /** @endcond */
702832 }
703833
 834+ /**
 835+ * @return string
 836+ */
704837 protected function footer() {
705838 return "};\n\n";
706839 }
@@ -714,6 +847,10 @@
715848 */
716849 class YamlFFS extends SimpleFFS {
717850
 851+ /**
 852+ * @param $data
 853+ * @return array
 854+ */
718855 public function readFromVariable( $data ) {
719856 // Authors first.
720857 $matches = array();
@@ -740,6 +877,10 @@
741878 );
742879 }
743880
 881+ /**
 882+ * @param $collection MessageCollection
 883+ * @return string
 884+ */
744885 protected function writeReal( MessageCollection $collection ) {
745886 $output = $this->doHeader( $collection );
746887 $output .= $this->doAuthors( $collection );
@@ -775,6 +916,10 @@
776917 return $output;
777918 }
778919
 920+ /**
 921+ * @param $collection MessageCollection
 922+ * @return string
 923+ */
779924 protected function doHeader( MessageCollection $collection ) {
780925 global $wgSitename;
781926 global $wgTranslateYamlLibrary;
@@ -792,6 +937,10 @@
793938 return $output;
794939 }
795940
 941+ /**
 942+ * @param $collection MessageCollection
 943+ * @return string
 944+ */
796945 protected function doAuthors( MessageCollection $collection ) {
797946 $output = '';
798947 $authors = $collection->getAuthors();
@@ -807,6 +956,10 @@
808957 /**
809958 * Flattens multidimensional array by using the path to the value as key
810959 * with each individual key separated by a dot.
 960+ *
 961+ * @param $messages array
 962+ *
 963+ * @return array
811964 */
812965 protected function flatten( $messages ) {
813966 $flat = true;
@@ -816,7 +969,8 @@
817970 continue;
818971 }
819972
820 - $flat = false; break;
 973+ $flat = false;
 974+ break;
821975 }
822976
823977 if ( $flat ) {
@@ -852,6 +1006,10 @@
8531007 /**
8541008 * Performs the reverse operation of flatten. Each dot in the key starts a
8551009 * new subarray in the final array.
 1010+ *
 1011+ * @param $messages array
 1012+ *
 1013+ * @return array
8561014 */
8571015 protected function unflatten( $messages ) {
8581016 $array = array();
@@ -902,13 +1060,21 @@
9031061 return $array;
9041062 }
9051063
 1064+ /**
 1065+ * @param $value
 1066+ * @return bool
 1067+ */
9061068 public function flattenPlural( $value ) {
9071069 return false;
9081070 }
9091071
9101072 /**
9111073 * Override this. Return false to skip processing this value. Otherwise
912 - * return array with keys and values.
 1074+ *
 1075+ * @param $key string
 1076+ * @param $value string
 1077+ *
 1078+ * @return array with keys and values.
9131079 */
9141080 public function unflattenPlural( $key, $value ) {
9151081 return array( $key => $value );
@@ -933,6 +1099,10 @@
9341100
9351101 /**
9361102 * Flattens ruby plural arrays into special plural syntax.
 1103+ *
 1104+ * @param $messages array
 1105+ *
 1106+ * @return bool|string
9371107 */
9381108 public function flattenPlural( $messages ) {
9391109
@@ -966,6 +1136,11 @@
9671137
9681138 /**
9691139 * Converts the special plural syntax to array or ruby style plurals
 1140+ *
 1141+ * @param $key string
 1142+ * @param $message string
 1143+ *
 1144+ * @return bool|array
9701145 */
9711146 public function unflattenPlural( $key, $message ) {
9721147 // Quick escape.
@@ -1053,6 +1228,9 @@
10541229 return $alts;
10551230 }
10561231
 1232+ /**
 1233+ * @return string
 1234+ */
10571235 protected function placeholder() {
10581236 static $i = 0;
10591237
@@ -1068,6 +1246,10 @@
10691247 private $fw = null;
10701248 static $data = null;
10711249
 1250+ /**
 1251+ * @param $code
 1252+ * @return array
 1253+ */
10721254 public function read( $code ) {
10731255 // TODO: Improve this code to not use static variables.
10741256 if ( !isset( self::$data[$this->group->getId()] ) ) {
@@ -1091,6 +1273,9 @@
10921274 return array( 'MESSAGES' => self::$data[$this->group->getId()][$code] );
10931275 }
10941276
 1277+ /**
 1278+ * @param $collection MessageCollection
 1279+ */
10951280 public function write( MessageCollection $collection ) {
10961281 if ( $this->fw === null ) {
10971282 $sourceLanguage = $this->group->getSourceLanguage();
@@ -1124,6 +1309,10 @@
11251310 fwrite( $this->fw, "\t},\n" );
11261311 }
11271312
 1313+ /**
 1314+ * @param $collection MessageCollection
 1315+ * @return string
 1316+ */
11281317 public function writeIntoVariable( MessageCollection $collection ) {
11291318 return <<<PHP
11301319 # -*- coding: utf-8 -*-
@@ -1134,6 +1323,10 @@
11351324 PHP;
11361325 }
11371326
 1327+ /**
 1328+ * @param $collection MessageCollection
 1329+ * @return string
 1330+ */
11381331 protected function writeBlock( MessageCollection $collection ) {
11391332 $block = '';
11401333 $messages = array();
@@ -1160,6 +1353,10 @@
11611354 return $block;
11621355 }
11631356
 1357+ /**
 1358+ * @param $collection MessageCollection
 1359+ * @return string
 1360+ */
11641361 protected function doAuthors( MessageCollection $collection ) {
11651362 $output = '';
11661363
Index: trunk/extensions/Translate/tag/RenderJob.php
@@ -14,6 +14,11 @@
1515 * @ingroup PageTranslation JobQueue
1616 */
1717 class RenderJob extends Job {
 18+
 19+ /**
 20+ * @param $target Title
 21+ * @return RenderJob
 22+ */
1823 public static function newJob( Title $target ) {
1924 global $wgTranslateFuzzyBotName;
2025
@@ -87,6 +92,9 @@
8893 return $this->params['summary'];
8994 }
9095
 96+ /**
 97+ * @param $user User
 98+ */
9199 public function setUser( $user ) {
92100 if ( $user instanceof User ) {
93101 $this->params['user'] = $user->getName();
@@ -97,6 +105,8 @@
98106
99107 /**
100108 * Get a user object for doing edits.
 109+ *
 110+ * @return User
101111 */
102112 public function getUser() {
103113 return User::newFromName( $this->params['user'], false );
Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -22,6 +22,8 @@
2323 * Hooks: SkinTemplateNavigation, SkinTemplateTabs
2424 * @param $skin Skin
2525 * @param $tabs Array
 26+ *
 27+ * @return bool
2628 */
2729 static function addNavigationTabs( $skin, &$tabs ) {
2830 global $wgRequest;
Index: trunk/extensions/Translate/utils/Font.php
@@ -19,6 +19,8 @@
2020 /**
2121 * Searches for suitable font in the system.
2222 * @param $code \string Language code.
 23+ *
 24+ * @return bool|string
2325 */
2426 public static function find( $code ) {
2527 if ( ini_get( 'open_basedir' ) ) {
Index: trunk/extensions/Translate/utils/TranslationMemoryUpdater.php
@@ -15,6 +15,13 @@
1616 /**
1717 * Shovels the new translation into translation memory.
1818 * Hook: Translate:newTranslation
 19+ *
 20+ * @param $handle MessageHandle
 21+ * @param $revision
 22+ * @param $text string
 23+ * @param $user User
 24+ *
 25+ * @return bool
1926 */
2027 public static function update( MessageHandle $handle, $revision, $text, User $user ) {
2128 global $wgContLang;
Index: trunk/extensions/Translate/utils/TranslateYaml.php
@@ -41,6 +41,9 @@
4242
4343 /**
4444 * Merges a document template (base) to actual definition (specific)
 45+ * @param $base
 46+ * @param $specific
 47+ * @return array
4548 */
4649 public static function mergeTemplate( $base, $specific ) {
4750 foreach ( $specific as $key => $value ) {
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -1145,7 +1145,8 @@
11461146 protected static $serviceFailurePeriod = 900;
11471147
11481148 /**
1149 - * Checks whether the given service has exceeded failure count */
 1149+ * Checks whether the given service has exceeded failure count
 1150+ */
11501151 public static function checkTranslationServiceFailure( $service ) {
11511152 global $wgMemc;
11521153
@@ -1197,6 +1198,9 @@
11981199 }
11991200 }
12001201
 1202+ /**
 1203+ * @param $out OutputPage
 1204+ */
12011205 public static function addModules( OutputPage $out ) {
12021206 $out->addModules( 'ext.translate.quickedit' );
12031207
Index: trunk/extensions/Translate/utils/RevTag.php
@@ -16,6 +16,8 @@
1717
1818 /**
1919 * Determines the schema version.
 20+ *
 21+ * @return int
2022 */
2123 public static function checkSchema() {
2224 if ( self::$schema !== false ) {
@@ -33,7 +35,7 @@
3436 /**
3537 * Returns value suitable for rt_type field.
3638 * @param $tag string tag name
37 - * return int|string
 39+ * @return int|string
3840 */
3941 public static function getType( $tag ) {
4042 if ( self::checkSchema() === 2 ) {
Index: trunk/extensions/Translate/specials/SpecialMagic.php
@@ -42,6 +42,8 @@
4343
4444 /**
4545 * @see SpecialPage::getDescription
 46+ *
 47+ * @return string
4648 */
4749 function getDescription() {
4850 return wfMsg( 'translate-magic-pagename' );

Status & tagging log