MediaWiki r21466 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r21465‎ | r21466 (on ViewVC)‎ | r21467 >
Date:14:04, 22 April 2007
Author:tstarling
Status:old
Tags:
Comment:
* Removed mysql5 SQL files, obviously we're collectively incapable of keeping them up to date. They were littered with errors. The only deliberate difference appears to be the table character set, which can be adjusted programatically using a variable.
* Added table option variable to the SQL patch files, so now upgrading a non-standard schema won't leave your database horribly corrupted.
* Added sql.php, for sourcing SQL files with MediaWiki variable substitution.
* Disable MySQL's strict mode at session start for MySQL 4.1+, to avoid the various problems that occur when it is on.
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/archives/patch-querycacheinfo.sql
@@ -9,4 +9,4 @@
1010
1111 UNIQUE KEY ( qci_type )
1212
13 -) TYPE=InnoDB;
 13+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-job.sql
@@ -17,4 +17,4 @@
1818
1919 PRIMARY KEY job_id (job_id),
2020 KEY (job_cmd, job_namespace, job_title)
21 -) TYPE=InnoDB;
 21+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-templatelinks.sql
@@ -15,5 +15,5 @@
1616 UNIQUE KEY tl_from(tl_from,tl_namespace,tl_title),
1717 KEY (tl_namespace,tl_title)
1818
19 -) TYPE=InnoDB;
 19+) /*$wgDBTableOptions*/;
2020
Index: trunk/phase3/maintenance/archives/patch-user_groups.sql
@@ -22,4 +22,4 @@
2323
2424 PRIMARY KEY (ug_user,ug_group),
2525 KEY (ug_group)
26 -) TYPE=InnoDB;
 26+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-querycachetwo.sql
@@ -19,4 +19,4 @@
2020 KEY qcc_title (qcc_type,qcc_namespace,qcc_title),
2121 KEY qcc_titletwo (qcc_type,qcc_namespacetwo,qcc_titletwo)
2222
23 -) TYPE=InnoDB;
 23+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-externallinks.sql
@@ -9,5 +9,5 @@
1010 KEY (el_from, el_to(40)),
1111 KEY (el_to(60), el_from),
1212 KEY (el_index(60))
13 -) TYPE=InnoDB;
 13+) /*$wgDBTableOptions*/;
1414
Index: trunk/phase3/maintenance/archives/patch-userlevels.sql
@@ -11,7 +11,7 @@
1212 gr_rights tinyblob,
1313 PRIMARY KEY (gr_id)
1414
15 -) TYPE=InnoDB;
 15+) /*$wgDBTableOptions*/;
1616
1717 -- Relation table between user and groups
1818 CREATE TABLE /*$wgDBprefix*/user_groups (
@@ -19,4 +19,4 @@
2020 ug_group int(5) unsigned NOT NULL default '0',
2121 PRIMARY KEY (ug_user,ug_group)
2222
23 -) TYPE=InnoDB;
 23+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-validate.sql
@@ -10,4 +10,4 @@
1111 `val_comment` varchar(255) NOT NULL default '',
1212 `val_ip` varchar(20) NOT NULL default '',
1313 KEY `val_user` (`val_user`,`val_revision`)
14 -) TYPE=InnoDB;
 14+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-objectcache.sql
@@ -6,4 +6,4 @@
77 unique key (keyname),
88 key (exptime)
99
10 -) TYPE=InnoDB;
 10+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-user_rights.sql
@@ -14,7 +14,7 @@
1515
1616 UNIQUE KEY ur_user (ur_user)
1717
18 -) TYPE=InnoDB;
 18+) /*$wgDBTableOptions*/;
1919
2020 INSERT INTO /*$wgDBprefix*/user_rights SELECT user_id,user_rights FROM /*$wgDBprefix*/user;
2121
Index: trunk/phase3/maintenance/archives/patch-interwiki.sql
@@ -17,4 +17,4 @@
1818
1919 UNIQUE KEY iw_prefix (iw_prefix)
2020
21 -) TYPE=InnoDB;
 21+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-categorylinks.sql
@@ -36,4 +36,4 @@
3737 -- Not really used?
3838 KEY cl_timestamp(cl_to,cl_timestamp)
3939
40 -) TYPE=InnoDB;
 40+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-page_restrictions.sql
