r113347 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113346‎ | r113347 | r113348 >
Date:03:41, 8 March 2012
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
[ToolserverI18N] clean up
- protocol relative urls where possible
- whitespace clean up
Modified paths:
  • /trunk/tools/ToolserverI18N/Functions.php (modified) (history)
  • /trunk/tools/ToolserverI18N/TsIntuition.php (modified) (history)
  • /trunk/tools/ToolserverI18N/TsIntuitionUtil.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/demo/demo2.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/demo/demo3.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/demo/demo6.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/demo/demo7.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/demo/demo8.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/demo/demoBase.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/index.php (modified) (history)

Diff [purge]

Index: trunk/tools/ToolserverI18N/TsIntuition.php
@@ -7,7 +7,7 @@
88 *
99 * This file is licensed under
1010 * the Creative Commons Attribution 3.0 Unported License
11 - * <http://creativecommons.org/licenses/by/3.0/>
 11+ * creativecommons.org/licenses/by/3.0/
1212 *
1313 * @package TsIntuition
1414 */
@@ -35,7 +35,7 @@
3636 public $mode = null; // 'in-tool', 'dashboard'
3737
3838 // Address to the dashboard home. Should end with a slash or .extension
39 - public $dashboardHome = 'http://toolserver.org/~intuition/';
 39+ public $dashboardHome = '//toolserver.org/~intuition/';
4040
4141 // Construct options
4242 private $currentTextdomain;
@@ -81,8 +81,8 @@
8282 private $includeVariables = array( 'messages', 'url' );
8383
8484 // Redirect address and status
85 - private $redirectTo = null;
86 -
 85+ private $redirectTo = null;
 86+
8787 // Instance of MessagesFunctions
8888 private $messagesFunctions = null;
8989
@@ -109,7 +109,7 @@
110110 if ( is_string( $options ) ) {
111111 $options = array( 'domain' => $options );
112112 }
113 -
 113+
114114 $defaultOptions = array(
115115 'domain' => 'general',
116116 'lang' => null,
@@ -124,7 +124,7 @@
125125 $options = array_merge( $defaultOptions, $options );
126126
127127 $this->mode = $options['mode'];
128 -
 128+
129129 $this->loadDomainRegistry();
130130
131131 // The textdomain of your tool can be set here.
@@ -190,7 +190,7 @@
191191 if ( function_exists( 'TsIntuition_inithook' ) ) {
192192 TsIntuition_inithook( $TsIntuition );
193193 }
194 -
 194+
195195 }
196196
197197
@@ -344,7 +344,7 @@
345345 } else {
346346 return $this->messagesFunctions;
347347 }
348 - }
 348+ }
349349
350350 /* Message functions
351351 * ------------------------------------------------- */
@@ -359,7 +359,7 @@
360360 * - lang: overrides the currently selected language
361361 * - variables: numerical array to do variable replacements ($1> var[0], $2> var[1], etc.)
362362 * - raw-variables: boolean to determine whether the variables should be escaped as well
363 - * - parsemag: boolean to determine whether the message sould be tranformed
 363+ * - parsemag: boolean to determine whether the message sould be tranformed
364364 * using magic phrases (PLURAL, etc.)
365365 * - escape: Optionally the return can be escaped. By default this takes place after variable
366366 * replacement. Set 'raw-variables' to true if you just want the raw message
@@ -439,7 +439,7 @@
440440 $n = $i + 1;
441441 $msg = str_replace( "\$$n", $val, $msg );
442442 }
443 -
 443+
444444 // Some parsing work
445445 if ( $options['parsemag'] === true ) {
446446 $msg = $this->getMessagesFunctions()->parse( $msg, $lang );
@@ -469,7 +469,7 @@
470470 } else {
471471 return null;
472472 }
473 - }
 473+ }
