r84981 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84980‎ | r84981 | r84982 >
Date:21:14, 29 March 2011
Author:krinkle
Status:deferred
Tags:
Comment:
Continue implementation of spec + added some stuff that I had in the TS working-copy but not locally.
* defines.txt is now parsable through parse_ini_file
* Instead of executing the 'svn info' shell command; parse .svn/entries (part of BaseTool's global kfGetSvnInfo() function.
* Implemented TsItuition::getAvailableLangs() returns array of language-codes and their language names for all languages that are currently available (= languages in which at least 1 message is defined)
* Temporary workaround to remove 'qqq' from getAvailableLangs by unset() on 'qqq' when loading messages
* Adding confirmation messages after clearing or renewing cookies eg. "Succesfully cleared cookies."
* Renamed message "clear-memory" in "Tsintuition" domain to "clear-cookies"
Modified paths:
  • /trunk/tools/ToolserverI18N/TsIntuition.php (modified) (history)
  • /trunk/tools/ToolserverI18N/TsIntuitionUtil.php (modified) (history)
  • /trunk/tools/ToolserverI18N/language/messages/Tsintuition.i18n.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/index.php (modified) (history)
  • /trunk/tools/ToolserverI18N/toolserver-defines.txt (modified) (history)

Diff [purge]

Index: trunk/tools/ToolserverI18N/TsIntuition.php
@@ -28,6 +28,7 @@
2929 * ------------------------------------------------- */
3030
3131 private $localBaseDir = '/home/krinkle/TsIntuition'; // to be moved to p_i18n
 32+ private $iniFilePath = '/toolserver-defines.txt';
3233
3334 private $suppresserrors = false;
3435 private $suppressnotices = true;
@@ -38,6 +39,10 @@
3940
4041 private $currentLanguage = 'en';
4142
 43+ // Not loaded/needed by default.
 44+ // This variable is used as cache for the ini file once loaded through loadIni()
 45+ private $iniCache = null;
 46+
4247 // Changing this will invalidate all cookies
4348 private $cookieNames = array( 'userlang' => 'TsIntuition_userlang', 'track-expire' => 'TsIntuition_expiry' );
4449
@@ -86,6 +91,7 @@
8792 * - param
8893 */
8994 function __construct( $options = array() ) {
 95+
9096 if ( is_string( $options) ) {
9197 $options = array( 'domain' => $options );
9298 }
@@ -483,7 +489,16 @@
484490 return is_array( $this->langNames ) ? $this->langNames : array();
485491 }
486492
 493+ public function getAvailableLangs() {
 494+ $return = array();
 495+ foreach( array_keys( $this->availableLanguages ) as $lang ) {
 496+ $return[$lang] = $this->getLangName( $lang );
 497+ }
 498+ ksort( $return );
 499+ return $return;
 500+ }
487501
 502+
488503 /* Textdomain functions
489504 * ------------------------------------------------- */
490505
@@ -540,6 +555,7 @@
541556 if ( !isset( $data['messages'] ) || !is_array( $data['messages'] ) ) {
542557 $this->errTrigger( 'No $messages array found', __METHOD__ , E_ERROR, $filePath );
543558 }
 559+ unset( $data['messages']['qqq'] ); // Workaround
544560 // Load the message into the blob
545561 // overwrites the existing array of messages if it already existed
546562 // If you need to add or overwrite some messages temporarily, use Itui::setMsg() or Itui::setMsgs() instead
@@ -587,7 +603,8 @@
588604 }
589605
590606 /**
591 - * @DOCME
 607+ * Browsers don't send the expiration date of cookies with the request
 608+ * In order to keep track of the expiration date, we set an additional cookie.
592609 */
593610 private function setExpiryTrackerCookie( $lifetime ) {
594611 $expire = time() + intval( $lifetime );
@@ -602,7 +619,7 @@
603620 foreach( $this->getCookieNames() as $name ) {
604621 $this->setCookie( $name, $_COOKIE[$name], $lifetime, false );
605622 }
606 - $this-setExpiryTrackerCookie();
 623+ $this->setExpiryTrackerCookie( $lifetime );
607624 return true;
608625 }
609626
@@ -642,6 +659,87 @@
643660 }
644661
645662
 663+ /* Load functions
 664+ * ------------------------------------------------- */
 665+
 666+
 667+ /**
 668+ * Load fallbacks
 669+ *
 670+ * @private
 671+ *
 672+ * @return true
 673+ */
 674+ private function loadFallbacks(){
 675+
 676+ // Don't load twice
 677+ if ( is_array( $this->langFallbacks ) ) {
 678+ return false;
 679+ }
 680+
 681+ $path = $this->localBaseDir . '/language/Fallbacks.php';
 682+ if ( !file_exists( $path ) ) {
 683+ $this->errTrigger( 'Fallbacks.php is missing', __METHOD__, E_NOTICE, __FILE__, __LINE__ );
 684+ return false;
 685+ }
 686+
 687+ // Load it
 688+ $fallbacks = array();
 689+ include( $path );
 690+ $this->langFallbacks = $fallbacks;
 691+
 692+ return true;
 693+ }
 694+
 695+ /**
 696+ * Load names
 697+ *
 698+ * @private
 699+ *
 700+ * @return true
 701+ */
 702+ private function loadNames(){
 703+
 704+ // Don't load twice
 705+ if ( is_array( $this->langNames ) ) {
 706+ return false;
 707+ }
 708+
 709+ $path = $this->localBaseDir . '/language/Names.php';
 710+ if ( !file_exists( $path ) ) {
 711+ $this->errTrigger( 'Names.php is missing', __METHOD__, E_NOTICE, __FILE__, __LINE__ );
 712+ return false;
 713+ }
 714+
 715+ // Load it
 716+ $wgLanguageNames = array();
 717+ include( $path );
 718+ $this->langNames = $wgLanguageNames;
 719+
 720+ return true;
 721+ }
 722+
 723+ /**
 724+ * Load ini
 725+ *
 726+ * @private
 727+ *
 728+ * @return true
 729+ */
 730+ public function loadIni(){
 731+
 732+ // Don't load twice
 733+ if ( !is_null( $this->iniCache ) ) {
 734+ return false;
 735+ }
 736+
 737+ // Load it
 738+ $this->iniCache = parse_ini_file( $this->localBaseDir . $this->iniFilePath, true, INI_SCANNER_RAW );
 739+ return true;
 740+ }
 741+
 742+
 743+