@@ -19,4 +19,4 @@
2020 KEY pr_typelevel (pr_type,pr_level),
2121 KEY pr_level (pr_level),
2222 KEY pr_cascade (pr_cascade)
23 -) TYPE=InnoDB;
\ No newline at end of file
 23+) /*$wgDBTableOptions*/;
\ No newline at end of file
Index: trunk/phase3/maintenance/archives/patch-linkscc.sql
@@ -9,4 +9,4 @@
1010 lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
1111 lcc_cacheobj MEDIUMBLOB NOT NULL
1212
13 -) TYPE=InnoDB;
 13+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-querycache.sql
@@ -13,4 +13,4 @@
1414
1515 KEY (qc_type,qc_value)
1616
17 -) TYPE=InnoDB;
 17+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-redirect.sql
@@ -15,7 +15,7 @@
1616
1717 PRIMARY KEY rd_from (rd_from),
1818 KEY rd_ns_title (rd_namespace,rd_title,rd_from)
19 -) TYPE=InnoDB;
 19+) /*$wgDBTableOptions*/;
2020
2121 -- Import existing redirects
2222 -- Using ignore because some of the redirect pages contain more than one link
Index: trunk/phase3/maintenance/archives/patch-transcache.sql
@@ -3,5 +3,5 @@
44 tc_contents TEXT,
55 tc_time INT NOT NULL,
66 UNIQUE INDEX tc_url_idx(tc_url)
7 -) TYPE=InnoDB;
 7+) /*$wgDBTableOptions*/;
88
Index: trunk/phase3/maintenance/archives/patch-parsercache.sql
@@ -12,4 +12,4 @@
1313 PRIMARY KEY (pc_pageid, pc_prefhash),
1414 KEY(pc_title),
1515 KEY(pc_expire)
16 -) TYPE=InnoDB;
 16+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-logging.sql
@@ -29,7 +29,7 @@
3030 KEY user_time (log_user, log_timestamp),
3131 KEY page_time (log_namespace, log_title, log_timestamp)
3232
33 -) TYPE=InnoDB;
 33+) /*$wgDBTableOptions*/;
3434
3535
3636 -- Change from unsigned to signed so we can store special pages
Index: trunk/phase3/maintenance/archives/patch-ipb_anon_only.sql
@@ -30,7 +30,7 @@
3131 INDEX ipb_timestamp (ipb_timestamp),
3232 INDEX ipb_expiry (ipb_expiry)
3333
34 -) TYPE=InnoDB;
 34+) /*$wgDBTableOptions*/;
3535
3636 INSERT IGNORE INTO /*$wgDBprefix*/ipblocks_newunique
3737 (ipb_id, ipb_address, ipb_user, ipb_by, ipb_reason, ipb_timestamp, ipb_auto, ipb_expiry, ipb_range_start, ipb_range_end, ipb_anon_only, ipb_create_account)
Index: trunk/phase3/maintenance/archives/patch-linktables.sql
@@ -16,7 +16,7 @@
1717 UNIQUE KEY l_from(l_from,l_to),
1818 KEY (l_to)
1919
20 -) TYPE=InnoDB;
 20+) /*$wgDBTableOptions*/;
2121
2222 --
2323 -- Track links to pages that don't yet exist.
@@ -35,7 +35,7 @@
3636 UNIQUE KEY bl_from(bl_from,bl_to),
3737 KEY (bl_to)
3838
39 -) TYPE=InnoDB;
 39+) /*$wgDBTableOptions*/;
4040
4141 --
4242 -- Track links to images *used inline*
@@ -55,7 +55,7 @@
5656 UNIQUE KEY il_from(il_from,il_to),
5757 KEY (il_to)
5858
59 -) TYPE=InnoDB;
 59+) /*$wgDBTableOptions*/;
6060
6161 --
6262 -- Stores (possibly gzipped) serialized objects with
@@ -67,4 +67,4 @@
6868 lcc_pageid INT UNSIGNED NOT NULL UNIQUE KEY,
6969 lcc_cacheobj MEDIUMBLOB NOT NULL
7070
71 -) TYPE=InnoDB;
 71+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-math.sql
