Merge "(bug 33602) list=allusers throws exceptions with invalid names"
authorBrion VIBBER <brion@wikimedia.org>
Thu, 26 Apr 2012 23:27:55 +0000 (23:27 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 26 Apr 2012 23:27:55 +0000 (23:27 +0000)
16 files changed:
RELEASE-NOTES-1.20
docs/hooks.txt
includes/DefaultSettings.php
includes/EditPage.php
includes/Title.php
includes/api/ApiBase.php
includes/api/ApiEditPage.php
includes/api/ApiEmailUser.php
includes/cache/GenderCache.php
includes/cache/LinkBatch.php
includes/filerepo/backend/FileBackendStore.php
includes/filerepo/backend/SwiftFileBackend.php
includes/filerepo/file/File.php
includes/specials/SpecialEmailuser.php
maintenance/backupTextPass.inc
tests/phpunit/includes/cache/GenderCacheTest.php [new file with mode: 0644]

index ebf30ca..318768c 100644 (file)
@@ -44,6 +44,7 @@ production.
   $wgDebugLogFile['memcached'] to some filepath.
 * (bug 35685) api.php URL and other entry point URLs are now listed on
   Special:Version
+* Edit notices can now be translated.
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
@@ -88,6 +89,7 @@ production.
 * (bug 33564) transwiki import sometimes result in invalid title.
 * (bug 35572) Blocks appear to succeed even if query fails due to wrong DB structure
 * (bug 31757) Add a word-separator between help-messages in HTMLForm
+* (bug 30410) Removed deprecated $wgFilterCallback and the 'filtered' API error.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index 1a9f41d..33db1c5 100644 (file)
@@ -904,6 +904,12 @@ $article: in case all revisions of the file are deleted a reference to the
 $user: user who performed the deletion
 $reason: reason
 
+'FileTransformed': When a file is transformed and moved into storage
+$file: reference to the File object
+$thumb: the MediaTransformOutput object
+$tmpThumbPath: The temporary file system path of the transformed file
+$thumbPath: The permanent storage path of the transformed file
+
 'FileUpload': When a file upload occurs
 $file : Image object representing the file that was uploaded
 $reupload : Boolean indicating if there was a previously another image there or not (since 1.17)
index 7c4db0d..d3c24ca 100644 (file)
@@ -3814,21 +3814,6 @@ $wgSpamRegex = array();
 /** Same as the above except for edit summaries */
 $wgSummarySpamRegex = array();
 
-/**
- * Similarly you can get a function to do the job. The function will be given
- * the following args:
- *   - a Title object for the article the edit is made on
- *   - the text submitted in the textarea (wpTextbox1)
- *   - the section number.
- * The return should be boolean indicating whether the edit matched some evilness:
- *  - true : block it
- *  - false : let it through
- *
- * @deprecated since 1.17 Use hooks. See SpamBlacklist extension.
- * @var $wgFilterCallback bool|string|Closure
- */
-$wgFilterCallback = false;
-
 /**
  * Whether to use DNS blacklists in $wgDnsBlacklistUrls to check for open proxies
  * @since 1.16
index 92bca9e..dce8d91 100644 (file)
@@ -36,11 +36,6 @@ class EditPage {
         */
        const AS_HOOK_ERROR                = 210;
 
-       /**
-        * Status: The filter function set in $wgFilterCallback returned true (= block it)
-        */
-       const AS_FILTERING                 = 211;
-
        /**
         * Status: A hook function returned an error
         */
@@ -990,7 +985,6 @@ class EditPage {
                                return true;
 
                        case self::AS_HOOK_ERROR:
-                       case self::AS_FILTERING:
                                return false;
 
                        case self::AS_SUCCESS_NEW_ARTICLE:
@@ -1062,8 +1056,7 @@ class EditPage {
         * AS_CONTENT_TOO_BIG and AS_BLOCKED_PAGE_FOR_USER. All that stuff needs to be cleaned up some time.
         */
        function internalAttemptSave( &$result, $bot = false ) {
-               global $wgFilterCallback, $wgUser, $wgRequest, $wgParser;
-               global $wgMaxArticleSize;
+               global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize;
 
                $status = Status::newGood();
 
@@ -1109,13 +1102,6 @@ class EditPage {
                        wfProfileOut( __METHOD__ );
                        return $status;
                }
-               if ( $wgFilterCallback && is_callable( $wgFilterCallback ) && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
-                       # Error messages or other handling should be performed by the filter function
-                       $status->setResult( false, self::AS_FILTERING );
-                       wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__ );
-                       return $status;
-               }
                if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
                        # Error messages etc. could be handled within the hook...
                        $status->fatal( 'hookaborted' );
@@ -1918,7 +1904,7 @@ class EditPage {
 
                # Optional notices on a per-namespace and per-page basis
                $editnotice_ns = 'editnotice-' . $this->mTitle->getNamespace();
-               $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
+               $editnotice_ns_message = wfMessage( $editnotice_ns );
                if ( $editnotice_ns_message->exists() ) {
                        $wgOut->addWikiText( $editnotice_ns_message->plain() );
                }
@@ -1927,7 +1913,7 @@ class EditPage {
                        $editnotice_base = $editnotice_ns;
                        while ( count( $parts ) > 0 ) {
                                $editnotice_base .= '-' . array_shift( $parts );
-                               $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
+                               $editnotice_base_msg = wfMessage( $editnotice_base );
                                if ( $editnotice_base_msg->exists() ) {
                                        $wgOut->addWikiText( $editnotice_base_msg->plain() );
                                }
@@ -1935,7 +1921,7 @@ class EditPage {
                } else {
                        # Even if there are no subpages in namespace, we still don't want / in MW ns.
                        $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->mTitle->getDBkey() );
-                       $editnoticeMsg = wfMessage( $editnoticeText )->inContentLanguage();
+                       $editnoticeMsg = wfMessage( $editnoticeText );
                        if ( $editnoticeMsg->exists() ) {
                                $wgOut->addWikiText( $editnoticeMsg->plain() );
                        }
index 1876d75..6764f8f 100644 (file)
@@ -711,17 +711,9 @@ class Title {
                        }
                }
 
-               // Strip off subpages
-               $pagename = $this->getText();
-               if ( strpos( $pagename, '/' ) !== false ) {
-                       list( $username , ) = explode( '/', $pagename, 2 );
-               } else {
-                       $username = $pagename;
-               }
-
                if ( $wgContLang->needsGenderDistinction() &&
                                MWNamespace::hasGenderDistinction( $this->mNamespace ) ) {
-                       $gender = GenderCache::singleton()->getGenderOf( $username, __METHOD__ );
+                       $gender = GenderCache::singleton()->getGenderOf( $this->getText(), __METHOD__ );
                        return $wgContLang->getGenderNsText( $this->mNamespace, $gender );
                }
 
index edd9aca..458214e 100644 (file)
@@ -1215,7 +1215,6 @@ abstract class ApiBase extends ContextSource {
                'noimageredirect-anon' => array( 'code' => 'noimageredirect-anon', 'info' => "Anonymous users can't create image redirects" ),
                'noimageredirect-logged' => array( 'code' => 'noimageredirect', 'info' => "You don't have permission to create image redirects" ),
                'spamdetected' => array( 'code' => 'spamdetected', 'info' => "Your edit was refused because it contained a spam fragment: \"\$1\"" ),
-               'filtered' => array( 'code' => 'filtered', 'info' => "The filter callback function refused your edit" ),
                'contenttoobig' => array( 'code' => 'contenttoobig', 'info' => "The content you supplied exceeds the article size limit of \$1 kilobytes" ),
                'noedit-anon' => array( 'code' => 'noedit-anon', 'info' => "Anonymous users can't edit pages" ),
                'noedit' => array( 'code' => 'noedit', 'info' => "You don't have permission to edit pages" ),
index 796b049..3153016 100644 (file)
@@ -291,9 +291,6 @@ class ApiEditPage extends ApiBase {
                        case EditPage::AS_SPAM_ERROR:
                                $this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
 
-                       case EditPage::AS_FILTERING:
-                               $this->dieUsageMsg( 'filtered' );
-
                        case EditPage::AS_BLOCKED_PAGE_FOR_USER:
                                $this->dieUsageMsg( 'blockedtext' );
 
@@ -398,7 +395,6 @@ class ApiEditPage extends ApiBase {
                                array( 'noimageredirect-logged' ),
                                array( 'spamdetected', 'spam' ),
                                array( 'summaryrequired' ),
-                               array( 'filtered' ),
                                array( 'blockedtext' ),
                                array( 'contenttoobig', $wgMaxArticleSize ),
                                array( 'noedit-anon' ),
index d9eed60..0032bd8 100644 (file)
@@ -55,7 +55,7 @@ class ApiEmailUser extends ApiBase {
                        'Subject' => $params['subject'],
                        'CCMe' => $params['ccme'],
                );
-               $retval = SpecialEmailUser::submit( $data );
+               $retval = SpecialEmailUser::submit( $data, $this->getContext() );
 
                if ( $retval instanceof Status ) {
                        // SpecialEmailUser sometimes returns a status
index 2cc1061..c27ab00 100644 (file)
@@ -48,7 +48,7 @@ class GenderCache {
                        $username = $username->getName();
                }
 
-               $username = strtr( $username, '_', ' ' );
+               $username = self::normalizeUsername( $username );
                if ( !isset( $this->cache[$username] ) ) {
 
                        if ( $this->misses >= $this->missLimit && $wgUser->getName() !== $username ) {
@@ -60,11 +60,7 @@ class GenderCache {
 
                        } else {
                                $this->misses++;
-                               if ( !User::isValidUserName( $username ) ) {
-                                       $this->cache[$username] = $this->getDefault();
-                               } else {
-                                       $this->doQuery( $username, $caller );
-                               }
+                               $this->doQuery( $username, $caller );
                        }
 
                }
@@ -86,7 +82,6 @@ class GenderCache {
                foreach ( $data as $ns => $pagenames ) {
                        if ( !MWNamespace::hasGenderDistinction( $ns ) ) continue;
                        foreach ( array_keys( $pagenames ) as $username ) {
-                               if ( isset( $this->cache[$username] ) ) continue;
                                $users[$username] = true;
                        }
                }
@@ -102,26 +97,28 @@ class GenderCache {
        public function doQuery( $users, $caller = '' ) {
                $default = $this->getDefault();
 
-               foreach ( (array) $users as $index => $value ) {
-                       $name = strtr( $value, '_', ' ' );
-                       if ( isset( $this->cache[$name] ) ) {
-                               // Skip users whose gender setting we already know
-                               unset( $users[$index] );
-                       } else {
-                               $users[$index] = $name;
+               $usersToCheck = array();
+               foreach ( (array) $users as $value ) {
+                       $name = self::normalizeUsername( $value );
+                       // Skip users whose gender setting we already know
+                       if ( !isset( $this->cache[$name] ) ) {
                                // For existing users, this value will be overwritten by the correct value
                                $this->cache[$name] = $default;
+                               // query only for valid names, which can be in the database
+                               if( User::isValidUserName( $name ) ) {
+                                       $usersToCheck[] = $name;
+                               }
                        }
                }
 
-               if ( count( $users ) === 0 ) {
+               if ( count( $usersToCheck ) === 0 ) {
                        return;
                }
 
                $dbr = wfGetDB( DB_SLAVE );
                $table = array( 'user', 'user_properties' );
                $fields = array( 'user_name', 'up_value' );
-               $conds = array( 'user_name' => $users );
+               $conds = array( 'user_name' => $usersToCheck );
                $joins = array( 'user_properties' =>
                        array( 'LEFT JOIN', array( 'user_id = up_user', 'up_property' => 'gender' ) ) );
 
@@ -129,11 +126,20 @@ class GenderCache {
                if ( strval( $caller ) !== '' ) {
                        $comment .= "/$caller";
                }
-               $res = $dbr->select( $table, $fields, $conds, $comment, $joins, $joins );
+               $res = $dbr->select( $table, $fields, $conds, $comment, array(), $joins );
 
                foreach ( $res as $row ) {
                        $this->cache[$row->user_name] = $row->up_value ? $row->up_value : $default;
                }
        }
 
+       private static function normalizeUsername( $username ) {
+               // Strip off subpages
+               $indexSlash = strpos( $username, '/' );
+               if ( $indexSlash !== false ) {
+                       $username = substr( $username, 0, $indexSlash );
+               }
+               // normalize underscore/spaces
+               return strtr( $username, '_', ' ' );
+       }
 }
index 29fde03..ab33dcf 100644 (file)
@@ -195,7 +195,7 @@ class LinkBatch {
                }
 
                $genderCache = GenderCache::singleton();
-               $genderCache->dolinkBatch( $this->data, $this->caller );
+               $genderCache->doLinkBatch( $this->data, $this->caller );
                return true;
        }
 
index f7e4529..be9357b 100644 (file)
@@ -19,6 +19,9 @@
  * @since 1.19
  */
 abstract class FileBackendStore extends FileBackend {
+       /** @var BagOStuff */
+       protected $memCache;
+
        /** @var Array Map of paths to small (RAM/disk) cache items */
        protected $cache = array(); // (storage path => key => value)
        protected $maxCacheSize = 100; // integer; max paths with entries
@@ -31,6 +34,16 @@ abstract class FileBackendStore extends FileBackend {
 
        protected $maxFileSize = 4294967296; // integer bytes (4GiB)
 
+       /**
+        * @see FileBackend::__construct()
+        *
+        * @param $config Array
+        */
+       public function __construct( array $config ) {
+               parent::__construct( $config );
+               $this->memCache = new EmptyBagOStuff(); // disabled by default
+       }
+
        /**
         * Get the maximum allowable file size given backend
         * medium restrictions and basic performance constraints.
@@ -390,11 +403,13 @@ abstract class FileBackendStore extends FileBackend {
 
                if ( $shard !== null ) { // confined to a single container/shard
                        $status->merge( $this->doCleanInternal( $fullCont, $dir, $params ) );
+                       $this->deleteContainerCache( $fullCont ); // purge cache
                } else { // directory is on several shards
                        wfDebug( __METHOD__ . ": iterating over all container shards.\n" );
                        list( $b, $shortCont, $r ) = self::splitStoragePath( $params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as $suffix ) {
                                $status->merge( $this->doCleanInternal( "{$fullCont}{$suffix}", $dir, $params ) );
+                               $this->deleteContainerCache( "{$fullCont}{$suffix}" ); // purge cache
                        }
                }
 
@@ -846,9 +861,12 @@ abstract class FileBackendStore extends FileBackend {
                        }
                }
 
-               // Clear any cache entries (after locks acquired)
+               // Clear any file cache entries (after locks acquired)
                $this->clearCache();
 
+               // Load from the persistent container cache
+               $this->primeContainerCache( $performOps );
+
                // Actually attempt the operation batch...
                $subStatus = FileOp::attemptBatch( $performOps, $opts, $this->fileJournal );
 
@@ -1140,6 +1158,87 @@ abstract class FileBackendStore extends FileBackend {
        protected function resolveContainerPath( $container, $relStoragePath ) {
                return $relStoragePath;
        }
+
+       /**
+        * Get the cache key for a container
+        *
+        * @param $container Resolved container name
+        * @return string
+        */
+       private function containerCacheKey( $container ) {
+               return wfMemcKey( 'backend', $this->getName(), 'container', $container );
+       }
+
+       /**
+        * Set the cached info for a container
+        *
+        * @param $container Resolved container name
+        * @param $val mixed Information to cache
+        * @return void
+        */
+       final protected function setContainerCache( $container, $val ) {
+               $this->memCache->set( $this->containerCacheKey( $container ), $val, 7*86400 );
+       }
+
+       /**
+        * Delete the cached info for a container
+        *
+        * @param $container Resolved container name
+        * @return void
+        */
+       final protected function deleteContainerCache( $container ) {
+               $this->memCache->delete( $this->containerCacheKey( $container ) );
+       }
+
+       /**
+        * Do a batch lookup from cache for container stats for all containers
+        * used in a list of container names, storage paths, or FileOp objects.
+        *
+        * @param $items Array List of storage paths or FileOps
+        * @return void
+        */
+       final protected function primeContainerCache( array $items ) {
+               $paths = array(); // list of storage paths
+               $contNames = array(); // (cache key => resolved container name)
+               // Get all the paths/containers from the items...
+               foreach ( $items as $item ) {
+                       if ( $item instanceof FileOp ) {
+                               $paths = array_merge( $paths, $item->storagePathsRead() );
+                               $paths = array_merge( $paths, $item->storagePathsChanged() );
+                       } elseif ( self::isStoragePath( $item ) ) {
+                               $paths[] = $item;
+                       } elseif ( is_string( $item ) ) { // full container name
+                               $contNames[$this->containerCacheKey( $item )] = $item;
+                       }
+               }
+               // Get all the corresponding cache keys for paths...
+               foreach ( $paths as $path ) {
+                       list( $fullCont, $r, $s ) = $this->resolveStoragePath( $path );
+                       if ( $fullCont !== null ) { // valid path for this backend
+                               $contNames[$this->containerCacheKey( $fullCont )] = $fullCont;
+                       }
+               }
+
+               $contInfo = array(); // (resolved container name => cache value)
+               // Get all cache entries for these container cache keys...
+               $values = $this->memCache->getBatch( array_keys( $contNames ) );
+               foreach ( $values as $cacheKey => $val ) {
+                       $contInfo[$contNames[$cacheKey]] = $val;
+               }
+
+               // Populate the container process cache for the backend...
+               $this->doPrimeContainerCache( array_filter( $contInfo, 'is_array' ) );
+       }
+
+       /**
+        * Fill the backend-specific process cache given an array of
+        * resolved container names and their corresponding cached info.
+        * Only containers that actually exist should appear in the map.
+        *
+        * @param $containerInfo Array Map of resolved container names to cached info
+        * @return void
+        */
+       protected function doPrimeContainerCache( array $containerInfo ) {}
 }
 
 /**
index af5d693..66720fc 100644 (file)
@@ -64,6 +64,8 @@ class SwiftFileBackend extends FileBackendStore {
                $this->shardViaHashLevels = isset( $config['shardViaHashLevels'] )
                        ? $config['shardViaHashLevels']
                        : '';
+               // Cache container info to mask latency
+               $this->memCache = wfGetMainCache();
        }
 
        /**
@@ -856,23 +858,30 @@ class SwiftFileBackend extends FileBackendStore {
         * Use $reCache if the file count or byte count is needed.
         *
         * @param $container string Container name
-        * @param $reCache bool Refresh the process cache
+        * @param $bypassCache bool Bypass all caches and load from Swift
         * @return CF_Container
+        * @throws InvalidResponseException
         */
-       protected function getContainer( $container, $reCache = false ) {
+       protected function getContainer( $container, $bypassCache = false ) {
                $conn = $this->getConnection(); // Swift proxy connection
-               if ( $reCache ) {
-                       unset( $this->connContainers[$container] ); // purge cache
+               if ( $bypassCache ) { // purge cache
+                       unset( $this->connContainers[$container] );
+               } elseif ( !isset( $this->connContainers[$container] ) ) {
+                       $this->primeContainerCache( array( $container ) ); // check persistent cache
                }
                if ( !isset( $this->connContainers[$container] ) ) {
                        $contObj = $conn->get_container( $container );
                        // NoSuchContainerException not thrown: container must exist
                        if ( count( $this->connContainers ) >= $this->maxContCacheSize ) { // trim cache?
                                reset( $this->connContainers );
-                               $key = key( $this->connContainers );
-                               unset( $this->connContainers[$key] );
+                               unset( $this->connContainers[key( $this->connContainers )] );
                        }
                        $this->connContainers[$container] = $contObj; // cache it
+                       if ( !$bypassCache ) {
+                               $this->setContainerCache( $container, // update persistent cache
+                                       array( 'bytes' => $contObj->bytes_used, 'count' => $contObj->object_count )
+                               );
+                       }
                }
                return $this->connContainers[$container];
        }
@@ -882,6 +891,7 @@ class SwiftFileBackend extends FileBackendStore {
         *
         * @param $container string Container name
         * @return CF_Container
+        * @throws InvalidResponseException
         */
        protected function createContainer( $container ) {
                $conn = $this->getConnection(); // Swift proxy connection
@@ -895,6 +905,7 @@ class SwiftFileBackend extends FileBackendStore {
         *
         * @param $container string Container name
         * @return void
+        * @throws InvalidResponseException
         */
        protected function deleteContainer( $container ) {
                $conn = $this->getConnection(); // Swift proxy connection
@@ -902,6 +913,28 @@ class SwiftFileBackend extends FileBackendStore {
                unset( $this->connContainers[$container] ); // purge cache
        }
 
+       /**
+        * @see FileBackendStore::doPrimeContainerCache()
+        * @return void
+        */
+       protected function doPrimeContainerCache( array $containerInfo ) {
+               try {
+                       $conn = $this->getConnection(); // Swift proxy connection
+                       foreach ( $containerInfo as $container => $info ) {
+                               $this->connContainers[$container] = new CF_Container(
+                                       $conn->cfs_auth,
+                                       $conn->cfs_http,
+                                       $container,
+                                       $info['count'],
+                                       $info['bytes']
+                               );
+                       }
+               } catch ( InvalidResponseException $e ) {
+               } catch ( Exception $e ) { // some other exception?
+                       $this->logException( $e, __METHOD__, array() );
+               }
+       }
+
        /**
         * Log an unexpected exception for this backend
         *
index 461c255..d32a0e3 100644 (file)
@@ -878,6 +878,8 @@ abstract class File {
                                } else {
                                        $thumb = $this->transformErrorOutput( $thumbPath, $thumbUrl, $params, $flags );
                                }
+                               // Give extensions a chance to do something with this thumbnail...
+                               wfRunHooks( 'FileTransformed', array( $this, $thumb, $tmpThumbPath, $thumbPath ) );
                        }
 
                        // Purge. Useful in the event of Core -> Squid connection failure or squid
index 314da72..55b500d 100644 (file)
@@ -61,7 +61,8 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        ),
                        'Subject' => array(
                                'type' => 'text',
-                               'default' => wfMsgExt( 'defemailsubject', array( 'content', 'parsemag' ), $this->getUser()->getName() ),
+                               'default' => $this->msg( 'defemailsubject',
+                                       $this->getUser()->getName() )->inContentLanguage()->text(),
                                'label-message' => 'emailsubject',
                                'maxlength' => 200,
                                'size' => 60,
@@ -124,11 +125,11 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                $this->mTargetObj = $ret;
 
                $form = new HTMLForm( $this->getFormFields(), $this->getContext() );
-               $form->addPreText( wfMsgExt( 'emailpagetext', 'parseinline' ) );
-               $form->setSubmitText( wfMsg( 'emailsend' ) );
+               $form->addPreText( $this->msg( 'emailpagetext' )->parse() );
+               $form->setSubmitTextMsg( 'emailsend' );
                $form->setTitle( $this->getTitle() );
-               $form->setSubmitCallback( array( __CLASS__, 'submit' ) );
-               $form->setWrapperLegend( wfMsgExt( 'email-legend', 'parsemag' ) );
+               $form->setSubmitCallback( array( __CLASS__, 'uiSubmit' ) );
+               $form->setWrapperLegendMsg( 'email-legend' );
                $form->loadData();
 
                if( !wfRunHooks( 'EmailUserForm', array( &$form ) ) ) {
@@ -224,14 +225,26 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'askusername' ) ) .
                        Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
                        Xml::openElement( 'fieldset' ) .
-                       Html::rawElement( 'legend', null, wfMessage( 'emailtarget' )->parse() ) .
-                       Xml::inputLabel( wfMessage( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' .
-                       Xml::submitButton( wfMessage( 'emailusernamesubmit' )->text() ) .
+                       Html::rawElement( 'legend', null, $this->msg( 'emailtarget' )->parse() ) .
+                       Xml::inputLabel( $this->msg( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' .
+                       Xml::submitButton( $this->msg( 'emailusernamesubmit' )->text() ) .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' ) . "\n";
                return $string;
        }
 
+       /**
+        * Submit callback for an HTMLForm object, will simply call submit().
+        *
+        * @since 1.20
+        * @param $data array
+        * @param $form HTMLForm object
+        * @return Status|string|bool
+        */
+       public static function uiSubmit( array $data, HTMLForm $form ) {
+               return self::submit( $data, $form->getContext() );
+       }
+
        /**
         * Really send a mail. Permissions should have been checked using
         * getPermissionsError(). It is probably also a good
@@ -240,25 +253,22 @@ class SpecialEmailUser extends UnlistedSpecialPage {
         * @return Mixed: Status object, or potentially a String on error
         * or maybe even true on success if anything uses the EmailUser hook.
         */
-       public static function submit( $data ) {
+       public static function submit( array $data, IContextSource $context ) {
                global $wgUser, $wgUserEmailUseReplyTo;
 
                $target = self::getTarget( $data['Target'] );
                if( !$target instanceof User ) {
-                       return wfMsgExt( $target . 'text', 'parse' );
+                       return $context->msg( $target . 'text' )->parseAsBlock();
                }
                $to = new MailAddress( $target );
-               $from = new MailAddress( $wgUser );
+               $from = new MailAddress( $context->getUser() );
                $subject = $data['Subject'];
                $text = $data['Text'];
 
                // Add a standard footer and trim up trailing newlines
                $text = rtrim( $text ) . "\n\n-- \n";
-               $text .= wfMsgExt(
-                       'emailuserfooter',
-                       array( 'content', 'parsemag' ),
-                       array( $from->name, $to->name )
-               );
+               $text .= $context->msg( 'emailuserfooter',
+                       $from->name, $to->name )->inContentLanguage()->text();
 
                $error = '';
                if( !wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$text, &$error ) ) ) {
@@ -302,11 +312,8 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        // unless they are emailing themselves, in which case one
                        // copy of the message is sufficient.
                        if ( $data['CCMe'] && $to != $from ) {
-                               $cc_subject = wfMsg(
-                                       'emailccsubject',
-                                       $target->getName(),
-                                       $subject
-                               );
+                               $cc_subject = $context->msg( 'emailccsubject' )->rawParams(
+                                       $target->getName(), $subject )->text();
                                wfRunHooks( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) );
                                $ccStatus = UserMailer::send( $from, $from, $cc_subject, $text );
                                $status->merge( $ccStatus );
index acf4a10..11f0cd5 100644 (file)
@@ -487,20 +487,22 @@ class TextPassDumper extends BackupDumper {
                        // Something went wrong; we did not a text that was plausible :(
                        $failures++;
 
-
-                       // After backing off for some time, we try to reboot the whole process as
-                       // much as possible to not carry over failures from one part to the other
-                       // parts
-                       sleep( $this->failureTimeout );
-                       try {
-                               $this->rotateDb();
-                               if ( $this->spawn ) {
-                                       $this->closeSpawn();
-                                       $this->openSpawn();
+                       // A failure in a prefetch hit does not warrant resetting db connection etc.
+                       if ( ! $tryIsPrefetch ) {
+                               // After backing off for some time, we try to reboot the whole process as
+                               // much as possible to not carry over failures from one part to the other
+                               // parts
+                               sleep( $this->failureTimeout );
+                               try {
+                                       $this->rotateDb();
+                                       if ( $this->spawn ) {
+                                               $this->closeSpawn();
+                                               $this->openSpawn();
+                                       }
+                               } catch ( Exception $e ) {
+                                       $this->progress( "Rebooting getText infrastructure failed (" . $e->getMessage() . ")" .
+                                               " Trying to continue anyways" );
                                }
-                       } catch ( Exception $e ) {
-                               $this->progress( "Rebooting getText infrastructure failed (" . $e->getMessage() . ")" .
-                                       " Trying to continue anyways" );
                        }
                }
 
diff --git a/tests/phpunit/includes/cache/GenderCacheTest.php b/tests/phpunit/includes/cache/GenderCacheTest.php
new file mode 100644 (file)
index 0000000..d62ee20
--- /dev/null
@@ -0,0 +1,100 @@
+<?php\r
+\r
+/**\r
+ * @group Database\r
+ * @group Cache\r
+ */\r
+class GenderCacheTest extends MediaWikiLangTestCase {\r
+\r
+       function setUp() {\r
+               parent::setUp();\r
+               //ensure the correct default gender\r
+               $wgDefaultUserOptions['gender'] = 'unknown';\r
+       }\r
+\r
+       function addDBData() {\r
+               $user = User::newFromName( 'UTMale' );\r
+               if( $user->getID() == 0 ) {\r
+                       $user->addToDatabase();\r
+                       $user->setPassword( 'UTMalePassword' );\r
+               }\r
+               //ensure the right gender\r
+               $user->setOption( 'gender', 'male' );\r
+               $user->saveSettings();\r
+\r
+               $user = User::newFromName( 'UTFemale' );\r
+               if( $user->getID() == 0 ) {\r
+                       $user->addToDatabase();\r
+                       $user->setPassword( 'UTFemalePassword' );\r
+               }\r
+               //ensure the right gender\r
+               $user->setOption( 'gender', 'female' );\r
+               $user->saveSettings();\r
+\r
+               $user = User::newFromName( 'UTDefaultGender' );\r
+               if( $user->getID() == 0 ) {\r
+                       $user->addToDatabase();\r
+                       $user->setPassword( 'UTDefaultGenderPassword' );\r
+               }\r
+               //ensure the default gender\r
+               $user->setOption( 'gender', null );\r
+               $user->saveSettings();\r
+       }\r
+\r
+       /**\r
+        * test usernames\r
+        *\r
+        * @dataProvider dataUserName\r
+        */\r
+       function testUserName( $username, $expectedGender ) {\r
+               $genderCache = GenderCache::singleton();\r
+               $gender = $genderCache->getGenderOf( $username );\r
+               $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );\r
+       }\r
+\r
+       /**\r
+        * genderCache should work with user objects, too\r
+        *\r
+        * @dataProvider dataUserName\r
+        */\r
+       function testUserObjects( $username, $expectedGender ) {\r
+               $genderCache = GenderCache::singleton();\r
+               $user = User::newFromName( $username );\r
+               $gender = $genderCache->getGenderOf( $user );\r
+               $this->assertEquals( $gender, $expectedGender, "GenderCache normal" );\r
+       }\r
+\r
+       function dataUserName() {\r
+               return array(\r
+                       array( 'UTMale', 'male' ),\r
+                       array( 'UTFemale', 'female' ),\r
+                       array( 'UTDefaultGender', 'unknown' ),\r
+                       array( 'UTNotExist', 'unknown' ),\r
+                       //some not valid user\r
+                       array( '127.0.0.1', 'unknown' ),\r
+                       array( 'user@test', 'unknown' ),\r
+               );\r
+       }\r
+\r
+       /**\r
+        * test strip of subpages to avoid unnecessary queries\r
+        * against the never existing username\r
+        *\r
+        * @dataProvider dataStripSubpages\r
+        */\r
+       function testStripSubpages( $pageWithSubpage, $expectedGender ) {\r
+               $genderCache = GenderCache::singleton();\r
+               $gender = $genderCache->getGenderOf( $pageWithSubpage );\r
+               $this->assertEquals( $gender, $expectedGender, "GenderCache must strip of subpages" );\r
+       }\r
+\r
+       function dataStripSubpages() {\r
+               return array(\r
+                       array( 'UTMale/subpage', 'male' ),\r
+                       array( 'UTFemale/subpage', 'female' ),\r
+                       array( 'UTDefaultGender/subpage', 'unknown' ),\r
+                       array( 'UTNotExist/subpage', 'unknown' ),\r
+                       array( '127.0.0.1/subpage', 'unknown' ),\r
+               );\r
+       }\r
+}\r