646744 /* Other functions
647745 * ------------------------------------------------- */
648746
@@ -716,62 +814,6 @@
717815 }
718816
719817 /**
720 - * Load fallbacks
721 - *
722 - * @private
723 - *
724 - * @return true
725 - */
726 - private function loadFallbacks(){
727 -
728 - // Don't load twice
729 - if ( is_array( $this->langFallbacks ) ) {
730 - return false;
731 - }
732 -
733 - $path = $this->localBaseDir . '/language/Fallbacks.php';
734 - if ( !file_exists( $path ) ) {
735 - $this->errTrigger( 'Fallbacks.php is missing', __METHOD__, E_NOTICE, __FILE__, __LINE__ );
736 - return false;
737 - }
738 -
739 - // Load it
740 - $fallbacks = array();
741 - include( $path );
742 - $this->langFallbacks = $fallbacks;
743 -
744 - return true;
745 - }
746 -
747 - /**
748 - * Load names
749 - *
750 - * @private
751 - *
752 - * @return true
753 - */
754 - private function loadNames(){
755 -
756 - // Don't load twice
757 - if ( is_array( $this->langNames ) ) {
758 - return false;
759 - }
760 -
761 - $path = $this->localBaseDir . '/language/Names.php';
762 - if ( !file_exists( $path ) ) {
763 - $this->errTrigger( 'Names.php is missing', __METHOD__, E_NOTICE, __FILE__, __LINE__ );
764 - return false;
765 - }
766 -
767 - // Load it
768 - $wgLanguageNames = array();
769 - include( $path );
770 - $this->langNames = $wgLanguageNames;
771 -
772 - return true;
773 - }
774 -
775 - /**
776818 * Check language choise tree in the following order:
777819 * - First: Construct override
778820 * - Second: Parameter override
Index: trunk/tools/ToolserverI18N/public_html/index.php
@@ -36,13 +36,13 @@
3737 */
3838 require_once( '/home/krinkle/common/InitTool.php' );
3939
40 -$svninfo = kfCwdSvnInfo();
 40+$svninfo = kfGetSvnInfo( '/home/krinkle/TsIntuition/' ); // parses .svn/entries
