r102212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102211‎ | r102212 | r102213 >
Date:23:59, 6 November 2011
Author:krinkle
Status:deferred
Tags:
Comment:
[TsIntuition] Sync bug fixes back from sandbox
* Add plural-support for weeks/days/hours
-- r102206 did it for renew-cookies, undoing that
-- Doing it for weeks/days/hours instead
-- Follows-up r102206

* Use TsIntuition::setCookie internally as well, don't use PHP's setcookie() anywhere directly (other than in TsIntuition::setCookie)
-- Removing '.toolserver.org' domain (makes testing easier), no need to support other subdomains.
-- Make setCookie fallback to the key
-- Fix minor issue where cookie 'track-expire' is set twice in renewCookies()
-- Add defines TSINT_COOKIE_NOTRACK & TSINT_COOKIE_TRACK instead of booleans directly
Modified paths:
  • /trunk/tools/ToolserverI18N/Defines.php (modified) (history)
  • /trunk/tools/ToolserverI18N/TsIntuition.php (modified) (history)
  • /trunk/tools/ToolserverI18N/public_html/index.php (modified) (history)

Diff [purge]

Index: trunk/tools/ToolserverI18N/TsIntuition.php
@@ -772,21 +772,22 @@
773773 *
774774 * @return boolean
775775 */
776 - public function setCookie( $name, $val, $lifetime = 2592000 /* 30 days */, $track = true ) {
 776+ public function setCookie( $key, $val, $lifetime = 2592000 /* 30 days */, $track = TSINT_COOKIE_TRACK ) {
777777 // Validate cookie name
778 - $name = $this->getCookieName( $name );
 778+ $name = $this->getCookieName( $key );
779779 if ( !$name ) {
780780 return false;
781781 }
 782+
782783 $val = strval( $val );
783784 $lifetime = intval( $lifetime );
784785 $expire = time() + $lifetime;
785786
786787 // Set a 30-day domain-wide cookie
787 - setcookie( $name, $val, $expire, '/', '.toolserver.org' );
 788+ setcookie( $name, $val, $expire, '/' );
788789
789790 // In order to keep track of the expiration date, we set another cookie
790 - if ( $track ) {
 791+ if ( $track === TSINT_COOKIE_TRACK ) {
791792 $this->setExpiryTrackerCookie( $lifetime );
792793 }
793794
@@ -798,8 +799,8 @@
799800 * In order to keep track of the expiration date, we set an additional cookie.
800801 */
801802 private function setExpiryTrackerCookie( $lifetime ) {
802 - $expire = time() + intval( $lifetime );
803 - setcookie( $this->getCookieName( 'track-expire' ), $expire, $expire, '/', '.toolserver.org' );
 803+ $val = time() + $lifetime;
 804+ $this->setCookie( 'track-expire', $val, $lifetime, TSINT_COOKIE_NOTRACK );
804805 return true;
805806 }
806807
@@ -807,8 +808,11 @@
808809 * Renew all cookies
809810 */
810811 public function renewCookies( $lifetime = 2592000 /* 30 days */ ) {
811 - foreach( $this->getCookieNames() as $name ) {
812 - $this->setCookie( $name, $_COOKIE[$name], $lifetime, false );
 812+ foreach( $this->getCookieNames() as $key => $name ) {
 813+ if ( $key === 'track-expire' ) {
 814+ continue;
 815+ }
 816+ $this->setCookie( $key, $_COOKIE[$name], $lifetime, TSINT_COOKIE_NOTRACK );
813817 }
814818 $this->setExpiryTrackerCookie( $lifetime );
815819 return true;
@@ -821,8 +825,8 @@
822826 */
823827 public function wipeCookies() {
824828 $week = 7 * 24 * 3600;
825 - foreach( $this->getCookieNames() as $name ) {
826 - setcookie( $name, '', time()-$week, '/', '.toolserver.org' );
 829+ foreach( $this->getCookieNames() as $key => $name ) {
 830+ $this->setCookie( $key, '', 0-$week, TSINT_COOKIE_NOTRACK );
827831 unset( $_COOKIE[$name] );
828832 }
829833 return true;
Index: trunk/tools/ToolserverI18N/public_html/index.php
@@ -148,7 +148,7 @@
149149 break;
150150 case 3:
151151 $Tool->addOut(
152 - _( 'renewcookies-success', array( 'variables' => array( '30 ' . _g( 'days' ) ) ) ),
 152+ _( 'renewcookies-success', array( 'variables' => array( '30 ' . _g( 'days', array( 'parsemag' => true, 'variables' => array( 30 ) ) ) ) ) ),
153153 'div',
154154 array( 'class' => 'msg ns success' )
155155 );
@@ -167,23 +167,27 @@
168168 // 29+ days
169169 if ( $lifetime > 29*24*3600 ) {
170170 $class = 'perfect';
171 - $time = floor( $lifetime/3600/24/7 ) . '+ ' . _g( 'weeks', array( 'parsemag' => true ) );
 171+ $number = floor( $lifetime/3600/24/7 );
 172+ $time = $number . '+ ' . _g( 'weeks', array( 'parsemag' => true, 'variables' => array( $number ) ) );
172173
173174 // 10+ days
174175 } elseif ( $lifetime > 10*24*3600 ) {
175176 $class = 'good';
176 - $time = floor( $lifetime/3600/24 ) . '+ ' . _g( 'days', array( 'parsemag' => true ) );
 177+ $number = floor( $lifetime/3600/24 );
 178+ $time = $number . '+ ' . _g( 'days', array( 'parsemag' => true, 'variables' => array( $number ) ) );
177179
178180 // 1+ day
179181 } elseif ( $lifetime > 24*3600 ) {
180182 $class = 'bad';
181 - $time = floor( $lifetime/3600/24 ) . '+ ' . _g( 'days', array( 'parsemag' => true ) );
 183+ $number = floor( $lifetime/3600/24 );
 184+ $time = $number . '+ ' . _g( 'days', array( 'parsemag' => true, 'variables' => array( $number ) ) );
182185 $after = $renew;
183186
184187 // Less than a day
185188 } else {
186189 $class = 'worst';
187 - $time = '<' . ceil( $lifetime/3600 ) . ' ' . _g( 'hours', array( 'parsemag' => true ) );
 190+ $number = ceil( $lifetime/3600 );
 191+ $time = '<' . $number . '+ ' . _g( 'hours', array( 'parsemag' => true, 'variables' => array( $number ) ) );
188192 $after = $renew;
189193
190194 }
@@ -204,7 +208,7 @@
205209 . $after
206210 . '</div></fieldset></form></div><!-- #tab-currentsettings -->'
207211 );
208 - $toolSettings['tabs']['#tab-currentsettings'] = _('tab-overview');
 212+ $toolSettings['tabs']['#tab-currentsettings'] = _( 'tab-overview' );
209213
210214
211215 }
Index: trunk/tools/ToolserverI18N/Defines.php
@@ -13,3 +13,6 @@
1414 define( 'TSINT_HELP_ALL', true );
1515 define( 'TSINT_HELP_NONE', false );
1616 define( 'TSINT_HELP_CURRENT', null );
 17+
 18+define( 'TSINT_COOKIE_TRACK', true );
 19+define( 'TSINT_COOKIE_NOTRACK', true );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102206[TsIntuition] Enable parsemag for 'renew-cookies' (it uses {{PLURAL}})krinkle23:07, 6 November 2011

Status & tagging log