Go to the documentation of this file.
50 $this->cliMode = $opts[
'cliMode'] ??
true;
51 $this->connLogger = new \Psr\Log\NullLogger();
52 $this->queryLogger = new \Psr\Log\NullLogger();
53 $this->errorLogger =
function ( Exception
$e ) {
54 wfWarn( get_class(
$e ) .
": {$e->getMessage()}" );
56 $this->deprecationLogger =
function ( $msg ) {
59 $this->currentDomain = DatabaseDomain::newUnspecified();
60 $this->
open(
'localhost',
'testuser',
'password',
'testdb',
null,
'' );
69 $lastSqls = implode(
'; ', $this->lastSqls );
83 $this->nextResult =
$res;
93 $this->nextError = [
'errno' => $errno,
'error' => $error ] +
$options;
98 $this->lastSqls[] = trim( preg_replace(
99 '/\s{2,}(?=FROM|WHERE|GROUP BY|ORDER BY|LIMIT)|(?<=SELECT|INSERT|UPDATE)\s{2,}/',
105 if (
$fname ===
'Wikimedia\\Rdbms\\Database::close' ) {
111 if ( preg_match(
'/^Wikimedia\\\\Rdbms\\\\Database::query \((.+)\)$/',
$fname, $m ) ) {
115 if ( substr( $check, 0, strlen( $this->testName ) ) !== $this->testName ) {
116 throw new MWException(
'function name does not start with test class. ' .
117 $fname .
' vs. ' . $this->testName .
'. ' .
118 'Please provide __METHOD__ to database methods.' );
124 return str_replace(
"'",
"\'",
$s );
139 $tableRaw = $this->
tableName( $table,
'raw' );
140 if ( isset( $this->sessionTempTables[$tableRaw] ) ) {
146 return in_array( $table, (
array)$this->tablesExists );
151 return parent::nativeReplace( $table,
$rows,
$fname );
159 $this->conn = (
object)[
'test' ];
201 return $this->
lastError[
'wasKnownStatementRollbackError'] ??
false;
229 return $this->conn ?
true :
false;
232 function ping( &$rtt =
null ) {
242 $sql = preg_replace(
'< /\* .+? \*/>',
'', $sql );
245 if ( $this->nextError ) {
247 $this->nextError =
null;
252 $this->nextResult = [];
255 return new FakeResultWrapper(
$res );
$testName
CLASS of the test suite, used to determine, if the function name is passed every time to query()
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
setUnionSupportsOrderAndLimit( $v)
isOpen()
Is a connection to the database open?
open( $server, $user, $password, $dbName, $schema, $tablePrefix)
Open a new connection to the database (closing any existing one)
numFields( $res)
Get the number of fields in a result object.
fieldInfo( $table, $field)
mysql_fetch_field() wrapper Returns false if the field doesn't exist
getLastSqls()
Returns SQL queries grouped by '; ' Clear the list of queries that have been done so far.
Stub profiler that does nothing.
doQuery( $sql)
Run a query and return a DBMS-dependent wrapper (that has all IResultWrapper methods)
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
nativeReplace( $table, $rows, $fname)
REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.
array $nextResult
List of row arrays.
fetchRow( $res)
Fetch the next row from the given result object, in associative array form.
wasKnownStatementRollbackError()
tableExists( $table, $fname=__METHOD__)
Query whether a given table exists.
forceNextQueryError( $errno, $error, $options=[])
getSoftwareLink()
Returns a wikitext link to the DB's website, e.g., return "[https://www.mysql.com/ MySQL]"; Should at...
strencode( $s)
Wrapper for addslashes()
unionSupportsOrderAndLimit()
Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within th...
lastError()
Get a description of the last error.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
$tablesExists
Array of tables to be considered as existing by tableExist() Use setExistingTables() to alter.
setExistingTables( $tablesExists)
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))
query( $sql, $fname='', $tempIgnore=false)
Run an SQL query and return the result.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
ping(&$rtt=null)
Ping the server and try to reconnect if it there is no connection.
numRows( $res)
Get the number of rows in a query result.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
getServerInfo()
A string describing the current software version, and possibly other details in a user-friendly way.
getServerVersion()
A string describing the current software version, like from mysql_get_server_info().
addIdentifierQuotes( $s)
Quotes an identifier using backticks or "double quotes" depending on the database type.
insertId()
Get the inserted value of an auto-increment row.
checkFunctionName( $fname)
dataSeek( $res, $row)
Change the position of the cursor in a result object.
Helper for testing the methods from the Database class.
fieldName( $res, $n)
Get a field name in a result object.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
indexInfo( $table, $index, $fname='Database::indexInfo')
Get information about an index into an object.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
$lastSqls
Array of lastSqls passed to query(), This is an array since some methods in Database can do more than...
closeConnection()
Closes underlying database connection.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
$unionSupportsOrderAndLimit
Value to return from unionSupportsOrderAndLimit()
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
fetchObject( $res)
Fetch the next row from the given result object, in object form.
__construct( $testName, array $opts=[])
Class to handle database/prefix specification for IDatabase domains.
lastErrno()
Get the last error number.