Add 'right-patrolmarks'
[lhc/web/wiklou.git] / maintenance / updaters.inc
1 <?php
2 /**
3 * @addtogroup Maintenance
4 */
5
6 /** */
7
8 if ( !defined( 'MEDIAWIKI' ) ) {
9 echo "This file is not a valid entry point\n";
10 exit( 1 );
11 }
12
13 require_once 'convertLinks.inc';
14 require_once 'userDupes.inc';
15 require_once 'deleteDefaultMessages.php';
16 # Extension updates
17 require_once( "$IP/includes/Hooks.php" );
18
19 /**
20 * List of update functions to call on a MySQL-based MediaWiki installation,
21 * in sequence. First item is function name, rest are parameters to pass.
22 */
23 $wgMysqlUpdates = array(
24 // 1.2
25 // update_passwords obsolete
26 array( 'add_field', 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ),
27 array( 'add_field', 'ipblocks', 'ipb_expiry', 'patch-ipb_expiry.sql' ),
28 array( 'do_interwiki_update' ),
29 array( 'do_index_update' ),
30 // do_linkscc_update obsolete
31 array( 'add_table', 'hitcounter', 'patch-hitcounter.sql' ),
32 array( 'add_field', 'recentchanges', 'rc_type', 'patch-rc_type.sql' ),
33
34 // 1.3
35 array( 'add_field', 'user', 'user_real_name', 'patch-user-realname.sql' ),
36 array( 'add_table', 'querycache', 'patch-querycache.sql' ),
37 array( 'add_table', 'objectcache', 'patch-objectcache.sql' ),
38 array( 'add_table', 'categorylinks', 'patch-categorylinks.sql' ),
39 // do_linkscc_1_3_update obsolete
40 array( 'do_old_links_update' ),
41 array( 'add_field', 'recentchanges', 'rc_ip', 'patch-rc_ip.sql' ),
42
43 // 1.4
44 array( 'do_image_name_unique_update' ),
45 array( 'add_field', 'recentchanges', 'rc_id', 'patch-rc_id.sql' ),
46 array( 'add_field', 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ),
47 array( 'add_table', 'logging', 'patch-logging.sql' ),
48 // do_user_rights_update obsolete
49 array( 'add_field', 'user', 'user_token', 'patch-user_token.sql' ),
50 // old, old_articleid, patch-remove-old-title-namespace.sql obsolete
51 // user_groups, patch-userlevels.sql obsolete
52 // do_group_update() obsolete
53 array( 'do_watchlist_update' ),
54 array( 'do_user_update' ),
55 // do_copy_newtalk_to_watchlist obsolete
56
57 // 1.5
58 array( 'do_schema_restructuring' ),
59 array( 'add_field', 'logging', 'log_params', 'patch-log_params.sql' ),
60 array( 'check_bin', 'logging', 'log_title', 'patch-logging-title.sql', ),
61 array( 'add_field', 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ),
62 array( 'add_field', 'page', 'page_len', 'patch-page_len.sql' ),
63 array( 'do_inverse_timestamp' ),
64 array( 'do_text_id' ),
65 array( 'add_field', 'revision', 'rev_deleted', 'patch-rev_deleted.sql' ),
66 array( 'add_field', 'image', 'img_width', 'patch-img_width.sql' ),
67 array( 'add_field', 'image', 'img_metadata', 'patch-img_metadata.sql' ),
68 array( 'add_field', 'user', 'user_email_token', 'patch-user_email_token.sql' ),
69 array( 'add_field', 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ),
70 array( 'do_namespace_size' ),
71 array( 'add_field', 'image', 'img_media_type', 'patch-img_media_type.sql' ),
72 array( 'do_pagelinks_update' ),
73 array( 'do_drop_img_type' ),
74 array( 'do_user_unique_update' ),
75 array( 'do_user_groups_update' ),
76 array( 'add_field', 'site_stats', 'ss_total_pages', 'patch-ss_total_articles.sql' ),
77 array( 'add_table', 'user_newtalk', 'patch-usernewtalk2.sql' ),
78 array( 'add_table', 'transcache', 'patch-transcache.sql' ),
79 array( 'add_field', 'interwiki', 'iw_trans', 'patch-interwiki-trans.sql' ),
80 array( 'add_table', 'trackbacks', 'patch-trackbacks.sql' ),
81
82 // 1.6
83 array( 'do_watchlist_null' ),
84 // do_image_index_update obsolete
85 array( 'do_logging_timestamp_index' ),
86 array( 'add_field', 'ipblocks', 'ipb_range_start', 'patch-ipb_range_start.sql' ),
87 array( 'do_page_random_update' ),
88 array( 'add_field', 'user', 'user_registration','patch-user_registration.sql' ),
89 array( 'do_templatelinks_update' ),
90 array( 'add_table', 'externallinks', 'patch-externallinks.sql' ),
91 array( 'add_table', 'job', 'patch-job.sql' ),
92 array( 'add_field', 'site_stats', 'ss_images', 'patch-ss_images.sql' ),
93 array( 'add_table', 'langlinks', 'patch-langlinks.sql' ),
94 array( 'add_table', 'querycache_info', 'patch-querycacheinfo.sql' ),
95 array( 'add_table', 'filearchive', 'patch-filearchive.sql' ),
96 array( 'add_field', 'ipblocks', 'ipb_anon_only', 'patch-ipb_anon_only.sql' ),
97 array( 'do_rc_indices_update' ),
98
99 // 1.9
100 array( 'add_field', 'user', 'user_newpass_time', 'patch-user_newpass_time.sql' ),
101 array( 'add_table', 'redirect', 'patch-redirect.sql' ),
102 array( 'add_table', 'querycachetwo', 'patch-querycachetwo.sql' ),
103 array( 'add_field', 'ipblocks', 'ipb_enable_autoblock', 'patch-ipb_optional_autoblock.sql' ),
104 array( 'do_backlinking_indices_update' ),
105 array( 'add_field', 'recentchanges', 'rc_old_len', 'patch-rc_len.sql' ),
106 array( 'add_field', 'user', 'user_editcount', 'patch-user_editcount.sql' ),
107
108 // 1.10
109 array( 'do_restrictions_update' ),
110 array( 'add_field', 'logging', 'log_id', 'patch-log_id.sql' ),
111 array( 'add_field', 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ),
112 array( 'add_field', 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ),
113 array( 'add_field', 'revision', 'rev_len', 'patch-rev_len.sql' ),
114 array( 'add_field', 'recentchanges', 'rc_deleted', 'patch-rc_deleted.sql' ),
115 array( 'add_field', 'logging', 'log_deleted', 'patch-log_deleted.sql' ),
116 array( 'add_field', 'archive', 'ar_deleted', 'patch-ar_deleted.sql' ),
117 array( 'add_field', 'ipblocks', 'ipb_deleted', 'patch-ipb_deleted.sql' ),
118 array( 'add_field', 'filearchive', 'fa_deleted', 'patch-fa_deleted.sql' ),
119 array( 'add_field', 'archive', 'ar_len', 'patch-ar_len.sql' ),
120
121 // 1.11
122 array( 'add_field', 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ),
123 array( 'do_categorylinks_indices_update' ),
124 array( 'add_field', 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql'),
125 array( 'do_archive_user_index' ),
126 array( 'do_image_user_index' ),
127 array( 'do_oldimage_user_index' ),
128 array( 'add_field', 'archive', 'ar_page_id', 'patch-archive-page_id.sql'),
129 array( 'add_field', 'image', 'img_sha1', 'patch-img_sha1.sql' ),
130
131 // 1.12
132 array( 'add_table', 'protected_titles', 'patch-protected_titles.sql' ),
133
134 // 1.13
135 array( 'add_field', 'ipblocks', 'ipb_by_text', 'patch-ipb_by_text.sql' ),
136 array( 'add_table', 'page_props', 'patch-page_props.sql' ),
137 array( 'add_table', 'updatelog', 'patch-updatelog.sql' ),
138 array( 'add_table', 'category', 'patch-category.sql' ),
139 array( 'do_category_population' ),
140 array( 'add_field', 'archive', 'ar_parent_id', 'patch-ar_parent_id.sql'),
141 array( 'add_field', 'user_newtalk', 'user_last_timestamp', 'patch-user_last_timestamp.sql'),
142 array( 'do_populate_parent_id' ),
143 array( 'check_bin', 'protected_titles', 'pt_title', 'patch-pt_title-encoding.sql', ),
144 array( 'maybe_do_profiling_memory_update' ),
145 );
146
147
148 # For extensions only, should be populated via hooks
149 # $wgDBtype should be checked to specifiy the proper file
150 $wgExtNewTables = array(); // table, dir
151 $wgExtNewFields = array(); // table, column, dir
152 $wgExtPGNewFields = array(); // table, column attributes; for PostgreSQL
153 $wgExtNewIndexes = array(); // table, index, dir
154
155 # Helper function: check if the given key is present in the updatelog table.
156 # Obviously, only use this for updates that occur after the updatelog table was
157 # created!
158 function update_row_exists( $key ) {
159 $dbr = wfGetDB( DB_SLAVE );
160 $row = $dbr->selectRow(
161 'updatelog',
162 '1',
163 array( 'ul_key' => $key ),
164 __FUNCTION__
165 );
166 return (bool)$row;
167 }
168
169 function rename_table( $from, $to, $patch ) {
170 global $wgDatabase;
171 if ( $wgDatabase->tableExists( $from ) ) {
172 if ( $wgDatabase->tableExists( $to ) ) {
173 echo "...can't move table $from to $to, $to already exists.\n";
174 } else {
175 echo "Moving table $from to $to...";
176 dbsource( archive($patch), $wgDatabase );
177 echo "ok\n";
178 }
179 } else {
180 // Source table does not exist
181 // Renames are done before creations, so this is typical for a new installation
182 // Ignore silently
183 }
184 }
185
186 function add_table( $name, $patch, $fullpath=false ) {
187 global $wgDatabase;
188 if ( $wgDatabase->tableExists( $name ) ) {
189 echo "...$name table already exists.\n";
190 } else {
191 echo "Creating $name table...";
192 if( $fullpath ) {
193 dbsource( $patch, $wgDatabase );
194 } else {
195 dbsource( archive($patch), $wgDatabase );
196 }
197 echo "ok\n";
198 }
199 }
200
201 function add_field( $table, $field, $patch, $fullpath=false ) {
202 global $wgDatabase;
203 if ( !$wgDatabase->tableExists( $table ) ) {
204 echo "...$table table does not exist, skipping new field patch\n";
205 } elseif ( $wgDatabase->fieldExists( $table, $field ) ) {
206 echo "...have $field field in $table table.\n";
207 } else {
208 echo "Adding $field field to table $table...";
209 if( $fullpath ) {
210 dbsource( $patch, $wgDatabase );
211 } else {
212 dbsource( archive($patch), $wgDatabase );
213 }
214 echo "ok\n";
215 }
216 }
217
218 function add_index( $table, $index, $patch, $fullpath=false ) {
219 global $wgDatabase;
220 if( $wgDatabase->indexExists( $table, $index ) ) {
221 echo "...$index key already set on $table table.\n";
222 } else {
223 echo "Adding $index key to table $table... ";
224 if( $fullpath ) {
225 dbsource( $patch, $wgDatabase );
226 } else {
227 dbsource( archive($patch), $wgDatabase );
228 }
229 echo "ok\n";
230 }
231 }
232
233 function do_revision_updates() {
234 global $wgSoftwareRevision;
235 if ( $wgSoftwareRevision < 1001 ) {
236 update_passwords();
237 }
238 }
239
240 function update_passwords() {
241 wfDebugDieBacktrace( "This function needs to be updated or removed.\n" );
242
243 global $wgDatabase;
244 $fname = "Update script: update_passwords()";
245 print "\nIt appears that you need to update the user passwords in your\n" .
246 "database. If you have already done this (if you've run this update\n" .
247 "script once before, for example), doing so again will make all your\n" .
248 "user accounts inaccessible, so be sure you only do this once.\n" .
249 "Update user passwords? (yes/no)";
250
251 $resp = readconsole();
252 if ( ! ( "Y" == $resp{0} || "y" == $resp{0} ) ) { return; }
253
254 $sql = "SELECT user_id,user_password FROM user";
255 $source = $wgDatabase->query( $sql, $fname );
256
257 while ( $row = $wgDatabase->fetchObject( $source ) ) {
258 $id = $row->user_id;
259 $oldpass = $row->user_password;
260 $newpass = md5( "{$id}-{$oldpass}" );
261
262 $sql = "UPDATE user SET user_password='{$newpass}' " .
263 "WHERE user_id={$id}";
264 $wgDatabase->query( $sql, $fname );
265 }
266 }
267
268 function do_interwiki_update() {
269 # Check that interwiki table exists; if it doesn't source it
270 global $wgDatabase, $IP;
271 if( $wgDatabase->tableExists( "interwiki" ) ) {
272 echo "...already have interwiki table\n";
273 return true;
274 }
275 echo "Creating interwiki table: ";
276 dbsource( archive("patch-interwiki.sql") );
277 echo "ok\n";
278 echo "Adding default interwiki definitions: ";
279 dbsource( "$IP/maintenance/interwiki.sql" );
280 echo "ok\n";
281 }
282
283 function do_index_update() {
284 # Check that proper indexes are in place
285 global $wgDatabase;
286 $meta = $wgDatabase->fieldInfo( "recentchanges", "rc_timestamp" );
287 if( !$meta->isMultipleKey() ) {
288 echo "Updating indexes to 20031107: ";
289 dbsource( archive("patch-indexes.sql") );
290 echo "ok\n";
291 return true;
292 }
293 echo "...indexes seem up to 20031107 standards\n";
294 return false;
295 }
296
297 function do_image_index_update() {
298 global $wgDatabase;
299
300 $meta = $wgDatabase->fieldInfo( "image", "img_major_mime" );
301 if( !$meta->isMultipleKey() ) {
302 echo "Updating indexes to 20050912: ";
303 dbsource( archive("patch-mimesearch-indexes.sql") );
304 echo "ok\n";
305 return true;
306 }
307 echo "...indexes seem up to 20050912 standards\n";
308 return false;
309 }
310
311 function do_image_name_unique_update() {
312 global $wgDatabase;
313 if( $wgDatabase->indexExists( 'image', 'PRIMARY' ) ) {
314 echo "...image primary key already set.\n";
315 } else {
316 echo "Making img_name the primary key... ";
317 dbsource( archive("patch-image_name_primary.sql"), $wgDatabase );
318 echo "ok\n";
319 }
320 }
321
322 function do_logging_timestamp_index() {
323 global $wgDatabase;
324 if( $wgDatabase->indexExists( 'logging', 'times' ) ) {
325 echo "...timestamp key on logging already exists.\n";
326 } else {
327 echo "Adding timestamp key on logging table... ";
328 dbsource( archive("patch-logging-times-index.sql"), $wgDatabase );
329 echo "ok\n";
330 }
331 }
332
333 function do_archive_user_index() {
334 global $wgDatabase;
335 if( $wgDatabase->indexExists( 'archive', 'usertext_timestamp' ) ) {
336 echo "...usertext,timestamp key on archive already exists.\n";
337 } else {
338 echo "Adding usertext,timestamp key on archive table... ";
339 dbsource( archive("patch-archive-user-index.sql"), $wgDatabase );
340 echo "ok\n";
341 }
342 }
343
344 function do_image_user_index() {
345 global $wgDatabase;
346 if( $wgDatabase->indexExists( 'image', 'img_usertext_timestamp' ) ) {
347 echo "...usertext,timestamp key on image already exists.\n";
348 } else {
349 echo "Adding usertext,timestamp key on image table... ";
350 dbsource( archive("patch-image-user-index.sql"), $wgDatabase );
351 echo "ok\n";
352 }
353 }
354
355 function do_oldimage_user_index() {
356 global $wgDatabase;
357 if( $wgDatabase->indexExists( 'oldimage', 'oi_usertext_timestamp' ) ) {
358 echo "...usertext,timestamp key on oldimage already exists.\n";
359 } else {
360 echo "Adding usertext,timestamp key on oldimage table... ";
361 dbsource( archive("patch-oldimage-user-index.sql"), $wgDatabase );
362 echo "ok\n";
363 }
364 }
365
366 function do_watchlist_update() {
367 global $wgDatabase;
368 $fname = 'do_watchlist_update';
369 if( $wgDatabase->fieldExists( 'watchlist', 'wl_notificationtimestamp' ) ) {
370 echo "The watchlist table is already set up for email notification.\n";
371 } else {
372 echo "Adding wl_notificationtimestamp field for email notification management.";
373 /* ALTER TABLE watchlist ADD (wl_notificationtimestamp varchar(14) binary NOT NULL default '0'); */
374 dbsource( archive( 'patch-email-notification.sql' ), $wgDatabase );
375 echo "ok\n";
376 }
377 # Check if we need to add talk page rows to the watchlist
378 $talk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'wl_namespace & 1', $fname );
379 $nontalk = $wgDatabase->selectField( 'watchlist', 'count(*)', 'NOT (wl_namespace & 1)', $fname );
380 if ( $talk != $nontalk ) {
381 echo "Adding missing watchlist talk page rows... ";
382 flush();
383
384 $wgDatabase->insertSelect( 'watchlist', 'watchlist',
385 array(
386 'wl_user' => 'wl_user',
387 'wl_namespace' => 'wl_namespace | 1',
388 'wl_title' => 'wl_title',
389 'wl_notificationtimestamp' => 'wl_notificationtimestamp'
390 ), array( 'NOT (wl_namespace & 1)' ), $fname, 'IGNORE' );
391 echo "ok\n";
392 } else {
393 echo "...watchlist talk page rows already present\n";
394 }
395 }
396
397 function do_copy_newtalk_to_watchlist() {
398 global $wgDatabase;
399 global $wgCommandLineMode; # this needs to be saved while getID() and getName() are called
400
401 $res = $wgDatabase->safeQuery( 'SELECT user_id, user_ip FROM !',
402 $wgDatabase->tableName( 'user_newtalk' ) );
403 $num_newtalks=$wgDatabase->numRows($res);
404 echo "Now converting ".$num_newtalks." user_newtalk entries to watchlist table entries ... \n";
405
406 $user = new User();
407 for ( $i = 1; $i <= $num_newtalks; $i++ ) {
408 $wluser = $wgDatabase->fetchObject( $res );
409 if ($wluser->user_id == 0) { # anonymous users ... have IP numbers as "names"
410 if ($user->isIP($wluser->user_ip)) { # do only if it really looks like an IP number (double checked)
411 $wgDatabase->replace( 'watchlist',
412 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )),
413 array('wl_user' => 0,
414 'wl_namespace' => NS_USER_TALK,
415 'wl_title' => $wluser->user_ip,
416 'wl_notificationtimestamp' => '19700101000000'
417 ), 'updaters.inc::do_watchlist_update2'
418 );
419 }
420 } else { # normal users ... have user_ids
421 $user->setID($wluser->user_id);
422 $wgDatabase->replace( 'watchlist',
423 array(array('wl_user','wl_namespace', 'wl_title', 'wl_notificationtimestamp' )),
424 array('wl_user' => $user->getID(),
425 'wl_namespace' => NS_USER_TALK,
426 'wl_title' => $user->getName(),
427 'wl_notificationtimestamp' => '19700101000000'
428 ), 'updaters.inc::do_watchlist_update3'
429 );
430 }
431 }
432 echo "Done.\n";
433 }
434
435
436 function do_user_update() {
437 global $wgDatabase;
438 if( $wgDatabase->fieldExists( 'user', 'user_emailauthenticationtimestamp' ) ) {
439 echo "User table contains old email authentication field. Dropping... ";
440 dbsource( archive( 'patch-email-authentication.sql' ), $wgDatabase );
441 echo "ok\n";
442 } else {
443 echo "...user table does not contain old email authentication field.\n";
444 }
445 }
446
447 /**
448 * 1.4 betas were missing the 'binary' marker from logging.log_title,
449 * which causes a collation mismatch error on joins in MySQL 4.1.
450 */
451 function check_bin( $table, $field, $patchFile ) {
452 global $wgDatabase, $wgDBtype;
453 if ($wgDBtype != 'mysql')
454 return;
455 $tableName = $wgDatabase->tableName( $table );
456 $res = $wgDatabase->query( "SELECT $field FROM $tableName LIMIT 0" );
457 $flags = explode( ' ', mysql_field_flags( $res->result, 0 ) );
458 $wgDatabase->freeResult( $res );
459
460 if( in_array( 'binary', $flags ) ) {
461 echo "$table table has correct $field encoding.\n";
462 } else {
463 echo "Fixing $field encoding on $table table... ";
464 dbsource( archive( $patchFile ), $wgDatabase );
465 echo "ok\n";
466 }
467 }
468
469 function do_schema_restructuring() {
470 global $wgDatabase;
471 $fname="do_schema_restructuring";
472 if ( $wgDatabase->tableExists( 'page' ) ) {
473 echo "...page table already exists.\n";
474 } else {
475 echo "...converting from cur/old to page/revision/text DB structure.\n"; flush();
476 echo wfTimestamp( TS_DB );
477 echo "......checking for duplicate entries.\n"; flush();
478
479 list ($cur, $old, $page, $revision, $text) = $wgDatabase->tableNamesN( 'cur', 'old', 'page', 'revision', 'text' );
480
481 $rows = $wgDatabase->query( "SELECT cur_title, cur_namespace, COUNT(cur_namespace) AS c
482 FROM $cur GROUP BY cur_title, cur_namespace HAVING c>1", $fname );
483
484 if ( $wgDatabase->numRows( $rows ) > 0 ) {
485 echo wfTimestamp( TS_DB );
486 echo "......<b>Found duplicate entries</b>\n";
487 echo ( sprintf( "<b> %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
488 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
489 if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
490 $duplicate[$row->cur_namespace] = array();
491 }
492 $duplicate[$row->cur_namespace][] = $row->cur_title;
493 echo ( sprintf( " %-60s %3s %5s\n", $row->cur_title, $row->cur_namespace, $row->c ) );
494 }
495 $sql = "SELECT cur_title, cur_namespace, cur_id, cur_timestamp FROM $cur WHERE ";
496 $firstCond = true;
497 foreach ( $duplicate as $ns => $titles ) {
498 if ( $firstCond ) {
499 $firstCond = false;
500 } else {
501 $sql .= ' OR ';
502 }
503 $sql .= "( cur_namespace = {$ns} AND cur_title in (";
504 $first = true;
505 foreach ( $titles as $t ) {
506 if ( $first ) {
507 $sql .= $wgDatabase->addQuotes( $t );
508 $first = false;
509 } else {
510 $sql .= ', ' . $wgDatabase->addQuotes( $t );
511 }
512 }
513 $sql .= ") ) \n";
514 }
515 # By sorting descending, the most recent entry will be the first in the list.
516 # All following entries will be deleted by the next while-loop.
517 $sql .= 'ORDER BY cur_namespace, cur_title, cur_timestamp DESC';
518
519 $rows = $wgDatabase->query( $sql, $fname );
520
521 $prev_title = $prev_namespace = false;
522 $deleteId = array();
523
524 while ( $row = $wgDatabase->fetchObject( $rows ) ) {
525 if ( $prev_title == $row->cur_title && $prev_namespace == $row->cur_namespace ) {
526 $deleteId[] = $row->cur_id;
527 }
528 $prev_title = $row->cur_title;
529 $prev_namespace = $row->cur_namespace;
530 }
531 $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
532 $rows = $wgDatabase->query( $sql, $fname );
533 echo wfTimestamp( TS_DB );
534 echo "......<b>Deleted</b> ".$wgDatabase->affectedRows()." records.\n";
535 }
536
537
538 echo wfTimestamp( TS_DB );
539 echo "......Creating tables.\n";
540 $wgDatabase->query("CREATE TABLE $page (
541 page_id int(8) unsigned NOT NULL auto_increment,
542 page_namespace int NOT NULL,
543 page_title varchar(255) binary NOT NULL,
544 page_restrictions tinyblob NOT NULL,
545 page_counter bigint(20) unsigned NOT NULL default '0',
546 page_is_redirect tinyint(1) unsigned NOT NULL default '0',
547 page_is_new tinyint(1) unsigned NOT NULL default '0',
548 page_random real unsigned NOT NULL,
549 page_touched char(14) binary NOT NULL default '',
550 page_latest int(8) unsigned NOT NULL,
551 page_len int(8) unsigned NOT NULL,
552
553 PRIMARY KEY page_id (page_id),
554 UNIQUE INDEX name_title (page_namespace,page_title),
555 INDEX (page_random),
556 INDEX (page_len)
557 ) TYPE=InnoDB", $fname );
558 $wgDatabase->query("CREATE TABLE $revision (
559 rev_id int(8) unsigned NOT NULL auto_increment,
560 rev_page int(8) unsigned NOT NULL,
561 rev_comment tinyblob NOT NULL,
562 rev_user int(5) unsigned NOT NULL default '0',
563 rev_user_text varchar(255) binary NOT NULL default '',
564 rev_timestamp char(14) binary NOT NULL default '',
565 rev_minor_edit tinyint(1) unsigned NOT NULL default '0',
566 rev_deleted tinyint(1) unsigned NOT NULL default '0',
567 rev_len int(8) unsigned,
568 rev_parent_id int(8) unsigned default NULL,
569 PRIMARY KEY rev_page_id (rev_page, rev_id),
570 UNIQUE INDEX rev_id (rev_id),
571 INDEX rev_timestamp (rev_timestamp),
572 INDEX page_timestamp (rev_page,rev_timestamp),
573 INDEX user_timestamp (rev_user,rev_timestamp),
574 INDEX usertext_timestamp (rev_user_text,rev_timestamp)
575 ) TYPE=InnoDB", $fname );
576
577 echo wfTimestamp( TS_DB );
578 echo "......Locking tables.\n";
579 $wgDatabase->query( "LOCK TABLES $page WRITE, $revision WRITE, $old WRITE, $cur WRITE", $fname );
580
581 $maxold = intval( $wgDatabase->selectField( 'old', 'max(old_id)', '', $fname ) );
582 echo wfTimestamp( TS_DB );
583 echo "......maxold is {$maxold}\n";
584
585 echo wfTimestamp( TS_DB );
586 global $wgLegacySchemaConversion;
587 if( $wgLegacySchemaConversion ) {
588 // Create HistoryBlobCurStub entries.
589 // Text will be pulled from the leftover 'cur' table at runtime.
590 echo "......Moving metadata from cur; using blob references to text in cur table.\n";
591 $cur_text = "concat('O:18:\"historyblobcurstub\":1:{s:6:\"mCurId\";i:',cur_id,';}')";
592 $cur_flags = "'object'";
593 } else {
594 // Copy all cur text in immediately: this may take longer but avoids
595 // having to keep an extra table around.
596 echo "......Moving text from cur.\n";
597 $cur_text = 'cur_text';
598 $cur_flags = "''";
599 }
600 $wgDatabase->query( "INSERT INTO $old (old_namespace, old_title, old_text, old_comment, old_user, old_user_text,
601 old_timestamp, old_minor_edit, old_flags)
602 SELECT cur_namespace, cur_title, $cur_text, cur_comment, cur_user, cur_user_text, cur_timestamp, cur_minor_edit, $cur_flags
603 FROM $cur", $fname );
604
605 echo wfTimestamp( TS_DB );
606 echo "......Setting up revision table.\n";
607 $wgDatabase->query( "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text, rev_timestamp,
608 rev_minor_edit)
609 SELECT old_id, cur_id, old_comment, old_user, old_user_text,
610 old_timestamp, old_minor_edit
611 FROM $old,$cur WHERE old_namespace=cur_namespace AND old_title=cur_title", $fname );
612
613 echo wfTimestamp( TS_DB );
614 echo "......Setting up page table.\n";
615 $wgDatabase->query( "INSERT INTO $page (page_id, page_namespace, page_title, page_restrictions, page_counter,
616 page_is_redirect, page_is_new, page_random, page_touched, page_latest, page_len)
617 SELECT cur_id, cur_namespace, cur_title, cur_restrictions, cur_counter, cur_is_redirect, cur_is_new,
618 cur_random, cur_touched, rev_id, LENGTH(cur_text)
619 FROM $cur,$revision
620 WHERE cur_id=rev_page AND rev_timestamp=cur_timestamp AND rev_id > {$maxold}", $fname );
621
622 echo wfTimestamp( TS_DB );
623 echo "......Unlocking tables.\n";
624 $wgDatabase->query( "UNLOCK TABLES", $fname );
625
626 echo wfTimestamp( TS_DB );
627 echo "......Renaming old.\n";
628 $wgDatabase->query( "ALTER TABLE $old RENAME TO $text", $fname );
629
630 echo wfTimestamp( TS_DB );
631 echo "...done.\n";
632 }
633 }
634
635 function do_inverse_timestamp() {
636 global $wgDatabase;
637 if( $wgDatabase->fieldExists( 'revision', 'inverse_timestamp' ) ) {
638 echo "Removing revision.inverse_timestamp and fixing indexes... ";
639 dbsource( archive( 'patch-inverse_timestamp.sql' ), $wgDatabase );
640 echo "ok\n";
641 } else {
642 echo "revision timestamp indexes already up to 2005-03-13\n";
643 }
644 }
645
646 function do_text_id() {
647 global $wgDatabase;
648 if( $wgDatabase->fieldExists( 'revision', 'rev_text_id' ) ) {
649 echo "...rev_text_id already in place.\n";
650 } else {
651 echo "Adding rev_text_id field... ";
652 dbsource( archive( 'patch-rev_text_id.sql' ), $wgDatabase );
653 echo "ok\n";
654 }
655 }
656
657 function do_namespace_size() {
658 $tables = array(
659 'page' => 'page',
660 'archive' => 'ar',
661 'recentchanges' => 'rc',
662 'watchlist' => 'wl',
663 'querycache' => 'qc',
664 'logging' => 'log',
665 );
666 foreach( $tables as $table => $prefix ) {
667 do_namespace_size_on( $table, $prefix );
668 flush();
669 }
670 }
671
672 function do_namespace_size_on( $table, $prefix ) {
673 global $wgDatabase, $wgDBtype;
674 if ($wgDBtype != 'mysql')
675 return;
676 $field = $prefix . '_namespace';
677
678 $tablename = $wgDatabase->tableName( $table );
679 $result = $wgDatabase->query( "SHOW COLUMNS FROM $tablename LIKE '$field'" );
680 $info = $wgDatabase->fetchObject( $result );
681 $wgDatabase->freeResult( $result );
682
683 if( substr( $info->Type, 0, 3 ) == 'int' ) {
684 echo "...$field is already a full int ($info->Type).\n";
685 } else {
686 echo "Promoting $field from $info->Type to int... ";
687
688 $sql = "ALTER TABLE $tablename MODIFY $field int NOT NULL";
689 $wgDatabase->query( $sql );
690
691 echo "ok\n";
692 }
693 }
694
695 function do_pagelinks_update() {
696 global $wgDatabase;
697 if( $wgDatabase->tableExists( 'pagelinks' ) ) {
698 echo "...already have pagelinks table.\n";
699 } else {
700 echo "Converting links and brokenlinks tables to pagelinks... ";
701 dbsource( archive( 'patch-pagelinks.sql' ), $wgDatabase );
702 echo "ok\n";
703 flush();
704
705 global $wgCanonicalNamespaceNames;
706 foreach( $wgCanonicalNamespaceNames as $ns => $name ) {
707 if( $ns != 0 ) {
708 do_pagelinks_namespace( $ns );
709 }
710 }
711 }
712 }
713
714 function do_pagelinks_namespace( $namespace ) {
715 global $wgDatabase, $wgContLang;
716
717 $ns = intval( $namespace );
718 echo "Cleaning up broken links for namespace $ns... ";
719
720 $pagelinks = $wgDatabase->tableName( 'pagelinks' );
721 $name = $wgContLang->getNsText( $ns );
722 $prefix = $wgDatabase->strencode( $name );
723 $likeprefix = str_replace( '_', '\\_', $prefix);
724
725 $sql = "UPDATE $pagelinks
726 SET pl_namespace=$ns,
727 pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
728 WHERE pl_namespace=0
729 AND pl_title LIKE '$likeprefix:%'";
730
731 $wgDatabase->query( $sql, 'do_pagelinks_namespace' );
732 echo "ok\n";
733 }
734
735 function do_drop_img_type() {
736 global $wgDatabase;
737
738 if( $wgDatabase->fieldExists( 'image', 'img_type' ) ) {
739 echo "Dropping unused img_type field in image table... ";
740 dbsource( archive( 'patch-drop_img_type.sql' ), $wgDatabase );
741 echo "ok\n";
742 } else {
743 echo "No img_type field in image table; Good.\n";
744 }
745 }
746
747 function do_old_links_update() {
748 global $wgDatabase;
749 if( $wgDatabase->tableExists( 'pagelinks' ) ) {
750 echo "Already have pagelinks; skipping old links table updates.\n";
751 } else {
752 convertLinks(); flush();
753 }
754 }
755
756 function do_user_unique_update() {
757 global $wgDatabase;
758 $duper = new UserDupes( $wgDatabase );
759 if( $duper->hasUniqueIndex() ) {
760 echo "Already have unique user_name index.\n";
761 } else {
762 if( !$duper->clearDupes() ) {
763 echo "WARNING: This next step will probably fail due to unfixed duplicates...\n";
764 }
765 echo "Adding unique index on user_name... ";
766 dbsource( archive( 'patch-user_nameindex.sql' ), $wgDatabase );
767 echo "ok\n";
768 }
769 }
770
771 function do_user_groups_update() {
772 $fname = 'do_user_groups_update';
773 global $wgDatabase;
774
775 if( $wgDatabase->tableExists( 'user_groups' ) ) {
776 echo "...user_groups table already exists.\n";
777 return do_user_groups_reformat();
778 }
779
780 echo "Adding user_groups table... ";
781 dbsource( archive( 'patch-user_groups.sql' ), $wgDatabase );
782 echo "ok\n";
783
784 if( !$wgDatabase->tableExists( 'user_rights' ) ) {
785 if( $wgDatabase->fieldExists( 'user', 'user_rights' ) ) {
786 echo "Upgrading from a 1.3 or older database? Breaking out user_rights for conversion...";
787 dbsource( archive( 'patch-user_rights.sql' ), $wgDatabase );
788 echo "ok\n";
789 } else {
790 echo "*** WARNING: couldn't locate user_rights table or field for upgrade.\n";
791 echo "*** You may need to manually configure some sysops by manipulating\n";
792 echo "*** the user_groups table.\n";
793 return;
794 }
795 }
796
797 echo "Converting user_rights table to user_groups... ";
798 $result = $wgDatabase->select( 'user_rights',
799 array( 'ur_user', 'ur_rights' ),
800 array( "ur_rights != ''" ),
801 $fname );
802
803 while( $row = $wgDatabase->fetchObject( $result ) ) {
804 $groups = array_unique(
805 array_map( 'trim',
806 explode( ',', $row->ur_rights ) ) );
807
808 foreach( $groups as $group ) {
809 $wgDatabase->insert( 'user_groups',
810 array(
811 'ug_user' => $row->ur_user,
812 'ug_group' => $group ),
813 $fname );
814 }
815 }
816 $wgDatabase->freeResult( $result );
817 echo "ok\n";
818 }
819
820 function do_user_groups_reformat() {
821 # Check for bogus formats from previous 1.5 alpha code.
822 global $wgDatabase;
823 $info = $wgDatabase->fieldInfo( 'user_groups', 'ug_group' );
824
825 if( $info->type() == 'int' ) {
826 $oldug = $wgDatabase->tableName( 'user_groups' );
827 $newug = $wgDatabase->tableName( 'user_groups_bogus' );
828 echo "user_groups is in bogus intermediate format. Renaming to $newug... ";
829 $wgDatabase->query( "ALTER TABLE $oldug RENAME TO $newug" );
830 echo "ok\n";
831
832 echo "Re-adding fresh user_groups table... ";
833 dbsource( archive( 'patch-user_groups.sql' ), $wgDatabase );
834 echo "ok\n";
835
836 echo "***\n";
837 echo "*** WARNING: You will need to manually fix up user permissions in the user_groups\n";
838 echo "*** table. Old 1.5 alpha versions did some pretty funky stuff...\n";
839 echo "***\n";
840 } else {
841 echo "...user_groups is in current format.\n";
842 }
843
844 }
845
846 function do_watchlist_null() {
847 # Make sure wl_notificationtimestamp can be NULL,
848 # and update old broken items.
849 global $wgDatabase;
850 $info = $wgDatabase->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
851
852 if( !$info->nullable() ) {
853 echo "Making wl_notificationtimestamp nullable... ";
854 dbsource( archive( 'patch-watchlist-null.sql' ), $wgDatabase );
855 echo "ok\n";
856 } else {
857 echo "...wl_notificationtimestamp is already nullable.\n";
858 }
859
860 }
861
862 /**
863 * @bug 3946
864 */
865 function do_page_random_update() {
866 global $wgDatabase;
867
868 echo "Setting page_random to a random value on rows where it equals 0...";
869
870 $page = $wgDatabase->tableName( 'page' );
871 $wgDatabase->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", 'do_page_random_update' );
872 $rows = $wgDatabase->affectedRows();
873
874 echo "changed $rows rows\n";
875 }
876
877 function do_templatelinks_update() {
878 global $wgDatabase, $wgLoadBalancer;
879 $fname = 'do_templatelinks_update';
880
881 if ( $wgDatabase->tableExists( 'templatelinks' ) ) {
882 echo "...templatelinks table already exists\n";
883 return;
884 }
885 echo "Creating templatelinks table...\n";
886 dbsource( archive('patch-templatelinks.sql'), $wgDatabase );
887 echo "Populating...\n";
888 if ( isset( $wgLoadBalancer ) && $wgLoadBalancer->getServerCount() > 1 ) {
889 // Slow, replication-friendly update
890 $res = $wgDatabase->select( 'pagelinks', array( 'pl_from', 'pl_namespace', 'pl_title' ),
891 array( 'pl_namespace' => NS_TEMPLATE ), $fname );
892 $count = 0;
893 while ( $row = $wgDatabase->fetchObject( $res ) ) {
894 $count = ($count + 1) % 100;
895 if ( $count == 0 ) {
896 if ( function_exists( 'wfWaitForSlaves' ) ) {
897 wfWaitForSlaves( 10 );
898 } else {
899 sleep( 1 );
900 }
901 }
902 $wgDatabase->insert( 'templatelinks',
903 array(
904 'tl_from' => $row->pl_from,
905 'tl_namespace' => $row->pl_namespace,
906 'tl_title' => $row->pl_title,
907 ), $fname
908 );
909
910 }
911 $wgDatabase->freeResult( $res );
912 } else {
913 // Fast update
914 $wgDatabase->insertSelect( 'templatelinks', 'pagelinks',
915 array(
916 'tl_from' => 'pl_from',
917 'tl_namespace' => 'pl_namespace',
918 'tl_title' => 'pl_title'
919 ), array(
920 'pl_namespace' => 10
921 ), $fname
922 );
923 }
924 echo "Done. Please run maintenance/refreshLinks.php for a more thorough templatelinks update.\n";
925 }
926
927 // Add index on ( rc_namespace, rc_user_text ) [Jul. 2006]
928 // Add index on ( rc_user_text, rc_timestamp ) [Nov. 2006]
929 function do_rc_indices_update() {
930 global $wgDatabase;
931 echo( "Checking for additional recent changes indices...\n" );
932
933 $indexes = array(
934 'rc_ns_usertext' => 'patch-recentchanges-utindex.sql',
935 'rc_user_text' => 'patch-rc_user_text-index.sql',
936 );
937
938 foreach( $indexes as $index => $patch ) {
939 $info = $wgDatabase->indexInfo( 'recentchanges', $index, __METHOD__ );
940 if( !$info ) {
941 echo( "...index `{$index}` not found; adding..." );
942 dbsource( archive( $patch ) );
943 echo( "done.\n" );
944 } else {
945 echo( "...index `{$index}` seems ok.\n" );
946 }
947 }
948 }
949
950 function index_has_field($table, $index, $field) {
951 global $wgDatabase;
952 echo( "Checking if $table index $index includes field $field...\n" );
953 $info = $wgDatabase->indexInfo( $table, $index, __METHOD__ );
954 if( $info ) {
955 foreach($info as $row) {
956 if($row->Column_name == $field) {
957 echo( "...index $index on table $table seems to be ok\n" );
958 return true;
959 }
960 }
961 }
962 echo( "...index $index on table $table has no field $field; adding\n" );
963 return false;
964 }
965
966 function do_backlinking_indices_update() {
967 echo( "Checking for backlinking indices...\n" );
968 if (!index_has_field('pagelinks', 'pl_namespace', 'pl_from') ||
969 !index_has_field('templatelinks', 'tl_namespace', 'tl_from') ||
970 !index_has_field('imagelinks', 'il_to', 'il_from'))
971 {
972 dbsource( archive( 'patch-backlinkindexes.sql' ) );
973 }
974 }
975
976 function do_categorylinks_indices_update() {
977 echo( "Checking for categorylinks indices...\n" );
978 if (!index_has_field('categorylinks', 'cl_sortkey', 'cl_from'))
979 {
980 dbsource( archive( 'patch-categorylinksindex.sql' ) );
981 }
982 }
983
984 function maybe_do_profiling_memory_update() {
985 global $wgDatabase;
986 if ( !$wgDatabase->tableExists( 'profiling' ) ) {
987 // Simply ignore
988 } elseif ( $wgDatabase->fieldExists( 'profiling', 'pf_memory' ) ) {
989 echo "profiling table has pf_memory field.\n";
990 } else {
991 echo "Adding pf_memory field to table profiling...";
992 dbsource( archive( 'patch-profiling-memory.sql' ), $wgDatabase );
993 echo "ok\n";
994 }
995 }
996
997 function do_stats_init() {
998 // Sometimes site_stats table is not properly populated.
999 global $wgDatabase;
1000 echo "Checking site_stats row...";
1001 $row = $wgDatabase->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
1002 if( $row === false ) {
1003 echo "data is missing! rebuilding...\n";
1004
1005 global $IP;
1006 require_once "$IP/maintenance/initStats.inc";
1007 wfInitStats();
1008 } else {
1009 echo "ok.\n";
1010 }
1011 }
1012
1013 function purge_cache() {
1014 global $wgDatabase;
1015 # We can't guarantee that the user will be able to use TRUNCATE,
1016 # but we know that DELETE is available to us
1017 echo( "Purging caches..." );
1018 $wgDatabase->delete( 'objectcache', '*', __METHOD__ );
1019 echo( "done.\n" );
1020 }
1021
1022 function do_all_updates( $shared = false, $purge = true ) {
1023 global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase, $wgDBtype, $IP;
1024
1025 wfRunHooks('LoadExtensionSchemaUpdates');
1026
1027 $doUser = !$wgSharedDB || $shared;
1028
1029 if ($wgDBtype === 'postgres') {
1030 do_postgres_updates();
1031 return;
1032 }
1033
1034 # Run core updates in sequence...
1035 global $wgMysqlUpdates;
1036 foreach( $wgMysqlUpdates as $params ) {
1037 $func = array_shift( $params );
1038 call_user_func_array( $func, $params );
1039 flush();
1040 }
1041
1042 /// @fixme clean up this mess too!
1043 global $wgExtNewTables, $wgExtNewFields, $wgExtNewIndexes;
1044 # Add missing extension tables
1045 foreach ( $wgExtNewTables as $tableRecord ) {
1046 add_table( $tableRecord[0], $tableRecord[1], true );
1047 flush();
1048 }
1049 # Add missing extension fields
1050 foreach ( $wgExtNewFields as $fieldRecord ) {
1051 if ( $fieldRecord[0] != 'user' || $doUser ) {
1052 add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
1053 }
1054 flush();
1055 }
1056 # Add missing extension indexes
1057 foreach ( $wgExtNewIndexes as $fieldRecord ) {
1058 add_index( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
1059 flush();
1060 }
1061
1062
1063 echo "Deleting old default messages (this may take a long time!)..."; flush();
1064 deleteDefaultMessages();
1065 echo "Done\n"; flush();
1066
1067 do_stats_init(); flush();
1068
1069 if( $purge ) {
1070 purge_cache();
1071 flush();
1072 }
1073 }
1074
1075 function archive($name) {
1076 global $wgDBtype, $IP;
1077 switch ($wgDBtype) {
1078 case "postgres":
1079 return "$IP/maintenance/postgres/archives/$name";
1080 default:
1081 return "$IP/maintenance/archives/$name";
1082 }
1083 }
1084
1085 function do_restrictions_update() {
1086 # Adding page_restrictions table, obsoleting page.page_restrictions.
1087 # Migrating old restrictions to new table
1088 # -- Andrew Garrett, January 2007.
1089
1090 global $wgDatabase;
1091
1092 $name = 'page_restrictions';
1093 $patch = 'patch-page_restrictions.sql';
1094 $patch2 = 'patch-page_restrictions_sortkey.sql';
1095
1096 if ( $wgDatabase->tableExists( $name ) ) {
1097 echo "...$name table already exists.\n";
1098 } else {
1099 echo "Creating $name table...";
1100 dbsource( archive($patch), $wgDatabase );
1101 dbsource( archive($patch2), $wgDatabase );
1102 echo "ok\n";
1103
1104 echo "Migrating old restrictions to new table...";
1105
1106 $res = $wgDatabase->select( 'page', array( 'page_id', 'page_restrictions' ), array("page_restrictions!=''", "page_restrictions!='edit=:move='"), __METHOD__ );
1107
1108 $count = 0;
1109
1110 while ($row = $wgDatabase->fetchObject($res) ) {
1111 $count = ($count + 1) % 100;
1112
1113 if ($count == 0) {
1114 if ( function_exists( 'wfWaitForSlaves' ) ) {
1115 wfWaitForSlaves( 10 );
1116 } else {
1117 sleep( 1 );
1118 }
1119 }
1120
1121 # Figure out what the restrictions are..
1122 $id = $row->page_id;
1123 $flatrestrictions = explode( ':', $row->page_restrictions );
1124
1125 $restrictions = array ();
1126 foreach( $flatrestrictions as $restriction ) {
1127 $thisrestriction = explode( '=', $restriction, 2 );
1128 if( count( $thisrestriction ) == 1 ) {
1129 // Compatibility with old protections from before
1130 // separate move protection was added.
1131 list( $level ) = $thisrestriction;
1132 if( $level ) {
1133 $restrictions['edit'] = $level;
1134 $restrictions['move'] = $level;
1135 }
1136 } else {
1137 list( $type, $level ) = $thisrestriction;
1138 if( $level ) {
1139 $restrictions[$type] = $level;
1140 }
1141 }
1142
1143 $wgDatabase->update( 'page', array ( 'page_restrictions' => ''), array( 'page_id' => $id ), __METHOD__ );
1144
1145 }
1146
1147 foreach( $restrictions as $type => $level ) {
1148 $wgDatabase->insert( 'page_restrictions', array ( 'pr_page' => $id,
1149 'pr_type' => $type,
1150 'pr_level' => $level,
1151 'pr_cascade' => 0,
1152 'pr_expiry' => 'infinity' ),
1153 __METHOD__ );
1154 }
1155 }
1156 print "ok\n";
1157 }
1158 }
1159
1160 function do_category_population() {
1161 if( update_row_exists( 'populate category' ) ) {
1162 echo "...category table already populated.\n";
1163 return;
1164 }
1165 require_once( 'populateCategory.inc' );
1166 echo "Populating category table, printing progress markers. ".
1167 "For large databases, you\n".
1168 "may want to hit Ctrl-C and do this manually with maintenance/\n".
1169 "populateCategory.php.\n";
1170 populateCategory( '', 10, 0, true );
1171 echo "Done populating category table.\n";
1172 }
1173
1174 function do_populate_parent_id() {
1175 if( update_row_exists( 'populate rev_parent_id' ) ) {
1176 echo "...rev_parent_id column already populated.\n";
1177 return;
1178 }
1179 require_once( 'populateParentId.inc' );
1180
1181 global $wgDatabase;
1182 populate_rev_parent_id( $wgDatabase );
1183 }
1184
1185 function
1186 pg_describe_table($table)
1187 {
1188 global $wgDatabase, $wgDBmwschema;
1189 $q = <<<END
1190 SELECT attname, attnum FROM pg_namespace, pg_class, pg_attribute
1191 WHERE pg_class.relnamespace = pg_namespace.oid
1192 AND attrelid=pg_class.oid AND attnum > 0
1193 AND relname=%s AND nspname=%s
1194 END;
1195 $res = $wgDatabase->query(sprintf($q,
1196 $wgDatabase->addQuotes($table),
1197 $wgDatabase->addQuotes($wgDBmwschema)));
1198 if (!$res)
1199 return null;
1200
1201 $cols = array();
1202 while ($r = $wgDatabase->fetchRow($res)) {
1203 $cols[] = array(
1204 "name" => $r[0],
1205 "ord" => $r[1],
1206 );
1207 }
1208 return $cols;
1209 }
1210
1211 function
1212 pg_describe_index($idx)
1213 {
1214 global $wgDatabase, $wgDBmwschema;
1215
1216 // first fetch the key (which is a list of columns ords) and
1217 // the table the index applies to (an oid)
1218 $q = <<<END
1219 SELECT indkey, indrelid FROM pg_namespace, pg_class, pg_index
1220 WHERE nspname=%s
1221 AND pg_class.relnamespace = pg_namespace.oid
1222 AND relname=%s
1223 AND indexrelid=pg_class.oid
1224 END;
1225 $res = $wgDatabase->query(sprintf($q,
1226 $wgDatabase->addQuotes($wgDBmwschema),
1227 $wgDatabase->addQuotes($idx)));
1228 if (!$res)
1229 return null;
1230 if (!($r = $wgDatabase->fetchRow($res))) {
1231 $wgDatabase->freeResult($res);
1232 return null;
1233 }
1234
1235 $indkey = $r[0];
1236 $relid = intval($r[1]);
1237 $indkeys = explode(" ", $indkey);
1238 $wgDatabase->freeResult($res);
1239
1240 $colnames = array();
1241 foreach ($indkeys as $rid) {
1242 $query = <<<END
1243 SELECT attname FROM pg_class, pg_attribute
1244 WHERE attrelid=$relid
1245 AND attnum=%d
1246 AND attrelid=pg_class.oid
1247 END;
1248 $r2 = $wgDatabase->query(sprintf($query, $rid));
1249 if (!$r2)
1250 return null;
1251 if (!($row2 = $wgDatabase->fetchRow($r2))) {
1252 $wgDatabase->freeResult($r2);
1253 return null;
1254 }
1255 $colnames[] = $row2[0];
1256 $wgDatabase->freeResult($r2);
1257 }
1258
1259 return $colnames;
1260 }
1261
1262 function
1263 pg_index_exists($table, $index)
1264 {
1265 global $wgDatabase, $wgDBmwschema;
1266 $exists = $wgDatabase->selectField("pg_indexes", "indexname",
1267 array( "indexname" => $index,
1268 "tablename" => $table,
1269 "schemaname" => $wgDBmwschema));
1270 return $exists === $index;
1271 }
1272
1273 function
1274 pg_fkey_deltype($fkey)
1275 {
1276 global $wgDatabase, $wgDBmwschema;
1277 $q = <<<END
1278 SELECT confdeltype FROM pg_constraint, pg_namespace
1279 WHERE connamespace=pg_namespace.oid
1280 AND nspname=%s
1281 AND conname=%s;
1282 END;
1283 $r = $wgDatabase->query(sprintf($q,
1284 $wgDatabase->addQuotes($wgDBmwschema),
1285 $wgDatabase->addQuotes($fkey)));
1286 if (!($row = $wgDatabase->fetchRow($r)))
1287 return null;
1288 return $row[0];
1289 }
1290
1291 function
1292 pg_rule_def($table, $rule)
1293 {
1294 global $wgDatabase, $wgDBmwschema;
1295 $q = <<<END
1296 SELECT definition FROM pg_rules
1297 WHERE schemaname = %s
1298 AND tablename = %s
1299 AND rulename = %s
1300 END;
1301 $r = $wgDatabase->query(sprintf($q,
1302 $wgDatabase->addQuotes($wgDBmwschema),
1303 $wgDatabase->addQuotes($table),
1304 $wgDatabase->addQuotes($rule)));
1305 $row = $wgDatabase->fetchRow($r);
1306 if (!$row)
1307 return null;
1308 $d = $row[0];
1309 $wgDatabase->freeResult($r);
1310 return $d;
1311 }
1312
1313 function do_postgres_updates() {
1314 global $wgDatabase, $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgShowExceptionDetails, $wgDBuser;
1315
1316 ## Gather version numbers in case we need them
1317 $version = $wgDatabase->getServerVersion(); ## long string
1318 $numver = $wgDatabase->numeric_version; ## X.Y e.g. 8.3
1319
1320 $wgShowExceptionDetails = 1;
1321
1322 # Just in case their LocalSettings.php does not have this:
1323 if ( !isset( $wgDBmwschema ))
1324 $wgDBmwschema = 'mediawiki';
1325
1326 # Verify that this user is configured correctly
1327 $safeuser = $wgDatabase->addQuotes($wgDBuser);
1328 $SQL = "SELECT array_to_string(useconfig,'*') FROM pg_catalog.pg_user WHERE usename = $safeuser";
1329 $config = pg_fetch_result( $wgDatabase->doQuery( $SQL ), 0, 0 );
1330 $conf = array();
1331 foreach( explode( '*', $config ) as $c ) {
1332 list( $x,$y ) = explode( '=', $c );
1333 $conf[$x] = $y;
1334 }
1335 if( !array_key_exists( 'search_path', $conf ) ) {
1336 $search_path = '';
1337 }
1338 else {
1339 $search_path = $conf['search_path'];
1340 }
1341 if( strpos( $search_path, $wgDBmwschema ) === false ) {
1342 echo "Adding in schema \"$wgDBmwschema\" to search_path for user \"$wgDBuser\"\n";
1343 $search_path = "$wgDBmwschema, $search_path";
1344 }
1345 if( strpos( $search_path, $wgDBts2schema ) === false ) {
1346 echo "Adding in schema \"$wgDBts2schema\" to search_path for user \"$wgDBuser\"\n";
1347 $search_path = "$search_path, $wgDBts2schema";
1348 }
1349 if( array_key_exists( 'search_path', $conf ) === false || $search_path != $conf['search_path'] ) {
1350 $wgDatabase->doQuery( "ALTER USER $wgDBuser SET search_path = $search_path" );
1351 $wgDatabase->doQuery( "SET search_path = $search_path" );
1352 }
1353 else {
1354 $path = $conf['search_path'];
1355 echo "... search_path for user \"$wgDBuser\" looks correct ($path)\n";
1356 }
1357 $goodconf = array(
1358 'client_min_messages' => 'error',
1359 'DateStyle' => 'ISO, YMD',
1360 'TimeZone' => 'GMT'
1361 );
1362 foreach( array_keys( $goodconf ) AS $key ) {
1363 $value = $goodconf[$key];
1364 if( !array_key_exists( $key, $conf ) or $conf[$key] !== $value ) {
1365 echo "Setting $key to '$value' for user \"$wgDBuser\"\n";
1366 $wgDatabase->doQuery( "ALTER USER $wgDBuser SET $key = '$value'" );
1367 $wgDatabase->doQuery( "SET $key = '$value'" );
1368 }
1369 else {
1370 echo "... default value of \"$key\" is correctly set to \"$value\" for user \"$wgDBuser\"\n";
1371 }
1372 }
1373
1374 $newsequences = array(
1375 "log_log_id_seq",
1376 "pr_id_val",
1377 );
1378
1379 $newtables = array(
1380 array("category", "patch-category.sql"),
1381 array("mediawiki_version", "patch-mediawiki_version.sql"),
1382 array("mwuser", "patch-mwuser.sql"),
1383 array("pagecontent", "patch-pagecontent.sql"),
1384 array("querycachetwo", "patch-querycachetwo.sql"),
1385 array("page_props", "patch-page_props.sql"),
1386 array("page_restrictions", "patch-page_restrictions.sql"),
1387 array("profiling", "patch-profiling.sql"),
1388 array("protected_titles", "patch-protected_titles.sql"),
1389 array("redirect", "patch-redirect.sql"),
1390 array("updatelog", "patch-updatelog.sql"),
1391 );
1392
1393 $newcols = array(
1394 array("archive", "ar_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1395 array("archive", "ar_len", "INTEGER"),
1396 array("archive", "ar_page_id", "INTEGER"),
1397 array("archive", "ar_parent_id", "INTEGER"),
1398 array("image", "img_sha1", "TEXT NOT NULL DEFAULT ''"),
1399 array("ipblocks", "ipb_anon_only", "CHAR NOT NULL DEFAULT '0'"),
1400 array("ipblocks", "ipb_by_text", "TEXT NOT NULL DEFAULT ''"),
1401 array("ipblocks", "ipb_block_email", "CHAR NOT NULL DEFAULT '0'"),
1402 array("ipblocks", "ipb_create_account", "CHAR NOT NULL DEFAULT '1'"),
1403 array("ipblocks", "ipb_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1404 array("ipblocks", "ipb_enable_autoblock", "CHAR NOT NULL DEFAULT '1'"),
1405 array("filearchive", "fa_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1406 array("logging", "log_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1407 array("logging", "log_id", "INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('log_log_id_seq')"),
1408 array("logging", "log_params", "TEXT"),
1409 array("mwuser", "user_editcount", "INTEGER"),
1410 array("mwuser", "user_newpass_time", "TIMESTAMPTZ"),
1411 array("oldimage", "oi_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1412 array("oldimage", "oi_metadata", "BYTEA NOT NULL DEFAULT ''"),
1413 array("oldimage", "oi_media_type", "TEXT"),
1414 array("oldimage", "oi_major_mime", "TEXT NOT NULL DEFAULT 'unknown'"),
1415 array("oldimage", "oi_minor_mime", "TEXT NOT NULL DEFAULT 'unknown'"),
1416 array("oldimage", "oi_sha1", "TEXT NOT NULL DEFAULT ''"),
1417 array("page_restrictions", "pr_id", "INTEGER NOT NULL UNIQUE DEFAULT nextval('pr_id_val')"),
1418 array("profiling", "pf_memory", "NUMERIC(18,10) NOT NULL DEFAULT 0"),
1419 array("recentchanges", "rc_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1420 array("recentchanges", "rc_log_action", "TEXT"),
1421 array("recentchanges", "rc_log_type", "TEXT"),
1422 array("recentchanges", "rc_logid", "INTEGER NOT NULL DEFAULT 0"),
1423 array("recentchanges", "rc_new_len", "INTEGER"),
1424 array("recentchanges", "rc_old_len", "INTEGER"),
1425 array("recentchanges", "rc_params", "TEXT"),
1426 array("revision", "rev_len", "INTEGER"),
1427 array("revision", "rev_deleted", "SMALLINT NOT NULL DEFAULT 0"),
1428 array("user_newtalk", "user_last_timestamp", "TIMESTAMPTZ"),
1429 );
1430
1431
1432 # table, column, desired type, USING clause if needed (with new default if needed)
1433 $typechanges = array(
1434 array("archive", "ar_deleted", "smallint", ""),
1435 array("archive", "ar_minor_edit", "smallint", "ar_minor_edit::smallint DEFAULT 0"),
1436 array("filearchive", "fa_deleted", "smallint", ""),
1437 array("filearchive", "fa_height", "integer", ""),
1438 array("filearchive", "fa_metadata", "bytea", "decode(fa_metadata,'escape')"),
1439 array("filearchive", "fa_size", "integer", ""),
1440 array("filearchive", "fa_width", "integer", ""),
1441 array("filearchive", "fa_storage_group","text", ""),
1442 array("filearchive", "fa_storage_key", "text", ""),
1443 array("image", "img_metadata", "bytea", "decode(img_metadata,'escape')"),
1444 array("image", "img_size", "integer", ""),
1445 array("image", "img_width", "integer", ""),
1446 array("image", "img_height", "integer", ""),
1447 array("interwiki", "iw_local", "smallint", "iw_local::smallint DEFAULT 0"),
1448 array("interwiki", "iw_trans", "smallint", "iw_trans::smallint DEFAULT 0"),
1449 array("ipblocks", "ipb_auto", "smallint", "ipb_auto::smallint DEFAULT 0"),
1450 array("ipblocks", "ipb_anon_only", "smallint", "ipb_anon_only::smallint DEFAULT 0"),
1451 array("ipblocks", "ipb_create_account", "smallint", "ipb_create_account::smallint DEFAULT 1"),
1452 array("ipblocks", "ipb_enable_autoblock", "smallint", "ipb_enable_autoblock::smallint DEFAULT 1"),
1453 array("ipblocks", "ipb_block_email", "smallint", "ipb_block_email::smallint DEFAULT 0"),
1454 array("ipblocks", "ipb_address", "text", "ipb_address::text"),
1455 array("ipblocks", "ipb_deleted", "smallint", "ipb_deleted::smallint"),
1456 array("math", "math_inputhash", "bytea", "decode(math_inputhash,'escape')"),
1457 array("math", "math_outputhash", "bytea", "decode(math_outputhash,'escape')"),
1458 array("mwuser", "user_token", "text", ""),
1459 array("mwuser", "user_email_token","text", ""),
1460 array("objectcache", "keyname", "text", ""),
1461 array("oldimage", "oi_height", "integer", ""),
1462 array("oldimage", "oi_size", "integer", ""),
1463 array("oldimage", "oi_width", "integer", ""),
1464 array("page", "page_is_redirect","smallint", "page_is_redirect::smallint DEFAULT 0"),
1465 array("page", "page_is_new", "smallint", "page_is_new::smallint DEFAULT 0"),
1466 array("querycache", "qc_value", "integer", ""),
1467 array("querycachetwo","qcc_value", "integer", ""),
1468 array("recentchanges","rc_bot", "smallint", "rc_bot::smallint DEFAULT 0"),
1469 array("recentchanges","rc_deleted", "smallint", ""),
1470 array("recentchanges","rc_minor", "smallint", "rc_minor::smallint DEFAULT 0"),
1471 array("recentchanges","rc_new", "smallint", "rc_new::smallint DEFAULT 0"),
1472 array("recentchanges","rc_type", "smallint", "rc_type::smallint DEFAULT 0"),
1473 array("recentchanges","rc_patrolled", "smallint", "rc_patrolled::smallint DEFAULT 0"),
1474 array("revision", "rev_minor_edit", "smallint", "rev_minor_edit::smallint DEFAULT 0"),
1475 array("templatelinks","tl_namespace", "smallint", "tl_namespace::smallint"),
1476 array("user_newtalk", "user_ip", "text", "host(user_ip)"),
1477 );
1478
1479 $newindexes = array(
1480 array("archive", "archive_user_text", "(ar_user_text)"),
1481 array("image", "img_sha1", "(img_sha1)"),
1482 array("oldimage", "oi_sha1", "(oi_sha1)"),
1483 array("revision", "rev_text_id_idx", "(rev_text_id)"),
1484 );
1485
1486 $newrules = array(
1487 );
1488
1489 foreach ($newsequences as $ns) {
1490 if ($wgDatabase->sequenceExists($ns)) {
1491 echo "... sequence \"$ns\" already exists\n";
1492 continue;
1493 }
1494
1495 echo "Creating sequence \"$ns\"\n";
1496 $wgDatabase->query("CREATE SEQUENCE $ns");
1497 }
1498
1499 foreach ($newtables as $nt) {
1500 if ($wgDatabase->tableExists($nt[0])) {
1501 echo "... table \"$nt[0]\" already exists\n";
1502 continue;
1503 }
1504
1505 echo "Creating table \"$nt[0]\"\n";
1506 dbsource(archive($nt[1]));
1507 }
1508
1509 ## Needed before newcols
1510 if ($wgDatabase->tableExists("archive2")) {
1511 echo "Converting \"archive2\" back to normal archive table\n";
1512 if ($wgDatabase->ruleExists("archive", "archive_insert")) {
1513 echo "Dropping rule \"archive_insert\"\n";
1514 $wgDatabase->query("DROP RULE archive_insert ON archive");
1515 }
1516 if ($wgDatabase->ruleExists("archive", "archive_delete")) {
1517 echo "Dropping rule \"archive_delete\"\n";
1518 $wgDatabase->query("DROP RULE archive_delete ON archive");
1519 }
1520 dbsource(archive("patch-remove-archive2.sql"));
1521 }
1522 else
1523 echo "... obsolete table \"archive2\" does not exist\n";
1524
1525 foreach ($newcols as $nc) {
1526 $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
1527 if (!is_null($fi)) {
1528 echo "... column \"$nc[0].$nc[1]\" already exists\n";
1529 continue;
1530 }
1531
1532 echo "Adding column \"$nc[0].$nc[1]\"\n";
1533 $wgDatabase->query("ALTER TABLE $nc[0] ADD $nc[1] $nc[2]");
1534 }
1535
1536 foreach ($typechanges as $tc) {
1537 $fi = $wgDatabase->fieldInfo($tc[0], $tc[1]);
1538 if (is_null($fi)) {
1539 echo "... error: expected column $tc[0].$tc[1] to exist\n";
1540 exit(1);
1541 }
1542
1543 if ($fi->type() === $tc[2])
1544 echo "... column \"$tc[0].$tc[1]\" is already of type \"$tc[2]\"\n";
1545 else {
1546 echo "Changing column type of \"$tc[0].$tc[1]\" from \"{$fi->type()}\" to \"$tc[2]\"\n";
1547 $sql = "ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2]";
1548 if (strlen($tc[3])) {
1549 $default = array();
1550 if (preg_match( '/DEFAULT (.+)/', $tc[3], $default)) {
1551 $sqldef = "ALTER TABLE $tc[0] ALTER $tc[1] SET DEFAULT $default[1]";
1552 $wgDatabase->query($sqldef);
1553 $tc[3] = preg_replace( '/\s*DEFAULT .+/', '', $tc[3]);
1554 }
1555 $sql .= " USING $tc[3]";
1556 }
1557 $sql .= ";\nCOMMIT;\n";
1558 $wgDatabase->query($sql);
1559 }
1560 }
1561
1562 if ($wgDatabase->fieldInfo('oldimage','oi_deleted')->type() !== 'smallint') {
1563 echo "Changing \"oldimage.oi_deleted\" to type \"smallint\"\n";
1564 $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted DROP DEFAULT" );
1565 $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted TYPE SMALLINT USING (oi_deleted::smallint)" );
1566 $wgDatabase->query( "ALTER TABLE oldimage ALTER oi_deleted SET DEFAULT 0" );
1567 }
1568 else
1569 echo "... column \"oldimage.oi_deleted\" is already of type \"smallint\"\n";
1570
1571
1572 foreach ($newindexes as $ni) {
1573 if (pg_index_exists($ni[0], $ni[1])) {
1574 echo "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n";
1575 continue;
1576 }
1577 echo "Creating index \"$ni[1]\" on table \"$ni[0]\" $ni[2]\n";
1578 $wgDatabase->query( "CREATE INDEX $ni[1] ON $ni[0] $ni[2]" );
1579 }
1580
1581 foreach ($newrules as $nr) {
1582 if ($wgDatabase->ruleExists($nr[0], $nr[1])) {
1583 echo "... rule \"$nr[1]\" on table \"$nr[0]\" already exists\n";
1584 continue;
1585 }
1586 echo "Adding rule \"$nr[1]\" to table \"$nr[0]\"\n";
1587 dbsource(archive($nr[2]));
1588 }
1589
1590 if ($wgDatabase->hasConstraint("oldimage_oi_name_fkey")) {
1591 echo "Making foriegn key on table \"oldimage\" (to image) a cascade delete\n";
1592 $wgDatabase->query( "ALTER TABLE oldimage DROP CONSTRAINT oldimage_oi_name_fkey" );
1593 $wgDatabase->query( "ALTER TABLE oldimage ADD CONSTRAINT oldimage_oi_name_fkey_cascade ".
1594 "FOREIGN KEY (oi_name) REFERENCES image(img_name) ON DELETE CASCADE" );
1595 }
1596 else
1597 echo "... table \"oldimage\" has correct cascade delete foreign key to image\n";
1598
1599 if (!$wgDatabase->triggerExists("page", "page_deleted")) {
1600 echo "Adding function and trigger \"page_deleted\" to table \"page\"\n";
1601 dbsource(archive('patch-page_deleted.sql'));
1602 }
1603 else
1604 echo "... table \"page\" has \"page_deleted\" trigger\n";
1605
1606 $fi = $wgDatabase->fieldInfo("recentchanges", "rc_cur_id");
1607 if (!$fi->nullable()) {
1608 echo "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n";
1609 dbsource(archive('patch-rc_cur_id-not-null.sql'));
1610 }
1611 else
1612 echo "... column \"recentchanges.rc_cur_id\" has a NOT NULL constraint\n";
1613
1614 $pu = pg_describe_index("pagelink_unique");
1615 if (!is_null($pu) && ($pu[0] != "pl_from" || $pu[1] != "pl_namespace" || $pu[2] != "pl_title")) {
1616 echo "Dropping obsolete version of index \"pagelink_unique index\"\n";
1617 $wgDatabase->query("DROP INDEX pagelink_unique");
1618 $pu = null;
1619 }
1620 else
1621 echo "... obsolete version of index \"pagelink_unique index\" does not exist\n";
1622
1623 if (is_null($pu)) {
1624 echo "Creating index \"pagelink_unique index\"\n";
1625 $wgDatabase->query("CREATE UNIQUE INDEX pagelink_unique ON pagelinks (pl_from,pl_namespace,pl_title)");
1626 }
1627 else
1628 echo "... index \"pagelink_unique_index\" aready exists\n";
1629
1630 if (pg_fkey_deltype("revision_rev_user_fkey") == 'r') {
1631 echo "... constraint \"revision_rev_user_fkey\" is ON DELETE RESTRICT\n";
1632 }
1633 else {
1634 echo "Changing constraint \"revision_rev_user_fkey\" to ON DELETE RESTRICT\n";
1635 dbsource(archive('patch-revision_rev_user_fkey.sql'));
1636 }
1637
1638 global $wgExtNewTables, $wgExtPGNewFields, $wgExtNewIndexes;
1639 # Add missing extension tables
1640 foreach ( $wgExtNewTables as $nt ) {
1641 if ($wgDatabase->tableExists($nt[0])) {
1642 echo "... table \"$nt[0]\" already exists\n";
1643 continue;
1644 }
1645 echo "Creating table \"$nt[0]\"\n";
1646 dbsource($nt[1]);
1647 }
1648 # Add missing extension fields
1649 foreach ( $wgExtPGNewFields as $nc ) {
1650 $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
1651 if (!is_null($fi)) {
1652 echo "... column \"$nc[0].$nc[1]\" already exists\n";
1653 continue;
1654 }
1655 echo "Adding column \"$nc[0].$nc[1]\"\n";
1656 $wgDatabase->query( "ALTER TABLE $nc[0] ADD $nc[1] $nc[2]" );
1657 }
1658 # Add missing extension indexes
1659 foreach ( $wgExtNewIndexes as $ni ) {
1660 if (pg_index_exists($ni[0], $ni[1])) {
1661 echo "... index \"$ni[1]\" on table \"$ni[0]\" already exists\n";
1662 continue;
1663 }
1664 echo "Creating index \"$ni[1]\" on table \"$ni[0]\"\n";
1665 dbsource($ni[2]);
1666 }
1667
1668 # Tweak the page_title tsearch2 trigger to filter out slashes
1669 # This is create or replace, so harmless to call if not needed
1670 dbsource(archive('patch-ts2pagetitle.sql'));
1671
1672 ## If the server is 8.3 or higher, rewrite teh tsearch2 triggers
1673 ## in case they have the old 'default' versions
1674 if ( $numver >= 8.3 )
1675 dbsource(archive('patch-tsearch2funcs.sql'));
1676
1677 return;
1678 }