Index: trunk/tools/ToolserverI18N/TsIntuition.php |
— | — | @@ -28,6 +28,7 @@ |
29 | 29 | * ------------------------------------------------- */ |
30 | 30 | |
31 | 31 | private $localBaseDir = '/home/krinkle/TsIntuition'; // to be moved to p_i18n |
| 32 | + private $iniFilePath = '/toolserver-defines.txt'; |
32 | 33 | |
33 | 34 | private $suppresserrors = false; |
34 | 35 | private $suppressnotices = true; |
— | — | @@ -38,6 +39,10 @@ |
39 | 40 | |
40 | 41 | private $currentLanguage = 'en'; |
41 | 42 | |
| 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 | + |
42 | 47 | // Changing this will invalidate all cookies |
43 | 48 | private $cookieNames = array( 'userlang' => 'TsIntuition_userlang', 'track-expire' => 'TsIntuition_expiry' ); |
44 | 49 | |
— | — | @@ -86,6 +91,7 @@ |
87 | 92 | * - param |
88 | 93 | */ |
89 | 94 | function __construct( $options = array() ) { |
| 95 | + |
90 | 96 | if ( is_string( $options) ) { |
91 | 97 | $options = array( 'domain' => $options ); |
92 | 98 | } |
— | — | @@ -483,7 +489,16 @@ |
484 | 490 | return is_array( $this->langNames ) ? $this->langNames : array(); |
485 | 491 | } |
486 | 492 | |
| 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 | + } |
487 | 501 | |
| 502 | + |
488 | 503 | /* Textdomain functions |
489 | 504 | * ------------------------------------------------- */ |
490 | 505 | |
— | — | @@ -540,6 +555,7 @@ |
541 | 556 | if ( !isset( $data['messages'] ) || !is_array( $data['messages'] ) ) { |
542 | 557 | $this->errTrigger( 'No $messages array found', __METHOD__ , E_ERROR, $filePath ); |
543 | 558 | } |
| 559 | + unset( $data['messages']['qqq'] ); // Workaround |
544 | 560 | // Load the message into the blob |
545 | 561 | // overwrites the existing array of messages if it already existed |
546 | 562 | // If you need to add or overwrite some messages temporarily, use Itui::setMsg() or Itui::setMsgs() instead |
— | — | @@ -587,7 +603,8 @@ |
588 | 604 | } |
589 | 605 | |
590 | 606 | /** |
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. |
592 | 609 | */ |
593 | 610 | private function setExpiryTrackerCookie( $lifetime ) { |
594 | 611 | $expire = time() + intval( $lifetime ); |
— | — | @@ -602,7 +619,7 @@ |
603 | 620 | foreach( $this->getCookieNames() as $name ) { |
604 | 621 | $this->setCookie( $name, $_COOKIE[$name], $lifetime, false ); |
605 | 622 | } |
606 | | - $this-setExpiryTrackerCookie(); |
| 623 | + $this->setExpiryTrackerCookie( $lifetime ); |
607 | 624 | return true; |
608 | 625 | } |
609 | 626 | |
— | — | @@ -642,6 +659,87 @@ |
643 | 660 | } |
644 | 661 | |
645 | 662 | |
| 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 | + |
646 | 744 | /* Other functions |
647 | 745 | * ------------------------------------------------- */ |
648 | 746 | |
— | — | @@ -716,62 +814,6 @@ |
717 | 815 | } |
718 | 816 | |
719 | 817 | /** |
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 | | - /** |
776 | 818 | * Check language choise tree in the following order: |
777 | 819 | * - First: Construct override |
778 | 820 | * - Second: Parameter override |
Index: trunk/tools/ToolserverI18N/public_html/index.php |
— | — | @@ -36,13 +36,13 @@ |
37 | 37 | */ |
38 | 38 | require_once( '/home/krinkle/common/InitTool.php' ); |
39 | 39 | |
40 | | -$svninfo = kfCwdSvnInfo(); |
| 40 | +$svninfo = kfGetSvnInfo( '/home/krinkle/TsIntuition/' ); // parses .svn/entries |
41 | 41 | $toolConfig = array( |
42 | 42 | 'displayTitle' => _( 'fullname' ), |
43 | 43 | 'krinklePrefix' => false, |
44 | 44 | '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'] ), |
47 | 47 | 'styles' => array( 'main.css' ), |
48 | 48 | ); |
49 | 49 | |
— | — | @@ -77,8 +77,12 @@ |
78 | 78 | switch ( $_GET['action'] ) { |
79 | 79 | case 'clearcookies': |
80 | 80 | $I18N->wipeCookies(); |
81 | | - $I18N->redirectTo( $Tool->remoteBasePath, 302 ); |
| 81 | + $I18N->redirectTo( $Tool->generatePermalink( array( 'msg' => 2 ) ), 302 ); |
82 | 82 | break; |
| 83 | + case 'renewcookies': |
| 84 | + $I18N->renewCookies(); |
| 85 | + $I18N->redirectTo( $Tool->generatePermalink( array( 'msg' => 3 ) ), 302 ); |
| 86 | + break; |
83 | 87 | } |
84 | 88 | } |
85 | 89 | |
— | — | @@ -88,10 +92,32 @@ |
89 | 93 | */ |
90 | 94 | $Tool->addOut( _g( 'welcome' ), 'h2' ); |
91 | 95 | |
| 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 | + |
92 | 116 | // Cookie has already been set, show "current-settings" box |
93 | 117 | if ( isset( $_COOKIE[ $I18N->getCookieName( 'userlang' ) ] ) ) { |
94 | 118 | |
95 | 119 | $lifetime = $I18N->getCookieLifetime(); |
| 120 | + $after = ''; |
| 121 | + $renew = ' (' . kfTag( _('renew-cookies'), 'a', array( 'href' => $Tool->generatePermalink(array('action' => 'renewcookies')) ) ) .')'; |
96 | 122 | // 29+ days |
97 | 123 | if ( $lifetime > 29*24*3600 ) { |
98 | 124 | $class = 'perfect'; |
— | — | @@ -106,11 +132,14 @@ |
107 | 133 | } elseif ( $lifetime > 24*3600 ) { |
108 | 134 | $class = 'bad'; |
109 | 135 | $time = floor( $lifetime/3600/24 ) . '+ ' . _g('days'); |
| 136 | + $after = $renew; |
110 | 137 | |
111 | 138 | // Less than a day |
112 | 139 | } else { |
113 | 140 | $class = 'worst'; |
114 | 141 | $time = '<' . ceil( $lifetime/3600 ) . ' ' . _g('hours'); |
| 142 | + $after = $renew; |
| 143 | + |
115 | 144 | } |
116 | 145 | |
117 | 146 | $Tool->addOut( |
— | — | @@ -119,37 +148,35 @@ |
120 | 149 | . kfTag( _( 'current-language' ) . _g( 'colon-separator' ) . ' ', 'label' ) |
121 | 150 | . kfTag( '', 'input', array( 'value' => $I18N->getLang(), 'readonly' => 'readonly' ) ) |
122 | 151 | . ' (' |
123 | | - . kfTag( _( 'clear-memory'), 'a', array( 'href' => $Tool->generatePermalink( array( 'action' => 'clearcookies' ) ) ) ) |
| 152 | + . kfTag( _( 'clear-cookies'), 'a', array( 'href' => $Tool->generatePermalink( array( 'action' => 'clearcookies' ) ) ) ) |
124 | 153 | . ')<br />' |
125 | 154 | . kfTag( _( 'cookie-expiration' ) . _g( 'colon-separator' ), 'label' ) . kfTag( '', 'input', array( 'value' => $time, 'class' => "cookie-health $class", 'readonly' => 'readonly' ) ) |
| 155 | + . $after |
126 | 156 | . '</form>' |
127 | 157 | ); |
128 | 158 | |
129 | 159 | |
130 | 160 | } |
131 | 161 | |
132 | | -// @TODO: This should be done with TsIntuition::getAvailableLanguages after loadig all domains |
133 | | -$langs = array( 'en', 'nl', 'de' ); |
134 | | - |
135 | 162 | // XXX: Quick way to build the form |
136 | 163 | $dropdown = '<select name="fpLang">'; |
137 | 164 | $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>'; |
141 | 168 | } |
142 | 169 | $dropdown .= '</select>'; |
143 | 170 | |
144 | 171 | $form = '<form action="' . $Tool->remoteBasePath . '" method="post" class="cleanform"><fieldset> |
145 | 172 | <legend>' . _( 'settings-legend' ) . '</legend> |
146 | 173 | |
147 | | - <label>' . _( 'choose-language' ) . _g( 'colon-separator' ) . '</label> |
| 174 | + <label>' . _html( 'choose-language' ) . _g( 'colon-separator' ) . '</label> |
148 | 175 | ' . $dropdown . ' |
149 | 176 | <br /> |
150 | 177 | |
151 | 178 | <input type="hidden" name="action" value="prefset" /> |
152 | 179 | <label></label> |
153 | | - <input type="submit" nof value="' . _g( 'form-submit' ) . '" /> |
| 180 | + <input type="submit" nof value="' . _html( 'form-submit', 'general' ) . '" /> |
154 | 181 | <br /> |
155 | 182 | |
156 | 183 | </fieldset></form>'; |
Index: trunk/tools/ToolserverI18N/language/messages/Tsintuition.i18n.php |
— | — | @@ -17,14 +17,19 @@ |
18 | 18 | 'current-language' => 'Currently selected language', |
19 | 19 | 'settings-legend' => 'Settings', |
20 | 20 | 'choose-language' => 'Choose a language', |
21 | | - 'clear-memory' => 'clear cookies', |
| 21 | + 'clear-cookies' => 'clear cookies', |
| 22 | + 'renew-cookies' => 'renew cookies', |
22 | 23 | 'cookie-expiration' => 'Cookie expiration', |
| 24 | + 'clearcookies-success' => 'Succesfully cleared cookies.', |
| 25 | + 'renewcookies-success' => 'Cookies renewed! You\'re all set for the next $1.', |
23 | 26 | ); |
24 | 27 | |
25 | 28 | /** |
26 | 29 | * Documentation |
27 | 30 | */ |
28 | 31 | $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")..', |
29 | 34 | ); |
30 | 35 | |
31 | 36 | /** |
— | — | @@ -38,8 +43,10 @@ |
39 | 44 | 'current-language' => 'Huidige taal', |
40 | 45 | 'settings-legend' => 'Instellingen', |
41 | 46 | 'choose-language' => 'Kies een taal', |
42 | | - 'clear-memory' => 'cookies wissen', |
| 47 | + 'clear-cookies' => 'cookies wissen', |
43 | 48 | 'cookie-expiration' => 'Cookie verlooptijd', |
| 49 | + 'clearcookies-success' => 'Cookies gewist.', |
| 50 | + 'renewcookies-success' => 'Cookies vernieuwd! Je bent weer helemaal gereed voor de komende $1.', |
44 | 51 | ); |
45 | 52 | |
46 | 53 | /** |
Index: trunk/tools/ToolserverI18N/TsIntuitionUtil.php |
— | — | @@ -54,7 +54,7 @@ |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
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 |
59 | 59 | * If atleast one argument is not a non-empty string, or if no arguments / NULL passed |
60 | 60 | * it will return false, otherwise true; |
61 | 61 | */ |
Index: trunk/tools/ToolserverI18N/toolserver-defines.txt |
— | — | @@ -1,13 +1,10 @@ |
2 | | -General |
| 2 | +[General] |
3 | 3 | |
4 | | -Getwikiapi |
5 | | - |
| 4 | +[Getwikiapi] |
6 | 5 | ignored = title |
7 | 6 | |
8 | | -Svgtranslate |
9 | | - |
| 7 | +[Svgtranslate] |
10 | 8 | optional = format-filename-example, format-fullurl-example |
11 | 9 | |
12 | | -Tsintuition |
13 | | - |
| 10 | +[Tsintuition] |
14 | 11 | ignored = title |
\ No newline at end of file |