r71250 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71249‎ | r71250 | r71251 >
Date:13:38, 18 August 2010
Author:reedy
Status:reverted
Tags:
Comment:
Kill some crappy "failFunction" stuff, marked as old in r14625
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseIbm_db2.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMssql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/includes/db/LoadBalancer.php (modified) (history)
  • /trunk/phase3/maintenance/tests/SearchUpdateTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/SearchUpdateTest.php
@@ -2,7 +2,7 @@
33
44 class DatabaseMock extends DatabaseBase {
55 function __construct( $server = false, $user = false, $password = false, $dbName = false,
6 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
 6+ $flags = 0, $tablePrefix = 'get from global' )
77 {
88 $this->mConn = true;
99 $this->mOpened = true;
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -185,10 +185,10 @@
186186 var $mFieldInfoCache = array();
187187
188188 function __construct( $server = false, $user = false, $password = false, $dbName = false,
189 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
 189+ $flags = 0, $tablePrefix = 'get from global' )
190190 {
191191 $tablePrefix = $tablePrefix == 'get from global' ? $tablePrefix : strtoupper( $tablePrefix );
192 - parent::__construct( $server, $user, $password, $dbName, $failFunction, $flags, $tablePrefix );
 192+ parent::__construct( $server, $user, $password, $dbName, $flags, $tablePrefix );
193193 wfRunHooks( 'DatabaseOraclePostInit', array( &$this ) );
194194 }
195195
@@ -218,14 +218,12 @@
219219 return true;
220220 }
221221
222 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
223 - {
224 - return new DatabaseOracle( $server, $user, $password, $dbName, $failFunction, $flags );
 222+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ){
 223+ return new DatabaseOracle( $server, $user, $password, $dbName, $flags );
225224 }
226225
227226 /**
228227 * Usually aborts on failure
229 - * If the failFunction is set to a non-zero integer, returns success
230228 */
231229 function open( $server, $user, $password, $dbName ) {
232230 if ( !function_exists( 'oci_connect' ) ) {
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -97,13 +97,10 @@
9898 var $mAffectedRows = null;
9999
100100 function DatabasePostgres($server = false, $user = false, $password = false, $dbName = false,
101 - $failFunction = false, $flags = 0 )
 101+ $flags = 0 )
102102 {
103 -
104 - $this->mFailFunction = $failFunction;
105103 $this->mFlags = $flags;
106104 $this->open( $server, $user, $password, $dbName);
107 -
108105 }
109106
110107 function getType() {
@@ -141,14 +138,12 @@
142139 return $this->numRows($res = $this->doQuery($SQL));
143140 }
144141
145 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0)
146 - {
147 - return new DatabasePostgres( $server, $user, $password, $dbName, $failFunction, $flags );
 142+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0) {
 143+ return new DatabasePostgres( $server, $user, $password, $dbName, $flags );
148144 }
149145
150146 /**
151147 * Usually aborts on failure
152 - * If the failFunction is set to a non-zero integer, returns success
153148 */
154149 function open( $server, $user, $password, $dbName ) {
155150 # Test for Postgres support, to avoid suppressed fatal error
@@ -188,11 +183,7 @@
189184 wfDebug( "DB connection error\n" );
190185 wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
191186 wfDebug( $this->lastError()."\n" );
192 - if ( !$this->mFailFunction ) {
193 - throw new DBConnectionError( $this, $phpError );
194 - } else {
195 - return false;
196 - }
 187+ return false;
197188 }
198189
199190 $this->mOpened = true;
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -112,7 +112,6 @@
113113 protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
114114 protected $mOut, $mOpened = false;
115115
116 - protected $mFailFunction;
117116 protected $mTablePrefix;
118117 protected $mFlags;
119118 protected $mTrxLevel = 0;
@@ -164,7 +163,6 @@
165164 * These can be safely inherited
166165 *
167166 * Getter/Setter: (18)
168 - * failFunction
169167 * bufferResults
170168 * ignoreErrors
171169 * trxLevel
@@ -405,22 +403,19 @@
406404 * @param $user String: username
407405 * @param $password String: password
408406 * @param $dbName String: database name on the server
409 - * @param $failFunction Callback (optional)
410407 * @param $flags Integer: database behaviour flags (optional, unused)
411408 * @param $schema String
412409 */
413410 public function DatabaseIbm_db2($server = false, $user = false, $password = false,
414 - $dbName = false, $failFunction = false, $flags = 0,
 411+ $dbName = false, $flags = 0,
415412 $schema = self::USE_GLOBAL )
416413 {
417 -
418414 global $wgOut, $wgDBmwschema;
419415 # Can't get a reference if it hasn't been set yet
420416 if ( !isset( $wgOut ) ) {
421417 $wgOut = null;
422418 }
423419 $this->mOut =& $wgOut;
424 - $this->mFailFunction = $failFunction;
425420 $this->mFlags = DBO_TRX | $flags;
426421
427422 if ( $schema == self::USE_GLOBAL ) {
@@ -579,13 +574,11 @@
580575 * @param $user String: username
581576 * @param $password String
582577 * @param $dbName String: database name on the server
583 - * @param $failFunction Callback (optional)
584578 * @param $flags Integer: database behaviour flags (optional, unused)
585579 * @return DatabaseIbm_db2 object
586580 */
587 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0)
588 - {
589 - return new DatabaseIbm_db2( $server, $user, $password, $dbName, $failFunction, $flags );
 581+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0) {
 582+ return new DatabaseIbm_db2( $server, $user, $password, $dbName, $flags );
590583 }
591584
592585 /**
Index: trunk/phase3/includes/db/Database.php
@@ -32,7 +32,6 @@
3333 protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
3434 protected $mOpened = false;
3535
36 - protected $mFailFunction;
3736 protected $mTablePrefix;
3837 protected $mFlags;
3938 protected $mTrxLevel = 0;
@@ -47,14 +46,6 @@
4847 # These optionally set a variable and return the previous state
4948
5049 /**
51 - * Fail function, takes a Database as a parameter
52 - * Set to false for default, 1 for ignore errors
53 - */
54 - function failFunction( $function = null ) {
55 - return wfSetVar( $this->mFailFunction, $function );
56 - }
57 -
58 - /**
5950 * Boolean, controls output of large amounts of debug information
6051 */
6152 function debug( $debug = null ) {
@@ -291,12 +282,11 @@
292283 * @param $user String: database user name
293284 * @param $password String: database user password
294285 * @param $dbName String: database name
295 - * @param $failFunction
296286 * @param $flags
297287 * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
298288 */
299289 function __construct( $server = false, $user = false, $password = false, $dbName = false,
300 - $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) {
 290+ $flags = 0, $tablePrefix = 'get from global' ) {
301291
302292 global $wgOut, $wgDBprefix, $wgCommandLineMode;
303293 # Can't get a reference if it hasn't been set yet
@@ -304,7 +294,6 @@
305295 $wgOut = null;
306296 }
307297
308 - $this->mFailFunction = $failFunction;
309298 $this->mFlags = $flags;
310299
311300 if ( $this->mFlags & DBO_DEFAULT ) {
@@ -340,18 +329,16 @@
341330 * @param $user String: database user name
342331 * @param $password String: database user password
343332 * @param $dbName String: database name
344 - * @param failFunction
345333 * @param $flags
346334 */
347 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
 335+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 )
348336 {
349337 wfDeprecated( __METHOD__ );
350 - return new DatabaseMysql( $server, $user, $password, $dbName, $failFunction, $flags );
 338+ return new DatabaseMysql( $server, $user, $password, $dbName, $flags );
351339 }
352340
353341 /**
354342 * Usually aborts on failure
355 - * If the failFunction is set to a non-zero integer, returns success
356343 * @param $server String: database server host
357344 * @param $user String: database user name
358345 * @param $password String: database user password
@@ -403,16 +390,7 @@
404391 $error = $myError;
405392 }
406393
407 - if ( $this->mFailFunction ) {
408 - # Legacy error handling method
409 - if ( !is_int( $this->mFailFunction ) ) {
410 - $ff = $this->mFailFunction;
411 - $ff( $this, $error );
412 - }
413 - } else {
414 - # New method
415 - throw new DBConnectionError( $this, $error );
416 - }
 394+ throw new DBConnectionError( $this, $error );
417395 }
418396
419397 /**
@@ -2547,7 +2525,7 @@
25482526 }
25492527
25502528 function getHTML() {
2551 - global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace;
 2529+ global $wgLang, $wgMessageCache, $wgUseFileCache, $wgShowDBErrorBacktrace, $wgContLang;
25522530
25532531 $sorry = 'Sorry! This site is experiencing technical difficulties.';
25542532 $again = 'Try waiting a few minutes and reloading.';
@@ -2582,6 +2560,13 @@
25832561 $cache = $this->fileCachedPage();
25842562 # Cached version on file system?
25852563 if( $cache !== null ) {
 2564+ # Adding support for RTL languages
 2565+ if ( $wgContLang !== null ) {
 2566+ if ( $wgContLang->isRTL() ) {
 2567+ $cache = str_replace( '<html>', '<html style="direction:rtl;">', $cache );
 2568+ }
 2569+ }
 2570+
25862571 # Hack: extend the body for error messages
25872572 $cache = str_replace( array('</html>','</body>'), '', $cache );
25882573 # Add cache notice...
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -18,12 +18,10 @@
1919 var $mAffectedRows = NULL;
2020
2121 function __construct( $server = false, $user = false, $password = false, $dbName = false,
22 - $failFunction = false, $flags = 0 )
 22+ $flags = 0 )
2323 {
24 - $this->mFailFunction = $failFunction;
2524 $this->mFlags = $flags;
2625 $this->open( $server, $user, $password, $dbName );
27 -
2826 }
2927
3028 function cascadingDeletes() {
@@ -51,14 +49,12 @@
5250 return false;
5351 }
5452
55 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
56 - {
57 - return new DatabaseMssql( $server, $user, $password, $dbName, $failFunction, $flags );
 53+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
 54+ return new DatabaseMssql( $server, $user, $password, $dbName, $flags );
5855 }
5956
6057 /**
6158 * Usually aborts on failure
62 - * If the failFunction is set to a non-zero integer, returns success
6359 */
6460 function open( $server, $user, $password, $dbName ) {
6561 # Test for driver support, to avoid suppressed fatal error
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -23,9 +23,8 @@
2424 * Constructor.
2525 * Parameters $server, $user and $password are not used.
2626 */
27 - function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) {
 27+ function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) {
2828 global $wgSharedDB;
29 - $this->mFailFunction = $failFunction;
3029 $this->mFlags = $flags;
3130 $this->mName = $dbName;
3231
@@ -53,8 +52,8 @@
5453 */
5554 function implicitGroupby() { return false; }
5655
57 - static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
58 - return new DatabaseSqlite( $server, $user, $password, $dbName, $failFunction, $flags );
 56+ static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
 57+ return new DatabaseSqlite( $server, $user, $password, $dbName, $flags );
5958 }
6059
6160 /** Open an SQLite database and return a resource handle to it
@@ -90,12 +89,7 @@
9190 }
9291 if ( $this->mConn === false ) {
9392 wfDebug( "DB connection error: $err\n" );
94 - if ( !$this->mFailFunction ) {
95 - throw new DBConnectionError( $this, $err );
96 - } else {
97 - return false;
98 - }
99 -
 93+ return false;
10094 }
10195 $this->mOpened = !!$this->mConn;
10296 # set error codes only, don't raise exceptions
Index: trunk/phase3/includes/db/LoadBalancer.php
@@ -14,7 +14,7 @@
1515 */
1616 class LoadBalancer {
1717 /* private */ var $mServers, $mConns, $mLoads, $mGroupLoads;
18 - /* private */ var $mFailFunction, $mErrorConnection;
 18+ /* private */ var $mErrorConnection;
1919 /* private */ var $mReadIndex, $mAllowLagged;
2020 /* private */ var $mWaitForPos, $mWaitTimeout;
2121 /* private */ var $mLaggedSlaveMode, $mLastError = 'Unknown error';
@@ -24,7 +24,6 @@
2525 /**
2626 * @param $params Array with keys:
2727 * servers Required. Array of server info structures.
28 - * failFunction Deprecated, use exceptions instead.
2928 * masterWaitTimeout Replication lag wait timeout
3029 * loadMonitor Name of a class used to fetch server lag and load.
3130 */
@@ -35,11 +34,6 @@
3635 }
3736 $this->mServers = $params['servers'];
3837
39 - if ( isset( $params['failFunction'] ) ) {
40 - $this->mFailFunction = $params['failFunction'];
41 - } else {
42 - $this->mFailFunction = false;
43 - }
4438 if ( isset( $params['waitTimeout'] ) ) {
4539 $this->mWaitTimeout = $params['waitTimeout'];
4640 } else {
@@ -73,9 +67,9 @@
7468 }
7569 }
7670
77 - static function newFromParams( $servers, $failFunction = false, $waitTimeout = 10 )
 71+ static function newFromParams( $servers, $waitTimeout = 10 )
7872 {
79 - return new LoadBalancer( $servers, $failFunction, $waitTimeout );
 73+ return new LoadBalancer( $servers, $waitTimeout );
8074 }
8175
8276 /**
@@ -672,19 +666,11 @@
673667 // No last connection, probably due to all servers being too busy
674668 wfLogDBError( "LB failure with no last connection\n" );
675669 $conn = new Database;
676 - if ( $this->mFailFunction ) {
677 - $conn->failFunction( $this->mFailFunction );
678 - $conn->reportConnectionError( $this->mLastError );
679 - } else {
680 - // If all servers were busy, mLastError will contain something sensible
681 - throw new DBConnectionError( $conn, $this->mLastError );
682 - }
 670+
 671+ // If all servers were busy, mLastError will contain something sensible
 672+ throw new DBConnectionError( $conn, $this->mLastError );
683673 } else {
684 - if ( $this->mFailFunction ) {
685 - $conn->failFunction( $this->mFailFunction );
686 - } else {
687 - $conn->failFunction( false );
688 - }
 674+
689675 $server = $conn->getProperty( 'mServer' );
690676 wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
691677 $conn->reportConnectionError( "{$this->mLastError} ({$server})" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r71251Minor followup to r71250...reedy13:40, 18 August 2010
r71252Fix wrong removal in r71250reedy13:50, 18 August 2010
r71253Remove some more parameters post r71250reedy13:55, 18 August 2010
r71254Revert r71250 r71251 r71252 r71253...reedy14:15, 18 August 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r14625Some initial work on exceptions. More to follow.tstarling23:07, 6 June 2006

Status & tagging log