21 $this->markTestSkipped(
'No SQLite support detected' );
24 if ( version_compare( $this->db->getServerVersion(),
'3.6.0',
'<' ) ) {
25 $this->markTestSkipped(
"SQLite at least 3.6 required, {$this->db->getServerVersion()} found" );
31 return preg_replace(
'/\s+/',
' ', $this->db->replaceVars( $sql ) );
35 $this->assertNotNull(
$res );
38 foreach ( $expected[$i]
as $key =>
$value ) {
39 $this->assertTrue( isset( $row->$key ) );
40 $this->assertEquals(
$value, $row->$key );
44 $this->assertEquals( count( $expected ), $i,
'Unexpected number of rows' );
53 'foo bar',
"'foo bar'"
56 'foo\'bar',
"'foo''bar'"
80 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
81 $this->assertEquals( $expected,
$db->
addQuotes(
$value ),
'string not quoted as expected' );
86 $this->assertTrue( $re !==
false,
'query failed' );
88 $row = $re->fetchRow();
94 $this->assertEquals(
$value, $row[0],
'string mangled by the database' );
96 $this->fail(
'query returned no result' );
104 $this->assertEquals(
'foo', $this->
replaceVars(
'foo' ),
"Don't break anything accidentally" );
107 "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
108 .
"foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
110 "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, "
111 .
"foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', "
112 .
"foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;"
117 "CREATE TABLE foo ( foo1 REAL, foo2 REAL, foo3 REAL );",
119 "CREATE TABLE foo ( foo1 FLOAT, foo2 DOUBLE( 1,10), foo3 DOUBLE PRECISION );"
123 $this->assertEquals(
"CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
124 $this->
replaceVars(
"CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
127 $this->assertEquals(
"CREATE TABLE text ( text_foo TEXT );",
128 $this->
replaceVars(
"CREATE TABLE text ( text_foo tinytext );" ),
132 $this->assertEquals(
"CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
133 $this->
replaceVars(
"CREATE TABLE foo ( foobar INT PRIMARY KEY NOT NULL AUTO_INCREMENT );" )
135 $this->assertEquals(
"CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
136 $this->
replaceVars(
"CREATE TABLE foo ( foobar INT PRIMARY KEY AUTO_INCREMENT NOT NULL );" )
139 $this->assertEquals(
"CREATE TABLE enums( enum1 TEXT, myenum TEXT)",
140 $this->
replaceVars(
"CREATE TABLE enums( enum1 ENUM('A', 'B'), myenum ENUM ('X', 'Y'))" )
143 $this->assertEquals(
"ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
144 $this->
replaceVars(
"ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
147 $this->assertEquals(
"DROP INDEX foo",
148 $this->
replaceVars(
"DROP INDEX /*i*/foo ON /*_*/bar" )
151 $this->assertEquals(
"DROP INDEX foo -- dropping index",
152 $this->
replaceVars(
"DROP INDEX /*i*/foo ON /*_*/bar -- dropping index" )
154 $this->assertEquals(
"INSERT OR IGNORE INTO foo VALUES ('bar')",
155 $this->
replaceVars(
"INSERT OR IGNORE INTO foo VALUES ('bar')" )
164 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
166 $this->assertEquals(
'sqlite_master',
$db->
tableName(
'sqlite_master' ) );
168 $this->assertEquals(
'sqlite_master',
$db->
tableName(
'sqlite_master' ) );
169 $this->assertEquals(
'foo_bar',
$db->
tableName(
'bar' ) );
176 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
177 $db->
query(
'CREATE TABLE foo(foo, barfoo)' );
178 $db->
query(
'CREATE INDEX index1 ON foo(foo)' );
179 $db->
query(
'CREATE UNIQUE INDEX index2 ON foo(barfoo)' );
182 $this->assertEquals(
'CREATE TABLE "bar"(foo, barfoo)',
184 'Normal table duplication'
186 $indexList =
$db->
query(
'PRAGMA INDEX_LIST("bar")' );
187 $index = $indexList->next();
188 $this->assertEquals(
'bar_index1', $index->name );
189 $this->assertEquals(
'0', $index->unique );
190 $index = $indexList->next();
191 $this->assertEquals(
'bar_index2', $index->name );
192 $this->assertEquals(
'1', $index->unique );
195 $this->assertEquals(
'CREATE TABLE "baz"(foo, barfoo)',
196 $db->
selectField(
'sqlite_temp_master',
'sql', [
'name' =>
'baz' ] ),
197 'Creation of temporary duplicate'
199 $indexList =
$db->
query(
'PRAGMA INDEX_LIST("baz")' );
200 $index = $indexList->next();
201 $this->assertEquals(
'baz_index1', $index->name );
202 $this->assertEquals(
'0', $index->unique );
203 $index = $indexList->next();
204 $this->assertEquals(
'baz_index2', $index->name );
205 $this->assertEquals(
'1', $index->unique );
206 $this->assertEquals( 0,
207 $db->
selectField(
'sqlite_master',
'COUNT(*)', [
'name' =>
'baz' ] ),
208 'Create a temporary duplicate only'
216 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
218 $this->markTestSkipped(
'FTS3 not supported, cannot create virtual tables' );
220 $db->
query(
'CREATE VIRTUAL TABLE "foo" USING FTS3(foobar)' );
223 $this->assertEquals(
'CREATE VIRTUAL TABLE "bar" USING FTS3(foobar)',
225 'Duplication of virtual tables'
229 $this->assertEquals(
'CREATE VIRTUAL TABLE "baz" USING FTS3(foobar)',
231 "Can't create temporary virtual tables, should fall back to non-temporary duplication"
239 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
240 $db->
query(
'CREATE TABLE a (a_1)', __METHOD__ );
241 $db->
query(
'CREATE TABLE b (b_1, b_2)', __METHOD__ );
250 [
'b_1' => 2,
'b_2' =>
'a' ],
251 [
'b_1' => 3,
'b_2' =>
'b' ],
255 $db->
deleteJoin(
'a',
'b',
'a_1',
'b_1', [
'b_2' =>
'a' ], __METHOD__ );
275 $this->assertTrue(
true );
303 'user_newtalk.user_last_timestamp',
306 $currentDB = DatabaseSqlite::newStandaloneInstance(
':memory:' );
307 $currentDB->sourceFile(
"$IP/maintenance/tables.sql" );
309 $profileToDb =
false;
312 if (
$out ===
'db' ) {
314 } elseif ( is_array(
$out ) && in_array(
'db',
$out ) ) {
319 if ( $profileToDb ) {
320 $currentDB->sourceFile(
"$IP/maintenance/sqlite/archives/patch-profiling.sql" );
322 $currentTables = $this->
getTables( $currentDB );
323 sort( $currentTables );
325 foreach ( $versions
as $version ) {
326 $versions =
"upgrading from $version to $wgVersion";
329 $this->assertEquals( $currentTables,
$tables,
"Different tables $versions" );
331 $currentCols = $this->
getColumns( $currentDB, $table );
334 array_keys( $currentCols ),
336 "Mismatching columns for table \"$table\" $versions"
338 foreach ( $currentCols
as $name => $column ) {
342 (
bool)$cols[
$name]->pk,
343 "PRIMARY KEY status does not match for column $fullName $versions"
345 if ( !in_array(
$fullName, $ignoredColumns ) ) {
347 (
bool)$column->notnull,
348 (
bool)$cols[
$name]->notnull,
349 "NOT NULL status does not match for column $fullName $versions"
353 $cols[
$name]->dflt_value,
354 "Default values does not match for column $fullName $versions"
358 $currentIndexes = $this->
getIndexes( $currentDB, $table );
361 array_keys( $currentIndexes ),
362 array_keys( $indexes ),
363 "mismatching indexes for table \"$table\" $versions"
374 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
376 $databaseCreation =
$db->
query(
'CREATE TABLE a ( a_1 )', __METHOD__ );
377 $this->assertInstanceOf( ResultWrapper::class, $databaseCreation,
"Database creation" );
379 $insertion =
$db->
insert(
'a', [
'a_1' => 10 ], __METHOD__ );
380 $this->assertTrue( $insertion,
"Insertion worked" );
382 $this->assertInternalType(
'integer',
$db->
insertId(),
"Actual typecheck" );
383 $this->assertTrue(
$db->
close(),
"closing database" );
390 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
391 $db->
query(
'CREATE TABLE testInsertAffectedRows ( foo )', __METHOD__ );
394 'testInsertAffectedRows',
402 $this->assertTrue( $insertion,
"Insertion worked" );
405 $this->assertTrue(
$db->
close(),
"closing database" );
409 static $maint =
null;
410 if ( $maint ===
null ) {
412 $maint->loadParamsAndArgs(
null, [
'quiet' => 1 ] );
416 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
417 $db->
sourceFile(
"$IP/tests/phpunit/data/db/sqlite/tables-$version.sql" );
431 'searchindex_content',
432 'searchindex_segments',
433 'searchindex_segdir',
435 'searchindex_docsize',
438 foreach ( $excluded
as $t ) {
441 $list = array_flip( $list );
450 $this->assertNotNull(
$res );
451 foreach (
$res as $col ) {
452 $cols[$col->name] = $col;
462 $this->assertNotNull(
$res );
463 foreach (
$res as $index ) {
464 $res2 =
$db->
query(
"PRAGMA index_info({$index->name})" );
465 $this->assertNotNull( $res2 );
466 $index->columns = [];
467 foreach ( $res2
as $col ) {
468 $index->columns[] = $col;
470 $indexes[$index->name] = $index;
482 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
484 $row =
$res->fetchRow();
485 $this->assertFalse( (
bool)$row[
'a'] );
492 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
494 $databaseCreation =
$db->
query(
'CREATE TABLE a ( a_1 )', __METHOD__ );
495 $this->assertInstanceOf( ResultWrapper::class, $databaseCreation,
"Failed to create table a" );
497 $this->assertEquals( 0,
$db->
numFields(
$res ),
"expects to get 0 fields for an empty table" );
498 $insertion =
$db->
insert(
'a', [
'a_1' => 10 ], __METHOD__ );
499 $this->assertTrue( $insertion,
"Insertion failed" );
503 $this->assertTrue(
$db->
close(),
"closing database" );
510 $db = DatabaseSqlite::newStandaloneInstance(
':memory:' );
514 $this->assertContains(
'SQLite ', $toString );
521 $attributes = Database::attributesFromType(
'sqlite' );
522 $this->assertTrue( $attributes[Database::ATTR_DB_LEVEL_LOCKING] );
528 $p[
'dbFilePath'] =
':memory:';
529 $p[
'schema'] =
false;
531 return Database::factory(
'SqliteMock', $p );
542 return parent::replaceVars(
$s );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgProfiler
Profiler configuration.
$wgVersion
MediaWiki version number.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
replaceVars( $s)
Override parent visibility to public.
query( $sql, $fname='', $flags=0)
Run an SQL query and return the result.
static newInstance(array $p=[])
testCaseInsensitiveLike()
@coversNothing
testDuplicateTableStructureVirtual()
DatabaseSqlite::duplicateTableStructure.
testInsertIdType()
DatabaseSqlite::insertId.
assertResultIs( $expected, $res)
testAddQuotes( $value, $expected)
provideAddQuotes() DatabaseSqlite::addQuotes
testUpgrades()
Runs upgrades of older databases and compares results with current schema.
static provideAddQuotes()
testInsertAffectedRows()
DatabaseSqlite::insert.
testToString()
\Wikimedia\Rdbms\DatabaseSqlite::__toString
testReplaceVars()
DatabaseSqlite::replaceVars.
testTableName()
DatabaseSqlite::tableName.
testEntireSchema()
@coversNothing
testNumFields()
DatabaseSqlite::numFields.
testDuplicateTableStructure()
DatabaseSqlite::duplicateTableStructure.
testsAttributes()
\Wikimedia\Rdbms\DatabaseSqlite::getAttributes()
testDeleteJoin()
DatabaseSqlite::deleteJoin.
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
Fake maintenance wrapper, mostly used for the web installer/updater.
static isPresent()
Checks whether PHP has SQLite support.
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
Allows to change the fields on the form that will be generated $name
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$page->newPageUpdater($user) $updater