MediaWiki  1.23.15
DatabaseSqlite.php
Go to the documentation of this file.
1 <?php
30  private static $fulltextEnabled = null;
31 
33  public $mDatabaseFile;
34 
36  protected $mAffectedRows;
37 
39  protected $mLastResult;
40 
42  protected $mConn;
43 
45  protected $lockMgr;
46 
47  function __construct( $p = null ) {
48  global $wgSharedDB, $wgSQLiteDataDir;
49 
50  if ( !is_array( $p ) ) { // legacy calling pattern
51  wfDeprecated( __METHOD__ . " method called without parameter array.", "1.22" );
52  $args = func_get_args();
53  $p = array(
54  'host' => isset( $args[0] ) ? $args[0] : false,
55  'user' => isset( $args[1] ) ? $args[1] : false,
56  'password' => isset( $args[2] ) ? $args[2] : false,
57  'dbname' => isset( $args[3] ) ? $args[3] : false,
58  'flags' => isset( $args[4] ) ? $args[4] : 0,
59  'tablePrefix' => isset( $args[5] ) ? $args[5] : 'get from global',
60  'schema' => 'get from global',
61  'foreign' => isset( $args[6] ) ? $args[6] : false
62  );
63  }
64  $this->mDBname = $p['dbname'];
65  parent::__construct( $p );
66  // parent doesn't open when $user is false, but we can work with $dbName
67  if ( $p['dbname'] && !$this->isOpen() ) {
68  if ( $this->open( $p['host'], $p['user'], $p['password'], $p['dbname'] ) ) {
69  if ( $wgSharedDB ) {
70  $this->attachDatabase( $wgSharedDB );
71  }
72  }
73  }
74 
75  $this->lockMgr = new FSLockManager( array( 'lockDirectory' => "$wgSQLiteDataDir/locks" ) );
76  }
77 
81  function getType() {
82  return 'sqlite';
83  }
84 
90  function implicitGroupby() {
91  return false;
92  }
93 
105  function open( $server, $user, $pass, $dbName ) {
106  global $wgSQLiteDataDir;
107 
108  $this->close();
109  $fileName = self::generateFileName( $wgSQLiteDataDir, $dbName );
110  if ( !is_readable( $fileName ) ) {
111  $this->mConn = false;
112  throw new DBConnectionError( $this, "SQLite database not accessible" );
113  }
114  $this->openFile( $fileName );
115 
116  return $this->mConn;
117  }
118 
126  function openFile( $fileName ) {
127  $err = false;
128 
129  $this->mDatabaseFile = $fileName;
130  try {
131  if ( $this->mFlags & DBO_PERSISTENT ) {
132  $this->mConn = new PDO( "sqlite:$fileName", '', '',
133  array( PDO::ATTR_PERSISTENT => true ) );
134  } else {
135  $this->mConn = new PDO( "sqlite:$fileName", '', '' );
136  }
137  } catch ( PDOException $e ) {
138  $err = $e->getMessage();
139  }
140 
141  if ( !$this->mConn ) {
142  wfDebug( "DB connection error: $err\n" );
143  throw new DBConnectionError( $this, $err );
144  }
145 
146  $this->mOpened = !!$this->mConn;
147  # set error codes only, don't raise exceptions
148  if ( $this->mOpened ) {
149  $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
150  # Enforce LIKE to be case sensitive, just like MySQL
151  $this->query( 'PRAGMA case_sensitive_like = 1' );
152 
153  return $this->mConn;
154  }
155 
156  return false;
157  }
158 
163  protected function closeConnection() {
164  $this->mConn = null;
165 
166  return true;
167  }
168 
175  public static function generateFileName( $dir, $dbName ) {
176  return "$dir/$dbName.sqlite";
177  }
178 
183  function checkForEnabledSearch() {
184  if ( self::$fulltextEnabled === null ) {
185  self::$fulltextEnabled = false;
186  $table = $this->tableName( 'searchindex' );
187  $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = '$table'", __METHOD__ );
188  if ( $res ) {
189  $row = $res->fetchRow();
190  self::$fulltextEnabled = stristr( $row['sql'], 'fts' ) !== false;
191  }
192  }
193 
194  return self::$fulltextEnabled;
195  }
196 
201  static function getFulltextSearchModule() {
202  static $cachedResult = null;
203  if ( $cachedResult !== null ) {
204  return $cachedResult;
205  }
206  $cachedResult = false;
207  $table = 'dummy_search_test';
208 
209  $db = new DatabaseSqliteStandalone( ':memory:' );
210 
211  if ( $db->query( "CREATE VIRTUAL TABLE $table USING FTS3(dummy_field)", __METHOD__, true ) ) {
212  $cachedResult = 'FTS3';
213  }
214  $db->close();
215 
216  return $cachedResult;
217  }
218 
230  function attachDatabase( $name, $file = false, $fname = __METHOD__ ) {
231  global $wgSQLiteDataDir;
232  if ( !$file ) {
233  $file = self::generateFileName( $wgSQLiteDataDir, $name );
234  }
235  $file = $this->addQuotes( $file );
236 
237  return $this->query( "ATTACH DATABASE $file AS $name", $fname );
238  }
239 
246  function isWriteQuery( $sql ) {
247  return parent::isWriteQuery( $sql ) && !preg_match( '/^ATTACH\b/i', $sql );
248  }
249 
256  protected function doQuery( $sql ) {
257  $res = $this->mConn->query( $sql );
258  if ( $res === false ) {
259  return false;
260  } else {
261  $r = $res instanceof ResultWrapper ? $res->result : $res;
262  $this->mAffectedRows = $r->rowCount();
263  $res = new ResultWrapper( $this, $r->fetchAll() );
264  }
265 
266  return $res;
267  }
268 
272  function freeResult( $res ) {
273  if ( $res instanceof ResultWrapper ) {
274  $res->result = null;
275  } else {
276  $res = null;
277  }
278  }
279 
284  function fetchObject( $res ) {
285  if ( $res instanceof ResultWrapper ) {
286  $r =& $res->result;
287  } else {
288  $r =& $res;
289  }
290 
291  $cur = current( $r );
292  if ( is_array( $cur ) ) {
293  next( $r );
294  $obj = new stdClass;
295  foreach ( $cur as $k => $v ) {
296  if ( !is_numeric( $k ) ) {
297  $obj->$k = $v;
298  }
299  }
300 
301  return $obj;
302  }
303 
304  return false;
305  }
306 
311  function fetchRow( $res ) {
312  if ( $res instanceof ResultWrapper ) {
313  $r =& $res->result;
314  } else {
315  $r =& $res;
316  }
317  $cur = current( $r );
318  if ( is_array( $cur ) ) {
319  next( $r );
320 
321  return $cur;
322  }
323 
324  return false;
325  }
326 
333  function numRows( $res ) {
334  $r = $res instanceof ResultWrapper ? $res->result : $res;
335 
336  return count( $r );
337  }
338 
343  function numFields( $res ) {
344  $r = $res instanceof ResultWrapper ? $res->result : $res;
345 
346  return is_array( $r ) ? count( $r[0] ) : 0;
347  }
348 
354  function fieldName( $res, $n ) {
355  $r = $res instanceof ResultWrapper ? $res->result : $res;
356  if ( is_array( $r ) ) {
357  $keys = array_keys( $r[0] );
358 
359  return $keys[$n];
360  }
361 
362  return false;
363  }
364 
372  function tableName( $name, $format = 'quoted' ) {
373  // table names starting with sqlite_ are reserved
374  if ( strpos( $name, 'sqlite_' ) === 0 ) {
375  return $name;
376  }
377 
378  return str_replace( '"', '', parent::tableName( $name, $format ) );
379  }
380 
387  function indexName( $index ) {
388  return $index;
389  }
390 
396  function insertId() {
397  // PDO::lastInsertId yields a string :(
398  return intval( $this->mConn->lastInsertId() );
399  }
400 
405  function dataSeek( $res, $row ) {
406  if ( $res instanceof ResultWrapper ) {
407  $r =& $res->result;
408  } else {
409  $r =& $res;
410  }
411  reset( $r );
412  if ( $row > 0 ) {
413  for ( $i = 0; $i < $row; $i++ ) {
414  next( $r );
415  }
416  }
417  }
418 
422  function lastError() {
423  if ( !is_object( $this->mConn ) ) {
424  return "Cannot return last error, no db connection";
425  }
426  $e = $this->mConn->errorInfo();
427 
428  return isset( $e[2] ) ? $e[2] : '';
429  }
430 
434  function lastErrno() {
435  if ( !is_object( $this->mConn ) ) {
436  return "Cannot return last error, no db connection";
437  } else {
438  $info = $this->mConn->errorInfo();
439 
440  return $info[1];
441  }
442  }
443 
447  function affectedRows() {
448  return $this->mAffectedRows;
449  }
450 
461  function indexInfo( $table, $index, $fname = __METHOD__ ) {
462  $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')';
463  $res = $this->query( $sql, $fname );
464  if ( !$res ) {
465  return null;
466  }
467  if ( $res->numRows() == 0 ) {
468  return false;
469  }
470  $info = array();
471  foreach ( $res as $row ) {
472  $info[] = $row->name;
473  }
474 
475  return $info;
476  }
477 
484  function indexUnique( $table, $index, $fname = __METHOD__ ) {
485  $row = $this->selectRow( 'sqlite_master', '*',
486  array(
487  'type' => 'index',
488  'name' => $this->indexName( $index ),
489  ), $fname );
490  if ( !$row || !isset( $row->sql ) ) {
491  return null;
492  }
493 
494  // $row->sql will be of the form CREATE [UNIQUE] INDEX ...
495  $indexPos = strpos( $row->sql, 'INDEX' );
496  if ( $indexPos === false ) {
497  return null;
498  }
499  $firstPart = substr( $row->sql, 0, $indexPos );
500  $options = explode( ' ', $firstPart );
501 
502  return in_array( 'UNIQUE', $options );
503  }
504 
511  function makeSelectOptions( $options ) {
512  foreach ( $options as $k => $v ) {
513  if ( is_numeric( $k ) && ( $v == 'FOR UPDATE' || $v == 'LOCK IN SHARE MODE' ) ) {
514  $options[$k] = '';
515  }
516  }
517 
518  return parent::makeSelectOptions( $options );
519  }
520 
525  protected function makeUpdateOptionsArray( $options ) {
526  $options = parent::makeUpdateOptionsArray( $options );
528 
529  return $options;
530  }
531 
536  static function fixIgnore( $options ) {
537  # SQLite uses OR IGNORE not just IGNORE
538  foreach ( $options as $k => $v ) {
539  if ( $v == 'IGNORE' ) {
540  $options[$k] = 'OR IGNORE';
541  }
542  }
543 
544  return $options;
545  }
546 
551  function makeInsertOptions( $options ) {
553 
554  return parent::makeInsertOptions( $options );
555  }
556 
565  function insert( $table, $a, $fname = __METHOD__, $options = array() ) {
566  if ( !count( $a ) ) {
567  return true;
568  }
569 
570  # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
571  if ( isset( $a[0] ) && is_array( $a[0] ) ) {
572  $ret = true;
573  foreach ( $a as $v ) {
574  if ( !parent::insert( $table, $v, "$fname/multi-row", $options ) ) {
575  $ret = false;
576  }
577  }
578  } else {
579  $ret = parent::insert( $table, $a, "$fname/single-row", $options );
580  }
581 
582  return $ret;
583  }
584 
592  function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
593  if ( !count( $rows ) ) {
594  return true;
595  }
596 
597  # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries
598  if ( isset( $rows[0] ) && is_array( $rows[0] ) ) {
599  $ret = true;
600  foreach ( $rows as $v ) {
601  if ( !$this->nativeReplace( $table, $v, "$fname/multi-row" ) ) {
602  $ret = false;
603  }
604  }
605  } else {
606  $ret = $this->nativeReplace( $table, $rows, "$fname/single-row" );
607  }
608 
609  return $ret;
610  }
611 
620  function textFieldSize( $table, $field ) {
621  return -1;
622  }
623 
627  function unionSupportsOrderAndLimit() {
628  return false;
629  }
630 
636  function unionQueries( $sqls, $all ) {
637  $glue = $all ? ' UNION ALL ' : ' UNION ';
638 
639  return implode( $glue, $sqls );
640  }
641 
645  function wasDeadlock() {
646  return $this->lastErrno() == 5; // SQLITE_BUSY
647  }
648 
652  function wasErrorReissuable() {
653  return $this->lastErrno() == 17; // SQLITE_SCHEMA;
654  }
655 
659  function wasReadOnlyError() {
660  return $this->lastErrno() == 8; // SQLITE_READONLY;
661  }
662 
666  public function getSoftwareLink() {
667  return "[{{int:version-db-sqlite-url}} SQLite]";
668  }
669 
673  function getServerVersion() {
674  $ver = $this->mConn->getAttribute( PDO::ATTR_SERVER_VERSION );
675 
676  return $ver;
677  }
678 
682  public function getServerInfo() {
683  return wfMessage( self::getFulltextSearchModule()
684  ? 'sqlite-has-fts'
685  : 'sqlite-no-fts', $this->getServerVersion() )->text();
686  }
687 
696  function fieldInfo( $table, $field ) {
697  $tableName = $this->tableName( $table );
698  $sql = 'PRAGMA table_info(' . $this->addQuotes( $tableName ) . ')';
699  $res = $this->query( $sql, __METHOD__ );
700  foreach ( $res as $row ) {
701  if ( $row->name == $field ) {
702  return new SQLiteField( $row, $tableName );
703  }
704  }
705 
706  return false;
707  }
708 
709  protected function doBegin( $fname = '' ) {
710  if ( $this->mTrxLevel == 1 ) {
711  $this->commit( __METHOD__ );
712  }
713  try {
714  $this->mConn->beginTransaction();
715  } catch ( PDOException $e ) {
716  throw new DBUnexpectedError( $this, 'Error in BEGIN query: ' . $e->getMessage() );
717  }
718  $this->mTrxLevel = 1;
719  }
720 
721  protected function doCommit( $fname = '' ) {
722  if ( $this->mTrxLevel == 0 ) {
723  return;
724  }
725  try {
726  $this->mConn->commit();
727  } catch ( PDOException $e ) {
728  throw new DBUnexpectedError( $this, 'Error in COMMIT query: ' . $e->getMessage() );
729  }
730  $this->mTrxLevel = 0;
731  }
732 
733  protected function doRollback( $fname = '' ) {
734  if ( $this->mTrxLevel == 0 ) {
735  return;
736  }
737  $this->mConn->rollBack();
738  $this->mTrxLevel = 0;
739  }
740 
745  function strencode( $s ) {
746  return substr( $this->addQuotes( $s ), 1, -1 );
747  }
748 
753  function encodeBlob( $b ) {
754  return new Blob( $b );
755  }
756 
761  function decodeBlob( $b ) {
762  if ( $b instanceof Blob ) {
763  $b = $b->fetch();
764  }
765 
766  return $b;
767  }
768 
773  function addQuotes( $s ) {
774  if ( $s instanceof Blob ) {
775  return "x'" . bin2hex( $s->fetch() ) . "'";
776  } elseif ( is_bool( $s ) ) {
777  return (int)$s;
778  } elseif ( strpos( $s, "\0" ) !== false ) {
779  // SQLite doesn't support \0 in strings, so use the hex representation as a workaround.
780  // This is a known limitation of SQLite's mprintf function which PDO should work around,
781  // but doesn't. I have reported this to php.net as bug #63419:
782  // https://bugs.php.net/bug.php?id=63419
783  // There was already a similar report for SQLite3::escapeString, bug #62361:
784  // https://bugs.php.net/bug.php?id=62361
785  return "x'" . bin2hex( $s ) . "'";
786  } else {
787  return $this->mConn->quote( $s );
788  }
789  }
790 
794  function buildLike() {
795  $params = func_get_args();
796  if ( count( $params ) > 0 && is_array( $params[0] ) ) {
797  $params = $params[0];
798  }
799 
800  return parent::buildLike( $params ) . "ESCAPE '\' ";
801  }
802 
806  public function getSearchEngine() {
807  return "SearchSqlite";
808  }
809 
815  public function deadlockLoop( /*...*/ ) {
816  $args = func_get_args();
817  $function = array_shift( $args );
818 
819  return call_user_func_array( $function, $args );
820  }
821 
826  protected function replaceVars( $s ) {
827  $s = parent::replaceVars( $s );
828  if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
829  // CREATE TABLE hacks to allow schema file sharing with MySQL
830 
831  // binary/varbinary column type -> blob
832  $s = preg_replace( '/\b(var)?binary(\(\d+\))/i', 'BLOB', $s );
833  // no such thing as unsigned
834  $s = preg_replace( '/\b(un)?signed\b/i', '', $s );
835  // INT -> INTEGER
836  $s = preg_replace( '/\b(tiny|small|medium|big|)int(\s*\(\s*\d+\s*\)|\b)/i', 'INTEGER', $s );
837  // floating point types -> REAL
838  $s = preg_replace(
839  '/\b(float|double(\s+precision)?)(\s*\(\s*\d+\s*(,\s*\d+\s*)?\)|\b)/i',
840  'REAL',
841  $s
842  );
843  // varchar -> TEXT
844  $s = preg_replace( '/\b(var)?char\s*\(.*?\)/i', 'TEXT', $s );
845  // TEXT normalization
846  $s = preg_replace( '/\b(tiny|medium|long)text\b/i', 'TEXT', $s );
847  // BLOB normalization
848  $s = preg_replace( '/\b(tiny|small|medium|long|)blob\b/i', 'BLOB', $s );
849  // BOOL -> INTEGER
850  $s = preg_replace( '/\bbool(ean)?\b/i', 'INTEGER', $s );
851  // DATETIME -> TEXT
852  $s = preg_replace( '/\b(datetime|timestamp)\b/i', 'TEXT', $s );
853  // No ENUM type
854  $s = preg_replace( '/\benum\s*\([^)]*\)/i', 'TEXT', $s );
855  // binary collation type -> nothing
856  $s = preg_replace( '/\bbinary\b/i', '', $s );
857  // auto_increment -> autoincrement
858  $s = preg_replace( '/\bauto_increment\b/i', 'AUTOINCREMENT', $s );
859  // No explicit options
860  $s = preg_replace( '/\)[^);]*(;?)\s*$/', ')\1', $s );
861  // AUTOINCREMENT should immedidately follow PRIMARY KEY
862  $s = preg_replace( '/primary key (.*?) autoincrement/i', 'PRIMARY KEY AUTOINCREMENT $1', $s );
863  } elseif ( preg_match( '/^\s*CREATE (\s*(?:UNIQUE|FULLTEXT)\s+)?INDEX/i', $s ) ) {
864  // No truncated indexes
865  $s = preg_replace( '/\(\d+\)/', '', $s );
866  // No FULLTEXT
867  $s = preg_replace( '/\bfulltext\b/i', '', $s );
868  } elseif ( preg_match( '/^\s*DROP INDEX/i', $s ) ) {
869  // DROP INDEX is database-wide, not table-specific, so no ON <table> clause.
870  $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s );
871  }
872 
873  return $s;
874  }
875 
876  public function lock( $lockName, $method, $timeout = 5 ) {
877  global $wgSQLiteDataDir;
878 
879  if ( !is_dir( "$wgSQLiteDataDir/locks" ) ) { // create dir as needed
880  if ( !is_writable( $wgSQLiteDataDir ) || !mkdir( "$wgSQLiteDataDir/locks" ) ) {
881  throw new DBError( "Cannot create directory \"$wgSQLiteDataDir/locks\"." );
882  }
883  }
884 
885  return $this->lockMgr->lock( array( $lockName ), LockManager::LOCK_EX, $timeout )->isOK();
886  }
887 
888  public function unlock( $lockName, $method ) {
889  return $this->lockMgr->unlock( array( $lockName ), LockManager::LOCK_EX )->isOK();
890  }
891 
898  function buildConcat( $stringList ) {
899  return '(' . implode( ') || (', $stringList ) . ')';
900  }
901 
902  public function buildGroupConcatField(
903  $delim, $table, $field, $conds = '', $join_conds = array()
904  ) {
905  $fld = "group_concat($field," . $this->addQuotes( $delim ) . ')';
906 
907  return '(' . $this->selectSQLText( $table, $fld, $conds, null, array(), $join_conds ) . ')';
908  }
909 
918  function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) {
919  $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" .
920  $this->addQuotes( $oldName ) . " AND type='table'", $fname );
921  $obj = $this->fetchObject( $res );
922  if ( !$obj ) {
923  throw new MWException( "Couldn't retrieve structure for table $oldName" );
924  }
925  $sql = $obj->sql;
926  $sql = preg_replace(
927  '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/',
928  $this->addIdentifierQuotes( $newName ),
929  $sql,
930  1
931  );
932  if ( $temporary ) {
933  if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) {
934  wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" );
935  } else {
936  $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql );
937  }
938  }
939 
940  return $this->query( $sql, $fname );
941  }
942 
951  function listTables( $prefix = null, $fname = __METHOD__ ) {
952  $result = $this->select(
953  'sqlite_master',
954  'name',
955  "type='table'"
956  );
957 
958  $endArray = array();
959 
960  foreach ( $result as $table ) {
961  $vars = get_object_vars( $table );
962  $table = array_pop( $vars );
963 
964  if ( !$prefix || strpos( $table, $prefix ) === 0 ) {
965  if ( strpos( $table, 'sqlite_' ) !== 0 ) {
966  $endArray[] = $table;
967  }
968  }
969  }
970 
971  return $endArray;
972  }
973 } // end DatabaseSqlite class
974 
980  public function __construct( $fileName, $flags = 0 ) {
981  $this->mFlags = $flags;
982  $this->tablePrefix( null );
983  $this->openFile( $fileName );
984  }
985 }
986 
990 class SQLiteField implements Field {
991  private $info, $tableName;
992 
993  function __construct( $info, $tableName ) {
994  $this->info = $info;
995  $this->tableName = $tableName;
996  }
997 
998  function name() {
999  return $this->info->name;
1000  }
1002  function tableName() {
1003  return $this->tableName;
1004  }
1005 
1006  function defaultValue() {
1007  if ( is_string( $this->info->dflt_value ) ) {
1008  // Typically quoted
1009  if ( preg_match( '/^\'(.*)\'$', $this->info->dflt_value ) ) {
1010  return str_replace( "''", "'", $this->info->dflt_value );
1011  }
1012  }
1013 
1014  return $this->info->dflt_value;
1015  }
1016 
1020  function isNullable() {
1021  return !$this->info->notnull;
1022  }
1023 
1024  function type() {
1025  return $this->info->type;
1026  }
1027 } // end SQLiteField
DatabaseSqlite\buildLike
buildLike()
Definition: DatabaseSqlite.php:789
DatabaseSqlite\fieldName
fieldName( $res, $n)
Definition: DatabaseSqlite.php:349
SQLiteField\$tableName
$tableName
Definition: DatabaseSqlite.php:986
$result
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. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag '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 '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. '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 '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 '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 wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() '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 User::isValidEmailAddr(), 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 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) '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:Associative array mapping language codes to prefixed links of the form "language:title". & $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. 'LinkBegin':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:1528
DatabaseSqlite\duplicateTableStructure
duplicateTableStructure( $oldName, $newName, $temporary=false, $fname=__METHOD__)
Definition: DatabaseSqlite.php:913
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
DatabaseSqlite\attachDatabase
attachDatabase( $name, $file=false, $fname=__METHOD__)
Attaches external database to our connection, see http://sqlite.org/lang_attach.html for details.
Definition: DatabaseSqlite.php:225
DatabaseSqlite\unlock
unlock( $lockName, $method)
Release a lock.
Definition: DatabaseSqlite.php:883
DatabaseSqlite\affectedRows
affectedRows()
Definition: DatabaseSqlite.php:442
FSLockManager
Simple version of LockManager based on using FS lock files.
Definition: FSLockManager.php:36
DatabaseSqlite\getSearchEngine
getSearchEngine()
Definition: DatabaseSqlite.php:801
DatabaseSqlite\unionSupportsOrderAndLimit
unionSupportsOrderAndLimit()
Definition: DatabaseSqlite.php:622
Field
Base for all database-specific classes representing information about database fields.
Definition: DatabaseUtility.php:69
DatabaseSqlite\decodeBlob
decodeBlob( $b)
Definition: DatabaseSqlite.php:756
DBO_PERSISTENT
const DBO_PERSISTENT
Definition: Defines.php:44
DatabaseSqlite\$lockMgr
FSLockManager $lockMgr
(hopefully on the same server as the DB) *
Definition: DatabaseSqlite.php:40
DatabaseSqlite\doQuery
doQuery( $sql)
SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result.
Definition: DatabaseSqlite.php:251
DatabaseBase\close
close()
Closes a database connection.
Definition: Database.php:914
DatabaseBase\query
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:1001
$pass
$pass
Definition: UtfNormalGenerate.php:131
DatabaseSqlite\replaceVars
replaceVars( $s)
Definition: DatabaseSqlite.php:821
DatabaseSqlite\replace
replace( $table, $uniqueIndexes, $rows, $fname=__METHOD__)
Definition: DatabaseSqlite.php:587
$n
$n
Definition: RandomTest.php:76
$ret
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 & $ret
Definition: hooks.txt:1530
DatabaseSqliteStandalone
This class allows simple acccess to a SQLite database independently from main database settings.
Definition: DatabaseSqlite.php:974
DatabaseSqlite\indexName
indexName( $index)
Index names have DB scope.
Definition: DatabaseSqlite.php:382
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:35
DatabaseSqlite\isWriteQuery
isWriteQuery( $sql)
Definition: DatabaseSqlite.php:241
DatabaseSqlite\freeResult
freeResult( $res)
Definition: DatabaseSqlite.php:267
DatabaseSqlite\wasErrorReissuable
wasErrorReissuable()
Definition: DatabaseSqlite.php:647
$params
$params
Definition: styleTest.css.php:40
DatabaseSqlite\closeConnection
closeConnection()
Does not actually close the connection, just destroys the reference for GC to do its work.
Definition: DatabaseSqlite.php:158
DatabaseSqlite\numFields
numFields( $res)
Definition: DatabaseSqlite.php:338
Blob
Utility class.
Definition: DatabaseUtility.php:53
$s
$s
Definition: mergeMessageFileList.php:156
DatabaseSqlite\getType
getType()
Definition: DatabaseSqlite.php:76
DatabaseSqlite\tableName
tableName( $name, $format='quoted')
Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks.
Definition: DatabaseSqlite.php:367
insert
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and insert
Definition: hooks.txt:1530
DatabaseSqlite\open
open( $server, $user, $pass, $dbName)
Open an SQLite database and return a resource handle to it NOTE: only $dbName is used,...
Definition: DatabaseSqlite.php:100
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2124
DatabaseBase\selectRow
selectRow( $table, $vars, $conds, $fname=__METHOD__, $options=array(), $join_conds=array())
Single row SELECT wrapper.
Definition: Database.php:1663
SQLiteField\isNullable
isNullable()
Definition: DatabaseSqlite.php:1015
DatabaseSqlite\generateFileName
static generateFileName( $dir, $dbName)
Generates a database file name.
Definition: DatabaseSqlite.php:170
DatabaseSqlite\doCommit
doCommit( $fname='')
Issues the COMMIT command to the database server.
Definition: DatabaseSqlite.php:716
DatabaseSqlite\makeSelectOptions
makeSelectOptions( $options)
Filter the options used in SELECT statements.
Definition: DatabaseSqlite.php:506
DatabaseBase\tablePrefix
tablePrefix( $prefix=null)
Get/set the table prefix.
Definition: Database.php:418
DatabaseSqlite\insert
insert( $table, $a, $fname=__METHOD__, $options=array())
Based on generic method (parent) with some prior SQLite-sepcific adjustments.
Definition: DatabaseSqlite.php:560
DatabaseSqlite\doRollback
doRollback( $fname='')
Issues the ROLLBACK command to the database server.
Definition: DatabaseSqlite.php:728
DatabaseBase\selectSQLText
selectSQLText( $table, $vars, $conds='', $fname=__METHOD__, $options=array(), $join_conds=array())
The equivalent of DatabaseBase::select() except that the constructed SQL is returned,...
Definition: Database.php:1598
SQLiteField
Definition: DatabaseSqlite.php:985
DatabaseSqlite\__construct
__construct( $p=null)
Constructor.
Definition: DatabaseSqlite.php:42
DatabaseSqlite\$mAffectedRows
int $mAffectedRows
The number of rows affected as an integer *.
Definition: DatabaseSqlite.php:34
MWException
MediaWiki exception.
Definition: MWException.php:26
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1174
DatabaseSqlite\lastError
lastError()
Definition: DatabaseSqlite.php:417
DatabaseBase\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=array(), $join_conds=array())
Execute a SELECT query constructed using the various parameters provided.
Definition: Database.php:1575
DatabaseSqlite\insertId
insertId()
This must be called after nextSequenceVal.
Definition: DatabaseSqlite.php:391
DatabaseSqlite\deadlockLoop
deadlockLoop()
No-op version of deadlockLoop.
Definition: DatabaseSqlite.php:810
DatabaseSqliteStandalone\__construct
__construct( $fileName, $flags=0)
Definition: DatabaseSqlite.php:975
tableName
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for tableName() and addQuotes(). You will need both of them. ------------------------------------------------------------------------ Basic query optimisation ------------------------------------------------------------------------ MediaWiki developers who need to write DB queries should have some understanding of databases and the performance issues associated with them. Patches containing unacceptably slow features will not be accepted. Unindexed queries are generally not welcome in MediaWiki
wfMessage
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
DatabaseBase\nativeReplace
nativeReplace( $table, $rows, $fname)
REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.
Definition: Database.php:2687
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
DatabaseSqlite\listTables
listTables( $prefix=null, $fname=__METHOD__)
List all tables on the database.
Definition: DatabaseSqlite.php:946
DatabaseSqlite\checkForEnabledSearch
checkForEnabledSearch()
Check if the searchindext table is FTS enabled.
Definition: DatabaseSqlite.php:178
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SQLiteField\defaultValue
defaultValue()
Definition: DatabaseSqlite.php:1001
DBConnectionError
Definition: DatabaseError.php:98
DBUnexpectedError
Definition: DatabaseError.php:438
DBError
Database error base class.
Definition: DatabaseError.php:28
DatabaseSqlite\makeUpdateOptionsArray
makeUpdateOptionsArray( $options)
Definition: DatabaseSqlite.php:520
DatabaseSqlite\doBegin
doBegin( $fname='')
Issues the BEGIN command to the database server.
Definition: DatabaseSqlite.php:704
DatabaseSqlite\makeInsertOptions
makeInsertOptions( $options)
Definition: DatabaseSqlite.php:546
$options
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
Definition: hooks.txt:1530
DatabaseSqlite\unionQueries
unionQueries( $sqls, $all)
Definition: DatabaseSqlite.php:631
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
DatabaseSqlite\fieldInfo
fieldInfo( $table, $field)
Get information about a given field Returns false if the field does not exist.
Definition: DatabaseSqlite.php:691
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
SQLiteField\$info
$info
Definition: DatabaseSqlite.php:986
DatabaseBase
Database abstraction object.
Definition: Database.php:219
DatabaseSqlite
Definition: DatabaseSqlite.php:28
DatabaseSqlite\lock
lock( $lockName, $method, $timeout=5)
Acquire a named lock.
Definition: DatabaseSqlite.php:871
DatabaseSqlite\buildConcat
buildConcat( $stringList)
Build a concatenation list to feed into a SQL query.
Definition: DatabaseSqlite.php:893
DatabaseSqlite\textFieldSize
textFieldSize( $table, $field)
Returns the size of a text field, or -1 for "unlimited" In SQLite this is SQLITE_MAX_LENGTH,...
Definition: DatabaseSqlite.php:615
DatabaseSqlite\openFile
openFile( $fileName)
Opens a database file.
Definition: DatabaseSqlite.php:121
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
DatabaseSqlite\getServerVersion
getServerVersion()
Definition: DatabaseSqlite.php:668
DatabaseBase\commit
commit( $fname=__METHOD__, $flush='')
Commits a transaction previously started using begin().
Definition: Database.php:3435
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
SQLiteField\tableName
tableName()
Name of table this field belongs to.
Definition: DatabaseSqlite.php:997
DatabaseSqlite\$mDatabaseFile
string $mDatabaseFile
File name for SQLite database file *.
Definition: DatabaseSqlite.php:32
DatabaseBase\addIdentifierQuotes
addIdentifierQuotes( $s)
Quotes an identifier using backticks or "double quotes" depending on the database type.
Definition: Database.php:2498
$args
if( $line===false) $args
Definition: cdb.php:62
DatabaseSqlite\fetchObject
fetchObject( $res)
Definition: DatabaseSqlite.php:279
DatabaseBase\isOpen
isOpen()
Is a connection to the database open?
Definition: Database.php:604
DatabaseSqlite\lastErrno
lastErrno()
Definition: DatabaseSqlite.php:429
$dir
if(count( $args)==0) $dir
Definition: importImages.php:49
as
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
$keys
$keys
Definition: testCompression.php:63
DatabaseSqlite\indexUnique
indexUnique( $table, $index, $fname=__METHOD__)
Definition: DatabaseSqlite.php:479
DatabaseSqlite\getSoftwareLink
getSoftwareLink()
Definition: DatabaseSqlite.php:661
DatabaseSqlite\getServerInfo
getServerInfo()
Definition: DatabaseSqlite.php:677
DatabaseSqlite\implicitGroupby
implicitGroupby()
Definition: DatabaseSqlite.php:85
DatabaseSqlite\$mConn
PDO $mConn
Definition: DatabaseSqlite.php:38
DatabaseSqlite\encodeBlob
encodeBlob( $b)
Definition: DatabaseSqlite.php:748
DatabaseSqlite\wasReadOnlyError
wasReadOnlyError()
Definition: DatabaseSqlite.php:654
DatabaseSqlite\strencode
strencode( $s)
Definition: DatabaseSqlite.php:740
SQLiteField\name
name()
Field name.
Definition: DatabaseSqlite.php:993
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:1684
SQLiteField\__construct
__construct( $info, $tableName)
Definition: DatabaseSqlite.php:988
DatabaseSqlite\addQuotes
addQuotes( $s)
Definition: DatabaseSqlite.php:768
LockManager\LOCK_EX
const LOCK_EX
Definition: LockManager.php:60
DatabaseSqlite\wasDeadlock
wasDeadlock()
Definition: DatabaseSqlite.php:640
DatabaseSqlite\numRows
numRows( $res)
The PDO::Statement class implements the array interface so count() will work.
Definition: DatabaseSqlite.php:328
$res
$res
Definition: database.txt:21
DatabaseSqlite\fetchRow
fetchRow( $res)
Definition: DatabaseSqlite.php:306
DatabaseSqlite\$mLastResult
resource $mLastResult
Definition: DatabaseSqlite.php:36
DatabaseSqlite\$fulltextEnabled
static $fulltextEnabled
Definition: DatabaseSqlite.php:30
DatabaseSqlite\fixIgnore
static fixIgnore( $options)
Definition: DatabaseSqlite.php:531
DatabaseSqlite\getFulltextSearchModule
static getFulltextSearchModule()
Returns version of currently supported SQLite fulltext search module or false if none present.
Definition: DatabaseSqlite.php:196
DatabaseSqlite\dataSeek
dataSeek( $res, $row)
Definition: DatabaseSqlite.php:400
SQLiteField\type
type()
Database type.
Definition: DatabaseSqlite.php:1019
ResultWrapper
Result wrapper for grabbing data queried by someone else.
Definition: DatabaseUtility.php:99
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:1632
DatabaseSqlite\buildGroupConcatField
buildGroupConcatField( $delim, $table, $field, $conds='', $join_conds=array())
Build a GROUP_CONCAT or equivalent statement for a query.
Definition: DatabaseSqlite.php:897
DatabaseSqlite\indexInfo
indexInfo( $table, $index, $fname=__METHOD__)
Returns information about an index Returns false if the index does not exist.
Definition: DatabaseSqlite.php:456