@@ -25,4 +25,4 @@
2626
2727 UNIQUE KEY math_inputhash (math_inputhash)
2828
29 -) TYPE=InnoDB;
 29+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-pagelinks.sql
@@ -30,7 +30,7 @@
3131 UNIQUE KEY pl_from(pl_from,pl_namespace,pl_title),
3232 KEY (pl_namespace,pl_title)
3333
34 -) TYPE=InnoDB;
 34+) /*$wgDBTableOptions*/;
3535
3636
3737 -- Import existing-page links
Index: trunk/phase3/maintenance/archives/patch-filearchive.sql
@@ -48,4 +48,4 @@
4949 INDEX (fa_deleted_timestamp), -- sort by deletion time
5050 INDEX (fa_deleted_user) -- sort by deleter
5151
52 -) TYPE=InnoDB;
 52+) /*$wgDBTableOptions*/;
Index: trunk/phase3/maintenance/archives/patch-langlinks.sql
@@ -10,5 +10,5 @@
1111
1212 UNIQUE KEY (ll_from, ll_lang),
1313 KEY (ll_lang, ll_title)
14 -) TYPE=InnoDB;
 14+) /*$wgDBTableOptions*/;
1515
Index: trunk/phase3/maintenance/sql.php
@@ -0,0 +1,67 @@
 2+<?php
 3+
 4+/**
 5+ * Send SQL queries from the specified file to the database, performing
 6+ * variable replacement along the way.
 7+ */
 8+
 9+require_once( dirname(__FILE__) . '/' . 'commandLine.inc' );
 10+
 11+if ( isset( $options['help'] ) ) {
 12+ echo "Send SQL queries to a MediaWiki database.\nUsage: php sql.php [<file>]\n";
 13+ exit( 1 );
 14+}
 15+
 16+if ( isset( $args[0] ) ) {
 17+ $fileName = $args[0];
 18+ $file = fopen( $fileName, 'r' );
 19+ $promptCallback = false;
 20+} else {
 21+ $file = STDIN;
 22+ $promptObject = new SqlPromptPrinter( "> " );
 23+ $promptCallback = $promptObject->cb();
 24+}
 25+
 26+if ( !$file ) {
 27+ echo "Unable to open input file\n";
 28+ exit( 1 );
 29+}
 30+
 31+$dbw =& wfGetDB( DB_MASTER );
 32+$error = $dbw->sourceStream( $file, $promptCallback, 'sqlPrintResult' );
 33+if ( $error !== true ) {
 34+ echo $error;
 35+ exit( 1 );
 36+} else {
 37+ exit( 0 );
 38+}
 39+
 40+//-----------------------------------------------------------------------------
 41+class SqlPromptPrinter {
 42+ function __construct( $prompt ) {
 43+ $this->prompt = $prompt;
 44+ }
 45+
 46+ function cb() {
 47+ return array( $this, 'printPrompt' );
 48+ }
 49+
 50+ function printPrompt() {
 51+ echo $this->prompt;
 52+ }
 53+}
 54+
 55+function sqlPrintResult( $res ) {
 56+ if ( !$res ) {
 57+ // Do nothing
 58+ } elseif ( $res->numRows() ) {
 59+ while ( $row = $res->fetchObject() ) {
 60+ print_r( $row );
 61+ }
 62+ } else {
 63+ $affected = $res->db->affectedRows();
 64+ echo "Query OK, $affected row(s) affected\n";
 65+ }
 66+}
 67+
 68+?>
Property changes on: trunk/phase3/maintenance/sql.php
___________________________________________________________________
Added: svn:eol-style
169 + native
Index: trunk/phase3/maintenance/tables.sql
@@ -130,7 +130,7 @@
131131 UNIQUE INDEX user_name (user_name),
132132 INDEX (user_email_token)
133133
134 -) TYPE=InnoDB;
 134+) /*$wgDBTableOptions*/;
135135
136136 --
137137 -- User permissions have been broken out to a separate table;
@@ -156,7 +156,7 @@
157157
158158 PRIMARY KEY (ug_user,ug_group),
159159 KEY (ug_group)
160 -) TYPE=InnoDB;
 160+) /*$wgDBTableOptions*/;
