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