82b130192979c62232f55746781f8a7c32bef042
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Maintenance
5 */
6
7 /** */
8
9 require_once 'convertLinks.inc';
10 require_once 'InitialiseMessages.inc';
11 require_once 'userDupes.inc';
12
13 $wgRenamedTables = array(
14 # from to patch file
15 # array( 'group', 'groups', 'patch-rename-group.sql' ),
16 );
17
18 $wgNewTables = array(
19 # table patch file (in maintenance/archives)
20 array( 'hitcounter', 'patch-hitcounter.sql' ),
21 array( 'querycache', 'patch-querycache.sql' ),
22 array( 'objectcache', 'patch-objectcache.sql' ),
23 array( 'categorylinks', 'patch-categorylinks.sql' ),
24 array( 'logging', 'patch-logging.sql' ),
25 array( 'validate', 'patch-validate.sql' ),
26 array( 'user_newtalk', 'patch-usernewtalk2.sql' ),
27 array( 'transcache', 'patch-transcache.sql' ),
28 );
29
30 $wgNewFields = array(
31 # table field patch file (in maintenance/archives)
32 array( 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
33 array( 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
34 array( 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
35 array( 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
36 array( 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
37 array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
38 array( 'user', 'user_real_name', 'patch-user-realname.sql' ),
39 array( 'user', 'user_token', 'patch-user_token.sql' ),
40 array( 'user', 'user_email_token', 'patch-user_email_token.sql' ),
41 array( 'logging', 'log_params', 'patch-log_params.sql' ),
42 array( 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ),
43 array( 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ),
44 array( 'page', 'page_len', 'patch-page_len.sql' ),
45 array( 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ),
46 array( 'image', 'img_width', 'patch-img_width.sql' ),
47 array( 'image', 'img_metadata', 'patch-img_metadata.sql' ),
48 array( 'image', 'img_media_type', 'patch-img_media_type.sql' ),
49 array( 'validate', 'val_ip', 'patch-val_ip.sql' ),
50 array( 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ),
51 array( 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ),
52 );
53
54 function rename_table( $from, $to, $patch ) {
55 global $wgDatabase;
56 if ( $wgDatabase->tableExists( $from ) ) {
57 if ( $wgDatabase->tableExists( $to ) ) {
58 echo "...can't move table $from to $to, $to already exists.\n";
59 } else {
60 echo "Moving table $from to $to...";
61 dbsource( "maintenance/archives/$patch", $wgDatabase );
62 echo "ok\n";
63 }
64 } else {
65 // Source table does not exist
66 // Renames are done before creations, so this is typical for a new installation
67 // Ignore silently
68 }
69 }
70
71 function add_table( $name, $patch ) {
72 global $wgDatabase;
73 if ( $wgDatabase->tableExists( $name ) ) {
74 echo "...$name table already exists.\n";
75 } else {
76 echo "Creating $name table...";
77 dbsource( "maintenance/archives/$patch", $wgDatabase );
78 echo "ok\n";
79 }
80 }
81
82 function add_field( $table, $field, $patch ) {
83 global $wgDatabase;
84 if ( !$wgDatabase->tableExists( $table ) ) {
85 echo "...$table table does not exist, skipping new field patch\n";
86 } elseif ( $wgDatabase->fieldExists( $table, $field ) ) {
87 echo "...have $field field in $table table.\n";
88 } else {
89 echo "Adding $field field to table $table...";
90 dbsource( "maintenance/archives/$patch" , $wgDatabase );
91 echo "ok\n";
92 }
93 }
94
95 function do_revision_updates() {
96 global $wgSoftwareRevision;
97 if ( $wgSoftwareRevision < 1001 ) {
98 update_passwords();
99 }
100 }
101
102 function update_passwords() {
103 wfDebugDieBacktrace( "This function needs to be updated or removed.\n" );
104
105 global $wgDatabase;
106 $fname = "Update script: update_passwords()";
107 print "\nIt appears that you need to update the user passwords in your\n" .
108 "database. If you have already done this (if you've run this update\n" .
109 "script once before, for example), doing so again will make all your\n" .
110 "user accounts inaccessible, so be sure you only do this once.\n" .
111 "Update user passwords? (yes/no)";
112
113 $resp = readconsole();
114 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
115
116 $sql = "SELECT user_id,user_password FROM user";
117 $source = $wgDatabase->query( $sql, $fname );
118
119 while ( $row = $wgDatabase->fetchObject( $source ) ) {
120 $id = $row->user_id;
121 $oldpass = $row->user_password;
122 $newpass = md5( "{$id}-{$oldpass}" );
123
124 $sql = "UPDATE user SET user_password='{$newpass}' " .
125 "WHERE user_id={$id}";
126 $wgDatabase->query( $sql, $fname );
127 }
128 }
129
130 function do_interwiki_update() {
131 # Check that interwiki table exists; if it doesn't source it
132 global $wgDatabase;
133 if( $wgDatabase->tableExists( "interwiki" ) ) {
134 echo "...already have interwiki table\n";
135 return true;
136 }
137 echo "Creating interwiki table: ";
138 dbsource( "maintenance/archives/patch-interwiki.sql" );
139 echo "ok\n";
140 echo "Adding default interwiki definitions: ";
141 dbsource( "maintenance/interwiki.sql" );
142 echo "ok\n";
143 }
144
145 function do_index_update() {
146 # Check that proper indexes are in place
147 global $wgDatabase;
148 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
149 if( $meta->multiple_key == 0 ) {
150 echo "Updating indexes to 20031107: ";
151 dbsource( "maintenance/archives/patch-indexes.sql" );
152 echo "ok\n";
153 return true;
154 }
155 echo "...indexes seem up to 20031107 standards\n";
156 return false;
157 }
158
159 function do_image_name_unique_update() {
160 global $wgDatabase;
161 if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
162 echo "...image primary key already set.\n";
163 } else {
164 echo "Making img_name the primary key... ";
165 dbsource( "maintenance/archives/patch-image_name_primary.sql", $wgDatabase );
166 echo "ok\n";
167 }
168 }
169
170 function do_watchlist_update() {
171 global $wgDatabase;
172 if( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
173 echo "The watchlist table is already set up for email notification.\n";
174 } else {
175 echo "Adding wl_notificationtimestamp field for email notification management.";
176 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
177 dbsource( "maintenance/archives/patch-email-notification.sql", $wgDatabase );
178 echo "ok\n";
179 }
180 }
181
182 function do_copy_newtalk_to_watchlist() {
183 global $wgDatabase;
184 global $wgCommandLineMode; # this needs to be saved while getID() and getName() are called
185
186 $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !',
187 $wgDatabase->tableName( 'user_newtalk' ) );
188 $num_newtalks=$wgDatabase->numRows($res);
189 echo "Now converting ".$num_newtalks." user_newtalk entries to watchlist table entries ... \n";
190
191 $user = new User();
192 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
193 $wluser = $wgDatabase->fetchObject( $res );
194 if ($wluser->user_id == 0) { # anonymous users ... have IP numbers as "names"
195 if ($user->isIP($wluser->user_ip)) { # do only if it really looks like an IP number (double checked)
196 $wgDatabase->replace( 'watchlist',
197 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )),
198 array('wl_user' => 0,
199 'wl_namespace' => NS_USER_TALK,
200 'wl_title' => $wluser->user_ip,
201 'wl_notificationtimestamp' => '19700101000000'
202 ), 'updaters.inc::do_watchlist_update2'
203 );
204 }
205 } else { # normal users ... have user_ids
206 $user->setID($wluser->user_id);
207 $wgDatabase->replace( 'watchlist',
208 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )),
209 array('wl_user' => $user->getID(),
210 'wl_namespace' => NS_USER_TALK,
211 'wl_title' => $user->getName(),
212 'wl_notificationtimestamp' => '19700101000000'
213 ), 'updaters.inc::do_watchlist_update3'
214 );
215 }
216 }
217 echo "Done.\n";
218 }
219
220
221 function do_user_update() {
222 global $wgDatabase;
223 if( $wgDatabase->fieldExists( 'user', 'user_emailauthenticationtimestamp' ) ) {
224 echo "User table contains old email authentication field. Dropping... ";
225 dbsource( "maintenance/archives/patch-email-authentication.sql", $wgDatabase );
226 echo "ok\n";
227 } else {
228 echo "...user table does not contain old email authentication field.\n";
229 }
230 }
231
232 /**
233 * 1.4 betas were missing the 'binary' marker from logging.log_title,
234 * which causes a collation mismatch error on joins in MySQL 4.1.
235 */
236 function do_logging_encoding() {
237 global $wgDatabase;
238 $logging = $wgDatabase->tableName( 'logging' );
239 $res = $wgDatabase->query( "SELECT log_title FROM $logging LIMIT 0" );
240 $flags = explode( ' ', mysql_field_flags( $res, 0 ) );
241 $wgDatabase->freeResult( $res );
242
243 if( in_array( 'binary', $flags ) ) {
244 echo "Logging table has correct title encoding.\n";
245 } else {
246 echo "Fixing title encoding on logging table... ";
247 dbsource( 'maintenance/archives/patch-logging-title.sql', $wgDatabase );
248 echo "ok\n";
249 }
250 }
251
252 function do_schema_restructuring() {
253 global $wgDatabase;
254 $fname="do_schema_restructuring";
255 if ( $wgDatabase->tableExists( 'page' ) ) {
256 echo "...page table already exists.\n";
257 } else {
258 echo "...converting from cur/old to page/revision/text DB structure.\n"; flush();
259 echo wfTimestamp();
260 echo "......checking for duplicate entries.\n"; flush();
261
262 extract( $wgDatabase->tableNames( 'cur', 'old', 'page', 'revision', 'text' ) );
263
264 $rows = $wgDatabase->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
265 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", $fname );
266
267 if ( $wgDatabase->numRows( $rows ) > 0 ) {
268 echo wfTimestamp();
269 echo "......<b>Found duplicate entries</b>\n";
270 echo ( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
271 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
272 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
273 $duplicate[$row->cur_namespace] = array();
274 }
275 $duplicate[$row->cur_namespace][] = $row->cur_title;
276 echo ( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
277 }
278 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
279 $firstCond = true;
280 foreach ( $duplicate as $ns => $titles ) {
281 if ( $firstCond ) {
282 $firstCond = false;
283 } else {
284 $sql .= ' OR ';
285 }
286 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
287 $first = true;
288 foreach ( $titles as $t ) {
289 if ( $first ) {
290 $sql .= $wgDatabase->addQuotes( $t );
291 $first = false;
292 } else {
293 $sql .= ', ' . $wgDatabase->addQuotes( $t );
294 }
295 }
296 $sql .= ") ) \n";
297 }
298 # By sorting descending, the most recent entry will be the first in the list.
299 # All following entries will be deleted by the next while-loop.
300 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
301
302 $rows = $wgDatabase->query( $sql, $fname );
303
304 $prev_title = $prev_namespace = false;
305 $deleteId = array();
306
307 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
308 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
309 $deleteId[] = $row->cur_id;
310 }
311 $prev_title = $row->cur_title;
312 $prev_namespace = $row->cur_namespace;
313 }
314 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
315 $rows = $wgDatabase->query( $sql, $fname );
316 echo wfTimestamp();
317 echo "......<b>Deleted</b> ".$wgDatabase->affectedRows()." records.\n";
318 }
319
320
321 echo wfTimestamp();
322 echo "......Creating tables.\n";
323 $wgDatabase->query("CREATE TABLE $page (
324 page_id int(8) unsigned NOT NULL auto_increment,
325 page_namespace int NOT NULL,
326 page_title varchar(255) binary NOT NULL,
327 page_restrictions tinyblob NOT NULL default '',
328 page_counter bigint(20) unsigned NOT NULL default '0',
329 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
330 page_is_new tinyint(1) unsigned NOT NULL default '0',
331 page_random real unsigned NOT NULL,
332 page_touched char(14) binary NOT NULL default '',
333 page_latest int(8) unsigned NOT NULL,
334 page_len int(8) unsigned NOT NULL,
335
336 PRIMARY KEY page_id (page_id),
337 UNIQUE INDEX name_title (page_namespace,page_title),
338 INDEX (page_random),
339 INDEX (page_len)
340 ) TYPE=InnoDB", $fname );
341 $wgDatabase->query("CREATE TABLE $revision (
342 rev_id int(8) unsigned NOT NULL auto_increment,
343 rev_page int(8) unsigned NOT NULL,
344 rev_comment tinyblob NOT NULL default '',
345 rev_user int(5) unsigned NOT NULL default '0',
346 rev_user_text varchar(255) binary NOT NULL default '',
347 rev_timestamp char(14) binary NOT NULL default '',
348 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
349 rev_deleted tinyint(1) unsigned NOT NULL default '0',
350
351 PRIMARY KEY rev_page_id (rev_page, rev_id),
352 UNIQUE INDEX rev_id (rev_id),
353 INDEX rev_timestamp (rev_timestamp),
354 INDEX page_timestamp (rev_page,rev_timestamp),
355 INDEX user_timestamp (rev_user,rev_timestamp),
356 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
357 ) TYPE=InnoDB", $fname );
358
359 echo wfTimestamp();
360 echo "......Locking tables.\n";
361 $wgDatabase->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
362
363 $maxold = $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname );
364 echo wfTimestamp();
365 echo "......maxold is {$maxold}\n";
366
367 echo wfTimestamp();
368 global $wgLegacySchemaConversion;
369 if( $wgLegacySchemaConversion ) {
370 // Create HistoryBlobCurStub entries.
371 // Text will be pulled from the leftover 'cur' table at runtime.
372 echo "......Moving metadata from cur; using blob references to text in cur table.\n";
373 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
374 $cur_flags = "'object'";
375 } else {
376 // Copy all cur text in immediately: this may take longer but avoids
377 // having to keep an extra table around.
378 echo "......Moving text from cur.\n";
379 $cur_text = 'cur_text';
380 $cur_flags = "''";
381 }
382 $wgDatabase->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
383 old_timestamp, old_minor_edit, old_flags)
384 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
385 FROM $cur", $fname );
386
387 echo wfTimestamp();
388 echo "......Setting up revision table.\n";
389 $wgDatabase->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
390 rev_minor_edit)
391 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
392 old_timestamp, old_minor_edit
393 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
394
395 echo wfTimestamp();
396 echo "......Setting up page table.\n";
397 $wgDatabase->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
398 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
399 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
400 cur_random, cur_touched, rev_id, LENGTH(cur_text)
401 FROM $cur,$revision
402 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
403
404 echo wfTimestamp();
405 echo "......Unlocking tables.\n";
406 $wgDatabase->query( "UNLOCK TABLES", $fname );
407
408 echo wfTimestamp();
409 echo "......Renaming old.\n";
410 $wgDatabase->query( "ALTER TABLE $old RENAME TO $text", $fname );
411
412 echo wfTimestamp();
413 echo "...done.\n";
414 }
415 }
416
417 function do_inverse_timestamp() {
418 global $wgDatabase;
419 $fname="do_schema_restructuring";
420 if( $wgDatabase->fieldExists( 'revision', 'inverse_timestamp' ) ) {
421 echo "Removing revision.inverse_timestamp and fixing indexes... ";
422 dbsource( 'maintenance/archives/patch-inverse_timestamp.sql', $wgDatabase );
423 echo "ok\n";
424 } else {
425 echo "revision timestamp indexes already up to 2005-03-13\n";
426 }
427 }
428
429 function do_text_id() {
430 global $wgDatabase;
431 if( $wgDatabase->fieldExists( 'revision', 'rev_text_id' ) ) {
432 echo "...rev_text_id already in place.\n";
433 } else {
434 echo "Adding rev_text_id field... ";
435 dbsource( 'maintenance/archives/patch-rev_text_id.sql', $wgDatabase );
436 echo "ok\n";
437 }
438 }
439
440 function do_namespace_size() {
441 $tables = array(
442 'page' => 'page',
443 'archive' => 'ar',
444 'recentchanges' => 'rc',
445 'watchlist' => 'wl',
446 'querycache' => 'qc',
447 'logging' => 'log',
448 );
449 foreach( $tables as $table => $prefix ) {
450 do_namespace_size_on( $table, $prefix );
451 flush();
452 }
453 }
454
455 function do_namespace_size_on( $table, $prefix ) {
456 global $wgDatabase;
457 $field = $prefix . '_namespace';
458
459 $tablename = $wgDatabase->tableName( $table );
460 $result = $wgDatabase->query( "SHOW COLUMNS FROM $tablename LIKE '$field'" );
461 $info = $wgDatabase->fetchObject( $result );
462 $wgDatabase->freeResult( $result );
463
464 if( substr( $info->Type, 0, 3 ) == 'int' ) {
465 echo "...$field is already a full int ($info->Type).\n";
466 } else {
467 echo "Promoting $field from $info->Type to int... ";
468
469 $sql = "ALTER TABLE $tablename MODIFY $field int NOT NULL";
470 $wgDatabase->query( $sql );
471
472 echo "ok\n";
473 }
474 }
475
476 function do_pagelinks_update() {
477 global $wgDatabase;
478 if( $wgDatabase->tableExists( 'pagelinks' ) ) {
479 echo "...already have pagelinks table.\n";
480 } else {
481 echo "Converting links and brokenlinks tables to pagelinks... ";
482 dbsource( "maintenance/archives/patch-pagelinks.sql", $wgDatabase );
483 echo "ok\n";
484 flush();
485
486 global $wgCanonicalNamespaceNames;
487 foreach( $wgCanonicalNamespaceNames as $ns => $name ) {
488 if( $ns != 0 ) {
489 do_pagelinks_namespace( $ns );
490 }
491 }
492 }
493 }
494
495 function do_pagelinks_namespace( $namespace ) {
496 global $wgDatabase, $wgContLang;
497
498 $ns = IntVal( $namespace );
499 echo "Cleaning up broken links for namespace $ns... ";
500
501 $pagelinks = $wgDatabase->tableName( 'pagelinks' );
502 $name = $wgContLang->getNsText( $ns );
503 $prefix = $wgDatabase->strencode( $name );
504 $likeprefix = str_replace( '_', '\\_', $prefix);
505
506 $sql = "UPDATE $pagelinks
507 SET pl_namespace=$ns,
508 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
509 WHERE pl_namespace=0
510 AND pl_title LIKE '$likeprefix:%'";
511
512 $wgDatabase->query( $sql, 'do_pagelinks_namespace' );
513 echo "ok\n";
514 }
515
516 function do_drop_img_type() {
517 global $wgDatabase;
518
519 if( $wgDatabase->fieldExists( 'image', 'img_type' ) ) {
520 echo "Dropping unused img_type field in image table... ";
521 dbsource( "maintenance/archives/patch-drop_img_type.sql", $wgDatabase );
522 echo "ok\n";
523 } else {
524 echo "No img_type field in image table; Good.\n";
525 }
526 }
527
528 function do_old_links_update() {
529 global $wgDatabase;
530 if( $wgDatabase->tableExists( 'pagelinks' ) ) {
531 echo "Already have pagelinks; skipping old links table updates.\n";
532 } else {
533 convertLinks(); flush();
534 }
535 }
536
537 function do_user_unique_update() {
538 global $wgDatabase;
539 $duper = new UserDupes( $wgDatabase );
540 if( $duper->hasUniqueIndex() ) {
541 echo "Already have unique user_name index.\n";
542 } else {
543 if( !$duper->clearDupes() ) {
544 echo "WARNING: This next step will probably fail due to unfixed duplicates...\n";
545 }
546 echo "Adding unique index on user_name... ";
547 dbsource( 'maintenance/archives/patch-user_nameindex.sql', $wgDatabase );
548 echo "ok\n";
549 }
550 }
551
552 function do_user_groups_update() {
553 $fname = 'do_user_groups_update';
554 global $wgDatabase;
555
556 if( $wgDatabase->tableExists( 'user_groups' ) ) {
557 echo "...user_groups table already exists.\n";
558 return do_user_groups_reformat();
559 }
560
561 echo "Adding user_groups table... ";
562 dbsource( 'maintenance/archives/patch-user_groups.sql', $wgDatabase );
563 echo "ok\n";
564
565 if( !$wgDatabase->tableExists( 'user_rights' ) ) {
566 if( $wgDatabase->fieldExists( 'user', 'user_rights' ) ) {
567 echo "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion...";
568 dbsource( 'maintenance/archives/patch-user_rights.sql', $wgDatabase );
569 echo "ok\n";
570 } else {
571 echo "*** WARNING: couldn't locate user_rights table or field for upgrade.\n";
572 echo "*** You may need to manually configure some sysops by manipulating\n";
573 echo "*** the user_groups table.\n";
574 return;
575 }
576 }
577
578 echo "Converting user_rights table to user_groups... ";
579 $result = $wgDatabase->select( 'user_rights',
580 array( 'ur_user', 'ur_rights' ),
581 array( "ur_rights != ''" ),
582 $fname );
583
584 while( $row = $wgDatabase->fetchObject( $result ) ) {
585 $groups = array_unique(
586 array_map( 'trim',
587 explode( ',', $row->ur_rights ) ) );
588
589 foreach( $groups as $group ) {
590 $wgDatabase->insert( 'user_groups',
591 array(
592 'ug_user' => $row->ur_user,
593 'ug_group' => $group ),
594 $fname );
595 }
596 }
597 $wgDatabase->freeResult( $result );
598 echo "ok\n";
599 }
600
601 function do_user_groups_reformat() {
602 # Check for bogus formats from previous 1.5 alpha code.
603 global $wgDatabase;
604 $info = $wgDatabase->fieldInfo( 'user_groups', 'ug_group' );
605
606 if( $info->type == 'int' ) {
607 $oldug = $wgDatabase->tableName( 'user_groups' );
608 $newug = $wgDatabase->tableName( 'user_groups_bogus' );
609 echo "user_groups is in bogus intermediate format. Renaming to $newug... ";
610 $wgDatabase->query( "ALTER TABLE $oldug RENAME TO $newug" );
611 echo "ok\n";
612
613 echo "Re-adding fresh user_groups table... ";
614 dbsource( 'maintenance/archives/patch-user_groups.sql', $wgDatabase );
615 echo "ok\n";
616
617 echo "***\n";
618 echo "*** WARNING: You will need to manually fix up user permissions in the user_groups\n";
619 echo "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n";
620 echo "***\n";
621 } else {
622 echo "...user_groups is in current format.\n";
623 }
624
625 }
626
627 function do_all_updates() {
628 global $wgNewTables, $wgNewFields, $wgRenamedTables;
629
630 # Rename tables
631 foreach ( $wgRenamedTables as $tableRecord ) {
632 rename_table( $tableRecord[0], $tableRecord[1], $tableRecord[2] );
633 }
634
635 # Add missing tables
636 foreach ( $wgNewTables as $tableRecord ) {
637 add_table( $tableRecord[0], $tableRecord[1] );
638 flush();
639 }
640
641 # Add missing fields
642 foreach ( $wgNewFields as $fieldRecord ) {
643 add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2] );
644 flush();
645 }
646
647 # Do schema updates which require special handling
648 do_interwiki_update(); flush();
649 do_index_update(); flush();
650 do_old_links_update(); flush();
651 do_image_name_unique_update(); flush();
652 do_watchlist_update(); flush();
653 do_user_update(); flush();
654 ###### do_copy_newtalk_to_watchlist(); flush();
655 do_logging_encoding(); flush();
656
657 do_schema_restructuring(); flush();
658 do_inverse_timestamp(); flush();
659 do_text_id(); flush();
660 do_namespace_size(); flush();
661
662 do_pagelinks_update(); flush();
663
664 do_drop_img_type(); flush();
665
666 do_user_unique_update(); flush();
667 do_user_groups_update(); flush();
668
669 initialiseMessages(); flush();
670 }
671
672 ?>