r99108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99107‎ | r99108 | r99109 >
Date:14:26, 6 October 2011
Author:reedy
Status:deferred (Comments)
Tags:
Comment:
Kill weird leading semi colon from jquery.form.js

More documentation stuff
Modified paths:
  • /trunk/extensions/Translate/resources/jquery.form.js (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialFirstSteps.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialLanguageStats.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialManageGroups.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMessageGroupStats.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialMyLanguage.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialSupportedLanguages.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialTranslate.php (modified) (history)
  • /trunk/extensions/Translate/specials/SpecialTranslationStats.php (modified) (history)
  • /trunk/extensions/Translate/tag/RenderJob.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslation.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslationDeletePage.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslationMovePage.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)
  • /trunk/extensions/Translate/utils/Html.php (modified) (history)
  • /trunk/phase3/includes/Cdb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Cdb.php
@@ -72,7 +72,7 @@
7373 *
7474 * @param $fileName string
7575 *
76 - * @return bool
 76+ * @return CdbWriter_DBA|CdbWriter_PHP
7777 */
7878 public static function open( $fileName ) {
7979 if ( CdbReader::haveExtension() ) {
Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -25,6 +25,8 @@
2626
2727 /**
2828 * Revision of the page, if applicaple.
 29+ *
 30+ * @var int
2931 */
3032 protected $revision = null;
3133
@@ -183,7 +185,7 @@
184186 /**
185187 * Returns MessageGroup used for translating this page. It may still be empty
186188 * if the page has not been ever marked.
187 - * @return \type{WikiPageMessageGroup}
 189+ * @return WikiPageMessageGroup
188190 */
189191 public function getMessageGroup() {
190192 return MessageGroups::getGroup( $this->getMessageGroupId() );
@@ -297,6 +299,11 @@
298300
299301 // Inner functionality //
300302
 303+ /**
 304+ * @param $holders
 305+ * @param $text
 306+ * @return mixed
 307+ */
301308 public static function armourNowiki( &$holders, $text ) {
302309 $re = '~(<nowiki>)(.*?)(</nowiki>)~s';
303310
@@ -309,6 +316,11 @@
310317 return $text;
311318 }
312319
 320+ /**
 321+ * @param $holders
 322+ * @param $text
 323+ * @return mixed
 324+ */
313325 public static function unArmourNowiki( $holders, $text ) {
314326 foreach ( $holders as $ph => $value ) {
315327 $text = str_replace( $ph, $value, $text );
@@ -500,7 +512,11 @@
501513 unset( self::$tagCache[$aid] );
502514 }
503515
504 - /// @return false if tag is not found
 516+ /**
 517+ * @param $tag
 518+ * @param $dbt int
 519+ * @return array|bool false if tag is not found
 520+ */
505521 protected function getTag( $tag, $dbt = DB_SLAVE ) {
506522 if ( !$this->getTitle()->exists() ) {
507523 return false;
@@ -530,6 +546,10 @@
531547 }
532548 }
533549
 550+ /**
 551+ * @param $code bool|string
 552+ * @return String
 553+ */
534554 public function getTranslationUrl( $code = false ) {
535555 $translate = SpecialPage::getTitleFor( 'Translate' );
536556 $params = array(
@@ -628,6 +648,11 @@
629649 return $temp;
630650 }
631651
 652+ /**
 653+ * @param $collection MessageCollection
 654+ * @param $markedRevs
 655+ * @return float|int
 656+ */
632657 protected function getPercentageInternal( $collection, $markedRevs ) {
633658 $count = count( $collection );
634659 if ( $count === 0 ) {
@@ -687,6 +712,10 @@
688713 return $db->selectField( 'revtag', $fields, $conds, __METHOD__, $options );
689714 }
690715
 716+ /**
 717+ * @param $title Title
 718+ * @return bool|TranslatablePage
 719+ */
691720 public static function isTranslationPage( Title $title ) {
692721 list( $key, $code ) = TranslateUtils::figureMessage( $title->getText() );
693722
@@ -721,6 +750,10 @@
722751 return Title::makeTitleSafe( $title->getNamespace(), $text );
723752 }
724753
 754+ /**
 755+ * @param $title Title
 756+ * @return bool
 757+ */
725758 public static function isSourcePage( Title $title ) {
726759 static $cache = null;
727760
Index: trunk/extensions/Translate/tag/RenderJob.php
@@ -93,7 +93,7 @@
9494 }
9595
9696 /**
97 - * @param $user User
 97+ * @param $user User|string
9898 */
9999 public function setUser( $user ) {
100100 if ( $user instanceof User ) {
Index: trunk/extensions/Translate/tag/SpecialPageTranslation.php
@@ -53,7 +53,6 @@
5454 // Check permissions
5555 if ( !$this->user->isAllowed( 'pagetranslation' ) ) {
5656 $wgOut->permissionRequired( 'pagetranslation' );
57 -
5857 return;
5958 }
6059
@@ -252,6 +251,12 @@
253252 }
254253 }
255254
 255+ /**
 256+ * @param $title Title
 257+ * @param $rev
 258+ * @param $latest
 259+ * @param string $old
 260+ */
256261 protected function actionLinks( $title, $rev, $latest, $old = 'old' ) {
257262 $actions = array();
258263
@@ -351,7 +356,11 @@
352357 return $sections;
353358 }
354359
355 - /** Displays the sections and changes for the user to review */
 360+ /**
 361+ * Displays the sections and changes for the user to review
 362+ * @param $page TranslatablePage
 363+ * @param $sections array
 364+ */
356365 public function showPage( TranslatablePage $page, Array $sections ) {
357366 global $wgOut, $wgContLang;
358367
@@ -548,6 +557,10 @@
549558 return false;
550559 }
551560
 561+ /**
 562+ * @param $page Article
 563+ * @param $changed
 564+ */
552565 public function addFuzzyTags( $page, $changed ) {
553566 if ( !count( $changed ) ) {
554567 self::superDebug( __METHOD__, 'nochanged', $page->getTitle() );
@@ -613,6 +626,8 @@
614627 * If this page is marked for the first time, /en may not yet exists.
615628 * If this is the case, add a RenderJob for it, but don't execute it
616629 * immediately, since the message group doesn't exist during this request.
 630+ * @param $page Article
 631+ * @param $titles array
617632 */
618633 protected function addInitialRenderJob( $page, $titles ) {
619634 global $wgContLang;
Index: trunk/extensions/Translate/tag/SpecialPageTranslationDeletePage.php
@@ -33,8 +33,9 @@
3434 /// Allow skipping non-translation subpages.
3535 protected $doSubpages = false;
3636
37 -
38 - /// TranslatablePage instance.
 37+ /**
 38+ * @var TranslatablePage
 39+ */
3940 protected $page;
4041 /// Contains the language code if we are working with translation page
4142 protected $code;
@@ -262,6 +263,10 @@
263264 $wgOut->addHTML( implode( "\n", $form ) );
264265 }
265266
 267+ /**
 268+ * @param $title Title
 269+ * @param $enabled bool
 270+ */
266271 protected function printChangeLine( $title, $enabled = true ) {
267272 global $wgOut;
268273 if ( $enabled ) {
@@ -361,6 +366,9 @@
362367 return $this->title->getSubpages();
363368 }
364369
 370+ /**
 371+ * @return bool
 372+ */
365373 protected function singleLanguage() {
366374 return $this->code !== '';
367375 }
Index: trunk/extensions/Translate/tag/SpecialPageTranslationMovePage.php
@@ -47,7 +47,7 @@
4848
4949
5050 /**
51 - * TranslatablePage instance.
 51+ * @var TranslatablePage instance.
5252 */
5353 protected $page;
5454
@@ -324,6 +324,12 @@
325325 $wgOut->addHTML( implode( "\n", $form ) );
326326 }
327327
 328+ /**
 329+ * @param $base
 330+ * @param $old Title
 331+ * @param $target
 332+ * @param bool $enabled
 333+ */
328334 protected function printChangeLine( $base, $old, $target, $enabled = true ) {
329335 global $wgOut;
330336
Index: trunk/extensions/Translate/utils/Html.php
@@ -59,7 +59,7 @@
6060 * Sets the tag content. Chain-accessor.
6161 *
6262 * @param $value \mixed Optional. Null to view and string to set the content.
63 - * @return \mixed The content as a string or self.
 63+ * @return HtmlTag|string The content as a string or self.
6464 */
6565 public function content( $value = null ) {
6666 if ( $value === null ) {
@@ -120,7 +120,7 @@
121121 *
122122 * @param $name \string The name of the parameter.
123123 * @param $value \mixed Optional. False to unset, null to view and string to set the value.
124 - * @return \mixed The value of the parameter or null if not set.
 124+ * @return null|HtmlTag The value of the parameter or null if not set.
125125 */
126126 public function style( $name, $value = null ) {
127127 $name = (string) $this->assert( 'is_string', $name );
Index: trunk/extensions/Translate/specials/SpecialManageGroups.php
@@ -18,7 +18,21 @@
1919 * messages, as well as import/update of messages in other languages.
2020 */
2121 class SpecialManageGroups extends SpecialPage {
22 - protected $skin, $user, $out;
 22+ /**
 23+ * @var Skin
 24+ */
 25+ protected $skin;
 26+
 27+ /**
 28+ * @var User
 29+ */
 30+ protected $user;
 31+
 32+ /**
 33+ * @var OutputPage
 34+ */
 35+ protected $out;
 36+
2337 /// Maximum allowed processing time in seconds.
2438 protected $processingTime = 30;
2539
@@ -139,6 +153,12 @@
140154 $wgOut->addHTML( '</ul>' );
141155 }
142156
 157+ /**
 158+ * @param $group MessageGroup
 159+ * @param $codes
 160+ * @param $from
 161+ * @return string
 162+ */
143163 protected function rebuildButton( $group, $codes, $from ) {
144164 $formParams = array(
145165 'method' => 'post',
@@ -160,6 +180,8 @@
161181
162182 /**
163183 * @todo Very long code block; split up.
 184+ *
 185+ * @param $group MessageGroup
164186 */
165187 public function importForm( $group, $code ) {
166188 $this->setSubtitle( $group, $code );
@@ -388,6 +410,9 @@
389411 }
390412 }
391413
 414+ /**
 415+ * @param $group MessageGroup
 416+ */
392417 public function doModLangs( $group ) {
393418 global $wgLang;
394419
Index: trunk/extensions/Translate/specials/SpecialMyLanguage.php
@@ -49,7 +49,7 @@
5050 * Make Special:MyLanguage links red if the target page doesn't exists.
5151 * A bit hacky because the core code is not so flexible.
5252 * @param $dummy
53 - * @param $target
 53+ * @param $target Title
5454 * @param $html
5555 * @param $customAttribs
5656 * @param $query
Index: trunk/extensions/Translate/specials/SpecialSupportedLanguages.php
@@ -245,7 +245,6 @@
246246 return $users;
247247 }
248248
249 -
250249 protected function outputLanguageCloud( $names ) {
251250 global $wgOut;
252251
Index: trunk/extensions/Translate/specials/SpecialTranslate.php
@@ -16,7 +16,15 @@
1717 * @ingroup SpecialPage TranslateSpecialPage
1818 */
1919 class SpecialTranslate extends SpecialPage {
 20+
 21+ /**
 22+ * @var Task
 23+ */
2024 protected $task = null;
 25+
 26+ /**
 27+ * @var MessageGroup
 28+ */
2129 protected $group = null;
2230
2331 protected $defaults = null;
@@ -222,6 +230,12 @@
223231 return $form;
224232 }
225233
 234+ /**
 235+ * @param $label
 236+ * @param $option
 237+ * @param $error null
 238+ * @return string
 239+ */
226240 private static function optionRow( $label, $option, $error = null ) {
227241 return
228242 Xml::openElement( 'tr' ) .
@@ -229,7 +243,6 @@
230244 Xml::tags( 'td', null, $option ) .
231245 ( $error ? Xml::tags( 'td', array( 'class' => 'mw-sp-translate-error' ), $error ) : '' ) .
232246 Xml::closeElement( 'tr' );
233 -
234247 }
235248
236249 /* Selectors ahead */
Index: trunk/extensions/Translate/specials/SpecialTranslationStats.php
@@ -183,9 +183,10 @@
184184
185185 /**
186186 * Constructs a table row with label and input in two columns.
187 - * @param $name \string Option name.
 187+ * @param $name string Option name.
188188 * @param $opts FormOptions
189 - * @return \string Html.
 189+ * @param $width int
 190+ * @return string Html.
190191 */
191192 protected function eInput( $name, FormOptions $opts, $width = 4 ) {
192193 $value = $opts[$name];
@@ -301,7 +302,7 @@
302303
303304 /**
304305 * Constructs a JavaScript enhanced group selector.
305 - * @return \type{JsSelectToInput}
 306+ * @return JsSelectToInput
306307 */
307308 protected function groupSelector() {
308309 $groups = MessageGroups::singleton()->getGroups();
@@ -497,6 +498,12 @@
498499 return $cutoff;
499500 }
500501
 502+ /**
 503+ * @param $ts
 504+ * @param $amount
 505+ * @param $dir
 506+ * @return int
 507+ */
501508 protected static function roundingAddition( $ts, $amount, $dir ) {
502509 if ( $dir === -1 ) {
503510 return -1 * ( $ts % $amount );
Index: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php
@@ -30,7 +30,7 @@
3131 public function getDescription() {
3232 return wfMessage( 'translate-mgs-pagename' )->text();
3333 }
34 -
 34+
3535 /// Overwritten from SpecialLanguageStats
3636 protected function getAllowedValues() {
3737 $groups = MessageGroups::getAllGroups();
@@ -109,7 +109,11 @@
110110 return $out;
111111 }
112112
113 - /// Overwriten from SpecialLanguageStats
 113+ /**
 114+ * Overwriten from SpecialLanguageStats
 115+ *
 116+ * @return string
 117+ */
114118 function getTable() {
115119 $table = $this->table;
116120 $out = '';
@@ -144,6 +148,11 @@
145149 }
146150 }
147151
 152+ /**
 153+ * @param $code
 154+ * @param $cache
 155+ * @return string
 156+ */
148157 protected function makeRow( $code, $cache ) {
149158 $stats = $cache[$code];
150159
@@ -175,6 +184,11 @@
176185 return $out;
177186 }
178187
 188+ /**
 189+ * @param $code
 190+ * @param $params
 191+ * @return string
 192+ */
179193 protected function getMainColumnCell( $code, $params ) {
180194 if ( !isset( $this->names ) ) {
181195 global $wgLang;
Index: trunk/extensions/Translate/specials/SpecialLanguageStats.php
@@ -21,10 +21,15 @@
2222 * @ingroup SpecialPage TranslateSpecialPage Stats
2323 */
2424 class SpecialLanguageStats extends IncludableSpecialPage {
25 - /// @var StatsTable
 25+
 26+ /**
 27+ * @var StatsTable
 28+ */
2629 protected $table;
2730
28 - /// @var String
 31+ /**
 32+ * @var String
 33+ */
2934 protected $targetValueName = 'code';
3035
3136 /**
@@ -68,6 +73,11 @@
6974 */
7075 protected $target;
7176
 77+ /**
 78+ * @var bool
 79+ */
 80+ protected $purge;
 81+
7282 public function __construct() {
7383 parent::__construct( 'LanguageStats' );
7484 global $wgLang;
@@ -257,6 +267,12 @@
258268 /// }
259269 }
260270
 271+ /**
 272+ * @param $item
 273+ * @param $cache
 274+ * @param $parent string
 275+ * @return string
 276+ */
261277 protected function makeGroupGroup( $item, $cache, $parent = '' ) {
262278 if ( !is_array( $item ) ) {
263279 return $this->makeGroupRow( $item, $cache, $parent === '' ? false : $parent );
@@ -272,9 +288,15 @@
273289 return $out;
274290 }
275291
 292+ /**
 293+ * @param $group
 294+ * @param $cache
 295+ * @param $parent bool
 296+ * @return string
 297+ */
276298 protected function makeGroupRow( $group, $cache, $parent = false ) {
277299 if ( $this->table->isBlacklisted( $group->getId(), $this->target ) !== null ) {
278 - return;
 300+ return '';
279301 }
280302
281303 $stats = $cache[$group->getId()];
Index: trunk/extensions/Translate/specials/SpecialFirstSteps.php
@@ -16,8 +16,22 @@
1717 * @ingroup SpecialPage TranslateSpecialPage
1818 */
1919 class SpecialFirstSteps extends UnlistedSpecialPage {
20 - protected $skin, $user, $out;
2120
 21+ /**
 22+ * @var Skin
 23+ */
 24+ protected $skin;
 25+
 26+ /**
 27+ * @var User
 28+ */
 29+ protected $user;
 30+
 31+ /**
 32+ * @var OutputPage
 33+ */
 34+ protected $out;
 35+
2236 public function __construct() {
2337 parent::__construct( 'FirstSteps' );
2438 }
Index: trunk/extensions/Translate/resources/jquery.form.js
@@ -8,7 +8,7 @@
99 * http://www.opensource.org/licenses/mit-license.php
1010 * http://www.gnu.org/licenses/gpl.html
1111 */
12 -;(function($) {
 12+(function($) {
1313
1414 /*
1515 Usage Note:

Comments

#Comment by Nikerabbit (talk | contribs)   17:33, 6 October 2011
       /**
        * @todo Very long code block; split up.
+        *
+        * @param $group MessageGroup
        */
       public function importForm( $group, $code ) {
#Comment by Krinkle (talk | contribs)   00:03, 8 October 2011

Interesting read: http://stackoverflow.com/questions/1873983/what-does-the-leading-semicolon-in-javascript-libraries-do

Several third party libraries don't end their script with a semi-colon, so other libraries started the habbot of starting the file with a (usually) no-op/innocent semi-colon. So that when a simple and optimistic concatenation framework concatenates two JS files, it will not result in a TypeError:

(function(){ ... })()(function(){ ... })()
> TypeError
#Comment by Krinkle (talk | contribs)   00:04, 8 October 2011

Although we don't need this since ResourceLoader and JavaScriptMinifier.php are way more advanced, but it is unlikely that jquery.forms is going to remove this semi-colon upstream, might as well keep it as-is (which would likely happen next time we update the plugin from remote)

#Comment by Catrope (talk | contribs)   15:11, 8 October 2011

Yeah, keep it in, it's harmless. ResourceLoader/JSMinifier already separate concatenated files with semicolons anyway. In the worst case, that'll result in something like lastStatementOfFoo;;;firstStatementOfJqueryForm but that's OK: empty statements like those are valid syntax and ignored by the interpreter.

Status & tagging log