MediaWiki  master
DatabaseSqliteTest.php
Go to the documentation of this file.
1 <?php
2 
10 
18  protected $db;
19 
20  protected function setUp() {
21  parent::setUp();
22 
23  if ( !Sqlite::isPresent() ) {
24  $this->markTestSkipped( 'No SQLite support detected' );
25  }
26  $this->db = $this->getMockBuilder( DatabaseSqlite::class )
27  ->setConstructorArgs( [ [
28  'dbFilePath' => ':memory:',
29  'schema' => false,
30  'host' => false,
31  'user' => false,
32  'password' => false,
33  'tablePrefix' => '',
34  'cliMode' => true,
35  'agent' => 'unit-tests',
36  'flags' => DBO_DEFAULT,
37  'variables' => [],
38  'profiler' => null,
39  'trxProfiler' => new TransactionProfiler(),
40  'connLogger' => new NullLogger(),
41  'queryLogger' => new NullLogger(),
42  'errorLogger' => null,
43  'deprecationLogger' => null,
44  ] ] )->setMethods( [ 'query' ] )
45  ->getMock();
46  $this->db->initConnection();
47  $this->db->method( 'query' )->willReturn( true );
48  if ( version_compare( $this->db->getServerVersion(), '3.6.0', '<' ) ) {
49  $this->markTestSkipped( "SQLite at least 3.6 required, {$this->db->getServerVersion()} found" );
50  }
51  }
52 
57  private function replaceVars( $sql ) {
58  $wrapper = TestingAccessWrapper::newFromObject( $this->db );
59  // normalize spacing to hide implementation details
60  return preg_replace( '/\s+/', ' ', $wrapper->replaceVars( $sql ) );
61  }
62 
63  private function assertResultIs( $expected, $res ) {
64  $this->assertNotNull( $res );
65  $i = 0;
66  foreach ( $res as $row ) {
67  foreach ( $expected[$i] as $key => $value ) {
68  $this->assertTrue( isset( $row->$key ) );
69  $this->assertEquals( $value, $row->$key );
70  }
71  $i++;
72  }
73  $this->assertEquals( count( $expected ), $i, 'Unexpected number of rows' );
74  }
75 
76  public static function provideAddQuotes() {
77  return [
78  [ // #0: empty
79  '', "''"
80  ],
81  [ // #1: simple
82  'foo bar', "'foo bar'"
83  ],
84  [ // #2: including quote
85  'foo\'bar', "'foo''bar'"
86  ],
87  // #3: including \0 (must be represented as hex, per https://bugs.php.net/bug.php?id=63419)
88  [
89  "x\0y",
90  "x'780079'",
91  ],
92  [ // #4: blob object (must be represented as hex)
93  new Blob( "hello" ),
94  "x'68656c6c6f'",
95  ],
96  [ // #5: null
97  null,
98  "''",
99  ],
100  ];
101  }
102 
107  public function testAddQuotes( $value, $expected ) {
108  // check quoting
109  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
110  $this->assertEquals( $expected, $db->addQuotes( $value ), 'string not quoted as expected' );
111 
112  // ok, quoting works as expected, now try a round trip.
113  $re = $db->query( 'select ' . $db->addQuotes( $value ) );
114 
115  $this->assertTrue( $re !== false, 'query failed' );
116 
117  $row = $re->fetchRow();
118  if ( $row ) {
119  if ( $value instanceof Blob ) {
120  $value = $value->fetch();
121  }
122 
123  $this->assertEquals( $value, $row[0], 'string mangled by the database' );
124  } else {
125  $this->fail( 'query returned no result' );
126  }
127  }
128 
132  public function testReplaceVars() {
133  $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
134 
135  $this->assertEquals(
136  "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
137  . "foo_bar TEXT, foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
138  $this->replaceVars(
139  "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, "
140  . "foo_bar char(13), foo_name varchar(255) binary NOT NULL DEFAULT '', "
141  . "foo_int tinyint ( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;"
142  )
143  );
144 
145  $this->assertEquals(
146  "CREATE TABLE foo ( foo1 REAL, foo2 REAL, foo3 REAL );",
147  $this->replaceVars(
148  "CREATE TABLE foo ( foo1 FLOAT, foo2 DOUBLE( 1,10), foo3 DOUBLE PRECISION );"
149  )
150  );
151 
152  $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
153  $this->replaceVars( "CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
154  );
155 
156  $this->assertEquals( "CREATE TABLE text ( text_foo TEXT );",
157  $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ),
158  'Table name changed'
159  );
160 
161  $this->assertEquals( "CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
162  $this->replaceVars( "CREATE TABLE foo ( foobar INT PRIMARY KEY NOT NULL AUTO_INCREMENT );" )
163  );
164  $this->assertEquals( "CREATE TABLE foo ( foobar INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL );",
165  $this->replaceVars( "CREATE TABLE foo ( foobar INT PRIMARY KEY AUTO_INCREMENT NOT NULL );" )
166  );
167 
168  $this->assertEquals( "CREATE TABLE enums( enum1 TEXT, myenum TEXT)",
169  $this->replaceVars( "CREATE TABLE enums( enum1 ENUM('A', 'B'), myenum ENUM ('X', 'Y'))" )
170  );
171 
172  $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
173  $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" )
174  );
175 
176  $this->assertEquals( "DROP INDEX foo",
177  $this->replaceVars( "DROP INDEX /*i*/foo ON /*_*/bar" )
178  );
179 
180  $this->assertEquals( "DROP INDEX foo -- dropping index",
181  $this->replaceVars( "DROP INDEX /*i*/foo ON /*_*/bar -- dropping index" )
182  );
183  $this->assertEquals( "INSERT OR IGNORE INTO foo VALUES ('bar')",
184  $this->replaceVars( "INSERT OR IGNORE INTO foo VALUES ('bar')" )
185  );
186  }
187 
191  public function testTableName() {
192  // @todo Moar!
193  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
194  $this->assertEquals( 'foo', $db->tableName( 'foo' ) );
195  $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
196  $db->tablePrefix( 'foo_' );
197  $this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
198  $this->assertEquals( 'foo_bar', $db->tableName( 'bar' ) );
199  }
200 
204  public function testDuplicateTableStructure() {
205  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
206  $db->query( 'CREATE TABLE foo(foo, barfoo)' );
207  $db->query( 'CREATE INDEX index1 ON foo(foo)' );
208  $db->query( 'CREATE UNIQUE INDEX index2 ON foo(barfoo)' );
209 
210  $db->duplicateTableStructure( 'foo', 'bar' );
211  $this->assertEquals( 'CREATE TABLE "bar"(foo, barfoo)',
212  $db->selectField( 'sqlite_master', 'sql', [ 'name' => 'bar' ] ),
213  'Normal table duplication'
214  );
215  $indexList = $db->query( 'PRAGMA INDEX_LIST("bar")' );
216  $index = $indexList->next();
217  $this->assertEquals( 'bar_index1', $index->name );
218  $this->assertEquals( '0', $index->unique );
219  $index = $indexList->next();
220  $this->assertEquals( 'bar_index2', $index->name );
221  $this->assertEquals( '1', $index->unique );
222 
223  $db->duplicateTableStructure( 'foo', 'baz', true );
224  $this->assertEquals( 'CREATE TABLE "baz"(foo, barfoo)',
225  $db->selectField( 'sqlite_temp_master', 'sql', [ 'name' => 'baz' ] ),
226  'Creation of temporary duplicate'
227  );
228  $indexList = $db->query( 'PRAGMA INDEX_LIST("baz")' );
229  $index = $indexList->next();
230  $this->assertEquals( 'baz_index1', $index->name );
231  $this->assertEquals( '0', $index->unique );
232  $index = $indexList->next();
233  $this->assertEquals( 'baz_index2', $index->name );
234  $this->assertEquals( '1', $index->unique );
235  $this->assertEquals( 0,
236  $db->selectField( 'sqlite_master', 'COUNT(*)', [ 'name' => 'baz' ] ),
237  'Create a temporary duplicate only'
238  );
239  }
240 
245  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
246  if ( $db->getFulltextSearchModule() != 'FTS3' ) {
247  $this->markTestSkipped( 'FTS3 not supported, cannot create virtual tables' );
248  }
249  $db->query( 'CREATE VIRTUAL TABLE "foo" USING FTS3(foobar)' );
250 
251  $db->duplicateTableStructure( 'foo', 'bar' );
252  $this->assertEquals( 'CREATE VIRTUAL TABLE "bar" USING FTS3(foobar)',
253  $db->selectField( 'sqlite_master', 'sql', [ 'name' => 'bar' ] ),
254  'Duplication of virtual tables'
255  );
256 
257  $db->duplicateTableStructure( 'foo', 'baz', true );
258  $this->assertEquals( 'CREATE VIRTUAL TABLE "baz" USING FTS3(foobar)',
259  $db->selectField( 'sqlite_master', 'sql', [ 'name' => 'baz' ] ),
260  "Can't create temporary virtual tables, should fall back to non-temporary duplication"
261  );
262  }
263 
267  public function testDeleteJoin() {
268  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
269  $db->query( 'CREATE TABLE a (a_1)', __METHOD__ );
270  $db->query( 'CREATE TABLE b (b_1, b_2)', __METHOD__ );
271  $db->insert( 'a', [
272  [ 'a_1' => 1 ],
273  [ 'a_1' => 2 ],
274  [ 'a_1' => 3 ],
275  ],
276  __METHOD__
277  );
278  $db->insert( 'b', [
279  [ 'b_1' => 2, 'b_2' => 'a' ],
280  [ 'b_1' => 3, 'b_2' => 'b' ],
281  ],
282  __METHOD__
283  );
284  $db->deleteJoin( 'a', 'b', 'a_1', 'b_1', [ 'b_2' => 'a' ], __METHOD__ );
285  $res = $db->query( "SELECT * FROM a", __METHOD__ );
286  $this->assertResultIs( [
287  [ 'a_1' => 1 ],
288  [ 'a_1' => 3 ],
289  ],
290  $res
291  );
292  }
293 
297  public function testEntireSchema() {
298  global $IP;
299 
300  $result = Sqlite::checkSqlSyntax( "$IP/maintenance/tables.sql" );
301  if ( $result !== true ) {
302  $this->fail( $result );
303  }
304  $this->assertTrue( true ); // avoid test being marked as incomplete due to lack of assertions
305  }
306 
312  public function testUpgrades() {
313  global $IP, $wgVersion, $wgProfiler;
314 
315  // Versions tested
316  $versions = [
317  // '1.13', disabled for now, was totally screwed up
318  // SQLite wasn't included in 1.14
319  '1.15',
320  '1.16',
321  '1.17',
322  '1.18',
323  '1.19',
324  '1.20',
325  '1.21',
326  '1.22',
327  '1.23',
328  ];
329 
330  // Mismatches for these columns we can safely ignore
331  $ignoredColumns = [
332  'user_newtalk.user_last_timestamp', // r84185
333  ];
334 
335  $currentDB = DatabaseSqlite::newStandaloneInstance( ':memory:' );
336  $currentDB->sourceFile( "$IP/maintenance/tables.sql" );
337 
338  $profileToDb = false;
339  if ( isset( $wgProfiler['output'] ) ) {
340  $out = $wgProfiler['output'];
341  if ( $out === 'db' ) {
342  $profileToDb = true;
343  } elseif ( is_array( $out ) && in_array( 'db', $out ) ) {
344  $profileToDb = true;
345  }
346  }
347 
348  if ( $profileToDb ) {
349  $currentDB->sourceFile( "$IP/maintenance/sqlite/archives/patch-profiling.sql" );
350  }
351  $currentTables = $this->getTables( $currentDB );
352  sort( $currentTables );
353 
354  foreach ( $versions as $version ) {
355  $versions = "upgrading from $version to $wgVersion";
356  $db = $this->prepareTestDB( $version );
357  $tables = $this->getTables( $db );
358  $this->assertEquals( $currentTables, $tables, "Different tables $versions" );
359  foreach ( $tables as $table ) {
360  $currentCols = $this->getColumns( $currentDB, $table );
361  $cols = $this->getColumns( $db, $table );
362  $this->assertEquals(
363  array_keys( $currentCols ),
364  array_keys( $cols ),
365  "Mismatching columns for table \"$table\" $versions"
366  );
367  foreach ( $currentCols as $name => $column ) {
368  $fullName = "$table.$name";
369  $this->assertEquals(
370  (bool)$column->pk,
371  (bool)$cols[$name]->pk,
372  "PRIMARY KEY status does not match for column $fullName $versions"
373  );
374  if ( !in_array( $fullName, $ignoredColumns ) ) {
375  $this->assertEquals(
376  (bool)$column->notnull,
377  (bool)$cols[$name]->notnull,
378  "NOT NULL status does not match for column $fullName $versions"
379  );
380  $this->assertEquals(
381  $column->dflt_value,
382  $cols[$name]->dflt_value,
383  "Default values does not match for column $fullName $versions"
384  );
385  }
386  }
387  $currentIndexes = $this->getIndexes( $currentDB, $table );
388  $indexes = $this->getIndexes( $db, $table );
389  $this->assertEquals(
390  array_keys( $currentIndexes ),
391  array_keys( $indexes ),
392  "mismatching indexes for table \"$table\" $versions"
393  );
394  }
395  $db->close();
396  }
397  }
398 
402  public function testInsertIdType() {
403  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
404 
405  $databaseCreation = $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ );
406  $this->assertInstanceOf( ResultWrapper::class, $databaseCreation, "Database creation" );
407 
408  $insertion = $db->insert( 'a', [ 'a_1' => 10 ], __METHOD__ );
409  $this->assertTrue( $insertion, "Insertion worked" );
410 
411  $this->assertInternalType( 'integer', $db->insertId(), "Actual typecheck" );
412  $this->assertTrue( $db->close(), "closing database" );
413  }
414 
418  public function testInsertAffectedRows() {
419  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
420  $db->query( 'CREATE TABLE testInsertAffectedRows ( foo )', __METHOD__ );
421 
422  $insertion = $db->insert(
423  'testInsertAffectedRows',
424  [
425  [ 'foo' => 10 ],
426  [ 'foo' => 12 ],
427  [ 'foo' => 1555 ],
428  ],
429  __METHOD__
430  );
431  $this->assertTrue( $insertion, "Insertion worked" );
432 
433  $this->assertSame( 3, $db->affectedRows() );
434  $this->assertTrue( $db->close(), "closing database" );
435  }
436 
437  private function prepareTestDB( $version ) {
438  static $maint = null;
439  if ( $maint === null ) {
440  $maint = new FakeMaintenance();
441  $maint->loadParamsAndArgs( null, [ 'quiet' => 1 ] );
442  }
443 
444  global $IP;
445  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
446  $db->sourceFile( "$IP/tests/phpunit/data/db/sqlite/tables-$version.sql" );
447  $updater = DatabaseUpdater::newForDB( $db, false, $maint );
448  $updater->doUpdates( [ 'core' ] );
449 
450  return $db;
451  }
452 
453  private function getTables( $db ) {
454  $list = array_flip( $db->listTables() );
455  $excluded = [
456  'external_user', // removed from core in 1.22
457  'math', // moved out of core in 1.18
458  'trackbacks', // removed from core in 1.19
459  'searchindex',
460  'searchindex_content',
461  'searchindex_segments',
462  'searchindex_segdir',
463  // FTS4 ready!!1
464  'searchindex_docsize',
465  'searchindex_stat',
466  ];
467  foreach ( $excluded as $t ) {
468  unset( $list[$t] );
469  }
470  $list = array_flip( $list );
471  sort( $list );
472 
473  return $list;
474  }
475 
476  private function getColumns( $db, $table ) {
477  $cols = [];
478  $res = $db->query( "PRAGMA table_info($table)" );
479  $this->assertNotNull( $res );
480  foreach ( $res as $col ) {
481  $cols[$col->name] = $col;
482  }
483  ksort( $cols );
484 
485  return $cols;
486  }
487 
488  private function getIndexes( $db, $table ) {
489  $indexes = [];
490  $res = $db->query( "PRAGMA index_list($table)" );
491  $this->assertNotNull( $res );
492  foreach ( $res as $index ) {
493  $res2 = $db->query( "PRAGMA index_info({$index->name})" );
494  $this->assertNotNull( $res2 );
495  $index->columns = [];
496  foreach ( $res2 as $col ) {
497  $index->columns[] = $col;
498  }
499  $indexes[$index->name] = $index;
500  }
501  ksort( $indexes );
502 
503  return $indexes;
504  }
505 
509  public function testCaseInsensitiveLike() {
510  // TODO: Test this for all databases
511  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
512  $res = $db->query( 'SELECT "a" LIKE "A" AS a' );
513  $row = $res->fetchRow();
514  $this->assertFalse( (bool)$row['a'] );
515  }
516 
520  public function testNumFields() {
521  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
522 
523  $databaseCreation = $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ );
524  $this->assertInstanceOf( ResultWrapper::class, $databaseCreation, "Failed to create table a" );
525  $res = $db->select( 'a', '*' );
526  $this->assertEquals( 0, $db->numFields( $res ), "expects to get 0 fields for an empty table" );
527  $insertion = $db->insert( 'a', [ 'a_1' => 10 ], __METHOD__ );
528  $this->assertTrue( $insertion, "Insertion failed" );
529  $res = $db->select( 'a', '*' );
530  $this->assertEquals( 1, $db->numFields( $res ), "wrong number of fields" );
531 
532  $this->assertTrue( $db->close(), "closing database" );
533  }
534 
538  public function testToString() {
539  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
540 
541  $toString = (string)$db;
542 
543  $this->assertContains( 'sqlite object', $toString );
544  }
545 
549  public function testsAttributes() {
550  $attributes = Database::attributesFromType( 'sqlite' );
551  $this->assertTrue( $attributes[Database::ATTR_DB_LEVEL_LOCKING] );
552  }
553 }
Helper class that detects high-contention DB queries via profiling calls.
testDeleteJoin()
DatabaseSqlite::deleteJoin.
tableName( $name, $format='quoted')
Use MySQL&#39;s naming (accounts for prefix etc) but remove surrounding backticks.
$wgVersion
MediaWiki version number.
affectedRows()
Get the number of rows affected by the last write query.
Definition: Database.php:4071
testDuplicateTableStructureVirtual()
DatabaseSqlite::duplicateTableStructure.
testDuplicateTableStructure()
DatabaseSqlite::duplicateTableStructure.
$IP
Definition: WebStart.php:41
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testsAttributes()
\Wikimedia\Rdbms\DatabaseSqlite::getAttributes()
selectField( $table, $var, $cond='', $fname=__METHOD__, $options=[], $join_conds=[])
A SELECT wrapper which returns a single field from a single result row.
Definition: Database.php:1572
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
Definition: hooks.txt:175
$value
testToString()
\Wikimedia\Rdbms\DatabaseSqlite::__toString
static getFulltextSearchModule()
Returns version of currently supported SQLite fulltext search module or false if none present...
query( $sql, $fname=__METHOD__, $flags=0)
Run an SQL query and return the result.
Definition: Database.php:1130
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
Definition: hooks.txt:979
insertId()
This must be called after nextSequenceVal.
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. '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
Definition: hooks.txt:1980
close()
Close the database connection.
Definition: Database.php:865
$fullName
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
Definition: hooks.txt:780
listTables( $prefix=null, $fname=__METHOD__)
List all tables on the database.
Fake maintenance wrapper, mostly used for the web installer/updater.
testNumFields()
DatabaseSqlite::numFields.
sqlite Database medium
sourceFile( $filename, callable $lineCallback=null, callable $resultCallback=null, $fname=false, callable $inputCallback=null)
Read and execute SQL commands from a file.
Definition: Database.php:4279
testInsertIdType()
DatabaseSqlite::insertId.
testReplaceVars()
DatabaseSqlite::replaceVars.
$res
Definition: database.txt:21
testAddQuotes( $value, $expected)
provideAddQuotes() DatabaseSqlite::addQuotes
assertResultIs( $expected, $res)
testInsertAffectedRows()
DatabaseSqlite::insert.
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 null
Definition: hooks.txt:780
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
Definition: distributors.txt:9
testTableName()
DatabaseSqlite::tableName.
tablePrefix( $prefix=null)
Get/set the table prefix.
Definition: Database.php:531
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
Definition: injection.txt:35
const DBO_DEFAULT
Definition: defines.php:13
static isPresent()
Checks whether PHP has SQLite support.
Definition: sqlite.inc:38
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1754
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
DELETE where the condition is a join.
Definition: Database.php:2923
duplicateTableStructure( $oldName, $newName, $temporary=false, $fname=__METHOD__)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
testUpgrades()
Runs upgrades of older databases and compares results with current schema.
$wgProfiler
Profiler configuration.
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.
Definition: sqlite.inc:50
insert( $table, $a, $fname=__METHOD__, $options=[])
Based on generic method (parent) with some prior SQLite-sepcific adjustments.