161161
162162 -- Stores notifications of user talk page changes, for the display
163163 -- of the "you have new messages" box
@@ -169,7 +169,7 @@
170170 INDEX user_id (user_id),
171171 INDEX user_ip (user_ip)
172172
173 -) TYPE=InnoDB;
 173+) /*$wgDBTableOptions*/;
174174
175175
176176 --
@@ -229,7 +229,7 @@
230230 INDEX (page_random),
231231 INDEX (page_len)
232232
233 -) TYPE=InnoDB;
 233+) /*$wgDBTableOptions*/;
234234
235235 --
236236 -- Every edit of a page creates also a revision row.
@@ -284,7 +284,7 @@
285285 INDEX user_timestamp (rev_user,rev_timestamp),
286286 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
287287
288 -) TYPE=InnoDB MAX_ROWS=10000000 AVG_ROW_LENGTH=1024;
 288+) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=1024;
289289 -- In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 4GB limit
290290
291291 --
@@ -320,7 +320,7 @@
321321
322322 PRIMARY KEY old_id (old_id)
323323
324 -) TYPE=InnoDB MAX_ROWS=10000000 AVG_ROW_LENGTH=10240;
 324+) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=10240;
325325 -- In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 4GB limit
326326
327327 --
@@ -379,7 +379,7 @@
380380
381381 KEY name_title_timestamp (ar_namespace,ar_title,ar_timestamp)
382382
383 -) TYPE=InnoDB;
 383+) /*$wgDBTableOptions*/;
384384
385385
386386 --
@@ -399,7 +399,7 @@
400400 UNIQUE KEY pl_from (pl_from,pl_namespace,pl_title),
401401 KEY (pl_namespace,pl_title,pl_from)
402402
403 -) TYPE=InnoDB;
 403+) /*$wgDBTableOptions*/;
404404
405405
406406 --
@@ -419,7 +419,7 @@
420420 UNIQUE KEY tl_from (tl_from,tl_namespace,tl_title),
421421 KEY (tl_namespace,tl_title,tl_from)
422422
423 -) TYPE=InnoDB;
 423+) /*$wgDBTableOptions*/;
424424
425425 --
426426 -- Track links to images *used inline*
@@ -438,7 +438,7 @@
439439 UNIQUE KEY il_from (il_from,il_to),
440440 KEY (il_to,il_from)
441441
442 -) TYPE=InnoDB;
 442+) /*$wgDBTableOptions*/;
443443
444444 --
445445 -- Track category inclusions *used inline*
@@ -478,7 +478,7 @@
479479 -- Not really used?
480480 KEY cl_timestamp (cl_to,cl_timestamp)
481481
482 -) TYPE=InnoDB;
 482+) /*$wgDBTableOptions*/;
483483
484484 --
485485 -- Track links to external URLs
@@ -506,7 +506,7 @@
507507 KEY (el_from, el_to(40)),
508508 KEY (el_to(60), el_from),
509509 KEY (el_index(60))
510 -) TYPE=InnoDB;
 510+) /*$wgDBTableOptions*/;
511511
512512 --
513513 -- Track interlanguage links
@@ -523,7 +523,7 @@
524524
525525 UNIQUE KEY (ll_from, ll_lang),
526526 KEY (ll_lang, ll_title)
527 -) TYPE=InnoDB;
 527+) /*$wgDBTableOptions*/;
528528
529529 --
530530 -- Contains a single row with some aggregate info
@@ -560,7 +560,7 @@
561561
562562 UNIQUE KEY ss_row_id (ss_row_id)
563563
564 -) TYPE=InnoDB;
 564+) /*$wgDBTableOptions*/;
565565
566566 --
567567 -- Stores an ID for every time any article is visited;
@@ -634,7 +634,7 @@
635635 INDEX ipb_timestamp (ipb_timestamp),
636636 INDEX ipb_expiry (ipb_expiry)
637637
638 -) TYPE=InnoDB;
 638+) /*$wgDBTableOptions*/;
639639
640640
641641 --
@@ -691,7 +691,7 @@
692692 -- Used by Special:Newimages and Special:Imagelist
693693 INDEX img_timestamp (img_timestamp)
694694
695 -) TYPE=InnoDB;
 695+) /*$wgDBTableOptions*/;
