r85270 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85269‎ | r85270 | r85271 >
Date:19:39, 3 April 2011
Author:krinkle
Status:deferred
Tags:
Comment:
begin of backlink and returnto implementation
Modified paths:
  • /trunk/tools/ToolserverI18N/TsIntuition.php (modified) (history)
  • /trunk/tools/ToolserverI18N/language/messages/Tsintuition.i18n.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/index.php (modified) (history)

Diff [purge]

Index: trunk/tools/ToolserverI18N/TsIntuition.php
@@ -78,6 +78,12 @@
7979 // These variable names will be extracted from the message files
8080 private $includeVariables = array( 'messages' );
8181
 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+
8288 /* Init
8389 * ------------------------------------------------- */
8490
@@ -784,23 +790,82 @@
785791
786792
787793
 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+
788834 /* Other functions
789835 * ------------------------------------------------- */
790836
791837 /**
792 - * Redirect or refrsh to url.
 838+ * Redirect or refresh to url. Pass null to undo redirection.
793839 *
 840+ * @param $url string
 841+ * @param $code integer (optional)
 842+ *
794843 * @return false on failure.
795844 */
796845 public function redirectTo( $url = 0, $code = 302 ) {
 846+ if ( is_null( $url ) ) {
 847+ $this->redirectTo = null;
 848+ return true;
 849+ }
797850 if ( !is_string( $url ) || !is_int( $code ) ) {
798851 return false;
799852 }
800 - header( 'Content-Type: text/html; charset=utf-8' );
801 - header( "Location: $url", true, $code );
802 - exit;
 853+ $this->redirectTo = array( $url, $code );
803854 }
804855
 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+
805870 /**
806871 * Get a localized date. Pass a format, time or both.
807872 * Defaults to the current timestamp in the language's default date format.
Index: trunk/tools/ToolserverI18N/public_html/index.php
@@ -99,6 +99,29 @@
100100 }
101101
102102 /**
 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+/**
103126 * Body (Just a quick hack for proof-of-concept)
104127 * -------------------------------------------------
105128 */
@@ -193,6 +216,8 @@
194217 <br />
195218
196219 <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' ) ) . '" />
197222 <label></label>
198223 <input type="submit" nof value="' . _html( 'form-submit', 'general' ) . '" />
199224 <br />
Index: trunk/tools/ToolserverI18N/language/messages/Tsintuition.i18n.php
@@ -24,6 +24,10 @@
2525 'renewcookies-success' => 'Cookies renewed! You\'re all set for the next $1.',
2626 'tab-overview' => 'Overview',
2727 '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.',
2832 );
2933
3034 /**
@@ -34,6 +38,10 @@
3539 '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")..',
3640 'tab-overview' => 'Dashboard tab for "Overview" which shows the current settings.',
3741 '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 .',
3846 );
3947
4048 /**
@@ -53,7 +61,7 @@
5462 'clearcookies-success' => 'Cookies gewist.',
5563 'renewcookies-success' => 'Cookies vernieuwd! Je bent weer helemaal gereed voor de komende $1.',
5664 'tab-overview' => 'Overzicht',
57 - 'tab-settings' => 'Instellingen',
 65+ 'tab-settings' => 'Verander instellingen',
5866 );
5967
6068 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r85289adding support for MonumentsAPI (for real this time) - on ignore for now for ...krinkle22:20, 3 April 2011

Status & tagging log