Merge "TextPassDumper -> backupTextPass.inc"
authorBrion VIBBER <brion@wikimedia.org>
Tue, 3 Apr 2012 17:31:37 +0000 (17:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 3 Apr 2012 17:31:37 +0000 (17:31 +0000)
12 files changed:
RELEASE-NOTES-1.20
includes/CryptRand.php
includes/Preferences.php
includes/User.php
includes/api/ApiBase.php
includes/api/ApiFormatBase.php
includes/specials/SpecialChangeEmail.php
includes/specials/SpecialUndelete.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc
tests/phpunit/includes/api/ApiBlockTest.php

index c51722e..40dbb32 100644 (file)
@@ -64,6 +64,7 @@ production.
 * (bug 34313) MediaWiki API intro message about "HTML format" should mention
   the format parameter.
 * (bug 32384) Allow descending order for list=watchlistraw
+* (bug 31883) Limit of bkusers of list=blocks and titles of action=query is not documented in API help
 
 === Languages updated in 1.20 ===
 
index 8994082..95905fb 100644 (file)
@@ -54,7 +54,7 @@ class MWCryptRand {
                // It'll also vary slightly across different machines
                $state = serialize( $_SERVER );
 
-               // To try and vary the system information of the state a bit more
+               // To try vary the system information of the state a bit more
                // by including the system's hostname into the state
                $state .= wfHostname();
 
@@ -72,10 +72,13 @@ class MWCryptRand {
                $files[] = dirname( dirname( __FILE__ ) );
 
                // The config file is likely the most often edited file we know should be around
-               // so if the constant with it's location is defined include it's stat info into the state
+               // so include its stat info into the state.
+               // The constant with its location will almost always be defined, as WebStart.php defines
+               // MW_CONFIG_FILE to $IP/LocalSettings.php unless being configured with MW_CONFIG_CALLBACK (eg. the installer)
                if ( defined( 'MW_CONFIG_FILE' ) ) {
                        $files[] = MW_CONFIG_FILE;
                }
+
                foreach ( $files as $file ) {
                        wfSuppressWarnings();
                        $stat = stat( $file );
@@ -281,7 +284,7 @@ class MWCryptRand {
                if ( strlen( $buffer ) < $bytes ) {
                        // If available make use of mcrypt_create_iv URANDOM source to generate randomness
                        // On unix-like systems this reads from /dev/urandom but does it without any buffering
-                       // and bypasses openbasdir restrictions so it's preferable to reading directly
+                       // and bypasses openbasedir restrictions, so it's preferable to reading directly
                        // On Windows starting in PHP 5.3.0 Windows' native CryptGenRandom is used to generate
                        // entropy so this is also preferable to just trying to read urandom because it may work
                        // on Windows systems as well.
@@ -300,9 +303,10 @@ class MWCryptRand {
                }
 
                if ( strlen( $buffer ) < $bytes ) {
-                       // If available make use of openssl's random_pesudo_bytes method to attempt to generate randomness.
+                       // If available make use of openssl's random_pseudo_bytes method to attempt to generate randomness.
                        // However don't do this on Windows with PHP < 5.3.4 due to a bug:
                        // http://stackoverflow.com/questions/1940168/openssl-random-pseudo-bytes-is-slow-php
+                       // http://git.php.net/?p=php-src.git;a=commitdiff;h=cd62a70863c261b07f6dadedad9464f7e213cad5
                        if ( function_exists( 'openssl_random_pseudo_bytes' )
                                && ( !wfIsWindows() || version_compare( PHP_VERSION, '5.3.4', '>=' ) )
                        ) {
index bc8e47f..f54d732 100644 (file)
@@ -1432,39 +1432,21 @@ class Preferences {
         * Try to set a user's email address.
         * This does *not* try to validate the address.
         * Caller is responsible for checking $wgAuth.
+        *
+        * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
         * @param $user User
         * @param $newaddr string New email address
         * @return Array (true on success or Status on failure, info string)
         */
        public static function trySetUserEmail( User $user, $newaddr ) {
-               global $wgEnableEmail, $wgEmailAuthentication;
-               $info = ''; // none
+               wfDeprecated( __METHOD__, '1.20' );
 
-               if ( $wgEnableEmail ) {
-                       $oldaddr = $user->getEmail();
-                       if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) {
-                               # The user has supplied a new email address on the login page
-                               # new behaviour: set this new emailaddr from login-page into user database record
-                               $user->setEmail( $newaddr );
-                               if ( $wgEmailAuthentication ) {
-                                       # Mail a temporary password to the dirty address.
-                                       # User can come back through the confirmation URL to re-enable email.
-                                       $type = $oldaddr != '' ? 'changed' : 'set';
-                                       $result = $user->sendConfirmationMail( $type );
-                                       if ( !$result->isGood() ) {
-                                               return array( $result, 'mailerror' );
-                                       }
-                                       $info = 'eauth';
-                               }
-                       } elseif ( $newaddr != $oldaddr ) { // if the address is the same, don't change it
-                               $user->setEmail( $newaddr );
-                       }
-                       if ( $oldaddr != $newaddr ) {
-                               wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
-                       }
+               $result = $user->setEmailWithConfirmation( $newaddr );
+               if ( $result->isGood() ) {
+                       return array( true, $result->value );
+               } else {
+                       return array( $result, 'mailerror' );
                }
-
-               return array( true, $info );
        }
 
        /**
index 105e011..9c5a11c 100644 (file)
@@ -2112,6 +2112,42 @@ class User {
                wfRunHooks( 'UserSetEmail', array( $this, &$this->mEmail ) );
        }
 
+       /**
+        * Set the user's e-mail address and a confirmation mail if needed.
+        *
+        * @since 1.20
+        * @param $str String New e-mail address
+        * @return Status
+        */
+       public function setEmailWithConfirmation( $str ) {
+               global $wgEnableEmail, $wgEmailAuthentication;
+
+               if ( !$wgEnableEmail ) {
+                       return Status::newFatal( 'emaildisabled' );
+               }
+
+               $oldaddr = $this->getEmail();
+               if ( $str === $oldaddr ) {
+                       return Status::newGood( true );
+               }
+
+               $this->setEmail( $str );
+
+               if ( $str !== '' && $wgEmailAuthentication ) {
+                       # Send a confirmation request to the new address if needed
+                       $type = $oldaddr != '' ? 'changed' : 'set';
+                       $result = $this->sendConfirmationMail( $type );
+                       if ( $result->isGood() ) {
+                               # Say the the caller that a confirmation mail has been sent
+                               $status->value = 'eauth';
+                       }
+               } else {
+                       $result = Status::newGood( true );
+               }
+
+               return $result;
+       }
+
        /**
         * Get the user's real name
         * @return String User's real name
index 607c47a..5bff0ca 100644 (file)
@@ -367,21 +367,30 @@ abstract class ApiBase extends ContextSource {
                                        $desc = implode( $paramPrefix, $desc );
                                }
 
+                               //handle shorthand
                                if ( !is_array( $paramSettings ) ) {
                                        $paramSettings = array(
                                                self::PARAM_DFLT => $paramSettings,
                                        );
                                }
 
-                               $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] ) ?
-                                               $paramSettings[self::PARAM_DEPRECATED] : false;
-                               if ( $deprecated ) {
+                               //handle missing type
+                               if ( !isset( $paramSettings[ApiBase::PARAM_TYPE] ) ) {
+                                       $dflt = isset( $paramSettings[ApiBase::PARAM_DFLT] ) ? $paramSettings[ApiBase::PARAM_DFLT] : null;
+                                       if ( is_bool( $dflt ) ) {
+                                               $paramSettings[ApiBase::PARAM_TYPE] = 'boolean';
+                                       } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
+                                               $paramSettings[ApiBase::PARAM_TYPE] = 'string';
+                                       } elseif ( is_int( $dflt ) ) {
+                                               $paramSettings[ApiBase::PARAM_TYPE] = 'integer';
+                                       }
+                               }
+
+                               if ( isset( $paramSettings[self::PARAM_DEPRECATED] ) && $paramSettings[self::PARAM_DEPRECATED] ) {
                                        $desc = "DEPRECATED! $desc";
                                }
 
-                               $required = isset( $paramSettings[self::PARAM_REQUIRED] ) ?
-                                               $paramSettings[self::PARAM_REQUIRED] : false;
-                               if ( $required ) {
+                               if ( isset( $paramSettings[self::PARAM_REQUIRED] ) && $paramSettings[self::PARAM_REQUIRED] ) {
                                        $desc .= $paramPrefix . "This parameter is required";
                                }
 
@@ -437,22 +446,20 @@ abstract class ApiBase extends ContextSource {
                                                                }
                                                                break;
                                                }
+                                       }
 
-                                               if ( isset( $paramSettings[self::PARAM_ISMULTI] ) ) {
-                                                       $isArray = is_array( $paramSettings[self::PARAM_TYPE] );
+                                       if ( isset( $paramSettings[self::PARAM_ISMULTI] ) && $paramSettings[self::PARAM_ISMULTI] ) {
+                                               $isArray = is_array( $type );
 
-                                                       if ( !$isArray
-                                                                       || $isArray && count( $paramSettings[self::PARAM_TYPE] ) > self::LIMIT_SML1 ) {
-                                                               $desc .= $paramPrefix . "Maximum number of values " .
-                                                                               self::LIMIT_SML1 . " (" . self::LIMIT_SML2 . " for bots)";
-                                                       }
+                                               if ( !$isArray
+                                                               || $isArray && count( $type ) > self::LIMIT_SML1 ) {
+                                                       $desc .= $paramPrefix . "Maximum number of values " .
+                                                                       self::LIMIT_SML1 . " (" . self::LIMIT_SML2 . " for bots)";
                                                }
                                        }
                                }
 
-                               $default = is_array( $paramSettings )
-                                               ? ( isset( $paramSettings[self::PARAM_DFLT] ) ? $paramSettings[self::PARAM_DFLT] : null )
-                                               : $paramSettings;
+                               $default = isset( $paramSettings[self::PARAM_DFLT] ) ? $paramSettings[self::PARAM_DFLT] : null;
                                if ( !is_null( $default ) && $default !== false ) {
                                        $desc .= $paramPrefix . "Default: $default";
                                }
index 57c641d..17e9225 100644 (file)
@@ -260,7 +260,8 @@ See the <a href='https://www.mediawiki.org/wiki/API'>complete documentation</a>,
                $text = htmlspecialchars( $text );
 
                // encode all comments or tags as safe blue strings
-               $text = preg_replace( '/\&lt;(!--.*?--|.*?)\&gt;/', '<span style="color:blue;">&lt;\1&gt;</span>', $text );
+               $text = str_replace( '&lt;', '<span style="color:blue;">&lt;', $text );
+               $text = str_replace( '&gt;', '&gt;</span>', $text );
                // identify URLs
                $protos = wfUrlProtocolsWithoutProtRel();
                // This regex hacks around bug 13218 (&quot; included in the URL)
index 0f85f51..bd5a443 100644 (file)
@@ -196,18 +196,20 @@ class SpecialChangeEmail extends UnlistedSpecialPage {
                        LoginForm::clearLoginThrottle( $user->getName() );
                }
 
-               list( $status, $info ) = Preferences::trySetUserEmail( $user, $newaddr );
-               if ( $status !== true ) {
-                       if ( $status instanceof Status ) {
-                               $this->getOutput()->addHTML(
-                                       '<p class="error">' .
-                                       $this->getOutput()->parseInline( $status->getWikiText( $info ) ) .
-                                       '</p>' );
-                       }
+               $oldaddr = $user->getEmail();
+               $status = $user->setEmailWithConfirmation( $newaddr );
+               if ( !$status->isGood() ) {
+                       $this->getOutput()->addHTML(
+                               '<p class="error">' .
+                               $this->getOutput()->parseInline( $status->getWikiText( $info ) ) .
+                               '</p>' );
                        return false;
                }
 
+               wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
+
                $user->saveSettings();
-               return $info ? $info : true;
+
+               return $status->value;
        }
 }
index e8f3df7..06b578d 100644 (file)
@@ -745,14 +745,20 @@ class SpecialUndelete extends SpecialPage {
                $out->addHTML( "<ul>\n" );
                foreach ( $result as $row ) {
                        $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
-                       $link = Linker::linkKnown(
-                               $undelete,
-                               htmlspecialchars( $title->getPrefixedText() ),
-                               array(),
-                               array( 'target' => $title->getPrefixedText() )
-                       );
+                       if ( $title !== null ) {
+                               $item = Linker::linkKnown(
+                                       $undelete,
+                                       htmlspecialchars( $title->getPrefixedText() ),
+                                       array(),
+                                       array( 'target' => $title->getPrefixedText() )
+                               );
+                       } else {
+                               // The title is no longer valid, show as text
+                               $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+                               $item = htmlspecialchars( $title->getPrefixedText() );
+                       }
                        $revs = $this->msg( 'undeleterevisions' )->numParams( $row->count )->parse();
-                       $out->addHTML( "<li>{$link} ({$revs})</li>\n" );
+                       $out->addHTML( "<li>{$item} ({$revs})</li>\n" );
                }
                $result->free();
                $out->addHTML( "</ul>\n" );
index 3cacacf..7dcfc60 100644 (file)
@@ -1147,6 +1147,7 @@ No e-mail will be sent for any of the following features.',
 'invalidemailaddress'        => 'The e-mail address cannot be accepted as it appears to have an invalid format.
 Please enter a well-formatted address or empty that field.',
 'cannotchangeemail'          => 'Account e-mail addresses cannot be changed on this wiki.',
+'emaildisabled'              => 'This site cannot send e-mails.',
 'accountcreated'             => 'Account created',
 'accountcreatedtext'         => 'The user account for $1 has been created.',
 'createaccount-title'        => 'Account creation for {{SITENAME}}',
index 6bd933c..26a8b98 100644 (file)
@@ -772,6 +772,7 @@ Parameters:
 'emailconfirmlink'           => 'Link to [[Special:ConfirmEmail]]. Appears in [[Special:Preferences]] > {{int:prefs-personal}} > {{int:email}} after saving your e-mail address but before it has been authenticated.',
 'invalidemailaddress'        => 'Shown as a warning when written an invalid e-mail adress in [[Special:Preferences]] and {{fullurl:Special:UserLogin|type=signup}} page',
 'cannotchangeemail'          => 'Error message shown when user goes to [[Special:ChangeEmail]] but email addresses cannot be changed on the site.',
+'emaildisabled'              => 'Error message shown when user tries to set an e-mail address but e-mail features are disabled.',
 'createaccount-title'        => 'This is the subject of an e-mail sent to the e-mail address entered at [[Special:CreateAccount]] if the button "by e-mail" is clicked.',
 'createaccount-text'         => 'This text is sent as an e-mail to the e-mail address entered at [[Special:CreateAccount]] if the button "by e-mail" is clicked.
 
index d88cc3f..230f397 100644 (file)
@@ -485,6 +485,7 @@ $wgMessageStructure = array(
                'emailconfirmlink',
                'invalidemailaddress',
                'cannotchangeemail',
+               'emaildisabled',
                'accountcreated',
                'accountcreatedtext',
                'createaccount-title',
index d9ea7b5..84c0fc2 100644 (file)
@@ -26,6 +26,16 @@ class ApiBlockTest extends ApiTestCase {
                }
        }
 
+       /**
+        * This test has probably always been broken and use an invalid token
+        * Bug tracking brokenness is https://bugzilla.wikimedia.org/35646
+        *
+        * Root cause is https://gerrit.wikimedia.org/r/3434
+        * Which made the Block/Unblock API to actually verify the token
+        * previously always considered valid (bug 34212).
+        *
+        * @group Broken
+        */
        function testMakeNormalBlock() {
 
                $data = $this->getTokens();