696696
697697 --
698698 -- Previous revisions of uploaded files.
@@ -718,7 +718,7 @@
719719
720720 INDEX oi_name (oi_name(10))
721721
722 -) TYPE=InnoDB;
 722+) /*$wgDBTableOptions*/;
723723
724724 --
725725 -- Record of deleted file data
@@ -773,7 +773,7 @@
774774 INDEX (fa_deleted_timestamp), -- sort by deletion time
775775 INDEX (fa_deleted_user) -- sort by deleter
776776
777 -) TYPE=InnoDB;
 777+) /*$wgDBTableOptions*/;
778778
779779 --
780780 -- Primarily a summary table for Special:Recentchanges,
@@ -856,7 +856,7 @@
857857 INDEX rc_ns_usertext (rc_namespace, rc_user_text),
858858 INDEX rc_user_text (rc_user_text, rc_timestamp)
859859
860 -) TYPE=InnoDB;
 860+) /*$wgDBTableOptions*/;
861861
862862 CREATE TABLE /*$wgDBprefix*/watchlist (
863863 -- Key to user.user_id
@@ -875,7 +875,7 @@
876876 UNIQUE KEY (wl_user, wl_namespace, wl_title),
877877 KEY namespace_title (wl_namespace, wl_title)
878878
879 -) TYPE=InnoDB;
 879+) /*$wgDBTableOptions*/;
880880
881881
882882 --
@@ -901,7 +901,7 @@
902902
903903 UNIQUE KEY math_inputhash (math_inputhash)
904904
905 -) TYPE=InnoDB;
 905+) /*$wgDBTableOptions*/;
906906
907907 --
908908 -- When using the default MySQL search backend, page titles
@@ -948,7 +948,7 @@
949949
950950 UNIQUE KEY iw_prefix (iw_prefix)
951951
952 -) TYPE=InnoDB;
 952+) /*$wgDBTableOptions*/;
953953
954954 --
955955 -- Used for caching expensive grouped queries
@@ -966,7 +966,7 @@
967967
968968 KEY (qc_type,qc_value)
969969
970 -) TYPE=InnoDB;
 970+) /*$wgDBTableOptions*/;
971971
972972 --
973973 -- For a few generic cache operations if not using Memcached
@@ -978,7 +978,7 @@
979979 UNIQUE KEY (keyname),
980980 KEY (exptime)
981981
982 -) TYPE=InnoDB;
 982+) /*$wgDBTableOptions*/;
983983
984984 --
985985 -- Cache of interwiki transclusion
@@ -988,7 +988,7 @@
989989 tc_contents text,
990990 tc_time int NOT NULL,
991991 UNIQUE INDEX tc_url_idx (tc_url)
992 -) TYPE=InnoDB;
 992+) /*$wgDBTableOptions*/;
993993
994994 CREATE TABLE /*$wgDBprefix*/logging (
995995 -- Symbolic keys for the general log type and the action type
@@ -1026,7 +1026,7 @@
10271027 KEY page_time (log_namespace, log_title, log_timestamp),
10281028 KEY times (log_timestamp)
10291029
1030 -) TYPE=InnoDB;
 1030+) /*$wgDBTableOptions*/;
10311031
10321032 CREATE TABLE /*$wgDBprefix*/trackbacks (
10331033 tb_id int auto_increment,
@@ -1038,7 +1038,7 @@
10391039
10401040 PRIMARY KEY (tb_id),
10411041 INDEX (tb_page)
1042 -) TYPE=InnoDB;
 1042+) /*$wgDBTableOptions*/;
10431043
10441044
10451045 -- Jobs performed by parallel apache threads or a command-line daemon
@@ -1059,7 +1059,7 @@
10601060
10611061 PRIMARY KEY job_id (job_id),
10621062 KEY (job_cmd, job_namespace, job_title)
1063 -) TYPE=InnoDB;
 1063+) /*$wgDBTableOptions*/;
