- * This is a MySQL-specific feature.
- *
- * @param $value Mixed: true for allow, false for deny, or "default" to restore the initial value
- */
- public function setBigSelects( $value = true ) {
- // no-op
- }
-}
-
-/******************************************************************************
- * Utility classes
- *****************************************************************************/
-
-/**
- * Utility class.
- * @ingroup Database
- */
-class DBObject {
- public $mData;
-
- function __construct( $data ) {
- $this->mData = $data;
- }
-
- function isLOB() {
- return false;
- }
-
- function data() {
- return $this->mData;
- }
-}
-
-/**
- * Utility class
- * @ingroup Database
- *
- * This allows us to distinguish a blob from a normal string and an array of strings
- */
-class Blob {
- private $mData;
-
- function __construct( $data ) {
- $this->mData = $data;
- }
-
- function fetch() {
- return $this->mData;
- }
-}
-
-/**
- * Base for all database-specific classes representing information about database fields
- * @ingroup Database
- */
-interface Field {
- /**
- * Field name
- * @return string
- */
- function name();
-
- /**
- * Name of table this field belongs to
- * @return string
- */
- function tableName();
-
- /**
- * Database type
- * @return string
- */
- function type();
-
- /**
- * Whether this field can store NULL values
- * @return bool
- */
- function isNullable();
-}
-
-/******************************************************************************
- * Error classes
- *****************************************************************************/
-
-/**
- * Database error base class
- * @ingroup Database
- */
-class DBError extends MWException {
- public $db;
-
- /**
- * Construct a database error
- * @param $db Database object which threw the error
- * @param $error A simple error message to be used for debugging
- */
- function __construct( DatabaseBase &$db, $error ) {
- $this->db =& $db;
- parent::__construct( $error );
- }
-
- function getText() {
- global $wgShowDBErrorBacktrace;
-
- $s = $this->getMessage() . "\n";
-
- if ( $wgShowDBErrorBacktrace ) {
- $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
- }
-
- return $s;
- }
-}
-
-/**
- * @ingroup Database
- */
-class DBConnectionError extends DBError {
- public $error;
-
- function __construct( DatabaseBase &$db, $error = 'unknown error' ) {
- $msg = 'DB connection error';
-
- if ( trim( $error ) != '' ) {
- $msg .= ": $error";
- }
-
- $this->error = $error;
-
- parent::__construct( $db, $msg );
- }
-
- function useOutputPage() {
- // Not likely to work
- return false;
- }
-
- function useMessageCache() {
- // Not likely to work
- return false;
- }
-
- function getLogMessage() {
- # Don't send to the exception log
- return false;
- }
-
- function getPageTitle() {
- global $wgSitename, $wgLang;
-
- $header = "$wgSitename has a problem";
-
- if ( $wgLang instanceof Language ) {
- $header = htmlspecialchars( $wgLang->getMessage( 'dberr-header' ) );
- }
-
- return $header;
- }
-
- function getHTML() {
- global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
-
- $sorry = 'Sorry! This site is experiencing technical difficulties.';
- $again = 'Try waiting a few minutes and reloading.';
- $info = '(Can\'t contact the database server: $1)';
-
- if ( $wgLang instanceof Language ) {
- $sorry = htmlspecialchars( $wgLang->getMessage( 'dberr-problems' ) );
- $again = htmlspecialchars( $wgLang->getMessage( 'dberr-again' ) );
- $info = htmlspecialchars( $wgLang->getMessage( 'dberr-info' ) );
- }
-
- # No database access
- if ( is_object( $wgMessageCache ) ) {
- $wgMessageCache->disable();
- }
-
- if ( trim( $this->error ) == '' ) {
- $this->error = $this->db->getProperty( 'mServer' );
- }
-
- $noconnect = "<p><strong>$sorry</strong><br />$again</p><p><small>$info</small></p>";
- $text = str_replace( '$1', $this->error, $noconnect );
-
- if ( $wgShowDBErrorBacktrace ) {
- $text .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
- }
-
- $extra = $this->searchForm();
-
- if ( $wgUseFileCache ) {
- try {
- $cache = $this->fileCachedPage();
- # Cached version on file system?
- if ( $cache !== null ) {
- # Hack: extend the body for error messages
- $cache = str_replace( array( '</html>', '</body>' ), '', $cache );
- # Add cache notice...
- $cachederror = "This is a cached copy of the requested page, and may not be up to date. ";
-
- # Localize it if possible...
- if ( $wgLang instanceof Language ) {
- $cachederror = htmlspecialchars( $wgLang->getMessage( 'dberr-cachederror' ) );
- }
-
- $warning = "<div style='color:red;font-size:150%;font-weight:bold;'>$cachederror</div>";
-
- # Output cached page with notices on bottom and re-close body
- return "{$cache}{$warning}<hr />$text<hr />$extra</body></html>";
- }
- } catch ( MWException $e ) {
- // Do nothing, just use the default page
- }
- }
-
- # Headers needed here - output is just the error message
- return $this->htmlHeader() . "$text<hr />$extra" . $this->htmlFooter();
- }
-
- function searchForm() {
- global $wgSitename, $wgServer, $wgLang;
-
- $usegoogle = "You can try searching via Google in the meantime.";
- $outofdate = "Note that their indexes of our content may be out of date.";
- $googlesearch = "Search";
-
- if ( $wgLang instanceof Language ) {
- $usegoogle = htmlspecialchars( $wgLang->getMessage( 'dberr-usegoogle' ) );
- $outofdate = htmlspecialchars( $wgLang->getMessage( 'dberr-outofdate' ) );
- $googlesearch = htmlspecialchars( $wgLang->getMessage( 'searchbutton' ) );
- }
-
- $search = htmlspecialchars( @$_REQUEST['search'] );
-
- $server = htmlspecialchars( $wgServer );
- $sitename = htmlspecialchars( $wgSitename );
-
- $trygoogle = <<<EOT
-<div style="margin: 1.5em">$usegoogle<br />
-<small>$outofdate</small></div>
-<!-- SiteSearch Google -->
-<form method="get" action="http://www.google.com/search" id="googlesearch">
- <input type="hidden" name="domains" value="$server" />
- <input type="hidden" name="num" value="50" />
- <input type="hidden" name="ie" value="UTF-8" />
- <input type="hidden" name="oe" value="UTF-8" />
-
- <input type="text" name="q" size="31" maxlength="255" value="$search" />
- <input type="submit" name="btnG" value="$googlesearch" />
- <div>
- <input type="radio" name="sitesearch" id="gwiki" value="$server" checked="checked" /><label for="gwiki">$sitename</label>
- <input type="radio" name="sitesearch" id="gWWW" value="" /><label for="gWWW">WWW</label>
- </div>
-</form>
-<!-- SiteSearch Google -->
-EOT;
- return $trygoogle;
- }
-
- private function fileCachedPage() {
- global $wgTitle, $wgLang, $wgOut;
-
- if ( $wgOut->isDisabled() ) {
- return; // Done already?
- }
-
- $mainpage = 'Main Page';
-
- if ( $wgLang instanceof Language ) {
- $mainpage = htmlspecialchars( $wgLang->getMessage( 'mainpage' ) );
- }
-
- if ( $wgTitle ) {
- $t =& $wgTitle;
- } else {
- $t = Title::newFromText( $mainpage );
- }
-
- $cache = new HTMLFileCache( $t );
- if ( $cache->isFileCached() ) {
- return $cache->fetchPageText();
- } else {
- return '';
- }
- }
-
- function htmlBodyOnly() {
- return true;
- }
-}
-
-/**
- * @ingroup Database
- */
-class DBQueryError extends DBError {
- public $error, $errno, $sql, $fname;
-
- function __construct( DatabaseBase &$db, $error, $errno, $sql, $fname ) {
- $message = "A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script\n" .
- "Query: $sql\n" .
- "Function: $fname\n" .
- "Error: $errno $error\n";
-
- parent::__construct( $db, $message );
-
- $this->error = $error;
- $this->errno = $errno;
- $this->sql = $sql;
- $this->fname = $fname;
- }
-
- function getText() {
- global $wgShowDBErrorBacktrace;
-
- if ( $this->useMessageCache() ) {
- $s = wfMsg( 'dberrortextcl', htmlspecialchars( $this->getSQL() ),
- htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) ) . "\n";
-
- if ( $wgShowDBErrorBacktrace ) {
- $s .= "Backtrace:\n" . $this->getTraceAsString() . "\n";
- }
-
- return $s;
- } else {
- return parent::getText();
- }
- }
-
- function getSQL() {
- global $wgShowSQLErrors;
-
- if ( !$wgShowSQLErrors ) {
- return $this->msg( 'sqlhidden', 'SQL hidden' );
- } else {
- return $this->sql;
- }
- }
-
- function getLogMessage() {
- # Don't send to the exception log
- return false;
- }
-
- function getPageTitle() {
- return $this->msg( 'databaseerror', 'Database error' );
- }
-
- function getHTML() {
- global $wgShowDBErrorBacktrace;
-
- if ( $this->useMessageCache() ) {
- $s = wfMsgNoDB( 'dberrortext', htmlspecialchars( $this->getSQL() ),
- htmlspecialchars( $this->fname ), $this->errno, htmlspecialchars( $this->error ) );
- } else {
- $s = nl2br( htmlspecialchars( $this->getMessage() ) );
- }
-
- if ( $wgShowDBErrorBacktrace ) {
- $s .= '<p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) );
- }
-
- return $s;
- }
-}
-
-/**
- * @ingroup Database
- */
-class DBUnexpectedError extends DBError {}
-
-
-/**
- * Result wrapper for grabbing data queried by someone else
- * @ingroup Database
- */
-class ResultWrapper implements Iterator {
- var $db, $result, $pos = 0, $currentRow = null;
-
- /**
- * Create a new result object from a result resource and a Database object