Alos simplify isCompatible() slightly and make the string
case in convertToString() explicit.
Change-Id: Ifb61bb5fb012491520525bbebfbde2269fa55b52
$wgSearchTypeAlternatives = null;
/**
$wgSearchTypeAlternatives = null;
/**
- * Table name prefix; this should be alphanumeric and not contain spaces nor hyphens
+ * Table name prefix.
+ * This should be alphanumeric, contain neither spaces nor hyphens, and end in "_"
*/
public function __construct( $database, $schema, $prefix ) {
if ( $database !== null && ( !is_string( $database ) || !strlen( $database ) ) ) {
*/
public function __construct( $database, $schema, $prefix ) {
if ( $database !== null && ( !is_string( $database ) || !strlen( $database ) ) ) {
- throw new InvalidArgumentException( "Database must be null or a non-empty string." );
+ throw new InvalidArgumentException( 'Database must be null or a non-empty string.' );
}
$this->database = $database;
if ( $schema !== null && ( !is_string( $schema ) || !strlen( $schema ) ) ) {
}
$this->database = $database;
if ( $schema !== null && ( !is_string( $schema ) || !strlen( $schema ) ) ) {
- throw new InvalidArgumentException( "Schema must be null or a non-empty string." );
+ throw new InvalidArgumentException( 'Schema must be null or a non-empty string.' );
}
$this->schema = $schema;
if ( !is_string( $prefix ) ) {
}
$this->schema = $schema;
if ( !is_string( $prefix ) ) {
- throw new InvalidArgumentException( "Prefix must be a string." );
+ throw new InvalidArgumentException( 'Prefix must be a string.' );
+ } elseif ( $prefix !== '' && substr( $prefix, -1, 1 ) !== '_' ) {
+ throw new InvalidArgumentException( 'A non-empty prefix must end with "_".' );
}
$this->prefix = $prefix;
}
}
$this->prefix = $prefix;
}
return true; // even the prefix doesn't matter
}
return true; // even the prefix doesn't matter
}
- $other = ( $other instanceof self ) ? $other : self::newFromId( $other );
+ $other = self::newFromId( $other );
return (
( $this->database === $other->database || $this->database === null ) &&
return (
( $this->database === $other->database || $this->database === null ) &&
* @return string
*/
private function convertToString() {
* @return string
*/
private function convertToString() {
- $parts = [ $this->database ];
+ $parts = [ (string)$this->database ];
if ( $this->schema !== null ) {
$parts[] = $this->schema;
}
if ( $this->schema !== null ) {
$parts[] = $this->schema;
}
public function provideGetWikiIdFromDomain() {
return [
public function provideGetWikiIdFromDomain() {
return [
- [ 'db-prefix', 'db-prefix' ],
+ [ 'db-prefix_', 'db-prefix_' ],
[ wfWikiID(), wfWikiID() ],
[ wfWikiID(), wfWikiID() ],
- [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ],
+ [ new DatabaseDomain( 'db-dash', null, 'prefix_' ), 'db-dash-prefix_' ],
[ wfWikiID(), wfWikiID() ],
[ wfWikiID(), wfWikiID() ],
- [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ],
- [ new DatabaseDomain( 'db', 'mediawiki', 'prefix' ), 'db-prefix' ], // schema ignored
- [ new DatabaseDomain( 'db', 'custom', 'prefix' ), 'db-custom-prefix' ],
+ [ new DatabaseDomain( 'db-dash', null, 'prefix_' ), 'db-dash-prefix_' ],
+ [ new DatabaseDomain( 'db', 'mediawiki', 'prefix_' ), 'db-prefix_' ], // schema ignored
+ [ new DatabaseDomain( 'db', 'custom', 'prefix_' ), 'db-custom-prefix_' ],
[ 'db', 'db', null, '' ],
[ 'db-schema-','db', 'schema', '' ],
[ 'db','db', 'mediawiki', '' ], // common b/c case
[ 'db', 'db', null, '' ],
[ 'db-schema-','db', 'schema', '' ],
[ 'db','db', 'mediawiki', '' ], // common b/c case
- [ 'db-prefix', 'db', null, 'prefix' ],
- [ 'db-schema-prefix', 'db', 'schema', 'prefix' ],
- [ 'db-prefix', 'db', 'mediawiki', 'prefix' ], // common b/c case
+ [ 'db-prefix_', 'db', null, 'prefix_' ],
+ [ 'db-schema-prefix_', 'db', 'schema', 'prefix_' ],
+ [ 'db-prefix_', 'db', 'mediawiki', 'prefix_' ], // common b/c case
// Bad hyphen cases (best effort support)
[ 'db-stuff', 'db-stuff', null, '' ],
// Bad hyphen cases (best effort support)
[ 'db-stuff', 'db-stuff', null, '' ],
- [ 'db-stuff-prefix', 'db-stuff', null, 'prefix' ],
+ [ 'db-stuff-prefix_', 'db-stuff', null, 'prefix_' ],
[ 'db-stuff-schema-', 'db-stuff', 'schema', '' ],
[ 'db-stuff-schema-', 'db-stuff', 'schema', '' ],
- [ 'db-stuff-schema-prefix', 'db-stuff', 'schema', 'prefix' ],
- [ 'db-stuff-prefix', 'db-stuff', 'mediawiki', 'prefix' ] // common b/c case
+ [ 'db-stuff-schema-prefix_', 'db-stuff', 'schema', 'prefix_' ],
+ [ 'db-stuff-prefix_', 'db-stuff', 'mediawiki', 'prefix_' ] // common b/c case
$db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$this->assertEquals( 'foo', $db->tableName( 'foo' ) );
$this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
$db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$this->assertEquals( 'foo', $db->tableName( 'foo' ) );
$this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
- $db->tablePrefix( 'foo' );
+ $db->tablePrefix( 'foo_' );
$this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
$this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
- $this->assertEquals( 'foobar', $db->tableName( 'bar' ) );
+ $this->assertEquals( 'foo_bar', $db->tableName( 'bar' ) );
- $factory->redefineLocalDomain( 'somedb-prefix' );
- $this->assertEquals( 'somedb-prefix', $factory->getLocalDomainID() );
+ $factory->redefineLocalDomain( 'somedb-prefix_' );
+ $this->assertEquals( 'somedb-prefix_', $factory->getLocalDomainID() );
- $domain = new DatabaseDomain( $wgDBname, null, 'pref' );
+ $domain = new DatabaseDomain( $wgDBname, null, 'pref_' );
$factory->redefineLocalDomain( $domain );
$n = 0;
$factory->redefineLocalDomain( $domain );
$n = 0;
public static function provideConstruct() {
return [
'All strings' =>
public static function provideConstruct() {
return [
'All strings' =>
- [ 'foo', 'bar', 'baz', 'foo-bar-baz' ],
+ [ 'foo', 'bar', 'baz_', 'foo-bar-baz_' ],
'Nothing' =>
[ null, null, '', '' ],
'Invalid $database' =>
'Nothing' =>
[ null, null, '', '' ],
'Invalid $database' =>
'Invalid $prefix' =>
[ 'foo', 'bar', 0, '', true ],
'Dash' =>
'Invalid $prefix' =>
[ 'foo', 'bar', 0, '', true ],
'Dash' =>
- [ 'foo-bar', 'baz', 'baa', 'foo?hbar-baz-baa' ],
+ [ 'foo-bar', 'baz', 'baa_', 'foo?hbar-baz-baa_' ],
- [ 'foo?bar', 'baz', 'baa', 'foo??bar-baz-baa' ],
+ [ 'foo?bar', 'baz', 'baa_', 'foo??bar-baz-baa_' ],
'Basic' =>
[ 'foo', 'foo', null, '' ],
'db+prefix' =>
'Basic' =>
[ 'foo', 'foo', null, '' ],
'db+prefix' =>
- [ 'foo-bar', 'foo', null, 'bar' ],
+ [ 'foo-bar_', 'foo', null, 'bar_' ],
- [ 'foo-bar-baz', 'foo', 'bar', 'baz' ],
+ [ 'foo-bar-baz_', 'foo', 'bar', 'baz_' ],
- [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa' ],
+ [ 'foo?hbar-baz-baa_', 'foo-bar', 'baz', 'baa_' ],
- [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
+ [ 'foo??bar-baz-baa_', 'foo?bar', 'baz', 'baa_' ],
- [ 'foo?bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
+ [ 'foo?bar-baz-baa_', 'foo?bar', 'baz', 'baa_' ],
- [ 'foo-bar-baz-baa', '', '', '', true ],
+ [ 'foo-bar-baz-baa_', '', '', '', true ],
'from instance' =>
[ DatabaseDomain::newUnspecified(), null, null, '' ],
];
'from instance' =>
[ DatabaseDomain::newUnspecified(), null, null, '' ],
];
'Basic' =>
[ 'foo', 'foo', null, '' ],
'db+prefix' =>
'Basic' =>
[ 'foo', 'foo', null, '' ],
'db+prefix' =>
- [ 'foo-bar', 'foo', null, 'bar' ],
+ [ 'foo-bar_', 'foo', null, 'bar_' ],
- [ 'foo-bar-baz', 'foo', 'bar', 'baz' ],
+ [ 'foo-bar-baz_', 'foo', 'bar', 'baz_' ],
- [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa' ],
+ [ 'foo?hbar-baz-baa_', 'foo-bar', 'baz', 'baa_' ],
- [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
+ [ 'foo??bar-baz-baa_', 'foo?bar', 'baz', 'baa_' ],
'Nothing' =>
[ '', null, null, '' ],
];
'Nothing' =>
[ '', null, null, '' ],
];
'Basic' =>
[ 'foo', 'foo', null, '', true ],
'db+prefix' =>
'Basic' =>
[ 'foo', 'foo', null, '', true ],
'db+prefix' =>
- [ 'foo-bar', 'foo', null, 'bar', true ],
+ [ 'foo-bar_', 'foo', null, 'bar_', true ],
- [ 'foo-bar-baz', 'foo', 'bar', 'baz', true ],
+ [ 'foo-bar-baz_', 'foo', 'bar', 'baz_', true ],
'db+dontcare_schema+prefix' =>
'db+dontcare_schema+prefix' =>
- [ 'foo-bar-baz', 'foo', null, 'baz', false ],
+ [ 'foo-bar-baz_', 'foo', null, 'baz_', false ],
- [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa', true ],
+ [ 'foo?hbar-baz-baa_', 'foo-bar', 'baz', 'baa_', true ],
- [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa', true ],
+ [ 'foo??bar-baz-baa_', 'foo?bar', 'baz', 'baa_', true ],
'Nothing' =>
[ '', null, null, '', true ],
'dontcaredb+dontcaredbschema+prefix' =>
'Nothing' =>
[ '', null, null, '', true ],
'dontcaredb+dontcaredbschema+prefix' =>
- [ 'mywiki-mediawiki-prefix', null, null, 'prefix', false ],
+ [ 'mywiki-mediawiki-prefix_', null, null, 'prefix_', false ],
'dontcaredb+schema+prefix' =>
'dontcaredb+schema+prefix' =>
- [ 'mywiki-schema-prefix', null, 'schema', 'prefix', false ],
+ [ 'mywiki-schema-prefix_', null, 'schema', 'prefix_', false ],
'db+dontcareschema+prefix' =>
'db+dontcareschema+prefix' =>
- [ 'mywiki-schema-prefix', 'mywiki', null, 'prefix', false ],
+ [ 'mywiki-schema-prefix_', 'mywiki', null, 'prefix_', false ],
'postgres-db-jobqueue' =>
[ 'postgres-mediawiki-', 'postgres', null, '', false ]
];
'postgres-db-jobqueue' =>
[ 'postgres-mediawiki-', 'postgres', null, '', false ]
];
public static function provideIsCompatible2() {
return [
'db+schema+prefix' =>
public static function provideIsCompatible2() {
return [
'db+schema+prefix' =>
- [ 'mywiki-schema-prefix', 'thatwiki', 'schema', 'prefix' ],
+ [ 'mywiki-schema-prefix_', 'thatwiki', 'schema', 'prefix_' ],
'dontcaredb+dontcaredbschema+prefix' =>
'dontcaredb+dontcaredbschema+prefix' =>
- [ 'thatwiki-mediawiki-otherprefix', null, null, 'prefix' ],
+ [ 'thatwiki-mediawiki-otherprefix_', null, null, 'prefix_' ],
'dontcaredb+schema+prefix' =>
'dontcaredb+schema+prefix' =>
- [ 'mywiki-otherschema-prefix', null, 'schema', 'prefix' ],
+ [ 'mywiki-otherschema-prefix_', null, 'schema', 'prefix_' ],
'db+dontcareschema+prefix' =>
'db+dontcareschema+prefix' =>
- [ 'notmywiki-schema-prefix', 'mywiki', null, 'prefix' ],
+ [ 'notmywiki-schema-prefix_', 'mywiki', null, 'prefix_' ],
$oldDomain = $this->db->getDomainId();
$this->assertInternalType( 'string', $old, 'Prefix is string' );
$this->assertSame( $old, $this->db->tablePrefix(), "Prefix unchanged" );
$oldDomain = $this->db->getDomainId();
$this->assertInternalType( 'string', $old, 'Prefix is string' );
$this->assertSame( $old, $this->db->tablePrefix(), "Prefix unchanged" );
- $this->assertSame( $old, $this->db->tablePrefix( 'xxx' ) );
- $this->assertSame( 'xxx', $this->db->tablePrefix(), "Prefix set" );
+ $this->assertSame( $old, $this->db->tablePrefix( 'xxx_' ) );
+ $this->assertSame( 'xxx_', $this->db->tablePrefix(), "Prefix set" );
$this->db->tablePrefix( $old );
$this->db->tablePrefix( $old );
- $this->assertNotEquals( 'xxx', $this->db->tablePrefix() );
+ $this->assertNotEquals( 'xxx_', $this->db->tablePrefix() );
$this->assertSame( $oldDomain, $this->db->getDomainId() );
$old = $this->db->dbSchema();
$this->assertSame( $oldDomain, $this->db->getDomainId() );
$old = $this->db->dbSchema();
$oldSchema = $this->db->dbSchema();
$oldPrefix = $this->db->tablePrefix();
$oldSchema = $this->db->dbSchema();
$oldPrefix = $this->db->tablePrefix();
- $this->db->selectDomain( 'testselectdb-xxx' );
+ $this->db->selectDomain( 'testselectdb-xxx_' );
$this->assertSame( 'testselectdb', $this->db->getDBname() );
$this->assertSame( '', $this->db->dbSchema() );
$this->assertSame( 'testselectdb', $this->db->getDBname() );
$this->assertSame( '', $this->db->dbSchema() );
- $this->assertSame( 'xxx', $this->db->tablePrefix() );
+ $this->assertSame( 'xxx_', $this->db->tablePrefix() );
$this->db->selectDomain( $oldDomain );
$this->assertSame( $oldDatabase, $this->db->getDBname() );
$this->db->selectDomain( $oldDomain );
$this->assertSame( $oldDatabase, $this->db->getDBname() );
$this->assertSame( $oldPrefix, $this->db->tablePrefix() );
$this->assertSame( $oldDomain, $this->db->getDomainId() );
$this->assertSame( $oldPrefix, $this->db->tablePrefix() );
$this->assertSame( $oldDomain, $this->db->getDomainId() );
- $this->db->selectDomain( 'testselectdb-schema-xxx' );
+ $this->db->selectDomain( 'testselectdb-schema-xxx_' );
$this->assertSame( 'testselectdb', $this->db->getDBname() );
$this->assertSame( 'schema', $this->db->dbSchema() );
$this->assertSame( 'testselectdb', $this->db->getDBname() );
$this->assertSame( 'schema', $this->db->dbSchema() );
- $this->assertSame( 'xxx', $this->db->tablePrefix() );
+ $this->assertSame( 'xxx_', $this->db->tablePrefix() );
$this->db->selectDomain( $oldDomain );
$this->assertSame( $oldDatabase, $this->db->getDBname() );
$this->db->selectDomain( $oldDomain );
$this->assertSame( $oldDatabase, $this->db->getDBname() );