4141 $toolConfig = array(
4242 'displayTitle' => _( 'fullname' ),
4343 'krinklePrefix' => false,
4444 'simplePath' => '/TsIntuition/',
45 - 'revisionId' => "0.1.0 (<a target=\"blank\" href=\"{$svninfo['cwd_last_rev_link']}\">r{$svninfo['cwd_last_rev']}</a>)",
46 - 'revisionDate' => $I18N->dateFormatted( $svninfo['cwd_last_date'] ),
 45+ 'revisionId' => "0.1.0 (<a target=\"blank\" href=\"{$svninfo['codereview-rev']}\">r{$svninfo['checkout-rev']}</a>)",
 46+ 'revisionDate' => $I18N->dateFormatted( $svninfo['directory-up-date'] ),
4747 'styles' => array( 'main.css' ),
4848 );
4949
@@ -77,8 +77,12 @@
7878 switch ( $_GET['action'] ) {
7979 case 'clearcookies':
8080 $I18N->wipeCookies();
81 - $I18N->redirectTo( $Tool->remoteBasePath, 302 );
 81+ $I18N->redirectTo( $Tool->generatePermalink( array( 'msg' => 2 ) ), 302 );
8282 break;
 83+ case 'renewcookies':
 84+ $I18N->renewCookies();
 85+ $I18N->redirectTo( $Tool->generatePermalink( array( 'msg' => 3 ) ), 302 );
 86+ break;
8387 }
8488 }
8589
@@ -88,10 +92,32 @@
8993 */
9094 $Tool->addOut( _g( 'welcome' ), 'h2' );
9195
 96+// Messages ?
 97+if ( isset( $_GET['msg'] ) ) {
 98+ switch ( $_GET['msg'] ) {
 99+ case 2:
 100+ $Tool->addOut(
 101+ _( 'clearcookies-success' ),
 102+ 'div',
 103+ array( 'class' => 'msg ns' )
 104+ );
 105+ break;
 106+ case 3:
 107+ $Tool->addOut(
 108+ _( 'renewcookies-success', array( 'variables' => array( '30 ' . _g( 'days' ) ) ) ),
 109+ 'div',
 110+ array( 'class' => 'msg ns success' )
 111+ );
 112+ break;
 113+ }
 114+}
 115+