474474
475475 /**
476476 * Don't show [brackets] when suppressing errors.
@@ -614,7 +614,7 @@
615615
616616 /**
617617 * Return all languages loaded in at least one domain
618 - * @param $domain
 618+ * @param $domain
619619 * false - Show languages for which there is a translation in the current domain
620620 * 'any' - Show languages for which there is a translation in at least one domain
621621 * domain name - Show languages for which there is a translation in the given domain
@@ -625,10 +625,10 @@
626626 } else {
627627 if ( $domain === false )
628628 $domain = $this->getDomain();
629 -
 629+
630630 $from = isset( $this->messageBlob[$domain] ) ? $this->messageBlob[$domain] : array();
631631 }
632 -
 632+
633633 $return = array();
634634 foreach( array_keys( $from ) as $lang ) {
635635 $return[$lang] = $this->getLangName( $lang );
@@ -694,12 +694,12 @@
695695
696696 // Load it
697697 $included = include( $filePath );
698 -
 698+
699699 if ( $included === false ) {
700700 $this->errTrigger( "File $filePath could not be loaded ", __METHOD__, E_NOTICE, __FILE__, __LINE__ );
701701 return false;
702702 }
703 -
 703+
704704 // Parse it
705705 $compact = compact( $this->includeVariables );
706706 $this->parseTextdomain( $compact, $domain, $filePath );
@@ -731,7 +731,7 @@
732732 }
733733
734734 // Was there a url defined in the textdomain file ?
735 - $fullurl = isset( $data['url'] ) ? "http://toolserver.org/{$data['url']}" : null;
 735+ $fullurl = isset( $data['url'] ) ? "//toolserver.org/{$data['url']}" : null;
736736 $path = isset( $data['url'] ) ? $data['url'] : null;
737737
738738 $this->loadedTextdomains[$domain] = array( 'url' => $fullurl, 'path' => $path );
@@ -749,7 +749,7 @@
750750 public function getDomainInfo( $domain ) {
751751 $domain = ucfirst( strtolower( $domain ) );
752752
753 - // Load if registered but not already loaded
 753+ // Load if registered but not already loaded
754754 $this->loadTextdomain( $domain );
755755
756756 if ( isset( $this->loadedTextdomains[$domain] ) && is_array( $this->loadedTextdomains[$domain] ) ) {
@@ -844,7 +844,7 @@
845845
846846 /**
847847 * Get expected lifetime left in seconds.
848 - * Returns 0 if expired or unavailable.
 848+ * Returns 0 if expired or unavailable.
849849 */
850850 public function getCookieLifetime() {
851851 $expire = $this->getCookieExpiration();
@@ -863,7 +863,7 @@
864864
865865 /**
866866 * FIXME: Implement in language/MessagesFunctions.php.
867 - *
 867+ *
868868 * @todo
869869 */
870870 public function gender( $male, $female, $neutral ) {
@@ -873,7 +873,7 @@
874874
875875 /**
876876 * Can be founded in language/MessagesFunctions.php.
877 - *
 877+ *
878878 * @see MessagesFunctions::parse
879879 * @see MessagesFunctions::plural
880880 * @deprecated
@@ -978,14 +978,14 @@
979979 * ------------------------------------------------- */
980980
981981 /**
982 - * Show a link that explains that this tool has been
 982+ * Show a link that explains that this tool has been
983983 * localized via Toolserver Intuition and that they
984984 * can change the language by setting their preference
985985 * in the dashboard. Or (if they've done so already)
986986 * that they can manage their settings there
987987 */
988988 public function dashboardBacklink() {
989 -
 989+
990990 if ( $this->hasCookies() ) {
991991 $text = $this->msg( 'bl-mysettings', 'tsintuition' );
992992 } else {
@@ -1017,7 +1017,7 @@
10181018
10191019 // Logo
10201020 if ( is_int( $imgSize ) && $imgSize > 0 ) {
1021 - $src = 'http://upload.wikimedia.org/wikipedia/commons/thumb/b/be'
 1021+ $src = '//upload.wikimedia.org/wikipedia/commons/thumb/b/be'
10221022 . '/Wikimedia_Community_Logo-Toolserver.svg'
10231023 . "/{$imgSize}px-Wikimedia_Community_Logo-Toolserver.svg.png";
10241024 $img = TsIntuitionUtil::tag( '', 'img', array(
@@ -1064,7 +1064,7 @@
10651065
10661066 $helpTranslateDomain = strtolower( $helpTranslateDomain );
10671067
1068 - // http://translatewiki.net/w/i.php?language=nl&title=Special:Translate&group=tsint-0-all
 1068+ // translatewiki.net/w/i.php?language=nl&title=Special:Translate&group=tsint-0-all
10691069 $twParams = array(
10701070 'title' => 'Special:Translate',
10711071 'language' => $this->getLang(),
@@ -1093,7 +1093,7 @@
10941094 * to return to the current page. To be used in other tools.
10951095 *
10961096 * @example:
1097 - * Location: http://toolserver.org/~foo/JohnDoe.php?wiki=loremwiki_p
 1097+ * Location: //toolserver.org/~foo/JohnDoe.php?wiki=loremwiki_p
10981098 * HTML:
10991099 * '<p>Change the settings <a href="' . $I18N->getDashboardReturnToUrl() . '">here</a>';
11001100 *
@@ -1349,13 +1349,13 @@
13501350 if ( $die && !$this->stayalive ) {
13511351 die;
13521352 } else {
1353 - echo "<br />\n";
 1353+ echo "<br/>\n";
13541354 }
13551355 }
1356 -
 1356+
13571357 /**
13581358 * Returns true if a language is Right-to-left
1359 - * @param $code String Language code to get the property from,
 1359+ * @param $code String Language code to get the property from,
13601360 * current language if missing
13611361 * @return Boolean
13621362 */
@@ -1364,10 +1364,10 @@
13651365 $code = $this->getLang();
13661366 }
13671367 require $this->localBaseDir . '/language/Rtl.php';
1368 -
 1368+
13691369 return in_array( $code, $rtlLanguages );
13701370 }
1371 -
 1371+
13721372 /**
13731373 * Return the correct HTML 'dir' attribute value for this language.
13741374 * @return String
Index: trunk/tools/ToolserverI18N/public_html/demo/demo6.php
@@ -12,12 +12,12 @@
1313 echo $I18N->parentheses( 'hello' );
1414
1515 // Variables
16 -echo '<br />' . $I18N->msg( 'toolversionstamp', array(
 16+echo '<br/>' . $I18N->msg( 'toolversionstamp', array(
1717 'variables' => array( '1.0', $I18N->dateFormatted( '2001-01-15' ) ),
1818 ) );
1919
2020 // msgExists
21 -echo '<br />msgExists: ';
 21+echo '<br/>msgExists: ';
2222 var_dump(
2323
2424 $I18N->msgExists( 'welcome' )
@@ -30,7 +30,7 @@
3131 );
3232
3333 // nonEmptyStr
34 -echo '<br />nonEmptyStr: ';
 34+echo '<br/>nonEmptyStr: ';
3535 var_dump(
3636
3737 TsIntuitionUtil::nonEmptyStr( 'one' )
@@ -38,7 +38,7 @@
3939 );
4040
4141 // nonEmptyStrs
42 -echo '<br />nonEmptyStrs: ';
 42+echo '<br/>nonEmptyStrs: ';
4343 var_dump(
4444
4545 TsIntuitionUtil::nonEmptyStrs( 'one', '', 'three' )
@@ -51,7 +51,7 @@
5252 );
5353
5454 // GetAcceptableLanguages
55 -echo "<br />getAcceptableLanguages: (default: \$_SERVER['HTTP_ACCEPT_LANGUAGE']: ", htmlspecialchars( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ), "):<br />";
 55+echo "<br/>getAcceptableLanguages: (default: \$_SERVER['HTTP_ACCEPT_LANGUAGE']: ", htmlspecialchars( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ), "):<br/>";
5656 var_dump(
5757
5858 TsIntuitionUtil::getAcceptableLanguages( @$_SERVER['HTTP_ACCEPT_LANGUAGE'] )
@@ -59,7 +59,7 @@
6060 );
6161
6262 $acceptLang = 'nl-be,nl;q=0.7,en-us,en;q=0.3';
63 -echo "<br />getAcceptableLanguages: ( '{$acceptLang}' ):<br />";
 63+echo "<br/>getAcceptableLanguages: ( '{$acceptLang}' ):<br/>";
6464 var_dump(
6565
6666 TsIntuitionUtil::getAcceptableLanguages( $acceptLang )
Index: trunk/tools/ToolserverI18N/public_html/demo/demo7.php
@@ -13,7 +13,7 @@
1414 echo $I18N->getLangName();
1515
1616 // - Specific language name
17 -echo '<br />' . $I18N->getLangName( 'fr' );
 17+echo '<br/>' . $I18N->getLangName( 'fr' );
1818
1919
2020
Index: trunk/tools/ToolserverI18N/public_html/demo/demo8.php
@@ -18,21 +18,21 @@
1919 // - Raw echo
2020 echo $I18N->msg( 'apple-stats' );
2121
22 -echo '<br />';
 22+echo '<br/>';
2323
2424 // - Pass variables
25 -echo '<br />' . $I18N->msg( 'welcomeback', array( 'variables' => array( 'John', 'coffee' ) ) );
 25+echo '<br/>' . $I18N->msg( 'welcomeback', array( 'variables' => array( 'John', 'coffee' ) ) );
2626
2727 // - Pass variables
28 -echo '<br />' . $I18N->msg( 'welcomeback', array( 'variables' => array( 'George', 'tea' ) ) );
 28+echo '<br/>' . $I18N->msg( 'welcomeback', array( 'variables' => array( 'George', 'tea' ) ) );
2929
30 -echo '<br />';
 30+echo '<br/>';
3131
3232 // - Trigger parser magic, setting $1 to '1'
33 -echo '<br />' . $I18N->msg( 'basket', array( 'variables' => array( '1' ), 'parsemag' => true ) );
 33+echo '<br/>' . $I18N->msg( 'basket', array( 'variables' => array( '1' ), 'parsemag' => true ) );
3434
3535 // - Trigger parser magic, setting $1 to '7'
36 -echo '<br />' . $I18N->msg( 'basket', array( 'variables' => array( '7' ), 'parsemag' => true ) );
 36+echo '<br/>' . $I18N->msg( 'basket', array( 'variables' => array( '7' ), 'parsemag' => true ) );
3737
3838
3939
Index: trunk/tools/ToolserverI18N/public_html/demo/demoBase.php
@@ -31,7 +31,7 @@
3232 body {
3333 font-family: sans-serif;
3434 }
35 - img {
 35+ img {
3636 vertical-align: middle;
3737 }
3838 h3 {
@@ -69,7 +69,7 @@
7070 echo $startHTML . "<p><em>&larr; <a href=\"../\">Return to Dashboard</a></em></p><ul>";
7171 foreach ( $demoRegistry as $demoFilename => $descr ) {
7272 $descr = htmlspecialchars( $descr );
73 - echo "<li><a href=\"$demoFilename.php\" title=\"$descr\">$demoFilename</a><br /><small>$descr</small></li>";
 73+ echo "<li><a href=\"$demoFilename.php\" title=\"$descr\">$demoFilename</a><br/><small>$descr</small></li>";
7474 }
7575 echo '</ul>';
7676 echo $outputHead;
Index: trunk/tools/ToolserverI18N/public_html/demo/demo2.php
@@ -13,7 +13,7 @@
1414
1515 // 2) Request an undefined message
1616 // Because 'suppressnotices' is true (default),
17 -// this won't trigger a Notice, and show a bracket msg: '[r4nd0mstr1n9]'
 17+// this won't trigger a Notice, and show a bracket msg: '[r4nd0mstr1n9]'
1818 echo $I18N->msg( 'r4nd0mstr1n9' );
1919
2020
Index: trunk/tools/ToolserverI18N/public_html/demo/demo3.php
@@ -16,7 +16,7 @@
1717
1818 // 2) Request an undefined message
1919 // Because 'suppressnotices' is false,
20 -// this will trigger a Notice: 'r4nd0mstr1n9' undefined
 20+// this will trigger a Notice: 'r4nd0mstr1n9' undefined
2121 echo $I18N->msg( 'r4nd0mstr1n9' );
2222
2323
Index: trunk/tools/ToolserverI18N/public_html/index.php
@@ -7,7 +7,7 @@
88 *
99 * This file is licensed under
1010 * the Creative Commons Attribution 3.0 Unported License
11 - * <http://creativecommons.org/licenses/by/3.0/>
 11+ * creativecommons.org/licenses/by/3.0/
1212 *
1313 * @package TsIntuition
1414 */
@@ -123,7 +123,7 @@
124124 } else {
125125 $returnToQuery = '';
126126 }
127 - $I18N->redirectTo( "http://{$_SERVER['SERVER_NAME']}$returnTo$returnToQuery", 302 );
 127+ $I18N->redirectTo( "//{$_SERVER['SERVER_NAME']}$returnTo$returnToQuery", 302 );
128128 }
129129 }
130130
@@ -200,11 +200,11 @@
201201 . kfTag( '', 'input', array( 'value' => $I18N->getLangName(), 'readonly' => 'readonly' ) )
202202 . ' ('
203203 . kfTag( _( 'clear-cookies' ), 'a', array( 'href' => $Tool->generatePermalink( array( 'action' => 'clearcookies' ) ) ) )
204 - . ')<br />'
 204+ . ')<br/>'
205205 . kfTag( _( 'cookie-expiration' ) . _g( 'colon-separator' ), 'label' ) . kfTag( '', 'input', array( 'value' => $time, 'class' => "cookie-health $class", 'readonly' => 'readonly' ) )
206206 . ' ('
207207 . kfTag( _( 'renew-cookies' ), 'a', array( 'href' => $Tool->generatePermalink( array( 'action' => 'renewcookies' ) ) ) )
208 - . ')<br />'
 208+ . ')<br/>'
209209 . $after
210210 . '</div></fieldset></form></div><!-- #tab-currentsettings -->'
211211 );
@@ -225,17 +225,17 @@
226226
227227 $form = '<div id="tab-settingsform"><form action="' . $Tool->remoteBasePath . '" method="post" class="cleanform"><fieldset>
228228 <legend>' . _( 'settings-legend' ) . '</legend><div class="inner">
229 -
 229+
230230 <label>' . _html( 'choose-language' ) . _g( 'colon-separator' ) . '</label>
231231 ' . $dropdown . '
232 - <br />
233 -
234 - <input type="hidden" name="action" value="prefset" />
235 - <input type="hidden" name="returnto" value="' . htmlspecialchars( $kgReq->getVal( 'returnto' ) ) . '" />
236 - <input type="hidden" name="returntoquery" value="' . htmlspecialchars( $kgReq->getVal( 'returntoquery' ) ) . '" />
 232+ <br/>
 233+
 234+ <input type="hidden" name="action" value="prefset"/>
 235+ <input type="hidden" name="returnto" value="' . htmlspecialchars( $kgReq->getVal( 'returnto' ) ) . '"/>
 236+ <input type="hidden" name="returntoquery" value="' . htmlspecialchars( $kgReq->getVal( 'returntoquery' ) ) . '"/>
237237 <label></label>
238 - <input type="submit" nof value="' . _html( 'form-submit', 'general' ) . '" />
239 - <br />
 238+ <input type="submit" nof value="' . _html( 'form-submit', 'general' ) . '"/>
 239+ <br/>
240240
241241 </div></fieldset></form></div>';
242242
@@ -245,7 +245,7 @@
246246
247247 // About tab
248248 $about = '<div id="tab-about">';
249 -
 249+
250250 $about .= '<a href="http://translatewiki.net/wiki/Translating:Toolserver">'
251251 . Html::element( 'img', array(
252252 'src' => 'http://translatewiki.net/w/i.php?title=Special:TranslationStats&graphit=1&preview=&count=edits&scale=weeks&days=30&width=520&height=400&group=tsint-0-all',
@@ -265,7 +265,7 @@
266266 $about .= '<li><a href="'
267267 . htmlspecialchars( $domainInfo['url'] )
268268 . '"><strong>' . htmlspecialchars( $title )
269 - . '</strong><br />'
 269+ . '</strong><br/>'
270270 . htmlspecialchars( $domainInfo['path'] )
271271 . '</a></li>';
272272 } else {
Index: trunk/tools/ToolserverI18N/TsIntuitionUtil.php
@@ -7,7 +7,7 @@
88 *
99 * This file is licensed under
1010 * the Creative Commons Attribution 3.0 Unported License
11 - * <http://creativecommons.org/licenses/by/3.0/>
 11+ * creativecommons.org/licenses/by/3.0/
1212 *
1313 * @package TsIntuition
1414 */
Index: trunk/tools/ToolserverI18N/Functions.php
@@ -7,7 +7,7 @@
88 *
99 * This file is licensed under
1010 * the Creative Commons Attribution 3.0 Unported License
11 - * <http://creativecommons.org/licenses/by/3.0/>
 11+ * creativecommons.org/licenses/by/3.0/
1212 *
1313 * @package TsIntuition
1414 */

Comments

#Comment by Nikerabbit (talk | contribs)   08:47, 8 March 2012

Most editors don't pick up protocol-less links from plain text, and if they do they default to http anyway, so I don't really see the point.

#Comment by Krinkle (talk | contribs)   10:04, 8 March 2012

The important urls fixed in this commit aren't plain text. They are

  • images from upload.wikimedia.org
  • links to the Toolserver Intuition dashboard (when using a tool over https, the "Set langauge" link used to be hardcoded to http, that's fixed now)
  • the returnTo query passed by tools was hardcoded to http as well.

the comment fixes are just normalization of the headers I use in my tools, not specific to TsInt

Status & tagging log