https://www.mediawiki.org/wiki/Special:Code/MediaWiki/102212
Revision: 102212
Author: krinkle
Date: 2011-11-06 23:59:56 +0000 (Sun, 06 Nov 2011)
Log Message:
-----------
[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
trunk/tools/ToolserverI18N/TsIntuition.php
trunk/tools/ToolserverI18N/public_html/index.php
Modified: trunk/tools/ToolserverI18N/Defines.php
===================================================================
--- trunk/tools/ToolserverI18N/Defines.php 2011-11-06 23:55:04 UTC (rev
102211)
+++ trunk/tools/ToolserverI18N/Defines.php 2011-11-06 23:59:56 UTC (rev
102212)
@@ -13,3 +13,6 @@
define( 'TSINT_HELP_ALL', true );
define( 'TSINT_HELP_NONE', false );
define( 'TSINT_HELP_CURRENT', null );
+
+define( 'TSINT_COOKIE_TRACK', true );
+define( 'TSINT_COOKIE_NOTRACK', true );
Modified: trunk/tools/ToolserverI18N/TsIntuition.php
===================================================================
--- trunk/tools/ToolserverI18N/TsIntuition.php 2011-11-06 23:55:04 UTC (rev
102211)
+++ trunk/tools/ToolserverI18N/TsIntuition.php 2011-11-06 23:59:56 UTC (rev
102212)
@@ -772,21 +772,22 @@
*
* @return boolean
*/
- public function setCookie( $name, $val, $lifetime = 2592000 /* 30 days
*/, $track = true ) {
+ public function setCookie( $key, $val, $lifetime = 2592000 /* 30 days
*/, $track = TSINT_COOKIE_TRACK ) {
// Validate cookie name
- $name = $this->getCookieName( $name );
+ $name = $this->getCookieName( $key );
if ( !$name ) {
return false;
}
+
$val = strval( $val );
$lifetime = intval( $lifetime );
$expire = time() + $lifetime;
// Set a 30-day domain-wide cookie
- setcookie( $name, $val, $expire, '/', '.toolserver.org'
);
+ setcookie( $name, $val, $expire, '/' );
// In order to keep track of the expiration date, we
set another cookie
- if ( $track ) {
+ if ( $track === TSINT_COOKIE_TRACK ) {
$this->setExpiryTrackerCookie( $lifetime );
}
@@ -798,8 +799,8 @@
* In order to keep track of the expiration date, we set an additional
cookie.
*/
private function setExpiryTrackerCookie( $lifetime ) {
- $expire = time() + intval( $lifetime );
- setcookie( $this->getCookieName( 'track-expire' ), $expire,
$expire, '/', '.toolserver.org' );
+ $val = time() + $lifetime;
+ $this->setCookie( 'track-expire', $val, $lifetime,
TSINT_COOKIE_NOTRACK );
return true;
}
@@ -807,8 +808,11 @@
* Renew all cookies
*/
public function renewCookies( $lifetime = 2592000 /* 30 days */ ) {
- foreach( $this->getCookieNames() as $name ) {
- $this->setCookie( $name, $_COOKIE[$name], $lifetime,
false );
+ foreach( $this->getCookieNames() as $key => $name ) {
+ if ( $key === 'track-expire' ) {
+ continue;
+ }
+ $this->setCookie( $key, $_COOKIE[$name], $lifetime,
TSINT_COOKIE_NOTRACK );
}
$this->setExpiryTrackerCookie( $lifetime );
return true;
@@ -821,8 +825,8 @@
*/
public function wipeCookies() {
$week = 7 * 24 * 3600;
- foreach( $this->getCookieNames() as $name ) {
- setcookie( $name, '', time()-$week, '/',
'.toolserver.org' );
+ foreach( $this->getCookieNames() as $key => $name ) {
+ $this->setCookie( $key, '', 0-$week,
TSINT_COOKIE_NOTRACK );
unset( $_COOKIE[$name] );
}
return true;
Modified: trunk/tools/ToolserverI18N/public_html/index.php
===================================================================
--- trunk/tools/ToolserverI18N/public_html/index.php 2011-11-06 23:55:04 UTC
(rev 102211)
+++ trunk/tools/ToolserverI18N/public_html/index.php 2011-11-06 23:59:56 UTC
(rev 102212)
@@ -148,7 +148,7 @@
break;
case 3:
$Tool->addOut(
- _( 'renewcookies-success', array( 'variables'
=> array( '30 ' . _g( 'days' ) ) ) ),
+ _( 'renewcookies-success', array( 'variables'
=> array( '30 ' . _g( 'days', array( 'parsemag' => true, 'variables' => array(
30 ) ) ) ) ) ),
'div',
array( 'class' => 'msg ns success' )
);
@@ -167,23 +167,27 @@
// 29+ days
if ( $lifetime > 29*24*3600 ) {
$class = 'perfect';
- $time = floor( $lifetime/3600/24/7 ) . '+ ' . _g( 'weeks',
array( 'parsemag' => true ) );
+ $number = floor( $lifetime/3600/24/7 );
+ $time = $number . '+ ' . _g( 'weeks', array( 'parsemag' =>
true, 'variables' => array( $number ) ) );
// 10+ days
} elseif ( $lifetime > 10*24*3600 ) {
$class = 'good';
- $time = floor( $lifetime/3600/24 ) . '+ ' . _g( 'days', array(
'parsemag' => true ) );
+ $number = floor( $lifetime/3600/24 );
+ $time = $number . '+ ' . _g( 'days', array( 'parsemag' => true,
'variables' => array( $number ) ) );
// 1+ day
} elseif ( $lifetime > 24*3600 ) {
$class = 'bad';
- $time = floor( $lifetime/3600/24 ) . '+ ' . _g( 'days', array(
'parsemag' => true ) );
+ $number = floor( $lifetime/3600/24 );
+ $time = $number . '+ ' . _g( 'days', array( 'parsemag' => true,
'variables' => array( $number ) ) );
$after = $renew;
// Less than a day
} else {
$class = 'worst';
- $time = '<' . ceil( $lifetime/3600 ) . ' ' . _g( 'hours',
array( 'parsemag' => true ) );
+ $number = ceil( $lifetime/3600 );
+ $time = '<' . $number . '+ ' . _g( 'hours', array( 'parsemag'
=> true, 'variables' => array( $number ) ) );
$after = $renew;
}
@@ -204,7 +208,7 @@
. $after
. '</div></fieldset></form></div><!-- #tab-currentsettings -->'
);
- $toolSettings['tabs']['#tab-currentsettings'] = _('tab-overview');
+ $toolSettings['tabs']['#tab-currentsettings'] = _( 'tab-overview' );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs