Merge "Make 'subnet' feature of $wgRateLimits work with IPv6"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 29 May 2013 16:55:30 +0000 (16:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 29 May 2013 16:55:30 +0000 (16:55 +0000)
1  2 
includes/DefaultSettings.php
includes/User.php

@@@ -2518,38 -2518,48 +2518,38 @@@ $wgLocalTZoffset = null
  $wgMimeType = 'text/html';
  
  /**
 - * The content type used in script tags.  This is mostly going to be ignored if
 - * $wgHtml5 is true, at least for actual HTML output, since HTML5 doesn't
 - * require a MIME type for JavaScript or CSS (those are the default script and
 - * style languages).
 + * Previously used as content type in HTML script tags. This is now ignored since
 + * HTML5 doesn't require a MIME type for script tags (javascript is the default).
 + * It was also previously used by RawAction to determine the ctype query parameter
 + * value that will result in a javascript response.
 + * @deprecated since 1.22
   */
 -$wgJsMimeType = 'text/javascript';
 +$wgJsMimeType = null;
  
  /**
 - * The HTML document type.  Ignored if $wgHtml5 is true, since <!DOCTYPE html>
 - * doesn't actually have a doctype part to put this variable's contents in.
 + * The default xmlns attribute. The option to define this has been removed.
 + * The value of this variable is no longer used by core and is set to a fixed
 + * value in Setup.php for compatibility with extensions that depend on the value
 + * of this variable being set. Such a dependency however is deprecated.
 + * @deprecated since 1.22
   */
 -$wgDocType = '-//W3C//DTD XHTML 1.0 Transitional//EN';
 +$wgXhtmlDefaultNamespace = null;
  
  /**
 - * The URL of the document type declaration.  Ignored if $wgHtml5 is true,
 - * since HTML5 has no DTD, and <!DOCTYPE html> doesn't actually have a DTD part
 - * to put this variable's contents in.
 - */
 -$wgDTD = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd';
 -
 -/**
 - * The default xmlns attribute.  Ignored if $wgHtml5 is true (or it's supposed
 - * to be), since we don't currently support XHTML5, and in HTML5 (i.e., served
 - * as text/html) the attribute has no effect, so why bother?
 - */
 -$wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
 -
 -/**
 - * Should we output an HTML5 doctype?  If false, use XHTML 1.0 Transitional
 - * instead, and disable HTML5 features.  This may eventually be removed and set
 - * to always true.  If it's true, a number of other settings will be irrelevant
 - * and have no effect.
 + * Previously used to determine if we should output an HTML5 doctype.
 + * This is no longer used as we always output HTML5 now. For compatibility with
 + * extensions that still check the value of this config it's value is now forced
 + * to true by Setup.php.
 + * @deprecated since 1.22
   */
  $wgHtml5 = true;
  
  /**
   * Defines the value of the version attribute in the &lt;html&gt; tag, if any.
 - * This is ignored if $wgHtml5 is false.  If $wgAllowRdfaAttributes and
 - * $wgHtml5 are both true, and this evaluates to boolean false (like if it's
 - * left at the default null value), it will be auto-initialized to the correct
 - * value for RDFa+HTML5.  As such, you should have no reason to ever actually
 - * set this to anything.
 + * If $wgAllowRdfaAttributes is true, and this evaluates to boolean false
 + * (like if it's left at the default null value), it will be auto-initialized
 + * to the correct value for RDFa+HTML5.  As such, you should have no reason to
 + * ever actually set this to anything.
   */
  $wgHtml5Version = null;
  
  $wgAllowRdfaAttributes = false;
  
  /**
 - * Enabled HTML5 microdata attributes for use in wikitext, if $wgHtml5 is also true.
 + * Enabled HTML5 microdata attributes for use in wikitext.
   */
  $wgAllowMicrodataAttributes = false;
  
@@@ -2594,7 -2604,8 +2594,7 @@@ $wgWellFormedXml = true
   * Normally we wouldn't have to define this in the root "<html>"
   * element, but IE needs it there in some circumstances.
   *
 - * This is ignored if $wgHtml5 is true, for the same reason as
 - * $wgXhtmlDefaultNamespace.
 + * This is ignored if $wgMimeType is set to a non-XML mimetype.
   */
  $wgXhtmlNamespaces = array();
  
@@@ -2647,6 -2658,20 +2647,6 @@@ $wgSkipSkin = ''
  /** Array for more like $wgSkipSkin. */
  $wgSkipSkins = array();
  
 -/**
 - * Optionally, we can specify a stylesheet to use for media="handheld".
 - * This is recognized by some, but not all, handheld/mobile/PDA browsers.
 - * If left empty, compliant handheld browsers won't pick up the skin
 - * stylesheet, which is specified for 'screen' media.
 - *
 - * Can be a complete URL, base-relative path, or $wgStylePath-relative path.
 - * Try 'chick/main.css' to apply the Chick styles to the MonoBook HTML.
 - *
 - * Will also be switched in when 'handheld=yes' is added to the URL, like
 - * the 'printable=yes' mode for print media.
 - */
 -$wgHandheldStyle = false;
 -
  /**
   * If set, 'screen' and 'handheld' media specifiers for stylesheets are
   * transformed such that they apply to the iPhone/iPod Touch Mobile Safari,
@@@ -3497,9 -3522,8 +3497,9 @@@ $wgNoFollowDomainExceptions = array()
  $wgAllowDisplayTitle = true;
  
  /**
 - * For consistency, restrict DISPLAYTITLE to titles that normalize to the same
 - * canonical DB key.
 + * For consistency, restrict DISPLAYTITLE to text that normalizes to the same
 + * canonical DB key. Also disallow some inline CSS rules like display: none;
 + * which can cause the text to be hidden or unselectable.
   */
  $wgRestrictDisplayTitle = true;
  
@@@ -4304,7 -4328,7 +4304,7 @@@ $wgRateLimits = array
                'user' => null, // for each logged-in user
                'newbie' => null, // for each recent (autoconfirmed) account; overrides 'user'
                'ip' => null, // for each anon and recent account
-               'subnet' => null, // ... with final octet removed
+               'subnet' => null, // ... within a /24 subnet in IPv4 or /64 in IPv6
        ),
        'move' => array(
                'user' => null,
diff --combined includes/User.php
@@@ -912,7 -912,7 +912,7 @@@ class User 
         *
         * @param $item String
         */
 -      private function setItemLoaded( $item ) {
 +      protected function setItemLoaded( $item ) {
                if ( is_array( $this->mLoadedItems ) ) {
                        $this->mLoadedItems[$item] = true;
                }
  
                $defOpt = $wgDefaultUserOptions;
                # default language setting
 -              $defOpt['variant'] = $wgContLang->getCode();
 -              $defOpt['language'] = $wgContLang->getCode();
 +              $defOpt['language'] = $defOpt['variant'] = $wgContLang->getCode();
                foreach ( SearchEngine::searchableNamespaces() as $nsnum => $nsname ) {
                        $defOpt['searchNs' . $nsnum] = !empty( $wgNamespacesToBeSearchedDefault[$nsnum] );
                }
                $limits = $wgRateLimits[$action];
                $keys = array();
                $id = $this->getId();
-               $ip = $this->getRequest()->getIP();
                $userLimit = false;
  
                if ( isset( $limits['anon'] ) && $id == 0 ) {
                                $keys[wfMemcKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
                        }
                        if ( isset( $limits['ip'] ) ) {
+                               $ip = $this->getRequest()->getIP();
                                $keys["mediawiki:limiter:$action:ip:$ip"] = $limits['ip'];
                        }
-                       $matches = array();
-                       if ( isset( $limits['subnet'] ) && preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $ip, $matches ) ) {
-                               $subnet = $matches[1];
-                               $keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
+                       if ( isset( $limits['subnet'] ) ) {
+                               $ip = $this->getRequest()->getIP();
+                               $matches = array();
+                               $subnet = false;
+                               if ( IP::isIPv6( $ip ) ) {
+                                       $parts = IP::parseRange( "$ip/64" );
+                                       $subnet = $parts[0];
+                               } elseif ( preg_match( '/^(\d+\.\d+\.\d+)\.\d+$/', $ip, $matches ) ) {
+                                       // IPv4
+                                       $subnet = $matches[1];
+                               }
+                               if ( $subnet !== false ) {
+                                       $keys["mediawiki:limiter:$action:subnet:$subnet"] = $limits['subnet'];
+                               }
                        }
                }
                // Check for group-specific permissions
         * @param &$expiration \mixed Accepts the expiration time
         * @return String New token
         */
 -      private function confirmationToken( &$expiration ) {
 +      protected function confirmationToken( &$expiration ) {
                global $wgUserEmailConfirmationTokenExpiry;
                $now = time();
                $expires = $now + $wgUserEmailConfirmationTokenExpiry;
         * @param string $token Accepts the email confirmation token
         * @return String New token URL
         */
 -      private function confirmationTokenUrl( $token ) {
 +      protected function confirmationTokenUrl( $token ) {
                return $this->getTokenUrl( 'ConfirmEmail', $token );
        }
  
         * @param string $token Accepts the email confirmation token
         * @return String New token URL
         */
 -      private function invalidationTokenUrl( $token ) {
 +      protected function invalidationTokenUrl( $token ) {
                return $this->getTokenUrl( 'InvalidateEmail', $token );
        }
  
         *       no matter the value of $wgUser
         *     - 'create2' for a logged in user creating an account for someone else
         *     - 'byemail' when the created user will receive its password by e-mail
 +       *     - 'autocreate' when the user is automatically created (such as by CentralAuth).
         *   - Boolean means whether the account was created by e-mail (deprecated):
         *     - true will be converted to 'byemail'
         *     - false will be converted to 'create' if this object is the same as
         *
         * @return array Array of HTML attributes suitable for feeding to
         *   Html::element(), directly or indirectly.  (Don't feed to Xml::*()!
 -       *   That will potentially output invalid XHTML 1.0 Transitional, and will
 -       *   get confused by the boolean attribute syntax used.)
 +       *   That will get confused by the boolean attribute syntax used.)
         */
        public static function passwordChangeInputAttribs() {
                global $wgMinimalPasswordLength;