Merge "Changed TransactionProfiler to only work via the DB classes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 6 Nov 2014 18:44:02 +0000 (18:44 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 6 Nov 2014 18:44:02 +0000 (18:44 +0000)
13 files changed:
RELEASE-NOTES-1.25
includes/AutoLoader.php
includes/CategoryViewer.php
includes/Cookie.php [deleted file]
includes/EditPage.php
includes/libs/ArrayUtils.php [new file with mode: 0644]
includes/libs/Cookie.php [new file with mode: 0644]
includes/logging/LogEventsList.php
includes/specials/SpecialNewimages.php
includes/specials/SpecialVersion.php
includes/utils/ArrayUtils.php [deleted file]
includes/utils/MWFunction.php
resources/Resources.php

index aa0d5a7..b649c2b 100644 (file)
@@ -180,6 +180,8 @@ changes to languages because of Bugzilla reports.
   tag, instead of after the <text> and <sha1> tags.
   The new schema version is 0.10, the new schema URI is
   <https://www.mediawiki.org/xml/export-0.10.xsd>.
+* MWFunction::call() and MWFunction::callArray() were removed, having being
+  deprecated in 1.22.
 
 == Compatibility ==
 
index 2cb6335..e89e500 100644 (file)
@@ -48,8 +48,6 @@ $wgAutoloadLocalClasses = array(
        'CollationCkb' => 'includes/Collation.php',
        'CollationEt' => 'includes/Collation.php',
        'ConcatenatedGzipHistoryBlob' => 'includes/HistoryBlob.php',
-       'Cookie' => 'includes/Cookie.php',
-       'CookieJar' => 'includes/Cookie.php',
        'CurlHttpRequest' => 'includes/HttpFunctions.php',
        'DeprecatedGlobal' => 'includes/DeprecatedGlobal.php',
        'DerivativeRequest' => 'includes/WebRequest.php',
@@ -675,6 +673,9 @@ $wgAutoloadLocalClasses = array(
        'FormatJson' => 'includes/json/FormatJson.php',
 
        # includes/libs
+       'ArrayUtils' => 'includes/libs/ArrayUtils.php',
+       'Cookie' => 'includes/libs/Cookie.php',
+       'CookieJar' => 'includes/libs/Cookie.php',
        'CSSMin' => 'includes/libs/CSSMin.php',
        'GenericArrayObject' => 'includes/libs/GenericArrayObject.php',
        'HashRing' => 'includes/libs/HashRing.php',
@@ -1151,7 +1152,6 @@ $wgAutoloadLocalClasses = array(
        'UploadStashNoSuchKeyException' => 'includes/upload/UploadStash.php',
 
        # includes/utils
-       'ArrayUtils' => 'includes/utils/ArrayUtils.php',
        'CdbException' => 'includes/utils/Cdb.php',
        'CdbFunctions' => 'includes/utils/CdbPHP.php',
        'CdbReader' => 'includes/utils/Cdb.php',
index 7581ae4..f68da95 100644 (file)
@@ -136,7 +136,7 @@ class CategoryViewer extends ContextSource {
                }
 
                $lang = $this->getLanguage();
-               $langAttribs = array( 'lang' => $lang->getCode(), 'dir' => $lang->getDir() );
+               $langAttribs = array( 'lang' => $lang->getHtmlCode(), 'dir' => $lang->getDir() );
                # put a div around the headings which are in the user language
                $r = Html::openElement( 'div', $langAttribs ) . $r . '</div>';
 
@@ -515,7 +515,7 @@ class CategoryViewer extends ContextSource {
                }
 
                $pageLang = $this->title->getPageLanguage();
-               $attribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
+               $attribs = array( 'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
                        'class' => 'mw-content-' . $pageLang->getDir() );
                $list = Html::rawElement( 'div', $attribs, $list );
 
diff --git a/includes/Cookie.php b/includes/Cookie.php
deleted file mode 100644 (file)
index cb04190..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-<?php
-/**
- * Cookie for HTTP requests.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup HTTP
- */
-
-class Cookie {
-       protected $name;
-       protected $value;
-       protected $expires;
-       protected $path;
-       protected $domain;
-       protected $isSessionKey = true;
-       // TO IMPLEMENT  protected $secure
-       // TO IMPLEMENT? protected $maxAge (add onto expires)
-       // TO IMPLEMENT? protected $version
-       // TO IMPLEMENT? protected $comment
-
-       function __construct( $name, $value, $attr ) {
-               $this->name = $name;
-               $this->set( $value, $attr );
-       }
-
-       /**
-        * Sets a cookie.  Used before a request to set up any individual
-        * cookies. Used internally after a request to parse the
-        * Set-Cookie headers.
-        *
-        * @param string $value The value of the cookie
-        * @param array $attr Possible key/values:
-        *        expires A date string
-        *        path    The path this cookie is used on
-        *        domain  Domain this cookie is used on
-        * @throws MWException
-        */
-       public function set( $value, $attr ) {
-               $this->value = $value;
-
-               if ( isset( $attr['expires'] ) ) {
-                       $this->isSessionKey = false;
-                       $this->expires = strtotime( $attr['expires'] );
-               }
-
-               if ( isset( $attr['path'] ) ) {
-                       $this->path = $attr['path'];
-               } else {
-                       $this->path = '/';
-               }
-
-               if ( isset( $attr['domain'] ) ) {
-                       if ( self::validateCookieDomain( $attr['domain'] ) ) {
-                               $this->domain = $attr['domain'];
-                       }
-               } else {
-                       throw new MWException( 'You must specify a domain.' );
-               }
-       }
-
-       /**
-        * Return the true if the cookie is valid is valid.  Otherwise,
-        * false.  The uses a method similar to IE cookie security
-        * described here:
-        * http://kuza55.blogspot.com/2008/02/understanding-cookie-security.html
-        * A better method might be to use a blacklist like
-        * http://publicsuffix.org/
-        *
-        * @todo fixme fails to detect 3-letter top-level domains
-        * @todo fixme fails to detect 2-letter top-level domains for single-domain use (probably
-        * not a big problem in practice, but there are test cases)
-        *
-        * @param string $domain The domain to validate
-        * @param string $originDomain (optional) the domain the cookie originates from
-        * @return bool
-        */
-       public static function validateCookieDomain( $domain, $originDomain = null ) {
-               $dc = explode( ".", $domain );
-
-               // Don't allow a trailing dot or addresses without a or just a leading dot
-               if ( substr( $domain, -1 ) == '.' ||
-                       count( $dc ) <= 1 ||
-                       count( $dc ) == 2 && $dc[0] === ''
-               ) {
-                       return false;
-               }
-
-               // Only allow full, valid IP addresses
-               if ( preg_match( '/^[0-9.]+$/', $domain ) ) {
-                       if ( count( $dc ) != 4 ) {
-                               return false;
-                       }
-
-                       if ( ip2long( $domain ) === false ) {
-                               return false;
-                       }
-
-                       if ( $originDomain == null || $originDomain == $domain ) {
-                               return true;
-                       }
-
-               }
-
-               // Don't allow cookies for "co.uk" or "gov.uk", etc, but allow "supermarket.uk"
-               if ( strrpos( $domain, "." ) - strlen( $domain ) == -3 ) {
-                       if ( ( count( $dc ) == 2 && strlen( $dc[0] ) <= 2 )
-                               || ( count( $dc ) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) {
-                               return false;
-                       }
-                       if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] == '' ) )
-                               && preg_match( '/(com|net|org|gov|edu)\...$/', $domain ) ) {
-                               return false;
-                       }
-               }
-
-               if ( $originDomain != null ) {
-                       if ( substr( $domain, 0, 1 ) != '.' && $domain != $originDomain ) {
-                               return false;
-                       }
-
-                       if ( substr( $domain, 0, 1 ) == '.'
-                               && substr_compare(
-                                       $originDomain,
-                                       $domain,
-                                       -strlen( $domain ),
-                                       strlen( $domain ),
-                                       true
-                               ) != 0
-                       ) {
-                               return false;
-                       }
-               }
-
-               return true;
-       }
-
-       /**
-        * Serialize the cookie jar into a format useful for HTTP Request headers.
-        *
-        * @param string $path The path that will be used. Required.
-        * @param string $domain The domain that will be used. Required.
-        * @return string
-        */
-       public function serializeToHttpRequest( $path, $domain ) {
-               $ret = '';
-
-               if ( $this->canServeDomain( $domain )
-                               && $this->canServePath( $path )
-                               && $this->isUnExpired() ) {
-                       $ret = $this->name . '=' . $this->value;
-               }
-
-               return $ret;
-       }
-
-       /**
-        * @param string $domain
-        * @return bool
-        */
-       protected function canServeDomain( $domain ) {
-               if ( $domain == $this->domain
-                       || ( strlen( $domain ) > strlen( $this->domain )
-                               && substr( $this->domain, 0, 1 ) == '.'
-                               && substr_compare(
-                                       $domain,
-                                       $this->domain,
-                                       -strlen( $this->domain ),
-                                       strlen( $this->domain ),
-                                       true
-                               ) == 0
-                       )
-               ) {
-                       return true;
-               }
-
-               return false;
-       }
-
-       /**
-        * @param string $path
-        * @return bool
-        */
-       protected function canServePath( $path ) {
-               return ( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 );
-       }
-
-       /**
-        * @return bool
-        */
-       protected function isUnExpired() {
-               return $this->isSessionKey || $this->expires > time();
-       }
-}
-
-class CookieJar {
-       private $cookie = array();
-
-       /**
-        * Set a cookie in the cookie jar. Make sure only one cookie per-name exists.
-        * @see Cookie::set()
-        * @param string $name
-        * @param string $value
-        * @param array $attr
-        */
-       public function setCookie( $name, $value, $attr ) {
-               /* cookies: case insensitive, so this should work.
-                * We'll still send the cookies back in the same case we got them, though.
-                */
-               $index = strtoupper( $name );
-
-               if ( isset( $this->cookie[$index] ) ) {
-                       $this->cookie[$index]->set( $value, $attr );
-               } else {
-                       $this->cookie[$index] = new Cookie( $name, $value, $attr );
-               }
-       }
-
-       /**
-        * @see Cookie::serializeToHttpRequest
-        * @param string $path
-        * @param string $domain
-        * @return string
-        */
-       public function serializeToHttpRequest( $path, $domain ) {
-               $cookies = array();
-
-               foreach ( $this->cookie as $c ) {
-                       $serialized = $c->serializeToHttpRequest( $path, $domain );
-
-                       if ( $serialized ) {
-                               $cookies[] = $serialized;
-                       }
-               }
-
-               return implode( '; ', $cookies );
-       }
-
-       /**
-        * Parse the content of an Set-Cookie HTTP Response header.
-        *
-        * @param string $cookie
-        * @param string $domain Cookie's domain
-        * @return null
-        */
-       public function parseCookieResponseHeader( $cookie, $domain ) {
-               $len = strlen( 'Set-Cookie:' );
-
-               if ( substr_compare( 'Set-Cookie:', $cookie, 0, $len, true ) === 0 ) {
-                       $cookie = substr( $cookie, $len );
-               }
-
-               $bit = array_map( 'trim', explode( ';', $cookie ) );
-
-               if ( count( $bit ) >= 1 ) {
-                       list( $name, $value ) = explode( '=', array_shift( $bit ), 2 );
-                       $attr = array();
-
-                       foreach ( $bit as $piece ) {
-                               $parts = explode( '=', $piece );
-                               if ( count( $parts ) > 1 ) {
-                                       $attr[strtolower( $parts[0] )] = $parts[1];
-                               } else {
-                                       $attr[strtolower( $parts[0] )] = true;
-                               }
-                       }
-
-                       if ( !isset( $attr['domain'] ) ) {
-                               $attr['domain'] = $domain;
-                       } elseif ( !Cookie::validateCookieDomain( $attr['domain'], $domain ) ) {
-                               return null;
-                       }
-
-                       $this->setCookie( $name, $value, $attr );
-               }
-       }
-}
index fa19c78..d106da2 100644 (file)
@@ -2956,7 +2956,7 @@ HTML
                );
 
                $pageLang = $this->mTitle->getPageLanguage();
-               $attribs['lang'] = $pageLang->getCode();
+               $attribs['lang'] = $pageLang->getHtmlCode();
                $attribs['dir'] = $pageLang->getDir();
 
                $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) );
diff --git a/includes/libs/ArrayUtils.php b/includes/libs/ArrayUtils.php
new file mode 100644 (file)
index 0000000..f934021
--- /dev/null
@@ -0,0 +1,187 @@
+<?php
+/**
+ * Methods to play with arrays.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * A collection of static methods to play with arrays.
+ *
+ * @since 1.21
+ */
+class ArrayUtils {
+       /**
+        * Sort the given array in a pseudo-random order which depends only on the
+        * given key and each element value. This is typically used for load
+        * balancing between servers each with a local cache.
+        *
+        * Keys are preserved. The input array is modified in place.
+        *
+        * Note: Benchmarking on PHP 5.3 and 5.4 indicates that for small
+        * strings, md5() is only 10% slower than hash('joaat',...) etc.,
+        * since the function call overhead dominates. So there's not much
+        * justification for breaking compatibility with installations
+        * compiled with ./configure --disable-hash.
+        *
+        * @param array $array Array to sort
+        * @param string $key
+        * @param string $separator A separator used to delimit the array elements and the
+        *     key. This can be chosen to provide backwards compatibility with
+        *     various consistent hash implementations that existed before this
+        *     function was introduced.
+        */
+       public static function consistentHashSort( &$array, $key, $separator = "\000" ) {
+               $hashes = array();
+               foreach ( $array as $elt ) {
+                       $hashes[$elt] = md5( $elt . $separator . $key );
+               }
+               uasort( $array, function ( $a, $b ) use ( $hashes ) {
+                       return strcmp( $hashes[$a], $hashes[$b] );
+               } );
+       }
+
+       /**
+        * Given an array of non-normalised probabilities, this function will select
+        * an element and return the appropriate key
+        *
+        * @param array $weights
+        * @return bool|int|string
+        */
+       public static function pickRandom( $weights ) {
+               if ( !is_array( $weights ) || count( $weights ) == 0 ) {
+                       return false;
+               }
+
+               $sum = array_sum( $weights );
+               if ( $sum == 0 ) {
+                       # No loads on any of them
+                       # In previous versions, this triggered an unweighted random selection,
+                       # but this feature has been removed as of April 2006 to allow for strict
+                       # separation of query groups.
+                       return false;
+               }
+               $max = mt_getrandmax();
+               $rand = mt_rand( 0, $max ) / $max * $sum;
+
+               $sum = 0;
+               foreach ( $weights as $i => $w ) {
+                       $sum += $w;
+                       # Do not return keys if they have 0 weight.
+                       # Note that the "all 0 weight" case is handed above
+                       if ( $w > 0 && $sum >= $rand ) {
+                               break;
+                       }
+               }
+
+               return $i;
+       }
+
+       /**
+        * Do a binary search, and return the index of the largest item that sorts
+        * less than or equal to the target value.
+        *
+        * @since 1.23
+        *
+        * @param callable $valueCallback A function to call to get the value with
+        *     a given array index.
+        * @param int $valueCount The number of items accessible via $valueCallback,
+        *     indexed from 0 to $valueCount - 1
+        * @param callable $comparisonCallback A callback to compare two values, returning
+        *     -1, 0 or 1 in the style of strcmp().
+        * @param string $target The target value to find.
+        *
+        * @return int|bool The item index of the lower bound, or false if the target value
+        *     sorts before all items.
+        */
+       public static function findLowerBound( $valueCallback, $valueCount,
+               $comparisonCallback, $target
+       ) {
+               if ( $valueCount === 0 ) {
+                       return false;
+               }
+
+               $min = 0;
+               $max = $valueCount;
+               do {
+                       $mid = $min + ( ( $max - $min ) >> 1 );
+                       $item = call_user_func( $valueCallback, $mid );
+                       $comparison = call_user_func( $comparisonCallback, $target, $item );
+                       if ( $comparison > 0 ) {
+                               $min = $mid;
+                       } elseif ( $comparison == 0 ) {
+                               $min = $mid;
+                               break;
+                       } else {
+                               $max = $mid;
+                       }
+               } while ( $min < $max - 1 );
+
+               if ( $min == 0 ) {
+                       $item = call_user_func( $valueCallback, $min );
+                       $comparison = call_user_func( $comparisonCallback, $target, $item );
+                       if ( $comparison < 0 ) {
+                               // Before the first item
+                               return false;
+                       }
+               }
+               return $min;
+       }
+
+       /**
+        * Do array_diff_assoc() on multi-dimensional arrays.
+        *
+        * Note: empty arrays are removed.
+        *
+        * @since 1.23
+        *
+        * @param array $array1 The array to compare from
+        * @param array $array2,... More arrays to compare against
+        * @return array An array containing all the values from array1
+        *               that are not present in any of the other arrays.
+        */
+       public static function arrayDiffAssocRecursive( $array1 ) {
+               $arrays = func_get_args();
+               array_shift( $arrays );
+               $ret = array();
+
+               foreach ( $array1 as $key => $value ) {
+                       if ( is_array( $value ) ) {
+                               $args = array( $value );
+                               foreach ( $arrays as $array ) {
+                                       if ( isset( $array[$key] ) ) {
+                                               $args[] = $array[$key];
+                                       }
+                               }
+                               $valueret = call_user_func_array( __METHOD__, $args );
+                               if ( count( $valueret ) ) {
+                                       $ret[$key] = $valueret;
+                               }
+                       } else {
+                               foreach ( $arrays as $array ) {
+                                       if ( isset( $array[$key] ) && $array[$key] === $value ) {
+                                               continue 2;
+                                       }
+                               }
+                               $ret[$key] = $value;
+                       }
+               }
+
+               return $ret;
+       }
+}
diff --git a/includes/libs/Cookie.php b/includes/libs/Cookie.php
new file mode 100644 (file)
index 0000000..56dc6ea
--- /dev/null
@@ -0,0 +1,291 @@
+<?php
+/**
+ * Cookie for HTTP requests.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup HTTP
+ */
+
+class Cookie {
+       protected $name;
+       protected $value;
+       protected $expires;
+       protected $path;
+       protected $domain;
+       protected $isSessionKey = true;
+       // TO IMPLEMENT  protected $secure
+       // TO IMPLEMENT? protected $maxAge (add onto expires)
+       // TO IMPLEMENT? protected $version
+       // TO IMPLEMENT? protected $comment
+
+       function __construct( $name, $value, $attr ) {
+               $this->name = $name;
+               $this->set( $value, $attr );
+       }
+
+       /**
+        * Sets a cookie.  Used before a request to set up any individual
+        * cookies. Used internally after a request to parse the
+        * Set-Cookie headers.
+        *
+        * @param string $value The value of the cookie
+        * @param array $attr Possible key/values:
+        *        expires A date string
+        *        path    The path this cookie is used on
+        *        domain  Domain this cookie is used on
+        * @throws MWException
+        */
+       public function set( $value, $attr ) {
+               $this->value = $value;
+
+               if ( isset( $attr['expires'] ) ) {
+                       $this->isSessionKey = false;
+                       $this->expires = strtotime( $attr['expires'] );
+               }
+
+               if ( isset( $attr['path'] ) ) {
+                       $this->path = $attr['path'];
+               } else {
+                       $this->path = '/';
+               }
+
+               if ( isset( $attr['domain'] ) ) {
+                       if ( self::validateCookieDomain( $attr['domain'] ) ) {
+                               $this->domain = $attr['domain'];
+                       }
+               } else {
+                       throw new InvalidArgumentException( '$attr must contain a domain' );
+               }
+       }
+
+       /**
+        * Return the true if the cookie is valid is valid.  Otherwise,
+        * false.  The uses a method similar to IE cookie security
+        * described here:
+        * http://kuza55.blogspot.com/2008/02/understanding-cookie-security.html
+        * A better method might be to use a blacklist like
+        * http://publicsuffix.org/
+        *
+        * @todo fixme fails to detect 3-letter top-level domains
+        * @todo fixme fails to detect 2-letter top-level domains for single-domain use (probably
+        * not a big problem in practice, but there are test cases)
+        *
+        * @param string $domain The domain to validate
+        * @param string $originDomain (optional) the domain the cookie originates from
+        * @return bool
+        */
+       public static function validateCookieDomain( $domain, $originDomain = null ) {
+               $dc = explode( ".", $domain );
+
+               // Don't allow a trailing dot or addresses without a or just a leading dot
+               if ( substr( $domain, -1 ) == '.' ||
+                       count( $dc ) <= 1 ||
+                       count( $dc ) == 2 && $dc[0] === ''
+               ) {
+                       return false;
+               }
+
+               // Only allow full, valid IP addresses
+               if ( preg_match( '/^[0-9.]+$/', $domain ) ) {
+                       if ( count( $dc ) != 4 ) {
+                               return false;
+                       }
+
+                       if ( ip2long( $domain ) === false ) {
+                               return false;
+                       }
+
+                       if ( $originDomain == null || $originDomain == $domain ) {
+                               return true;
+                       }
+
+               }
+
+               // Don't allow cookies for "co.uk" or "gov.uk", etc, but allow "supermarket.uk"
+               if ( strrpos( $domain, "." ) - strlen( $domain ) == -3 ) {
+                       if ( ( count( $dc ) == 2 && strlen( $dc[0] ) <= 2 )
+                               || ( count( $dc ) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) {
+                               return false;
+                       }
+                       if ( ( count( $dc ) == 2 || ( count( $dc ) == 3 && $dc[0] == '' ) )
+                               && preg_match( '/(com|net|org|gov|edu)\...$/', $domain ) ) {
+                               return false;
+                       }
+               }
+
+               if ( $originDomain != null ) {
+                       if ( substr( $domain, 0, 1 ) != '.' && $domain != $originDomain ) {
+                               return false;
+                       }
+
+                       if ( substr( $domain, 0, 1 ) == '.'
+                               && substr_compare(
+                                       $originDomain,
+                                       $domain,
+                                       -strlen( $domain ),
+                                       strlen( $domain ),
+                                       true
+                               ) != 0
+                       ) {
+                               return false;
+                       }
+               }
+
+               return true;
+       }
+
+       /**
+        * Serialize the cookie jar into a format useful for HTTP Request headers.
+        *
+        * @param string $path The path that will be used. Required.
+        * @param string $domain The domain that will be used. Required.
+        * @return string
+        */
+       public function serializeToHttpRequest( $path, $domain ) {
+               $ret = '';
+
+               if ( $this->canServeDomain( $domain )
+                               && $this->canServePath( $path )
+                               && $this->isUnExpired() ) {
+                       $ret = $this->name . '=' . $this->value;
+               }
+
+               return $ret;
+       }
+
+       /**
+        * @param string $domain
+        * @return bool
+        */
+       protected function canServeDomain( $domain ) {
+               if ( $domain == $this->domain
+                       || ( strlen( $domain ) > strlen( $this->domain )
+                               && substr( $this->domain, 0, 1 ) == '.'
+                               && substr_compare(
+                                       $domain,
+                                       $this->domain,
+                                       -strlen( $this->domain ),
+                                       strlen( $this->domain ),
+                                       true
+                               ) == 0
+                       )
+               ) {
+                       return true;
+               }
+
+               return false;
+       }
+
+       /**
+        * @param string $path
+        * @return bool
+        */
+       protected function canServePath( $path ) {
+               return ( $this->path && substr_compare( $this->path, $path, 0, strlen( $this->path ) ) == 0 );
+       }
+
+       /**
+        * @return bool
+        */
+       protected function isUnExpired() {
+               return $this->isSessionKey || $this->expires > time();
+       }
+}
+
+class CookieJar {
+       private $cookie = array();
+
+       /**
+        * Set a cookie in the cookie jar. Make sure only one cookie per-name exists.
+        * @see Cookie::set()
+        * @param string $name
+        * @param string $value
+        * @param array $attr
+        */
+       public function setCookie( $name, $value, $attr ) {
+               /* cookies: case insensitive, so this should work.
+                * We'll still send the cookies back in the same case we got them, though.
+                */
+               $index = strtoupper( $name );
+
+               if ( isset( $this->cookie[$index] ) ) {
+                       $this->cookie[$index]->set( $value, $attr );
+               } else {
+                       $this->cookie[$index] = new Cookie( $name, $value, $attr );
+               }
+       }
+
+       /**
+        * @see Cookie::serializeToHttpRequest
+        * @param string $path
+        * @param string $domain
+        * @return string
+        */
+       public function serializeToHttpRequest( $path, $domain ) {
+               $cookies = array();
+
+               foreach ( $this->cookie as $c ) {
+                       $serialized = $c->serializeToHttpRequest( $path, $domain );
+
+                       if ( $serialized ) {
+                               $cookies[] = $serialized;
+                       }
+               }
+
+               return implode( '; ', $cookies );
+       }
+
+       /**
+        * Parse the content of an Set-Cookie HTTP Response header.
+        *
+        * @param string $cookie
+        * @param string $domain Cookie's domain
+        * @return null
+        */
+       public function parseCookieResponseHeader( $cookie, $domain ) {
+               $len = strlen( 'Set-Cookie:' );
+
+               if ( substr_compare( 'Set-Cookie:', $cookie, 0, $len, true ) === 0 ) {
+                       $cookie = substr( $cookie, $len );
+               }
+
+               $bit = array_map( 'trim', explode( ';', $cookie ) );
+
+               if ( count( $bit ) >= 1 ) {
+                       list( $name, $value ) = explode( '=', array_shift( $bit ), 2 );
+                       $attr = array();
+
+                       foreach ( $bit as $piece ) {
+                               $parts = explode( '=', $piece );
+                               if ( count( $parts ) > 1 ) {
+                                       $attr[strtolower( $parts[0] )] = $parts[1];
+                               } else {
+                                       $attr[strtolower( $parts[0] )] = true;
+                               }
+                       }
+
+                       if ( !isset( $attr['domain'] ) ) {
+                               $attr['domain'] = $domain;
+                       } elseif ( !Cookie::validateCookieDomain( $attr['domain'], $domain ) ) {
+                               return null;
+                       }
+
+                       $this->setCookie( $name, $value, $attr );
+               }
+       }
+}
index 8421672..5d11f84 100644 (file)
@@ -557,7 +557,7 @@ class LogEventsList extends ContextSource {
                if ( $logBody ) {
                        if ( $msgKey[0] ) {
                                $dir = $context->getLanguage()->getDir();
-                               $lang = $context->getLanguage()->getCode();
+                               $lang = $context->getLanguage()->getHtmlCode();
 
                                $s = Xml::openElement( 'div', array(
                                        'class' => "mw-warning-with-logexcerpt mw-content-$dir",
index b9d1872..bc16925 100644 (file)
@@ -59,7 +59,7 @@ class SpecialNewFiles extends IncludableSpecialPage {
                if ( !$message->isDisabled() ) {
                        $this->getOutput()->addWikiText(
                                Html::rawElement( 'p',
-                                       array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
+                                       array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ),
                                        "\n" . $message->plain() . "\n"
                                ),
                                /* $lineStart */ false,
index 6b9173f..97b2f9b 100644 (file)
@@ -808,7 +808,7 @@ class SpecialVersion extends SpecialPage {
                $html .= Html::rawElement( 'td', array( 'class' => 'mw-version-ext-description' ), $description );
                $html .= Html::rawElement( 'td', array( 'class' => 'mw-version-ext-authors' ), $authors );
 
-               $html .= Html::closeElement( 'td' );
+               $html .= Html::closeElement( 'tr' );
 
                return $html;
        }
@@ -1203,7 +1203,7 @@ class SpecialVersion extends SpecialPage {
                $language = $this->getLanguage();
                $thAttribures = array(
                        'dir' => $language->getDir(),
-                       'lang' => $language->getCode()
+                       'lang' => $language->getHtmlCode()
                );
                $out = Html::element(
                                'h2',
diff --git a/includes/utils/ArrayUtils.php b/includes/utils/ArrayUtils.php
deleted file mode 100644 (file)
index 1e521cb..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-<?php
-/**
- * Methods to play with arrays.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * A collection of static methods to play with arrays.
- *
- * @since 1.21
- */
-class ArrayUtils {
-       /**
-        * Sort the given array in a pseudo-random order which depends only on the
-        * given key and each element value. This is typically used for load
-        * balancing between servers each with a local cache.
-        *
-        * Keys are preserved. The input array is modified in place.
-        *
-        * Note: Benchmarking on PHP 5.3 and 5.4 indicates that for small
-        * strings, md5() is only 10% slower than hash('joaat',...) etc.,
-        * since the function call overhead dominates. So there's not much
-        * justification for breaking compatibility with installations
-        * compiled with ./configure --disable-hash.
-        *
-        * @param array $array Array to sort
-        * @param string $key
-        * @param string $separator A separator used to delimit the array elements and the
-        *     key. This can be chosen to provide backwards compatibility with
-        *     various consistent hash implementations that existed before this
-        *     function was introduced.
-        */
-       public static function consistentHashSort( &$array, $key, $separator = "\000" ) {
-               $hashes = array();
-               foreach ( $array as $elt ) {
-                       $hashes[$elt] = md5( $elt . $separator . $key );
-               }
-               uasort( $array, function ( $a, $b ) use ( $hashes ) {
-                       return strcmp( $hashes[$a], $hashes[$b] );
-               } );
-       }
-
-       /**
-        * Given an array of non-normalised probabilities, this function will select
-        * an element and return the appropriate key
-        *
-        * @param array $weights
-        * @return bool|int|string
-        */
-       public static function pickRandom( $weights ) {
-               if ( !is_array( $weights ) || count( $weights ) == 0 ) {
-                       return false;
-               }
-
-               $sum = array_sum( $weights );
-               if ( $sum == 0 ) {
-                       # No loads on any of them
-                       # In previous versions, this triggered an unweighted random selection,
-                       # but this feature has been removed as of April 2006 to allow for strict
-                       # separation of query groups.
-                       return false;
-               }
-               $max = mt_getrandmax();
-               $rand = mt_rand( 0, $max ) / $max * $sum;
-
-               $sum = 0;
-               foreach ( $weights as $i => $w ) {
-                       $sum += $w;
-                       # Do not return keys if they have 0 weight.
-                       # Note that the "all 0 weight" case is handed above
-                       if ( $w > 0 && $sum >= $rand ) {
-                               break;
-                       }
-               }
-
-               return $i;
-       }
-
-       /**
-        * Do a binary search, and return the index of the largest item that sorts
-        * less than or equal to the target value.
-        *
-        * @since 1.23
-        *
-        * @param array $valueCallback A function to call to get the value with
-        *     a given array index.
-        * @param int $valueCount The number of items accessible via $valueCallback,
-        *     indexed from 0 to $valueCount - 1
-        * @param array $comparisonCallback A callback to compare two values, returning
-        *     -1, 0 or 1 in the style of strcmp().
-        * @param string $target The target value to find.
-        *
-        * @return int|bool The item index of the lower bound, or false if the target value
-        *     sorts before all items.
-        */
-       public static function findLowerBound( $valueCallback, $valueCount,
-               $comparisonCallback, $target
-       ) {
-               if ( $valueCount === 0 ) {
-                       return false;
-               }
-
-               $min = 0;
-               $max = $valueCount;
-               do {
-                       $mid = $min + ( ( $max - $min ) >> 1 );
-                       $item = call_user_func( $valueCallback, $mid );
-                       $comparison = call_user_func( $comparisonCallback, $target, $item );
-                       if ( $comparison > 0 ) {
-                               $min = $mid;
-                       } elseif ( $comparison == 0 ) {
-                               $min = $mid;
-                               break;
-                       } else {
-                               $max = $mid;
-                       }
-               } while ( $min < $max - 1 );
-
-               if ( $min == 0 ) {
-                       $item = call_user_func( $valueCallback, $min );
-                       $comparison = call_user_func( $comparisonCallback, $target, $item );
-                       if ( $comparison < 0 ) {
-                               // Before the first item
-                               return false;
-                       }
-               }
-               return $min;
-       }
-
-       /**
-        * Do array_diff_assoc() on multi-dimensional arrays.
-        *
-        * Note: empty arrays are removed.
-        *
-        * @since 1.23
-        *
-        * @param array $array1 The array to compare from
-        * @param array $array2,... More arrays to compare against
-        * @return array An array containing all the values from array1
-        *               that are not present in any of the other arrays.
-        */
-       public static function arrayDiffAssocRecursive( $array1 ) {
-               $arrays = func_get_args();
-               array_shift( $arrays );
-               $ret = array();
-
-               foreach ( $array1 as $key => $value ) {
-                       if ( is_array( $value ) ) {
-                               $args = array( $value );
-                               foreach ( $arrays as $array ) {
-                                       if ( isset( $array[$key] ) ) {
-                                               $args[] = $array[$key];
-                                       }
-                               }
-                               $valueret = call_user_func_array( __METHOD__, $args );
-                               if ( count( $valueret ) ) {
-                                       $ret[$key] = $valueret;
-                               }
-                       } else {
-                               foreach ( $arrays as $array ) {
-                                       if ( isset( $array[$key] ) && $array[$key] === $value ) {
-                                               continue 2;
-                                       }
-                               }
-                               $ret[$key] = $value;
-                       }
-               }
-
-               return $ret;
-       }
-}
index 3a0492d..9fb4c19 100644 (file)
 
 class MWFunction {
 
-       /**
-        * @deprecated since 1.22; use call_user_func()
-        * @param callable $callback
-        * @return mixed
-        */
-       public static function call( $callback ) {
-               wfDeprecated( __METHOD__, '1.22' );
-               $args = func_get_args();
-
-               return call_user_func_array( 'call_user_func', $args );
-       }
-
-       /**
-        * @deprecated since 1.22; use call_user_func_array()
-        * @param callable $callback
-        * @param array $argsarams
-        * @return mixed
-        */
-       public static function callArray( $callback, $argsarams ) {
-               wfDeprecated( __METHOD__, '1.22' );
-
-               return call_user_func_array( $callback, $argsarams );
-       }
-
        /**
         * @param string $class
         * @param array $args
index 24e2fc2..e53ed54 100644 (file)
@@ -1002,6 +1002,7 @@ return array(
                'dependencies' => array(
                        'jquery.cookie',
                ),
+               'targets' => array( 'desktop', 'mobile' ),
        ),
        'mediawiki.toolbar' => array(
                'class' => 'ResourceLoaderEditToolbarModule',