MediaWiki  REL1_31
sqlite.inc
Go to the documentation of this file.
1 <?php
26 
32 class Sqlite {
33 
38  public static function isPresent() {
39  return extension_loaded( 'pdo_sqlite' );
40  }
41 
50  public static function checkSqlSyntax( $files ) {
51  if ( !self::isPresent() ) {
52  throw new MWException( "Can't check SQL syntax: SQLite not found" );
53  }
54  if ( !is_array( $files ) ) {
55  $files = [ $files ];
56  }
57 
58  $allowedTypes = array_flip( [
59  'integer',
60  'real',
61  'text',
62  'blob', // NULL type is omitted intentionally
63  ] );
64 
65  $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
66  try {
67  foreach ( $files as $file ) {
68  $err = $db->sourceFile( $file );
69  if ( $err != true ) {
70  return $err;
71  }
72  }
73 
74  $tables = $db->query( "SELECT name FROM sqlite_master WHERE type='table'", __METHOD__ );
75  foreach ( $tables as $table ) {
76  if ( strpos( $table->name, 'sqlite_' ) === 0 ) {
77  continue;
78  }
79 
80  $columns = $db->query( "PRAGMA table_info({$table->name})", __METHOD__ );
81  foreach ( $columns as $col ) {
82  if ( !isset( $allowedTypes[strtolower( $col->type )] ) ) {
83  $db->close();
84 
85  return "Table {$table->name} has column {$col->name} with non-native type '{$col->type}'";
86  }
87  }
88  }
89  } catch ( DBError $e ) {
90  return $e->getMessage();
91  }
92  $db->close();
93 
94  return true;
95  }
96 }
Sqlite
This class contains code common to different SQLite-related maintenance scripts.
Definition: sqlite.inc:32
Wikimedia\Rdbms\DatabaseSqlite
Definition: DatabaseSqlite.php:37
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
Wikimedia\Rdbms\DBError
Database error base class.
Definition: DBError.php:30
php
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:37
MWException
MediaWiki exception.
Definition: MWException.php:26
Sqlite\isPresent
static isPresent()
Checks whether PHP has SQLite support.
Definition: sqlite.inc:38
Sqlite\checkSqlSyntax
static checkSqlSyntax( $files)
Checks given files for correctness of SQL syntax.
Definition: sqlite.inc:50
$tables
this hook is for auditing only RecentChangesLinked and Watchlist 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:1015
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:22
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2171