r78185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78184‎ | r78185 | r78186 >
Date:14:17, 10 December 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Last $wgDBtype usages in core. Use a $db member variable so we can use it in other useful places too.
Modified paths:
  • /trunk/phase3/maintenance/tests/parser/parserTest.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/parser/parserTest.inc
@@ -49,6 +49,11 @@
5050 private $databaseSetupDone = false;
5151
5252 /**
 53+ * Our connection to the database
 54+ */
 55+ private $db;
 56+
 57+ /**
5358 * string $oldTablePrefix Original table prefix
5459 */
5560 private $oldTablePrefix;
@@ -64,7 +69,7 @@
6570 * Sets terminal colorization and diff/quick modes depending on OS and
6671 * command-line options (--color and --quick).
6772 */
68 - public function ParserTest( $options = array() ) {
 73+ public function __construct( $options = array() ) {
6974 # Only colorize output if stdout is a terminal.
7075 $this->color = !wfIsWindows() && posix_isatty( 1 );
7176
@@ -584,8 +589,6 @@
585590 * Ideally this should replace the global configuration entirely.
586591 */
587592 private function setupGlobals( $opts = '', $config = '' ) {
588 - global $wgDBtype;
589 -
590593 # Find out values for some special options.
591594 $lang =
592595 self::getOptionValue( 'language', $opts, 'en' );
@@ -615,7 +618,7 @@
616619 'wgStyleSheetPath' => '/skins',
617620 'wgSitename' => 'MediaWiki',
618621 'wgLanguageCode' => $lang,
619 - 'wgDBprefix' => $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_',
 622+ 'wgDBprefix' => $this->db->getType() != 'oracle' ? 'parsertest_' : 'pt_',
620623 'wgRawHtml' => isset( $opts['rawhtml'] ),
621624 'wgLang' => null,
622625 'wgContLang' => null,
@@ -695,8 +698,6 @@
696699 * Some of these probably aren't necessary.
697700 */
698701 private function listTables() {
699 - global $wgDBtype;
700 -
701702 $tables = array( 'user', 'user_properties', 'page', 'page_restrictions',
702703 'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks',
703704 'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks',
@@ -706,7 +707,7 @@
707708 'archive', 'user_groups', 'page_props', 'category', 'msg_resource', 'msg_resource_links'
708709 );
709710
710 - if ( in_array( $wgDBtype, array( 'mysql', 'sqlite', 'oracle' ) ) )
 711+ if ( in_array( $this->db->getType(), array( 'mysql', 'sqlite', 'oracle' ) ) )
711712 array_push( $tables, 'searchindex' );
712713
713714 // Allow extensions to add to the list of tables to duplicate;
@@ -729,8 +730,8 @@
730731 return;
731732 }
732733
733 - $db = wfGetDB( DB_MASTER );
734 - $dbType = $db->getType();
 734+ $this->db = wfGetDB( DB_MASTER );
 735+ $dbType = $this->db->getType();
735736
736737 if ( $wgDBprefix === 'parsertest_' || ( $dbType == 'oracle' && $wgDBprefix === 'pt_' ) ) {
737738 throw new MWException( 'setupDatabase should be called before setupGlobals' );
@@ -756,27 +757,27 @@
757758 # works correctly across DB engines, we need to change the pre-
758759 # fix back and forth so tableName() works right.
759760 $this->changePrefix( $this->oldTablePrefix );
760 - $oldTableName = $db->tableName( $tbl );
 761+ $oldTableName = $this->db->tableName( $tbl );
761762 $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' );
762 - $newTableName = $db->tableName( $tbl );
 763+ $newTableName = $this->db->tableName( $tbl );
763764
764765 if ( $dbType == 'mysql' ) {
765 - $db->query( "DROP TABLE IF EXISTS $newTableName" );
 766+ $this->db->query( "DROP TABLE IF EXISTS $newTableName" );
766767 } elseif ( in_array( $dbType, array( 'postgres', 'oracle' ) ) ) {
767768 /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669)
768769 * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That
769770 * syntax would also work for mysql.
770771 */
771 - } elseif ( $db->tableExists( $tbl ) ) {
772 - $db->query( "DROP TABLE $newTableName" );
 772+ } elseif ( $this->db->tableExists( $tbl ) ) {
 773+ $this->db->query( "DROP TABLE $newTableName" );
773774 }
774775
775776 # Create new table
776 - $db->duplicateTableStructure( $oldTableName, $newTableName, $temporary );
 777+ $this->db->duplicateTableStructure( $oldTableName, $newTableName, $temporary );
777778 }
778779
779780 if ( $dbType == 'oracle' )
780 - $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
 781+ $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
781782
782783 $this->changePrefix( $dbType != 'oracle' ? 'parsertest_' : 'pt_' );
783784
@@ -784,14 +785,14 @@
785786 # Insert 0 user to prevent FK violations
786787
787788 # Anonymous user
788 - $db->insert( 'user', array(
 789+ $this->db->insert( 'user', array(
789790 'user_id' => 0,
790791 'user_name' => 'Anonymous' ) );
791792 }
792793
793794 # Hack: insert a few Wikipedia in-project interwiki prefixes,
794795 # for testing inter-language links
795 - $db->insert( 'interwiki', array(
 796+ $this->db->insert( 'interwiki', array(
796797 array( 'iw_prefix' => 'wikipedia',
797798 'iw_url' => 'http://en.wikipedia.org/wiki/$1',
798799 'iw_api' => '',
@@ -826,7 +827,7 @@
827828
828829
829830 # Update certain things in site_stats
830 - $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) );
 831+ $this->db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) );
831832
832833 # Reinitialise the LocalisationCache to match the database state
833834 Language::getLocalisationCache()->unloadAll();
@@ -848,7 +849,7 @@
849850 'metadata' => serialize( array() ),
850851 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
851852 'fileExists' => true
852 - ), $db->timestamp( '20010115123500' ), $user );
 853+ ), $this->db->timestamp( '20010115123500' ), $user );
853854
854855 # This image will be blacklisted in [[MediaWiki:Bad image list]]
855856 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
@@ -862,7 +863,7 @@
863864 'metadata' => serialize( array() ),
864865 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
865866 'fileExists' => true
866 - ), $db->timestamp( '20010115123500' ), $user );
 867+ ), $this->db->timestamp( '20010115123500' ), $user );
867868 }
868869
869870 /**
@@ -899,15 +900,14 @@
900901 }
901902
902903 $tables = $this->listTables();
903 - $db = wfGetDB( DB_MASTER );
904904
905905 foreach ( $tables as $table ) {
906 - $sql = $db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
907 - $db->query( $sql );
 906+ $sql = $this->db->getType() == 'oracle' ? "DROP TABLE pt_$table DROP CONSTRAINTS" : "DROP TABLE `parsertest_$table`";
 907+ $this->db->query( $sql );
908908 }
909909
910 - if ( $db->getType() == 'oracle' )
911 - $db->query( 'BEGIN FILL_WIKI_INFO; END;' );
 910+ if ( $this->db->getType() == 'oracle' )
 911+ $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
912912
913913 $this->teardownGlobals();
914914 }

Comments

#Comment by 😂 (talk | contribs)   14:17, 10 December 2010

The only places it's still used:

  • LoadBalancer code where we don't have a DB connection yet
  • Installer code - asking for and setting $wgDBtype
  • DefaultSettings/Setup stuff

Status & tagging log