10641064
10651065
10661066 -- Details of updates to cached special pages
@@ -1074,7 +1074,7 @@
10751075
10761076 UNIQUE KEY ( qci_type )
10771077
1078 -) TYPE=InnoDB;
 1078+) /*$wgDBTableOptions*/;
10791079
10801080 -- For each redirect, this table contains exactly one row defining its target
10811081 CREATE TABLE /*$wgDBprefix*/redirect (
@@ -1090,7 +1090,7 @@
10911091
10921092 PRIMARY KEY rd_from (rd_from),
10931093 KEY rd_ns_title (rd_namespace,rd_title,rd_from)
1094 -) TYPE=InnoDB;
 1094+) /*$wgDBTableOptions*/;
10951095
10961096 -- Used for caching expensive grouped queries that need two links (for example double-redirects)
10971097 CREATE TABLE /*$wgDBprefix*/querycachetwo (
@@ -1112,7 +1112,7 @@
11131113 KEY qcc_title (qcc_type,qcc_namespace,qcc_title),
11141114 KEY qcc_titletwo (qcc_type,qcc_namespacetwo,qcc_titletwo)
11151115
1116 -) TYPE=InnoDB;
 1116+) /*$wgDBTableOptions*/;
11171117
11181118 --- Used for storing page restrictions (i.e. protection levels)
11191119 CREATE TABLE /*$wgDBprefix*/page_restrictions (
@@ -1138,6 +1138,6 @@
11391139 KEY pr_typelevel (pr_type,pr_level),
11401140 KEY pr_level (pr_level),
11411141 KEY pr_cascade (pr_cascade)
1142 -) TYPE=InnoDB;
 1142+) /*$wgDBTableOptions*/;
11431143
11441144 -- vim: sw=2 sts=2 et
Index: trunk/phase3/includes/DefaultSettings.php
@@ -505,8 +505,12 @@
506506 $wgSearchType = null;
507507 /** Table name prefix */
508508 $wgDBprefix = '';
 509+/** MySQL table options to use during installation or update */
 510+$wgDBTableOptions = 'TYPE=InnoDB';
 511+
509512 /**#@-*/
510513
 514+
511515 /** Live high performance sites should disable this - some checks acquire giant mysql locks */
512516 $wgCheckDBSchema = true;
513517
@@ -1168,6 +1172,7 @@
11691173 $wgEnotifRevealEditorAddress = false; # UPO; reply-to address may be filled with page editor's address (if user allowed this in the preferences)
11701174 $wgEnotifMinorEdits = true; # UPO; false: "minor edits" on pages do not trigger notification mails.
11711175 # # Attention: _every_ change on a user_talk page trigger a notification mail (if the user is not yet notified)
 1176+$wgUsersNotifedOnAllChanges = array();
