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