Index: trunk/tools/ToolserverI18N/TsIntuition.php |
— | — | @@ -78,6 +78,12 @@ |
79 | 79 | // These variable names will be extracted from the message files |
80 | 80 | private $includeVariables = array( 'messages' ); |
81 | 81 | |
| 82 | + // Address to the dashboard home. Should end with a slash or .extension |
| 83 | + private $dashboardHome = 'http://toolserver.org/~krinkle/TsIntuition/'; |
| 84 | + |
| 85 | + // Redirect address and status |
| 86 | + private $redirectTo = null; |
| 87 | + |
82 | 88 | /* Init |
83 | 89 | * ------------------------------------------------- */ |
84 | 90 | |
— | — | @@ -784,23 +790,82 @@ |
785 | 791 | |
786 | 792 | |
787 | 793 | |
| 794 | + /* Output promo and dashboard backlinks |
| 795 | + * ------------------------------------------------- */ |
| 796 | + /** |
| 797 | + * Show a link that explains that this tool has been |
| 798 | + * localized via Toolserver Intuition and that they |
| 799 | + * can change the language by setting their preference |
| 800 | + * in the dashboard. Or (if they've done so already) |
| 801 | + * that they can manage their settings there |
| 802 | + */ |
| 803 | + public function dashboardBacklink() { |
| 804 | + |
| 805 | + if ( $this->hasCookies() ) { |
| 806 | + $text = $this->msg( 'bl-mysettings', 'tsintuition' ); |
| 807 | + } else { |
| 808 | + $text = $this->msg( 'bl-mysettings-new', 'tsintuition' ); |
| 809 | + } |
| 810 | + $p = array( |
| 811 | + 'returnto' => $_SERVER['SCRIPT_NAME'], |
| 812 | + 'returntoquery' => http_build_query( $_GET ), |
| 813 | + ); |
| 814 | + $p = http_build_query( $p ); |
| 815 | + return kfTag( |
| 816 | + $text, |
| 817 | + 'a', |
| 818 | + array( |
| 819 | + 'href' => "{$this->dashboardHome}?$p", |
| 820 | + 'title' => $this->msg( 'bl-changelanguage', 'tsintuition' ), |
| 821 | + ) |
| 822 | + ); |
| 823 | + } |
| 824 | + |
| 825 | + public function showPromo(){ |
| 826 | + // http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Wikimedia_Community_Logo-Toolserver.svg/21px-Wikimedia_Community_Logo-Toolserver.svg.png |
| 827 | + |
| 828 | + // bl-promo |
| 829 | + // bl-changelanguage |
| 830 | + return ''; |
| 831 | + } |
| 832 | + |
| 833 | + |
788 | 834 | /* Other functions |
789 | 835 | * ------------------------------------------------- */ |
790 | 836 | |
791 | 837 | /** |
792 | | - * Redirect or refrsh to url. |
| 838 | + * Redirect or refresh to url. Pass null to undo redirection. |
793 | 839 | * |
| 840 | + * @param $url string |
| 841 | + * @param $code integer (optional) |
| 842 | + * |
794 | 843 | * @return false on failure. |
795 | 844 | */ |
796 | 845 | public function redirectTo( $url = 0, $code = 302 ) { |
| 846 | + if ( is_null( $url ) ) { |
| 847 | + $this->redirectTo = null; |
| 848 | + return true; |
| 849 | + } |
797 | 850 | if ( !is_string( $url ) || !is_int( $code ) ) { |
798 | 851 | return false; |
799 | 852 | } |
800 | | - header( 'Content-Type: text/html; charset=utf-8' ); |
801 | | - header( "Location: $url", true, $code ); |
802 | | - exit; |
| 853 | + $this->redirectTo = array( $url, $code ); |
803 | 854 | } |
804 | 855 | |
| 856 | + public function doRedirect(){ |
| 857 | + if ( is_array( $this->redirectTo ) ) { |
| 858 | + header( 'Content-Type: text/html; charset=utf-8' ); |
| 859 | + header( 'Location: ' . $this->redirectTo[0], true, $this->redirectTo[1] ); |
| 860 | + exit; |
| 861 | + } else { |
| 862 | + return false; |
| 863 | + } |
| 864 | + } |
| 865 | + |
| 866 | + public function isRedirecting(){ |
| 867 | + return is_array( $this->redirectTo ); |
| 868 | + } |
| 869 | + |
805 | 870 | /** |
806 | 871 | * Get a localized date. Pass a format, time or both. |
807 | 872 | * Defaults to the current timestamp in the language's default date format. |
Index: trunk/tools/ToolserverI18N/public_html/index.php |
— | — | @@ -99,6 +99,29 @@ |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
| 103 | + * Custom return to |
| 104 | + * ------------------------------------------------- |
| 105 | + */ |
| 106 | +// Tools can pass returnto and returntoquery parameters |
| 107 | +// to redirect visitors back to them after setting, changing |
| 108 | +// or doing something (eg. clearcookies, renewcookies or prefset) |
| 109 | +if ( $I18N->isRedirecting() ) { |
| 110 | + $returnTo = $kgReq->getVal( 'returnto' ); |
| 111 | + $returnToQuery = $kgReq->getVal( 'returntoquery' ); |
| 112 | + if ( TsIntuitionUtil::nonEmptyStr( $returnTo ) ) { |
| 113 | + if ( !TsIntuitionUtil::nonEmptyStr( $returnToQuery ) ) { |
| 114 | + $returnToQuery = '?' . urldecode( $returnToQuery ); |
| 115 | + } else { |
| 116 | + $returnToQuery = ''; |
| 117 | + } |
| 118 | + $I18N->redirectTo( "http://{$_SERVER['SERVER_NAME']}$returnTo$returnToQuery", 302 ); |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | +$I18N->doRedirect(); |
| 124 | + |
| 125 | +/** |
103 | 126 | * Body (Just a quick hack for proof-of-concept) |
104 | 127 | * ------------------------------------------------- |
105 | 128 | */ |
— | — | @@ -193,6 +216,8 @@ |
194 | 217 | <br /> |
195 | 218 | |
196 | 219 | <input type="hidden" name="action" value="prefset" /> |
| 220 | + <input type="hidden" name="returnto" value="' . htmlspecialchars( $kgReq->getVal( 'returnto' ) ) . '" /> |
| 221 | + <input type="hidden" name="returntoquery" value="' . htmlspecialchars( $kgReq->getVal( 'returntoquery' ) ) . '" /> |
197 | 222 | <label></label> |
198 | 223 | <input type="submit" nof value="' . _html( 'form-submit', 'general' ) . '" /> |
199 | 224 | <br /> |
Index: trunk/tools/ToolserverI18N/language/messages/Tsintuition.i18n.php |
— | — | @@ -24,6 +24,10 @@ |
25 | 25 | 'renewcookies-success' => 'Cookies renewed! You\'re all set for the next $1.', |
26 | 26 | 'tab-overview' => 'Overview', |
27 | 27 | 'tab-settings' => 'Settings', |
| 28 | + 'bl-mysettings' => 'My translation settings', |
| 29 | + 'bl-mysettings-new' => 'Change language!', |
| 30 | + 'bl-promo' => 'Translation is powered by $1 and $2.', |
| 31 | + 'bl-changelanguage' => 'Click here to change the interface language of this tool.', |
28 | 32 | ); |
29 | 33 | |
30 | 34 | /** |
— | — | @@ -34,6 +38,10 @@ |
35 | 39 | '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")..', |
36 | 40 | 'tab-overview' => 'Dashboard tab for "Overview" which shows the current settings.', |
37 | 41 | 'tab-settings' => 'Dashboard tab for "Settings" which allows the user to edit the settings.', |
| 42 | + 'bl-mysettings' => 'Backlink from within other tools to the dashboard for users that have used TsIntuition before.', |
| 43 | + 'bl-mysettings-new' => 'Backlink to TsIntuition for users that are new to TsIntuition!', |
| 44 | + 'bl-promo' => 'Sentence displayed at the bottom of other tools promoting TranslateWiki and Toolserver Intuition. $1 is a link to TranslateWiki\'s main page , $2 the link to TsIntuition\'s about page.', |
| 45 | + 'bl-changelanguage' => 'Clickable link displayed at the bottom of other tools to the dashboard .', |
38 | 46 | ); |
39 | 47 | |
40 | 48 | /** |
— | — | @@ -53,7 +61,7 @@ |
54 | 62 | 'clearcookies-success' => 'Cookies gewist.', |
55 | 63 | 'renewcookies-success' => 'Cookies vernieuwd! Je bent weer helemaal gereed voor de komende $1.', |
56 | 64 | 'tab-overview' => 'Overzicht', |
57 | | - 'tab-settings' => 'Instellingen', |
| 65 | + 'tab-settings' => 'Verander instellingen', |
58 | 66 | ); |
59 | 67 | |
60 | 68 | /** |