$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.
* (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.
$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)
/** 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
*/
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
*/
return true;
case self::AS_HOOK_ERROR:
- case self::AS_FILTERING:
return false;
case self::AS_SUCCESS_NEW_ARTICLE:
* 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();
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' );
# 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() );
}
$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() );
}
} 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() );
}
}
}
- // 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 );
}
'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" ),
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' );
array( 'noimageredirect-logged' ),
array( 'spamdetected', 'spam' ),
array( 'summaryrequired' ),
- array( 'filtered' ),
array( 'blockedtext' ),
array( 'contenttoobig', $wgMaxArticleSize ),
array( 'noedit-anon' ),
'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
$username = $username->getName();
}
- $username = strtr( $username, '_', ' ' );
+ $username = self::normalizeUsername( $username );
if ( !isset( $this->cache[$username] ) ) {
if ( $this->misses >= $this->missLimit && $wgUser->getName() !== $username ) {
} else {
$this->misses++;
- if ( !User::isValidUserName( $username ) ) {
- $this->cache[$username] = $this->getDefault();
- } else {
- $this->doQuery( $username, $caller );
- }
+ $this->doQuery( $username, $caller );
}
}
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;
}
}
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' ) ) );
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, '_', ' ' );
+ }
}
}
$genderCache = GenderCache::singleton();
- $genderCache->dolinkBatch( $this->data, $this->caller );
+ $genderCache->doLinkBatch( $this->data, $this->caller );
return true;
}
* @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
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.
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
}
}
}
}
- // 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 );
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 ) {}
}
/**
$this->shardViaHashLevels = isset( $config['shardViaHashLevels'] )
? $config['shardViaHashLevels']
: '';
+ // Cache container info to mask latency
+ $this->memCache = wfGetMainCache();
}
/**
* 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];
}
*
* @param $container string Container name
* @return CF_Container
+ * @throws InvalidResponseException
*/
protected function createContainer( $container ) {
$conn = $this->getConnection(); // Swift proxy connection
*
* @param $container string Container name
* @return void
+ * @throws InvalidResponseException
*/
protected function deleteContainer( $container ) {
$conn = $this->getConnection(); // Swift proxy connection
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
*
} 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
),
'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,
$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 ) ) ) {
$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
* @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 ) ) ) {
// 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 );
// 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" );
}
}
--- /dev/null
+<?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