92116 // Cookie has already been set, show "current-settings" box
93117 if ( isset( $_COOKIE[ $I18N->getCookieName( 'userlang' ) ] ) ) {
94118
95119 $lifetime = $I18N->getCookieLifetime();
 120+ $after = '';
 121+ $renew = ' (' . kfTag( _('renew-cookies'), 'a', array( 'href' => $Tool->generatePermalink(array('action' => 'renewcookies')) ) ) .')';
96122 // 29+ days
97123 if ( $lifetime > 29*24*3600 ) {
98124 $class = 'perfect';
@@ -106,11 +132,14 @@
107133 } elseif ( $lifetime > 24*3600 ) {
108134 $class = 'bad';
109135 $time = floor( $lifetime/3600/24 ) . '+ ' . _g('days');
 136+ $after = $renew;
110137
111138 // Less than a day
112139 } else {
113140 $class = 'worst';
114141 $time = '<' . ceil( $lifetime/3600 ) . ' ' . _g('hours');
 142+ $after = $renew;
 143+
115144 }
116145
117146 $Tool->addOut(
@@ -119,37 +148,35 @@
120149 . kfTag( _( 'current-language' ) . _g( 'colon-separator' ) . ' ', 'label' )
121150 . kfTag( '', 'input', array( 'value' => $I18N->getLang(), 'readonly' => 'readonly' ) )
122151 . ' ('
123 - . kfTag( _( 'clear-memory'), 'a', array( 'href' => $Tool->generatePermalink( array( 'action' => 'clearcookies' ) ) ) )
 152+ . kfTag( _( 'clear-cookies'), 'a', array( 'href' => $Tool->generatePermalink( array( 'action' => 'clearcookies' ) ) ) )
124153 . ')<br />'
125154 . kfTag( _( 'cookie-expiration' ) . _g( 'colon-separator' ), 'label' ) . kfTag( '', 'input', array( 'value' => $time, 'class' => "cookie-health $class", 'readonly' => 'readonly' ) )
 155+ . $after
126156 . '</form>'
127157 );
128158
129159
130160 }
131161
132 -// @TODO: This should be done with TsIntuition::getAvailableLanguages after loadig all domains
133 -$langs = array( 'en', 'nl', 'de' );
134 -
135162 // XXX: Quick way to build the form
136163 $dropdown = '<select name="fpLang">';
137164 $selected = ' selected="selected"';
138 -foreach ( $langs as $lang ) {
139 - $attr = $lang == $I18N->getLang() ? $selected : '';
140 - $dropdown .= '<option value="' . $lang . '"' . $attr . '>' . $I18N->getlangName( $lang ) . '</option>';
 165+foreach ( $I18N->getAvailableLangs() as $langCode => $langName ) {
 166+ $attr = $langCode == $I18N->getLang() ? $selected : '';
 167+ $dropdown .= '<option value="' . $langCode . '"' . $attr . '>' . $langName . '</option>';
141168 }
142169 $dropdown .= '</select>';
143170
144171 $form = '<form action="' . $Tool->remoteBasePath . '" method="post" class="cleanform"><fieldset>
145172 <legend>' . _( 'settings-legend' ) . '</legend>
146173
147 - <label>' . _( 'choose-language' ) . _g( 'colon-separator' ) . '</label>
 174+ <label>' . _html( 'choose-language' ) . _g( 'colon-separator' ) . '</label>
148175 ' . $dropdown . '
149176 <br />
150177
151178 <input type="hidden" name="action" value="prefset" />
152179 <label></label>
153 - <input type="submit" nof value="' . _g( 'form-submit' ) . '" />
 180+ <input type="submit" nof value="' . _html( 'form-submit', 'general' ) . '" />
154181 <br />
155182
156183 </fieldset></form>';
Index: trunk/tools/ToolserverI18N/language/messages/Tsintuition.i18n.php
@@ -17,14 +17,19 @@
1818 'current-language' => 'Currently selected language',
1919 'settings-legend' => 'Settings',
2020 'choose-language' => 'Choose a language',
21 - 'clear-memory' => 'clear cookies',
 21+ 'clear-cookies' => 'clear cookies',
 22+ 'renew-cookies' => 'renew cookies',
2223 'cookie-expiration' => 'Cookie expiration',
 24+ 'clearcookies-success' => 'Succesfully cleared cookies.',
 25+ 'renewcookies-success' => 'Cookies renewed! You\'re all set for the next $1.',
2326 );
2427
2528 /**
2629 * Documentation
2730 */
2831 $messages['qqq'] = array(
 32+ 'clearcookies-success' => 'Message displayed after cookies are cleared.',
 33+ 'renewcookies-success' => 'This message is shown after the cookies are renewed. The $1 variable contains the period of time until the cookies will expire (eg. "30 days")..',
2934 );
3035
3136 /**
@@ -38,8 +43,10 @@
3944 'current-language' => 'Huidige taal',
4045 'settings-legend' => 'Instellingen',
4146 'choose-language' => 'Kies een taal',
42 - 'clear-memory' => 'cookies wissen',
 47+ 'clear-cookies' => 'cookies wissen',
4348 'cookie-expiration' => 'Cookie verlooptijd',
 49+ 'clearcookies-success' => 'Cookies gewist.',
 50+ 'renewcookies-success' => 'Cookies vernieuwd! Je bent weer helemaal gereed voor de komende $1.',
4451 );
4552
4653 /**
Index: trunk/tools/ToolserverI18N/TsIntuitionUtil.php
@@ -54,7 +54,7 @@
5555 }
5656
5757 /**
58 - * Pass one or more arguments which will be checked untill one fails
 58+ * Pass one or more arguments which will be checked until one fails
5959 * If atleast one argument is not a non-empty string, or if no arguments / NULL passed
6060 * it will return false, otherwise true;
6161 */
Index: trunk/tools/ToolserverI18N/toolserver-defines.txt
@@ -1,13 +1,10 @@
2 -General
 2+[General]
33
4 -Getwikiapi
5 -
 4+[Getwikiapi]
65 ignored = title
76
8 -Svgtranslate
9 -
 7+[Svgtranslate]
108 optional = format-filename-example, format-fullurl-example
119
12 -Tsintuition
13 -
 10+[Tsintuition]
1411 ignored = title
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r94305Change getAvailableLangs (added in r84981) to return by default the languages...platonides23:53, 11 August 2011

Status & tagging log