11721177
11731178 /** Show watching users in recent changes, watchlist and page history views */
11741179 $wgRCShowWatchingUsers = false; # UPO
Index: trunk/phase3/includes/Database.php
@@ -610,12 +610,19 @@
611611 }
612612
613613 if ( $success ) {
614 - global $wgDBmysql5;
615 - if( $wgDBmysql5 ) {
 614+ $version = $this->getServerVersion();
 615+ if ( version_compare( $version, '4.1' ) >= 0 ) {
616616 // Tell the server we're communicating with it in UTF-8.
617617 // This may engage various charset conversions.
618 - $this->query( 'SET NAMES utf8' );
 618+ global $wgDBmysql5;
 619+ if( $wgDBmysql5 ) {
 620+ $this->query( 'SET NAMES utf8', __METHOD__ );
 621+ }
 622+ // Turn off strict mode
 623+ $this->query( "SET sql_mode = ''", __METHOD__ );
619624 }
 625+
 626+ // Turn off strict mode if it is on
620627 } else {
621628 $this->reportConnectionError();
622629 }
@@ -2098,18 +2105,36 @@
20992106 /**
21002107 * Read and execute SQL commands from a file.
21012108 * Returns true on success, error string on failure
 2109+ * @param string $filename File name to open
 2110+ * @param callback $lineCallback Optional function called before reading each line
 2111+ * @param callback $resultCallback Optional function called for each MySQL result
21022112 */
2103 - function sourceFile( $filename ) {
 2113+ function sourceFile( $filename, $lineCallback = false, $resultCallback = false ) {
21042114 $fp = fopen( $filename, 'r' );
21052115 if ( false === $fp ) {
21062116 return "Could not open \"{$filename}\".\n";
21072117 }
 2118+ $error = $this->sourceStream( $fp, $lineCallback, $resultCallback );
 2119+ fclose( $fp );
 2120+ return $error;
 2121+ }
21082122
 2123+ /**
 2124+ * Read and execute commands from an open file handle
 2125+ * Returns true on success, error string on failure
 2126+ * @param string $fp File handle
 2127+ * @param callback $lineCallback Optional function called before reading each line
 2128+ * @param callback $resultCallback Optional function called for each MySQL result
 2129+ */
 2130+ function sourceStream( $fp, $lineCallback = false, $resultCallback = false ) {
21092131 $cmd = "";
21102132 $done = false;
21112133 $dollarquote = false;
21122134
21132135 while ( ! feof( $fp ) ) {
 2136+ if ( $lineCallback ) {
 2137+ call_user_func( $lineCallback );
 2138+ }
21142139 $line = trim( fgets( $fp, 1024 ) );
21152140 $sl = strlen( $line ) - 1;
21162141
@@ -2139,7 +2164,10 @@
21402165 if ( $done ) {
21412166 $cmd = str_replace(';;', ";", $cmd);
21422167 $cmd = $this->replaceVars( $cmd );
2143 - $res = $this->query( $cmd, 'dbsource', true );
 2168+ $res = $this->query( $cmd, __METHOD__, true );
 2169+ if ( $resultCallback ) {
 2170+ call_user_func( $resultCallback, $this->resultObject( $res ) );
 2171+ }
21442172
21452173 if ( false === $res ) {
21462174 $err = $this->lastError();
@@ -2150,10 +2178,10 @@
21512179 $done = false;
21522180 }
21532181 }
2154 - fclose( $fp );
21552182 return true;
21562183 }
21572184
 2185+
21582186 /**
21592187 * Replace variables in sourced SQL
21602188 */
@@ -2161,7 +2189,7 @@
21622190 $varnames = array(
21632191 'wgDBserver', 'wgDBname', 'wgDBintlname', 'wgDBuser',
21642192 'wgDBpassword', 'wgDBsqluser', 'wgDBsqlpassword',
2165 - 'wgDBadminuser', 'wgDBadminpassword',
 2193+ 'wgDBadminuser', 'wgDBadminpassword', 'wgDBTableOptions',
21662194 );
21672195
21682196 // Ordinary variables
Index: trunk/phase3/config/index.php
@@ -226,6 +226,26 @@
227227 function getSitename() { return $this->getEncoded( $this->Sitename ); }
228228 function getSysopName() { return $this->getEncoded( $this->SysopName ); }
229229 function getSysopPass() { return $this->getEncoded( $this->SysopPass ); }
 230+
 231+ function setSchema( $schema ) {
 232+ $this->DBschema = $schema;
 233+ switch ( $this->DBschema ) {
 234+ case 'mysql5':
 235+ $this->DBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=utf8';
 236+ $this->DBmysql5 = 'true';
 237+ break;
 238+ case 'mysql5-binary':
 239+ $this->DBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=binary';
 240+ $this->DBmysql5 = 'true';
 241+ break;
 242+ default:
 243+ $this->DBTableOptions = 'TYPE=InnoDB';
 244+ $this->DBmysql5 = 'false';
 245+ }
 246+ # Set the global for use during install
 247+ global $wgDBTableOptions;
 248+ $wgDBTableOptions = $this->DBTableOptions;
 249+ }
230250 }
231251
232252 ?>
@@ -522,10 +542,7 @@
523543
524544 ## MySQL specific:
525545 $conf->DBprefix = importPost( "DBprefix" );
526 - $conf->DBschema = importPost( "DBschema", "mysql4" );
527 - $conf->DBmysql5 = ($conf->DBschema == "mysql5" ||
528 - $conf->DBschema == "mysql5-binary")
529 - ? "true" : "false";
 546+ $conf->setSchema( importPost( "DBschema", "mysql4" ) );
530547 $conf->LanguageCode = importPost( "LanguageCode", "en" );
531548
532549 ## Postgres specific:
@@ -813,6 +830,32 @@
814831 if( $wgDatabase->tableExists( "cur" ) || $wgDatabase->tableExists( "revision" ) ) {
815832 print "<li>There are already MediaWiki tables in this database. Checking if updates are needed...</li>\n";
816833
 834+ # Determine existing default character set
 835+ if ( $wgDatabase->tableExists( "revision" ) ) {
 836+ $revision = $wgDatabase->escapeLike( $conf->DBprefix . 'revision' );
 837+ $res = $wgDatabase->query( "SHOW TABLE STATUS LIKE '$revision'" );
 838+ $row = $wgDatabase->fetchObject( $res );
 839+ if ( !$row ) {
 840+ echo "<li>SHOW TABLE STATUS query failed!</li>\n";
 841+ $existingSchema = false;
 842+ } elseif ( preg_match( '/^latin1/', $row->Collation ) ) {
 843+ $existingSchema = 'mysql4';
 844+ } elseif ( preg_match( '/^utf8/', $row->Collation ) ) {
 845+ $existingSchema = 'mysql5';
 846+ } elseif ( preg_match( '/^binary/', $row->Collation ) ) {
 847+ $existingSchema = 'mysql5-binary';
 848+ } else {
 849+ $existingSchema = false;
 850+ echo "<li><strong>Warning:</strong> Unrecognised existing collation</li>\n";
 851+ }
 852+ if ( $existingSchema && $existingSchema != $conf->DBschema ) {
 853+ print "<li><strong>Warning:</strong> you requested the {$conf->DBschema} schema, " .
 854+ "but the existing database has the $existingSchema schema. This upgrade script ".
 855+ "can't convert it, so it will remain $existingSchema.</li>\n";
 856+ $conf->setSchema( $existingSchema );
 857+ }
 858+ }
 859+
817860 # Create user if required (todo: other databases)
818861 if ( $conf->Root && $conf->DBtype == 'mysql') {
819862 $conn = $dbc->newFromParams( $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, 1 );
@@ -828,33 +871,18 @@
829872 dbsource( "../maintenance/users.sql", $wgDatabase );
830873 }
831874 }
832 - print "<pre>\n";
 875+ print "</ul><pre>\n";
833876 chdir( ".." );
834877 flush();
835878 do_all_updates();
836879 chdir( "config" );
837880 print "</pre>\n";
838 - print "<li>Finished update checks.</li>\n";
 881+ print "<ul><li>Finished update checks.</li>\n";
839882 } else {
840883 # FIXME: Check for errors
841884 print "<li>Creating tables...";
842885 if ($conf->DBtype == 'mysql') {
843 - switch( $conf->DBschema ) {
844 - case "mysql4":
845 - print " using MySQL 4 table defs...";
846 - dbsource( "../maintenance/tables.sql", $wgDatabase );
847 - break;
848 - case "mysql5":
849 - print " using MySQL 5 UTF-8 table defs...";
850 - dbsource( "../maintenance/mysql5/tables.sql", $wgDatabase );
851 - break;
852 - case "mysql5-binary":
853 - print " using MySQL 5 binary table defs...";
854 - dbsource( "../maintenance/mysql5/tables-binary.sql", $wgDatabase );
855 - break;
856 - default:
857 - dieout( " <b>invalid schema selection!</b></li>" );
858 - }
 886+ dbsource( "../maintenance/tables.sql", $wgDatabase );
859887 dbsource( "../maintenance/interwiki.sql", $wgDatabase );
860888 } else if ($conf->DBtype == 'postgres') {
861889 $wgDatabase->setup_database();
@@ -1431,6 +1459,9 @@
14321460 \$wgDBport = \"{$slconf['DBport']}\";
14331461 \$wgDBprefix = \"{$slconf['DBprefix']}\";
14341462
 1463+# MySQL table options to use during installation or update
 1464+\$wgDBTableOptions = \"{$slconf['DBTableOptions']}\";
 1465+
14351466 # Schemas for Postgres
14361467 \$wgDBmwschema = \"{$slconf['DBmwschema']}\";
14371468 \$wgDBts2schema = \"{$slconf['DBts2schema']}\";