Merge SCHEMA_WORK into HEAD. Lots of changes, some things are probably broken:
[lhc/web/wiklou.git] / includes / Database.php
1 <?php
2 /**
3 * This file deals with MySQL interface functions
4 * and query specifics/optimisations
5 * @package MediaWiki
6 */
7
8 /**
9 * Depends on the CacheManager
10 */
11 require_once( 'CacheManager.php' );
12
13 /** See Database::makeList() */
14 define( 'LIST_COMMA', 0 );
15 define( 'LIST_AND', 1 );
16 define( 'LIST_SET', 2 );
17 define( 'LIST_NAMES', 3);
18
19 /** Number of times to re-try an operation in case of deadlock */
20 define( 'DEADLOCK_TRIES', 4 );
21 /** Minimum time to wait before retry, in microseconds */
22 define( 'DEADLOCK_DELAY_MIN', 500000 );
23 /** Maximum time to wait before retry */
24 define( 'DEADLOCK_DELAY_MAX', 1500000 );
25
26 /**
27 * Database abstraction object
28 * @package MediaWiki
29 */
30 class Database {
31
32 #------------------------------------------------------------------------------
33 # Variables
34 #------------------------------------------------------------------------------
35 /**#@+
36 * @access private
37 */
38 var $mLastQuery = '';
39
40 var $mServer, $mUser, $mPassword, $mConn, $mDBname;
41 var $mOut, $mOpened = false;
42
43 var $mFailFunction;
44 var $mTablePrefix;
45 var $mFlags;
46 var $mTrxLevel = 0;
47 /**#@-*/
48
49 #------------------------------------------------------------------------------
50 # Accessors
51 #------------------------------------------------------------------------------
52 # These optionally set a variable and return the previous state
53
54 /**
55 * Fail function, takes a Database as a parameter
56 * Set to false for default, 1 for ignore errors
57 */
58 function failFunction( $function = NULL ) {
59 return wfSetVar( $this->mFailFunction, $function );
60 }
61
62 /**
63 * Output page, used for reporting errors
64 * FALSE means discard output
65 */
66 function &setOutputPage( &$out ) {
67 $this->mOut =& $out;
68 }
69
70 /**
71 * Boolean, controls output of large amounts of debug information
72 */
73 function debug( $debug = NULL ) {
74 return wfSetBit( $this->mFlags, DBO_DEBUG, $debug );
75 }
76
77 /**
78 * Turns buffering of SQL result sets on (true) or off (false).
79 * Default is "on" and it should not be changed without good reasons.
80 */
81 function bufferResults( $buffer = NULL ) {
82 if ( is_null( $buffer ) ) {
83 return !(bool)( $this->mFlags & DBO_NOBUFFER );
84 } else {
85 return !wfSetBit( $this->mFlags, DBO_NOBUFFER, !$buffer );
86 }
87 }
88
89 /**
90 * Turns on (false) or off (true) the automatic generation and sending
91 * of a "we're sorry, but there has been a database error" page on
92 * database errors. Default is on (false). When turned off, the
93 * code should use wfLastErrno() and wfLastError() to handle the
94 * situation as appropriate.
95 */
96 function ignoreErrors( $ignoreErrors = NULL ) {
97 return wfSetBit( $this->mFlags, DBO_IGNORE, $ignoreErrors );
98 }
99
100 /**
101 * The current depth of nested transactions
102 * @param integer $level
103 */
104 function trxLevel( $level = NULL ) {
105 return wfSetVar( $this->mTrxLevel, $level );
106 }
107
108 /**#@+
109 * Get function
110 */
111 function lastQuery() { return $this->mLastQuery; }
112 function isOpen() { return $this->mOpened; }
113 /**#@-*/
114
115 #------------------------------------------------------------------------------
116 # Other functions
117 #------------------------------------------------------------------------------
118
119 /**#@+
120 * @param string $server database server host
121 * @param string $user database user name
122 * @param string $password database user password
123 * @param string $dbname database name
124 */
125
126 /**
127 * @param failFunction
128 * @param $flags
129 * @param string $tablePrefix Database table prefixes. By default use the prefix gave in LocalSettings.php
130 */
131 function Database( $server = false, $user = false, $password = false, $dbName = false,
132 $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) {
133
134 global $wgOut, $wgDBprefix, $wgCommandLineMode;
135 # Can't get a reference if it hasn't been set yet
136 if ( !isset( $wgOut ) ) {
137 $wgOut = NULL;
138 }
139 $this->mOut =& $wgOut;
140
141 $this->mFailFunction = $failFunction;
142 $this->mFlags = $flags;
143
144 if ( $this->mFlags & DBO_DEFAULT ) {
145 if ( $wgCommandLineMode ) {
146 $this->mFlags &= ~DBO_TRX;
147 } else {
148 $this->mFlags |= DBO_TRX;
149 }
150 }
151
152 /** Get the default table prefix*/
153 if ( $tablePrefix == 'get from global' ) {
154 $this->mTablePrefix = $wgDBprefix;
155 } else {
156 $this->mTablePrefix = $tablePrefix;
157 }
158
159 if ( $server ) {
160 $this->open( $server, $user, $password, $dbName );
161 }
162 }
163
164 /**
165 * @static
166 * @param failFunction
167 * @param $flags
168 */
169 function newFromParams( $server, $user, $password, $dbName,
170 $failFunction = false, $flags = 0 )
171 {
172 return new Database( $server, $user, $password, $dbName, $failFunction, $flags );
173 }
174
175 /**
176 * Usually aborts on failure
177 * If the failFunction is set to a non-zero integer, returns success
178 */
179 function open( $server, $user, $password, $dbName ) {
180 # Test for missing mysql.so
181 # First try to load it
182 if (!@extension_loaded('mysql')) {
183 @dl('mysql.so');
184 }
185
186 # Otherwise we get a suppressed fatal error, which is very hard to track down
187 if ( !function_exists( 'mysql_connect' ) ) {
188 die( "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
189 }
190
191 $this->close();
192 $this->mServer = $server;
193 $this->mUser = $user;
194 $this->mPassword = $password;
195 $this->mDBname = $dbName;
196
197 $success = false;
198
199 @/**/$this->mConn = mysql_connect( $server, $user, $password );
200 if ( $dbName != '' ) {
201 if ( $this->mConn !== false ) {
202 $success = @/**/mysql_select_db( $dbName, $this->mConn );
203 if ( !$success ) {
204 wfDebug( "Error selecting database \"$dbName\": " . $this->lastError() . "\n" );
205 }
206 } else {
207 wfDebug( "DB connection error\n" );
208 wfDebug( "Server: $server, User: $user, Password: " .
209 substr( $password, 0, 3 ) . "...\n" );
210 $success = false;
211 }
212 } else {
213 # Delay USE query
214 $success = !!$this->mConn;
215 }
216
217 if ( !$success ) {
218 $this->reportConnectionError();
219 $this->close();
220 }
221 $this->mOpened = $success;
222 return $success;
223 }
224 /**#@-*/
225
226 /**
227 * Closes a database connection.
228 * if it is open : commits any open transactions
229 *
230 * @return bool operation success. true if already closed.
231 */
232 function close()
233 {
234 $this->mOpened = false;
235 if ( $this->mConn ) {
236 if ( $this->trxLevel() ) {
237 $this->immediateCommit();
238 }
239 return mysql_close( $this->mConn );
240 } else {
241 return true;
242 }
243 }
244
245 /**
246 * @access private
247 * @param string $msg error message ?
248 * @todo parameter $msg is not used
249 */
250 function reportConnectionError( $msg = '') {
251 if ( $this->mFailFunction ) {
252 if ( !is_int( $this->mFailFunction ) ) {
253 $ff = $this->mFailFunction;
254 $ff( $this, mysql_error() );
255 }
256 } else {
257 wfEmergencyAbort( $this, mysql_error() );
258 }
259 }
260
261 /**
262 * Usually aborts on failure
263 * If errors are explicitly ignored, returns success
264 */
265 function query( $sql, $fname = '', $tempIgnore = false ) {
266 global $wgProfiling, $wgCommandLineMode;
267
268 if ( $wgProfiling ) {
269 # generalizeSQL will probably cut down the query to reasonable
270 # logging size most of the time. The substr is really just a sanity check.
271 $profName = 'query: ' . substr( Database::generalizeSQL( $sql ), 0, 255 );
272 wfProfileIn( $profName );
273 }
274
275 $this->mLastQuery = $sql;
276
277 if ( $this->debug() ) {
278 $sqlx = substr( $sql, 0, 500 );
279 $sqlx = wordwrap(strtr($sqlx,"\t\n",' '));
280 wfDebug( "SQL: $sqlx\n" );
281 }
282 # Add a comment for easy SHOW PROCESSLIST interpretation
283 if ( $fname ) {
284 $commentedSql = "/* $fname */ $sql";
285 } else {
286 $commentedSql = $sql;
287 }
288
289 # If DBO_TRX is set, start a transaction
290 if ( ( $this->mFlags & DBO_TRX ) && !$this->trxLevel() && $sql != 'BEGIN' ) {
291 $this->begin();
292 }
293
294 # Do the query and handle errors
295 $ret = $this->doQuery( $commentedSql );
296 if ( false === $ret ) {
297 $this->reportQueryError( $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore );
298 }
299
300 if ( $wgProfiling ) {
301 wfProfileOut( $profName );
302 }
303 return $ret;
304 }
305
306 /**
307 * The DBMS-dependent part of query()
308 * @param string $sql SQL query.
309 */
310 function doQuery( $sql ) {
311 if( $this->bufferResults() ) {
312 $ret = mysql_query( $sql, $this->mConn );
313 } else {
314 $ret = mysql_unbuffered_query( $sql, $this->mConn );
315 }
316 return $ret;
317 }
318
319 /**
320 * @param $error
321 * @param $errno
322 * @param $sql
323 * @param string $fname
324 * @param bool $tempIgnore
325 */
326 function reportQueryError( $error, $errno, $sql, $fname, $tempIgnore = false ) {
327 global $wgCommandLineMode, $wgFullyInitialised;
328 # Ignore errors during error handling to avoid infinite recursion
329 $ignore = $this->ignoreErrors( true );
330
331 if( $ignore || $tempIgnore ) {
332 wfDebug("SQL ERROR (ignored): " . $error . "\n");
333 } else {
334 $sql1line = str_replace( "\n", "\\n", $sql );
335 wfLogDBError("$fname\t$errno\t$error\t$sql1line\n");
336 wfDebug("SQL ERROR: " . $error . "\n");
337 if ( $wgCommandLineMode || !$this->mOut || empty( $wgFullyInitialised ) ) {
338 $message = "A database error has occurred\n" .
339 "Query: $sql\n" .
340 "Function: $fname\n" .
341 "Error: $errno $error\n";
342 if ( !$wgCommandLineMode ) {
343 $message = nl2br( $message );
344 }
345 wfDebugDieBacktrace( $message );
346 } else {
347 // this calls wfAbruptExit()
348 $this->mOut->databaseError( $fname, $sql, $error, $errno );
349 }
350 }
351 $this->ignoreErrors( $ignore );
352 }
353
354
355 /**
356 * Intended to be compatible with the PEAR::DB wrapper functions.
357 * http://pear.php.net/manual/en/package.database.db.intro-execute.php
358 *
359 * ? = scalar value, quoted as necessary
360 * ! = raw SQL bit (a function for instance)
361 * & = filename; reads the file and inserts as a blob
362 * (we don't use this though...)
363 */
364 function prepare( $sql, $func = 'Database::prepare' ) {
365 /* MySQL doesn't support prepared statements (yet), so just
366 pack up the query for reference. We'll manually replace
367 the bits later. */
368 return array( 'query' => $sql, 'func' => $func );
369 }
370
371 function freePrepared( $prepared ) {
372 /* No-op for MySQL */
373 }
374
375 /**
376 * Execute a prepared query with the various arguments
377 * @param string $prepared the prepared sql
378 * @param mixed $args Either an array here, or put scalars as varargs
379 */
380 function execute( $prepared, $args = null ) {
381 if( !is_array( $args ) ) {
382 # Pull the var args
383 $args = func_get_args();
384 array_shift( $args );
385 }
386 $sql = $this->fillPrepared( $prepared['query'], $args );
387 return $this->query( $sql, $prepared['func'] );
388 }
389
390 /**
391 * Prepare & execute an SQL statement, quoting and inserting arguments
392 * in the appropriate places.
393 * @param
394 */
395 function safeQuery( $query, $args = null ) {
396 $prepared = $this->prepare( $query, 'Database::safeQuery' );
397 if( !is_array( $args ) ) {
398 # Pull the var args
399 $args = func_get_args();
400 array_shift( $args );
401 }
402 $retval = $this->execute( $prepared, $args );
403 $this->freePrepared( $prepared );
404 return $retval;
405 }
406
407 /**
408 * For faking prepared SQL statements on DBs that don't support
409 * it directly.
410 * @param string $preparedSql - a 'preparable' SQL statement
411 * @param array $args - array of arguments to fill it with
412 * @return string executable SQL
413 */
414 function fillPrepared( $preparedQuery, $args ) {
415 $n = 0;
416 reset( $args );
417 $this->preparedArgs =& $args;
418 return preg_replace_callback( '/(\\\\[?!&]|[?!&])/',
419 array( &$this, 'fillPreparedArg' ), $preparedQuery );
420 }
421
422 /**
423 * preg_callback func for fillPrepared()
424 * The arguments should be in $this->preparedArgs and must not be touched
425 * while we're doing this.
426 *
427 * @param array $matches
428 * @return string
429 * @access private
430 */
431 function fillPreparedArg( $matches ) {
432 switch( $matches[1] ) {
433 case '\\?': return '?';
434 case '\\!': return '!';
435 case '\\&': return '&';
436 }
437 list( $n, $arg ) = each( $this->preparedArgs );
438 switch( $matches[1] ) {
439 case '?': return $this->addQuotes( $arg );
440 case '!': return $arg;
441 case '&':
442 # return $this->addQuotes( file_get_contents( $arg ) );
443 wfDebugDieBacktrace( '& mode is not implemented. If it\'s really needed, uncomment the line above.' );
444 default:
445 wfDebugDieBacktrace( 'Received invalid match. This should never happen!' );
446 }
447 }
448
449 /**#@+
450 * @param mixed $res A SQL result
451 */
452 /**
453 * Free a result object
454 */
455 function freeResult( $res ) {
456 if ( !@/**/mysql_free_result( $res ) ) {
457 wfDebugDieBacktrace( "Unable to free MySQL result\n" );
458 }
459 }
460
461 /**
462 * Fetch the next row from the given result object, in object form
463 */
464 function fetchObject( $res ) {
465 @/**/$row = mysql_fetch_object( $res );
466 if( mysql_errno() ) {
467 wfDebugDieBacktrace( 'Error in fetchObject(): ' . htmlspecialchars( mysql_error() ) );
468 }
469 return $row;
470 }
471
472 /**
473 * Fetch the next row from the given result object
474 * Returns an array
475 */
476 function fetchRow( $res ) {
477 @/**/$row = mysql_fetch_array( $res );
478 if (mysql_errno() ) {
479 wfDebugDieBacktrace( 'Error in fetchRow(): ' . htmlspecialchars( mysql_error() ) );
480 }
481 return $row;
482 }
483
484 /**
485 * Get the number of rows in a result object
486 */
487 function numRows( $res ) {
488 @/**/$n = mysql_num_rows( $res );
489 if( mysql_errno() ) {
490 wfDebugDieBacktrace( 'Error in numRows(): ' . htmlspecialchars( mysql_error() ) );
491 }
492 return $n;
493 }
494
495 /**
496 * Get the number of fields in a result object
497 * See documentation for mysql_num_fields()
498 */
499 function numFields( $res ) { return mysql_num_fields( $res ); }
500
501 /**
502 * Get a field name in a result object
503 * See documentation for mysql_field_name()
504 */
505 function fieldName( $res, $n ) { return mysql_field_name( $res, $n ); }
506
507 /**
508 * Get the inserted value of an auto-increment row
509 *
510 * The value inserted should be fetched from nextSequenceValue()
511 *
512 * Example:
513 * $id = $dbw->nextSequenceValue('cur_cur_id_seq');
514 * $dbw->insert('cur',array('cur_id' => $id));
515 * $id = $dbw->insertId();
516 */
517 function insertId() { return mysql_insert_id( $this->mConn ); }
518
519 /**
520 * Change the position of the cursor in a result object
521 * See mysql_data_seek()
522 */
523 function dataSeek( $res, $row ) { return mysql_data_seek( $res, $row ); }
524
525 /**
526 * Get the last error number
527 * See mysql_errno()
528 */
529 function lastErrno() { return mysql_errno(); }
530
531 /**
532 * Get a description of the last error
533 * See mysql_error() for more details
534 */
535 function lastError() { return mysql_error(); }
536
537 /**
538 * Get the number of rows affected by the last write query
539 * See mysql_affected_rows() for more details
540 */
541 function affectedRows() { return mysql_affected_rows( $this->mConn ); }
542 /**#@-*/ // end of template : @param $result
543
544 /**
545 * Simple UPDATE wrapper
546 * Usually aborts on failure
547 * If errors are explicitly ignored, returns success
548 *
549 * This function exists for historical reasons, Database::update() has a more standard
550 * calling convention and feature set
551 */
552 function set( $table, $var, $value, $cond, $fname = 'Database::set' )
553 {
554 $table = $this->tableName( $table );
555 $sql = "UPDATE $table SET $var = '" .
556 $this->strencode( $value ) . "' WHERE ($cond)";
557 return !!$this->query( $sql, DB_MASTER, $fname );
558 }
559
560 /**
561 * Simple SELECT wrapper, returns a single field, input must be encoded
562 * Usually aborts on failure
563 * If errors are explicitly ignored, returns FALSE on failure
564 */
565 function selectField( $table, $var, $cond='', $fname = 'Database::selectField', $options = array() ) {
566 if ( !is_array( $options ) ) {
567 $options = array( $options );
568 }
569 $options['LIMIT'] = 1;
570
571 $res = $this->select( $table, $var, $cond, $fname, $options );
572 if ( $res === false || !$this->numRows( $res ) ) {
573 return false;
574 }
575 $row = $this->fetchRow( $res );
576 if ( $row !== false ) {
577 $this->freeResult( $res );
578 return $row[0];
579 } else {
580 return false;
581 }
582 }
583
584 /**
585 * Returns an optional USE INDEX clause to go after the table, and a
586 * string to go at the end of the query
587 */
588 function makeSelectOptions( $options ) {
589 if ( !is_array( $options ) ) {
590 $options = array( $options );
591 }
592
593 $tailOpts = '';
594
595 if ( isset( $options['ORDER BY'] ) ) {
596 $tailOpts .= " ORDER BY {$options['ORDER BY']}";
597 }
598 if ( isset( $options['LIMIT'] ) ) {
599 $tailOpts .= " LIMIT {$options['LIMIT']}";
600 }
601
602 if ( is_numeric( array_search( 'FOR UPDATE', $options ) ) ) {
603 $tailOpts .= ' FOR UPDATE';
604 }
605
606 if ( is_numeric( array_search( 'LOCK IN SHARE MODE', $options ) ) ) {
607 $tailOpts .= ' LOCK IN SHARE MODE';
608 }
609
610 if ( isset( $options['USE INDEX'] ) ) {
611 $useIndex = $this->useIndexClause( $options['USE INDEX'] );
612 } else {
613 $useIndex = '';
614 }
615 return array( $useIndex, $tailOpts );
616 }
617
618 /**
619 * SELECT wrapper
620 */
621 function select( $table, $vars, $conds='', $fname = 'Database::select', $options = array() )
622 {
623 if( is_array( $vars ) ) {
624 $vars = implode( ',', $vars );
625 }
626 if( is_array( $table ) ) {
627 $from = ' FROM ' . implode( ',', array_map( array( &$this, 'tableName' ), $table ) );
628 } elseif ($table!='') {
629 $from = ' FROM ' .$this->tableName( $table );
630 } else {
631 $from = '';
632 }
633
634 list( $useIndex, $tailOpts ) = $this->makeSelectOptions( $options );
635
636 if( !empty( $conds ) ) {
637 if ( is_array( $conds ) ) {
638 $conds = $this->makeList( $conds, LIST_AND );
639 }
640 $sql = "SELECT $vars $from $useIndex WHERE $conds $tailOpts";
641 } else {
642 $sql = "SELECT $vars $from $useIndex $tailOpts";
643 }
644 return $this->query( $sql, $fname );
645 }
646
647 /**
648 * Single row SELECT wrapper
649 * Aborts or returns FALSE on error
650 *
651 * $vars: the selected variables
652 * $conds: a condition map, terms are ANDed together.
653 * Items with numeric keys are taken to be literal conditions
654 * Takes an array of selected variables, and a condition map, which is ANDed
655 * e.g. selectRow( "page", array( "page_id" ), array( "page_namespace" => 0, "page_title" => "Astronomy" ) )
656 * would return an object where $obj->page_id is the ID of the Astronomy article
657 *
658 * @todo migrate documentation to phpdocumentor format
659 */
660 function selectRow( $table, $vars, $conds, $fname = 'Database::selectRow', $options = array() ) {
661 $options['LIMIT'] = 1;
662 $res = $this->select( $table, $vars, $conds, $fname, $options );
663 if ( $res === false || !$this->numRows( $res ) ) {
664 return false;
665 }
666 $obj = $this->fetchObject( $res );
667 $this->freeResult( $res );
668 return $obj;
669
670 }
671
672 /**
673 * Removes most variables from an SQL query and replaces them with X or N for numbers.
674 * It's only slightly flawed. Don't use for anything important.
675 *
676 * @param string $sql A SQL Query
677 * @static
678 */
679 function generalizeSQL( $sql ) {
680 # This does the same as the regexp below would do, but in such a way
681 # as to avoid crashing php on some large strings.
682 # $sql = preg_replace ( "/'([^\\\\']|\\\\.)*'|\"([^\\\\\"]|\\\\.)*\"/", "'X'", $sql);
683
684 $sql = str_replace ( "\\\\", '', $sql);
685 $sql = str_replace ( "\\'", '', $sql);
686 $sql = str_replace ( "\\\"", '', $sql);
687 $sql = preg_replace ("/'.*'/s", "'X'", $sql);
688 $sql = preg_replace ('/".*"/s', "'X'", $sql);
689
690 # All newlines, tabs, etc replaced by single space
691 $sql = preg_replace ( "/\s+/", ' ', $sql);
692
693 # All numbers => N
694 $sql = preg_replace ('/-?[0-9]+/s', 'N', $sql);
695
696 return $sql;
697 }
698
699 /**
700 * Determines whether a field exists in a table
701 * Usually aborts on failure
702 * If errors are explicitly ignored, returns NULL on failure
703 */
704 function fieldExists( $table, $field, $fname = 'Database::fieldExists' ) {
705 $table = $this->tableName( $table );
706 $res = $this->query( 'DESCRIBE '.$table, DB_SLAVE, $fname );
707 if ( !$res ) {
708 return NULL;
709 }
710
711 $found = false;
712
713 while ( $row = $this->fetchObject( $res ) ) {
714 if ( $row->Field == $field ) {
715 $found = true;
716 break;
717 }
718 }
719 return $found;
720 }
721
722 /**
723 * Determines whether an index exists
724 * Usually aborts on failure
725 * If errors are explicitly ignored, returns NULL on failure
726 */
727 function indexExists( $table, $index, $fname = 'Database::indexExists' ) {
728 $info = $this->indexInfo( $table, $index, $fname );
729 if ( is_null( $info ) ) {
730 return NULL;
731 } else {
732 return $info !== false;
733 }
734 }
735
736
737 /**
738 * Get information about an index into an object
739 * Returns false if the index does not exist
740 */
741 function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) {
742 # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
743 # SHOW INDEX should work for 3.x and up:
744 # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
745 $table = $this->tableName( $table );
746 $sql = 'SHOW INDEX FROM '.$table;
747 $res = $this->query( $sql, $fname );
748 if ( !$res ) {
749 return NULL;
750 }
751
752 while ( $row = $this->fetchObject( $res ) ) {
753 if ( $row->Key_name == $index ) {
754 return $row;
755 }
756 }
757 return false;
758 }
759
760 /**
761 * Query whether a given table exists
762 */
763 function tableExists( $table ) {
764 $table = $this->tableName( $table );
765 $old = $this->ignoreErrors( true );
766 $res = $this->query( "SELECT 1 FROM $table LIMIT 1" );
767 $this->ignoreErrors( $old );
768 if( $res ) {
769 $this->freeResult( $res );
770 return true;
771 } else {
772 return false;
773 }
774 }
775
776 /**
777 * mysql_fetch_field() wrapper
778 * Returns false if the field doesn't exist
779 *
780 * @param $table
781 * @param $field
782 */
783 function fieldInfo( $table, $field ) {
784 $table = $this->tableName( $table );
785 $res = $this->query( "SELECT * FROM $table LIMIT 1" );
786 $n = mysql_num_fields( $res );
787 for( $i = 0; $i < $n; $i++ ) {
788 $meta = mysql_fetch_field( $res, $i );
789 if( $field == $meta->name ) {
790 return $meta;
791 }
792 }
793 return false;
794 }
795
796 /**
797 * mysql_field_type() wrapper
798 */
799 function fieldType( $res, $index ) {
800 return mysql_field_type( $res, $index );
801 }
802
803 /**
804 * Determines if a given index is unique
805 */
806 function indexUnique( $table, $index ) {
807 $indexInfo = $this->indexInfo( $table, $index );
808 if ( !$indexInfo ) {
809 return NULL;
810 }
811 return !$indexInfo->Non_unique;
812 }
813
814 /**
815 * INSERT wrapper, inserts an array into a table
816 *
817 * $a may be a single associative array, or an array of these with numeric keys, for
818 * multi-row insert.
819 *
820 * Usually aborts on failure
821 * If errors are explicitly ignored, returns success
822 */
823 function insert( $table, $a, $fname = 'Database::insert', $options = array() ) {
824 # No rows to insert, easy just return now
825 if ( !count( $a ) ) {
826 return true;
827 }
828
829 $table = $this->tableName( $table );
830 if ( !is_array( $options ) ) {
831 $options = array( $options );
832 }
833 if ( isset( $a[0] ) && is_array( $a[0] ) ) {
834 $multi = true;
835 $keys = array_keys( $a[0] );
836 } else {
837 $multi = false;
838 $keys = array_keys( $a );
839 }
840
841 $sql = 'INSERT ' . implode( ' ', $options ) .
842 " INTO $table (" . implode( ',', $keys ) . ') VALUES ';
843
844 if ( $multi ) {
845 $first = true;
846 foreach ( $a as $row ) {
847 if ( $first ) {
848 $first = false;
849 } else {
850 $sql .= ',';
851 }
852 $sql .= '(' . $this->makeList( $row ) . ')';
853 }
854 } else {
855 $sql .= '(' . $this->makeList( $a ) . ')';
856 }
857 return !!$this->query( $sql, $fname );
858 }
859
860 /**
861 * UPDATE wrapper, takes a condition array and a SET array
862 */
863 function update( $table, $values, $conds, $fname = 'Database::update' ) {
864 $table = $this->tableName( $table );
865 $sql = "UPDATE $table SET " . $this->makeList( $values, LIST_SET );
866 $sql .= " WHERE " . $this->makeList( $conds, LIST_AND );
867 $this->query( $sql, $fname );
868 }
869
870 /**
871 * Makes a wfStrencoded list from an array
872 * $mode: LIST_COMMA - comma separated, no field names
873 * LIST_AND - ANDed WHERE clause (without the WHERE)
874 * LIST_SET - comma separated with field names, like a SET clause
875 * LIST_NAMES - comma separated field names
876 */
877 function makeList( $a, $mode = LIST_COMMA ) {
878 if ( !is_array( $a ) ) {
879 wfDebugDieBacktrace( 'Database::makeList called with incorrect parameters' );
880 }
881
882 $first = true;
883 $list = '';
884 foreach ( $a as $field => $value ) {
885 if ( !$first ) {
886 if ( $mode == LIST_AND ) {
887 $list .= ' AND ';
888 } else {
889 $list .= ',';
890 }
891 } else {
892 $first = false;
893 }
894 if ( $mode == LIST_AND && is_numeric( $field ) ) {
895 $list .= "($value)";
896 } elseif ( $mode == LIST_AND && is_array ($value) ) {
897 $list .= $field." IN (".$this->makeList($value).") ";
898 } else {
899 if ( $mode == LIST_AND || $mode == LIST_SET ) {
900 $list .= $field.'=';
901 }
902 $list .= ($mode==LIST_NAMES?$value:$this->addQuotes( $value ));
903 }
904 }
905 return $list;
906 }
907
908 /**
909 * Change the current database
910 */
911 function selectDB( $db ) {
912 $this->mDBname = $db;
913 return mysql_select_db( $db, $this->mConn );
914 }
915
916 /**
917 * Starts a timer which will kill the DB thread after $timeout seconds
918 */
919 function startTimer( $timeout ) {
920 global $IP;
921 if( function_exists( 'mysql_thread_id' ) ) {
922 # This will kill the query if it's still running after $timeout seconds.
923 $tid = mysql_thread_id( $this->mConn );
924 exec( "php $IP/includes/killthread.php $timeout $tid &>/dev/null &" );
925 }
926 }
927
928 /**
929 * Stop a timer started by startTimer()
930 * Currently unimplemented.
931 *
932 */
933 function stopTimer() { }
934
935 /**
936 * Format a table name ready for use in constructing an SQL query
937 *
938 * This does two important things: it quotes table names which as necessary,
939 * and it adds a table prefix if there is one.
940 *
941 * All functions of this object which require a table name call this function
942 * themselves. Pass the canonical name to such functions. This is only needed
943 * when calling query() directly.
944 *
945 * @param string $name database table name
946 */
947 function tableName( $name ) {
948 global $wgSharedDB;
949 if ( $this->mTablePrefix !== '' ) {
950 if ( strpos( '.', $name ) === false ) {
951 $name = $this->mTablePrefix . $name;
952 }
953 }
954 if ( isset( $wgSharedDB ) && 'user' == $name ) {
955 $name = $wgSharedDB . '.' . $name;
956 }
957 if( $name == 'group' ) {
958 $name = '`' . $name . '`';
959 }
960 return $name;
961 }
962
963 /**
964 * Fetch a number of table names into an array
965 * This is handy when you need to construct SQL for joins
966 *
967 * Example:
968 * extract($dbr->tableNames('user','watchlist'));
969 * $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user
970 * WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
971 */
972 function tableNames() {
973 $inArray = func_get_args();
974 $retVal = array();
975 foreach ( $inArray as $name ) {
976 $retVal[$name] = $this->tableName( $name );
977 }
978 return $retVal;
979 }
980
981 /**
982 * Wrapper for addslashes()
983 * @param string $s String to be slashed.
984 * @return string slashed string.
985 */
986 function strencode( $s ) {
987 return addslashes( $s );
988 }
989
990 /**
991 * If it's a string, adds quotes and backslashes
992 * Otherwise returns as-is
993 */
994 function addQuotes( $s ) {
995 if ( is_null( $s ) ) {
996 $s = 'NULL';
997 } else {
998 # This will also quote numeric values. This should be harmless,
999 # and protects against weird problems that occur when they really
1000 # _are_ strings such as article titles and string->number->string
1001 # conversion is not 1:1.
1002 $s = "'" . $this->strencode( $s ) . "'";
1003 }
1004 return $s;
1005 }
1006
1007 /**
1008 * Returns an appropriately quoted sequence value for inserting a new row.
1009 * MySQL has autoincrement fields, so this is just NULL. But the PostgreSQL
1010 * subclass will return an integer, and save the value for insertId()
1011 */
1012 function nextSequenceValue( $seqName ) {
1013 return NULL;
1014 }
1015
1016 /**
1017 * USE INDEX clause
1018 * PostgreSQL doesn't have them and returns ""
1019 */
1020 function useIndexClause( $index ) {
1021 return 'USE INDEX ('.$index.')';
1022 }
1023
1024 /**
1025 * REPLACE query wrapper
1026 * PostgreSQL simulates this with a DELETE followed by INSERT
1027 * $row is the row to insert, an associative array
1028 * $uniqueIndexes is an array of indexes. Each element may be either a
1029 * field name or an array of field names
1030 *
1031 * It may be more efficient to leave off unique indexes which are unlikely to collide.
1032 * However if you do this, you run the risk of encountering errors which wouldn't have
1033 * occurred in MySQL
1034 *
1035 * @todo migrate comment to phodocumentor format
1036 */
1037 function replace( $table, $uniqueIndexes, $rows, $fname = 'Database::replace' ) {
1038 $table = $this->tableName( $table );
1039
1040 # Single row case
1041 if ( !is_array( reset( $rows ) ) ) {
1042 $rows = array( $rows );
1043 }
1044
1045 $sql = "REPLACE INTO $table (" . implode( ',', array_keys( $rows[0] ) ) .') VALUES ';
1046 $first = true;
1047 foreach ( $rows as $row ) {
1048 if ( $first ) {
1049 $first = false;
1050 } else {
1051 $sql .= ',';
1052 }
1053 $sql .= '(' . $this->makeList( $row ) . ')';
1054 }
1055 return $this->query( $sql, $fname );
1056 }
1057
1058 /**
1059 * DELETE where the condition is a join
1060 * MySQL does this with a multi-table DELETE syntax, PostgreSQL does it with sub-selects
1061 *
1062 * For safety, an empty $conds will not delete everything. If you want to delete all rows where the
1063 * join condition matches, set $conds='*'
1064 *
1065 * DO NOT put the join condition in $conds
1066 *
1067 * @param string $delTable The table to delete from.
1068 * @param string $joinTable The other table.
1069 * @param string $delVar The variable to join on, in the first table.
1070 * @param string $joinVar The variable to join on, in the second table.
1071 * @param array $conds Condition array of field names mapped to variables, ANDed together in the WHERE clause
1072 */
1073 function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'Database::deleteJoin' ) {
1074 if ( !$conds ) {
1075 wfDebugDieBacktrace( 'Database::deleteJoin() called with empty $conds' );
1076 }
1077
1078 $delTable = $this->tableName( $delTable );
1079 $joinTable = $this->tableName( $joinTable );
1080 $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
1081 if ( $conds != '*' ) {
1082 $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
1083 }
1084
1085 return $this->query( $sql, $fname );
1086 }
1087
1088 /**
1089 * Returns the size of a text field, or -1 for "unlimited"
1090 */
1091 function textFieldSize( $table, $field ) {
1092 $table = $this->tableName( $table );
1093 $sql = "SHOW COLUMNS FROM $table LIKE \"$field\";";
1094 $res = $this->query( $sql, 'Database::textFieldSize' );
1095 $row = $this->fetchObject( $res );
1096 $this->freeResult( $res );
1097
1098 if ( preg_match( "/\((.*)\)/", $row->Type, $m ) ) {
1099 $size = $m[1];
1100 } else {
1101 $size = -1;
1102 }
1103 return $size;
1104 }
1105
1106 /**
1107 * @return string Always return 'LOW_PRIORITY'
1108 */
1109 function lowPriorityOption() {
1110 return 'LOW_PRIORITY';
1111 }
1112
1113 /**
1114 * DELETE query wrapper
1115 *
1116 * Use $conds == "*" to delete all rows
1117 */
1118 function delete( $table, $conds, $fname = 'Database::delete' ) {
1119 if ( !$conds ) {
1120 wfDebugDieBacktrace( 'Database::delete() called with no conditions' );
1121 }
1122 $table = $this->tableName( $table );
1123 $sql = "DELETE FROM $table ";
1124 if ( $conds != '*' ) {
1125 $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
1126 }
1127 return $this->query( $sql, $fname );
1128 }
1129
1130 /**
1131 * INSERT SELECT wrapper
1132 * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...)
1133 * Source items may be literals rather than field names, but strings should be quoted with Database::addQuotes()
1134 * $conds may be "*" to copy the whole table
1135 */
1136 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'Database::insertSelect' ) {
1137 $destTable = $this->tableName( $destTable );
1138 $srcTable = $this->tableName( $srcTable );
1139 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
1140 ' SELECT ' . implode( ',', $varMap ) .
1141 " FROM $srcTable";
1142 if ( $conds != '*' ) {
1143 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
1144 }
1145 return $this->query( $sql, $fname );
1146 }
1147
1148 /**
1149 * Construct a LIMIT query with optional offset
1150 * This is used for query pages
1151 */
1152 function limitResult($limit,$offset) {
1153 return ' LIMIT '.(is_numeric($offset)?"{$offset},":"")."{$limit} ";
1154 }
1155
1156 /**
1157 * Returns an SQL expression for a simple conditional.
1158 * Uses IF on MySQL.
1159 *
1160 * @param string $cond SQL expression which will result in a boolean value
1161 * @param string $trueVal SQL expression to return if true
1162 * @param string $falseVal SQL expression to return if false
1163 * @return string SQL fragment
1164 */
1165 function conditional( $cond, $trueVal, $falseVal ) {
1166 return " IF($cond, $trueVal, $falseVal) ";
1167 }
1168
1169 /**
1170 * Determines if the last failure was due to a deadlock
1171 */
1172 function wasDeadlock() {
1173 return $this->lastErrno() == 1213;
1174 }
1175
1176 /**
1177 * Perform a deadlock-prone transaction.
1178 *
1179 * This function invokes a callback function to perform a set of write
1180 * queries. If a deadlock occurs during the processing, the transaction
1181 * will be rolled back and the callback function will be called again.
1182 *
1183 * Usage:
1184 * $dbw->deadlockLoop( callback, ... );
1185 *
1186 * Extra arguments are passed through to the specified callback function.
1187 *
1188 * Returns whatever the callback function returned on its successful,
1189 * iteration, or false on error, for example if the retry limit was
1190 * reached.
1191 */
1192 function deadlockLoop() {
1193 $myFname = 'Database::deadlockLoop';
1194
1195 $this->query( 'BEGIN', $myFname );
1196 $args = func_get_args();
1197 $function = array_shift( $args );
1198 $oldIgnore = $dbw->ignoreErrors( true );
1199 $tries = DEADLOCK_TRIES;
1200 if ( is_array( $function ) ) {
1201 $fname = $function[0];
1202 } else {
1203 $fname = $function;
1204 }
1205 do {
1206 $retVal = call_user_func_array( $function, $args );
1207 $error = $this->lastError();
1208 $errno = $this->lastErrno();
1209 $sql = $this->lastQuery();
1210
1211 if ( $errno ) {
1212 if ( $dbw->wasDeadlock() ) {
1213 # Retry
1214 usleep( mt_rand( DEADLOCK_DELAY_MIN, DEADLOCK_DELAY_MAX ) );
1215 } else {
1216 $dbw->reportQueryError( $error, $errno, $sql, $fname );
1217 }
1218 }
1219 } while( $dbw->wasDeadlock && --$tries > 0 );
1220 $this->ignoreErrors( $oldIgnore );
1221 if ( $tries <= 0 ) {
1222 $this->query( 'ROLLBACK', $myFname );
1223 $this->reportQueryError( $error, $errno, $sql, $fname );
1224 return false;
1225 } else {
1226 $this->query( 'COMMIT', $myFname );
1227 return $retVal;
1228 }
1229 }
1230
1231 /**
1232 * Do a SELECT MASTER_POS_WAIT()
1233 *
1234 * @param string $file the binlog file
1235 * @param string $pos the binlog position
1236 * @param integer $timeout the maximum number of seconds to wait for synchronisation
1237 */
1238 function masterPosWait( $file, $pos, $timeout ) {
1239 $encFile = $this->strencode( $file );
1240 $sql = "SELECT MASTER_POS_WAIT('$encFile', $pos, $timeout)";
1241 $res = $this->query( $sql, 'Database::masterPosWait' );
1242 if ( $res && $row = $this->fetchRow( $res ) ) {
1243 $this->freeResult( $res );
1244 return $row[0];
1245 } else {
1246 return false;
1247 }
1248 }
1249
1250 /**
1251 * Get the position of the master from SHOW SLAVE STATUS
1252 */
1253 function getSlavePos() {
1254 $res = $this->query( 'SHOW SLAVE STATUS', 'Database::getSlavePos' );
1255 $row = $this->fetchObject( $res );
1256 if ( $row ) {
1257 return array( $row->Master_Log_File, $row->Read_Master_Log_Pos );
1258 } else {
1259 return array( false, false );
1260 }
1261 }
1262
1263 /**
1264 * Get the position of the master from SHOW MASTER STATUS
1265 */
1266 function getMasterPos() {
1267 $res = $this->query( 'SHOW MASTER STATUS', 'Database::getMasterPos' );
1268 $row = $this->fetchObject( $res );
1269 if ( $row ) {
1270 return array( $row->File, $row->Position );
1271 } else {
1272 return array( false, false );
1273 }
1274 }
1275
1276 /**
1277 * Begin a transaction, or if a transaction has already started, continue it
1278 */
1279 function begin( $fname = 'Database::begin' ) {
1280 if ( !$this->mTrxLevel ) {
1281 $this->immediateBegin( $fname );
1282 } else {
1283 $this->mTrxLevel++;
1284 }
1285 }
1286
1287 /**
1288 * End a transaction, or decrement the nest level if transactions are nested
1289 */
1290 function commit( $fname = 'Database::commit' ) {
1291 if ( $this->mTrxLevel ) {
1292 $this->mTrxLevel--;
1293 }
1294 if ( !$this->mTrxLevel ) {
1295 $this->immediateCommit( $fname );
1296 }
1297 }
1298
1299 /**
1300 * Rollback a transaction
1301 */
1302 function rollback( $fname = 'Database::rollback' ) {
1303 $this->query( 'ROLLBACK', $fname );
1304 $this->mTrxLevel = 0;
1305 }
1306
1307 /**
1308 * Begin a transaction, committing any previously open transaction
1309 */
1310 function immediateBegin( $fname = 'Database::immediateBegin' ) {
1311 $this->query( 'BEGIN', $fname );
1312 $this->mTrxLevel = 1;
1313 }
1314
1315 /**
1316 * Commit transaction, if one is open
1317 */
1318 function immediateCommit( $fname = 'Database::immediateCommit' ) {
1319 $this->query( 'COMMIT', $fname );
1320 $this->mTrxLevel = 0;
1321 }
1322
1323 /**
1324 * Return MW-style timestamp used for MySQL schema
1325 */
1326 function timestamp( $ts=0 ) {
1327 return wfTimestamp(TS_MW,$ts);
1328 }
1329
1330 /**
1331 * @todo document
1332 */
1333 function &resultObject( &$result ) {
1334 if( empty( $result ) ) {
1335 return NULL;
1336 } else {
1337 return new ResultWrapper( $this, $result );
1338 }
1339 }
1340
1341 /**
1342 * Return aggregated value alias
1343 */
1344 function aggregateValue ($valuedata,$valuename='value') {
1345 return $valuename;
1346 }
1347
1348 /**
1349 * @return string wikitext of a link to the server software's web site
1350 */
1351 function getSoftwareLink() {
1352 return "[http://www.mysql.com/ MySQL]";
1353 }
1354
1355 /**
1356 * @return string Version information from the database
1357 */
1358 function getServerVersion() {
1359 return mysql_get_server_info();
1360 }
1361 }
1362
1363 /**
1364 * Database abstraction object for mySQL
1365 * Inherit all methods and properties of Database::Database()
1366 *
1367 * @package MediaWiki
1368 * @see Database
1369 */
1370 class DatabaseMysql extends Database {
1371 # Inherit all
1372 }
1373
1374
1375 /**
1376 * Result wrapper for grabbing data queried by someone else
1377 *
1378 * @package MediaWiki
1379 */
1380 class ResultWrapper {
1381 var $db, $result;
1382
1383 /**
1384 * @todo document
1385 */
1386 function ResultWrapper( $database, $result ) {
1387 $this->db =& $database;
1388 $this->result =& $result;
1389 }
1390
1391 /**
1392 * @todo document
1393 */
1394 function numRows() {
1395 return $this->db->numRows( $this->result );
1396 }
1397
1398 /**
1399 * @todo document
1400 */
1401 function &fetchObject() {
1402 return $this->db->fetchObject( $this->result );
1403 }
1404
1405 /**
1406 * @todo document
1407 */
1408 function &fetchRow() {
1409 return $this->db->fetchRow( $this->result );
1410 }
1411
1412 /**
1413 * @todo document
1414 */
1415 function free() {
1416 $this->db->freeResult( $this->result );
1417 unset( $this->result );
1418 unset( $this->db );
1419 }
1420 }
1421
1422 #------------------------------------------------------------------------------
1423 # Global functions
1424 #------------------------------------------------------------------------------
1425
1426 /**
1427 * Standard fail function, called by default when a connection cannot be
1428 * established.
1429 * Displays the file cache if possible
1430 */
1431 function wfEmergencyAbort( &$conn, $error ) {
1432 global $wgTitle, $wgUseFileCache, $title, $wgInputEncoding, $wgSiteNotice, $wgOutputEncoding;
1433 global $wgSitename, $wgServer;
1434
1435 # I give up, Brion is right. Getting the message cache to work when there is no DB is tricky.
1436 # Hard coding strings instead.
1437
1438 $noconnect = 'Sorry! The wiki is experiencing some technical difficulties, and cannot contact the database server. <br />
1439 $1';
1440 $mainpage = 'Main Page';
1441 $searchdisabled = <<<EOT
1442 <p style="margin: 1.5em 2em 1em">$wgSitename search is disabled for performance reasons. You can search via Google in the meantime.
1443 <span style="font-size: 89%; display: block; margin-left: .2em">Note that their indexes of $wgSitename content may be out of date.</span></p>',
1444 EOT;
1445
1446 $googlesearch = "
1447 <!-- SiteSearch Google -->
1448 <FORM method=GET action=\"http://www.google.com/search\">
1449 <TABLE bgcolor=\"#FFFFFF\"><tr><td>
1450 <A HREF=\"http://www.google.com/\">
1451 <IMG SRC=\"http://www.google.com/logos/Logo_40wht.gif\"
1452 border=\"0\" ALT=\"Google\"></A>
1453 </td>
1454 <td>
1455 <INPUT TYPE=text name=q size=31 maxlength=255 value=\"$1\">
1456 <INPUT type=submit name=btnG VALUE=\"Google Search\">
1457 <font size=-1>
1458 <input type=hidden name=domains value=\"$wgServer\"><br /><input type=radio name=sitesearch value=\"\"> WWW <input type=radio name=sitesearch value=\"$wgServer\" checked> $wgServer <br />
1459 <input type='hidden' name='ie' value='$2'>
1460 <input type='hidden' name='oe' value='$2'>
1461 </font>
1462 </td></tr></TABLE>
1463 </FORM>
1464 <!-- SiteSearch Google -->";
1465 $cachederror = "The following is a cached copy of the requested page, and may not be up to date. ";
1466
1467
1468 if( !headers_sent() ) {
1469 header( 'HTTP/1.0 500 Internal Server Error' );
1470 header( 'Content-type: text/html; charset='.$wgOutputEncoding );
1471 /* Don't cache error pages! They cause no end of trouble... */
1472 header( 'Cache-control: none' );
1473 header( 'Pragma: nocache' );
1474 }
1475 $msg = $wgSiteNotice;
1476 if($msg == '') {
1477 $msg = str_replace( '$1', $error, $noconnect );
1478 }
1479 $text = $msg;
1480
1481 if($wgUseFileCache) {
1482 if($wgTitle) {
1483 $t =& $wgTitle;
1484 } else {
1485 if($title) {
1486 $t = Title::newFromURL( $title );
1487 } elseif (@/**/$_REQUEST['search']) {
1488 $search = $_REQUEST['search'];
1489 echo $searchdisabled;
1490 echo str_replace( array( '$1', '$2' ), array( htmlspecialchars( $search ),
1491 $wgInputEncoding ), $googlesearch );
1492 wfErrorExit();
1493 } else {
1494 $t = Title::newFromText( $mainpage );
1495 }
1496 }
1497
1498 $cache = new CacheManager( $t );
1499 if( $cache->isFileCached() ) {
1500 $msg = '<p style="color: red"><b>'.$msg."<br />\n" .
1501 $cachederror . "</b></p>\n";
1502
1503 $tag = '<div id="article">';
1504 $text = str_replace(
1505 $tag,
1506 $tag . $msg,
1507 $cache->fetchPageText() );
1508 }
1509 }
1510
1511 echo $text;
1512 wfErrorExit();
1513 }
1514
1515 ?>