Phpdoc comments and place holder. Part of the subpackage "maintenance", archives...
[lhc/web/wiklou.git] / maintenance / archives / convertdb.php
1 <?php
2 /**
3 * @deprecated
4 * @package MediaWiki
5 * @subpackage MaintenanceArchive
6 */
7
8 /** */
9 print "This script is obsolete!";
10 print "It is retained in the source here in case some of its
11 code might be useful for ad-hoc conversion tasks, but it is
12 not maintained and probably won't even work as is.";
13 exit();
14
15 # Database conversion (from May 2002 format). Assumes that
16 # the old tables have been loaded into an empty database from
17 # dump files.
18
19 global $IP;
20 require_once( "../LocalSettings.php" );
21 require_once( "../AdminSettings.php" );
22 require_once( "$IP/Setup.php" );
23
24 $wgTitle = Title::newFromText( "Conversion script" );
25 require_once( "./rebuildLinks.inc" );
26 require_once( "./rebuildRecentchanges.inc" );
27 require_once( "./buildTables.inc" );
28 set_time_limit(0);
29
30 $wgDBuser = "wikiadmin";
31 $wgDBpassword = $wgDBadminpassword;
32 # $wgImageDirectory = "/usr/local/apache/htdocs/wikiimages";
33 $wgImageDirectory = "/usr/local/apache/htdocs/upload";
34 $wgMetaImageDirectory = "/usr/local/apache/htdocs-meta/upload";
35
36 renameOldTables();
37 buildTables();
38 initializeTables();
39
40 # convertImageDirectories();
41 convertUserTable();
42 convertOldTable();
43 convertCurTable();
44
45 buildIndexes();
46
47 rebuildLinkTablesPass1();
48 rebuildLinkTablesPass2();
49
50 # This is kinda ugly, could be done cleaner
51 convertImageDirectories();
52 #rebuildLinkTablesPass1();
53 #rebuildLinkTablesPass2();
54 #
55
56 removeOldTables();
57
58 refillRandom();
59 rebuildRecentChangesTable();
60
61 print "Done.\n";
62 exit();
63
64 ########## End of script, beginning of functions.
65
66 function convertUserTable()
67 {
68 $count = 0;
69 print "Converting USER table.\n";
70
71 $sql = "LOCK TABLES old_user READ, user WRITE";
72 $newres = wfQuery( $sql, DB_MASTER );
73
74 $sql = "SELECT user_id,user_name,user_rights,user_password," .
75 "user_email,user_options,user_watch FROM old_user";
76 $oldres = wfQuery( $sql, DB_SLAVE );
77
78 $sql = "DELETE FROM user";
79 $newres = wfQuery( $sql, DB_MASTER );
80
81 $sql = "";
82 while ( $row = mysql_fetch_object( $oldres ) ) {
83 $name = addslashes( fixUserName( $row->user_name ) );
84 if ( "" == $name ) continue; # Don't convert illegal names
85
86 if ( 0 == ( $count % 10 ) ) {
87 if ( 0 != $count ) { $newres = wfQuery( $sql, DB_MASTER ); }
88
89 $sql = "INSERT INTO user (user_id,user_name,user_rights," .
90 "user_password,user_newpassword,user_email,user_options," .
91 "user_watch) VALUES ";
92 } else {
93 $sql .= ",";
94 }
95 $ops = addslashes( fixUserOptions( $row->user_options ) );
96 $rights = addslashes( fixUserRights( $row->user_rights ) );
97 $email = addslashes( $row->user_email );
98 $pwd = addslashes( md5( $row->user_password ) );
99 $watch = addslashes( $row->user_watch );
100
101 $sql .= "({$row->user_id},'{$name}','{$rights}','{$pwd}',''," .
102 "'{$email}','{$ops}','{$watch}')";
103
104 if ( ( ++$count % 1000 ) == 0 ) {
105 print "$count user records processed.\n";
106 }
107 }
108 if ( $sql ) { $newres = wfQuery( $sql, DB_MASTER ); }
109
110 print "$count user records processed.\n";
111 mysql_free_result( $oldres );
112
113 $sql = "UNLOCK TABLES";
114 $newres = wfQuery( $sql, DB_MASTER );
115 }
116
117 # Convert May 2002 version of database into new format.
118 #
119 function convertCurTable()
120 {
121 $count = $countables = 0;
122 print "Converting CUR table.\n";
123
124 $sql = "LOCK TABLES old_cur READ, cur WRITE, site_stats WRITE";
125 $newres = wfQuery( $sql, DB_MASTER );
126
127 $sql = "SELECT cur_id,cur_title,cur_text,cur_comment,cur_user," .
128 "cur_timestamp,cur_minor_edit,cur_restrictions," .
129 "cur_counter,cur_ind_title,cur_user_text FROM old_cur";
130 $oldres = wfQuery( $sql, DB_SLAVE );
131
132 $sql = "DELETE FROM cur";
133 wfQuery( $sql, DB_MASTER );
134
135 $sql = "DELETE FROM site_stats";
136 wfQuery( $sql, DB_MASTER );
137
138 $sql = "";
139 while ( $row = mysql_fetch_object( $oldres ) ) {
140 $nt = Title::newFromDBkey( $row->cur_title );
141 $title = addslashes( $nt->getDBkey() );
142 $ns = $nt->getNamespace();
143 $text = addslashes( convertMediaLinks( $row->cur_text ) );
144
145 $ititle = addslashes( indexTitle( $nt->getText() ) );
146 $itext = addslashes( indexText( $text, $ititle ) );
147
148 $com = addslashes( $row->cur_comment );
149 $cr = addslashes( fixUserRights( $row->cur_restrictions ) );
150 $cut = addslashes( $row->cur_user_text );
151 if ( "" == $cut ) { $cut = "Unknown"; }
152
153 if ( 2 == $row->cur_minor_edit ) { $isnew = 1; }
154 else { $isnew = 0; }
155 if ( 0 != $row->cur_minor_edit ) { $isme = 1; }
156 else { $isme = 0; }
157
158 # $counter = $row->cur_counter;
159 # if ( ! $counter ) { $counter = 0; }
160
161 if ( preg_match( "/^#redirect/i", $text ) ) {
162 $redir = 1;
163 $text = fixRedirect( $text );
164 } else { $redir = 0; }
165
166 $sql = "INSERT INTO cur (cur_id,cur_namespace," .
167 "cur_title,cur_text,cur_comment,cur_user," .
168 "cur_timestamp,cur_minor_edit,cur_is_new," .
169 "cur_restrictions,cur_counter,cur_ind_title," .
170 "cur_ind_text,cur_is_redirect,cur_user_text) VALUES ";
171 $sql .= "({$row->cur_id},{$ns},'{$title}','{$text}'," .
172 "'{$com}',{$row->cur_user},'{$row->cur_timestamp}'," .
173 "{$isme},{$isnew},'{$cr}',0,'{$ititle}','{$itext}'," .
174 "{$redir},'{$cut}')";
175 wfQuery( $sql, DB_MASTER );
176
177 if ( ( ++$count % 1000 ) == 0 ) {
178 print "$count article records processed.\n";
179 }
180 if ( 0 != $ns ) { continue; }
181 if ( 0 != $redir ) { continue; }
182 if ( false === strstr( $text, "," ) ) { continue; }
183 ++$countables;
184 }
185 print "$count article records processed.\n";
186 mysql_free_result( $oldres );
187
188 $sql = "REPLACE INTO site_stats (ss_row_id,ss_total_views," .
189 "ss_total_edits,ss_good_articles) VALUES (1,0,0,{$countables})";
190 wfQuery( $sql, DB_MASTER );
191
192 $sql = "UNLOCK TABLES";
193 $newres = wfQuery( $sql, DB_MASTER );
194 }
195
196 # Convert May 2002 version of database into new format.
197 #
198 function convertOldTable()
199 {
200 $count = 0;
201 print "Converting OLD table.\n";
202
203 $sql = "LOCK TABLES old_old READ, old WRITE";
204 $newres = wfQuery( $sql, DB_MASTER );
205
206 $sql = "SELECT old_id,old_title,old_text,old_comment,old_user," .
207 "old_timestamp,old_minor_edit,old_user_text FROM old_old";
208 $oldres = wfQuery( $sql, DB_SLAVE );
209
210 $sql = "DELETE FROM old";
211 $newres = wfQuery( $sql, DB_MASTER );
212
213 while ( $row = mysql_fetch_object( $oldres ) ) {
214 $nt = Title::newFromDBkey( $row->old_title );
215 $title = addslashes( $nt->getDBkey() );
216 $ns = $nt->getNamespace();
217 #$text = addslashes( convertMediaLinks( $row->old_text ) );
218 # DO NOT convert media links on old versions!!!!!
219 # Old table should always be left intact
220 $text = addslashes($row->old_text);
221
222 $com = addslashes( $row->old_comment );
223 $cut = addslashes( $row->old_user_text );
224 if ( "" == $cut ) { $cut = "Unknown"; }
225
226 if ( 0 != $row->old_minor_edit ) { $isme = 1; }
227 else { $isme = 0; }
228
229 if ( preg_match( "/^#redirect/i", $text ) ) {
230 $redir = 1;
231 $text = fixRedirect( $text );
232 } else { $redir = 0; }
233
234 $sql = "INSERT INTO old (old_id,old_namespace,old_title," .
235 "old_text,old_comment,old_user," .
236 "old_timestamp,old_minor_edit,old_user_text) VALUES ";
237 $sql .= "({$row->old_id},{$ns},'{$title}','{$text}'," .
238 "'{$com}',{$row->old_user},'{$row->old_timestamp}'," .
239 "{$isme},'{$cut}')";
240 wfQuery( $sql, DB_MASTER );
241
242 if ( ( ++$count % 1000 ) == 0 ) {
243 print "$count history records processed.\n";
244 }
245 }
246 print "$count history records processed.\n";
247 mysql_free_result( $oldres );
248
249 $sql = "UNLOCK TABLES";
250 $newres = wfQuery( $sql, DB_MASTER );
251 }
252
253 function convertImageDirectoriesX()
254 {
255 global $wgImageDirectory, $wgMetaImageDirectory, $wgUploadDirectory;
256 $count = 0;
257
258 print "Moving image files.\n";
259 $dir = opendir( $wgImageDirectory ) or die(
260 "Couldn't open directory \"{$wgImageDirectory}\".\n" );
261
262 while ( false !== ( $oname = readdir( $dir ) ) ) {
263 if ( "." == $oname{0} ) continue;
264
265 $nt = Title::newFromText( $oname );
266 $nname = $nt->getDBkey();
267
268 $exts = array( "png", "gif", "jpg", "jpeg", "ogg" );
269 $ext = strrchr( $nname, "." );
270 if ( false === $ext ) { $ext = ""; }
271 else { $ext = strtolower( substr( $ext, 1 ) ); }
272 if ( ! in_array( $ext, $exts ) ) {
273 print "Skipping \"{$oname}\"\n";
274 continue;
275 }
276 $oldumask = umask(0);
277 $hash = md5( $nname );
278 $dest = $wgUploadDirectory . "/" . $hash{0};
279 if ( ! is_dir( $dest ) ) {
280 mkdir( $dest, 0777 ) or die( "Can't create \"{$dest}\".\n" );
281 }
282 $dest .= "/" . substr( $hash, 0, 2 );
283 if ( ! is_dir( $dest ) ) {
284 mkdir( $dest, 0777 ) or die( "Can't create \"{$dest}\".\n" );
285 }
286 umask( $oldumask );
287
288 if ( copy( "{$wgImageDirectory}/{$oname}", "{$dest}/{$nname}" ) ) {
289 ++$count;
290
291 $sql = "DELETE FROM image WHERE img_name='" .
292 addslashes( $nname ) . "'";
293 $res = wfQuery( $sql, DB_MASTER );
294
295 $sql = "INSERT INTO image (img_name,img_timestamp,img_user," .
296 "img_user_text,img_size,img_description) VALUES ('" .
297 addslashes( $nname ) . "','" .
298 date( "YmdHis" ) . "',0,'(Automated conversion)','" .
299 filesize( "{$dest}/{$nname}" ) . "','')";
300 $res = wfQuery( $sql, DB_MASTER );
301 } else {
302 die( "Couldn't copy \"{$oname}\" to \"{$nname}\"\n" );
303 }
304 }
305 print "{$count} images moved.\n";
306 }
307
308 function convertImageDirectories()
309 {
310 global $wgImageDirectory, $wgMetaImageDirectory, $wgUploadDirectory;
311 $count = 0;
312
313
314 $sql = "SELECT DISTINCT il_to FROM imagelinks";
315 $result = wfQuery ( $sql, DB_SLAVE ) ;
316
317 while ( $row = mysql_fetch_object ( $result ) ) {
318 $oname = $row->il_to ;
319 $nname = ucfirst ( $oname ) ;
320
321 $exts = array( "png", "gif", "jpg", "jpeg", "ogg" );
322 $ext = strrchr( $nname, "." );
323 if ( false === $ext ) { $ext = ""; }
324 else { $ext = strtolower( substr( $ext, 1 ) ); }
325 if ( ! in_array( $ext, $exts ) ) {
326 print "Skipping \"{$oname}\"\n";
327 continue;
328 }
329 $oldumask = umask(0);
330 $hash = md5( $nname );
331 $dest = $wgUploadDirectory . "/" . $hash{0};
332 $wgImageDirectoryHash = $wgImageDirectory . "/" . $hash{0} . "/" . substr ( $hash , 0, 2);
333 $wgMetaImageDirectoryHash = $wgMetaImageDirectory . "/" . $hash{0} . "/" . substr( $hash, 0, 2);
334 if ( ! is_dir( $dest ) ) {
335 mkdir( $dest, 0777 ) or die( "Can't create \"{$dest}\".\n" );
336 }
337 $dest .= "/" . substr( $hash, 0, 2 );
338 if ( ! is_dir( $dest ) ) {
339 mkdir( $dest, 0777 ) or die( "Can't create \"{$dest}\".\n" );
340 }
341 umask( $oldumask );
342
343 #echo "Would be copying {$wgImageDirectoryHash}/{$oname} to {$dest}/{$nname}\n";
344 #continue;
345
346 if ( copy( "{$wgImageDirectoryHash}/{$nname}", "{$dest}/{$nname}" )
347 or copy( "{$wgImageDirectory}/{$oname}", "{$dest}/{$nname}" )
348 or copy( "{$wgImageDirectory}/".strtolower($oname), "{$dest}/{$nname}" )
349 or copy( "{$wgMetaImageDirectoryHash}/{$oname}", "{$dest}/{$nname}" )
350 or copy( "{$wgMetaImageDirectory}/{$oname}", "{$dest}/{$nname}" )
351 or copy( "{$wgMetaImageDirectory}/".strtolower($oname), "{$dest}/{$nname}" ) ) {
352 ++$count;
353
354 $sql = "DELETE FROM image WHERE img_name='" .
355 addslashes( $nname ) . "'";
356 $res = wfQuery( $sql, DB_MASTER );
357
358 $sql = "INSERT INTO image (img_name,img_timestamp,img_user," .
359 "img_user_text,img_size,img_description) VALUES ('" .
360 addslashes( $nname ) . "','" .
361 date( "YmdHis" ) . "',0,'(Automated conversion)','" .
362 filesize( "{$dest}/{$nname}" ) . "','')";
363 $res = wfQuery( $sql, DB_MASTER );
364 } else {
365 echo( "Couldn't copy \"{$oname}\" to \"{$nname}\"\n" );
366 }
367 }
368 }
369
370 # Utility functions for the above.
371 #
372 function convertMediaLinks( $text )
373 {
374 global $wgLang;
375 $ins = $wgLang->getNsText( Namespace::getImage() );
376
377 $q = $text;
378 $text = preg_replace(
379 "/(^|[^[])http:\/\/(www.||meta.)wikipedia.(?:com|org)\/upload\/(?:[0-9a-f]\/[0-9a-f][0-9a-f]\/|)" .
380 "([a-zA-Z0-9_:.~\%\-]+)\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)/",
381 "\\1[[{$ins}:\\3.\\4]]", $text );
382 $text = preg_replace(
383 "/(^|[^[])http:\/\/(www.||meta.)wikipedia.(?:com|org)\/images\/uploads\/" .
384 "([a-zA-Z0-9_:.~\%\-]+)\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)/",
385 "\\1[[{$ins}:\\3.\\4]]", $text );
386
387 $text = preg_replace(
388 "/(^|[^[])http:\/\/(www.||meta.)wikipedia.(?:com|org)\/upload\/(?:[0-9a-f]\/[0-9a-f][0-9a-f]\/|)" .
389 "([a-zA-Z0-9_:.~\%\-]+)/", "\\1[[media:\\3]]", $text );
390 $text = preg_replace(
391 "/(^|[^[])http:\/\/(www.||meta.)wikipedia.(?:com|org)\/images\/uploads\/" .
392 "([a-zA-Z0-9_:.~\%\-]+)/", "\\1[[media:\\3]]", $text );
393
394 if ($q != $text) echo "BOOF!"; else echo ".";
395 return $text;
396 }
397
398 function fixRedirect( $text )
399 {
400 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\xA0-\\xff]";
401 $re = "#redirect";
402 if ( preg_match( "/^{$re}\\s*\\[{$tc}+\\]/i", $text ) ) {
403 $text = preg_replace( "/^({$re})\\s*\\[\\s*({$tc}+)\\]/i",
404 "\\1 [[\\2]]", $text, 1 );
405 } else if ( preg_match( "/^{$re}\\s+{$tc}+/i", $text ) ) {
406 $text = preg_replace( "/^({$re})\\s+({$tc}+)/i",
407 "\\1 [[\\2]]", $text, 1 );
408 }
409 return $text;
410 }
411
412 function fixUserOptions( $in )
413 {
414 $s = urldecode( $in );
415 $a = explode( "\n", $s );
416
417 foreach ( $a as $l ) {
418 if ( preg_match( "/^([A-Za-z0-9_]+)=(.*)/", $l, $m ) ) {
419 $ops[$m[1]] = $m[2];
420 }
421 }
422 $nops = array();
423
424 $q = strtolower( $ops["quickBar"] );
425 if ( $q == "none" ) { $q = 0; }
426 else { $q = 1; } # Default to left
427 $nops["quickbar"] = $q;
428
429 if ( $ops["markupNewTopics"] == "inverse" ) {
430 $nops["highlightbroken"] = 1;
431 }
432 $sk = substr( strtolower( $ops["skin"] ), 0, 4 );
433 if ( "star" == $sk ) { $sk = 0; }
434 else if ( "nost" == $sk ) { $sk = 1; }
435 else if ( "colo" == $sk ) { $sk = 2; }
436 else { $sk = 0; }
437 $nops["skin"] = $sk;
438
439 $u = strtolower( $ops["underlineLinks"] );
440 if ( "yes" == $u || "on" == $u ) { $nops["underline"] = 1; }
441 else { $nops["underline"] = 0; }
442
443 $t = ( (int) ($ops["hourDiff"]) );
444 if ( $t < -23 || $t > 23 ) { $t = 0; }
445 if ( 0 != $t ) { $nops["timecorrection"] = $t; }
446
447 $j = strtolower( $ops["justify"] );
448 if ( "yes" == $j || "on" == $j ) { $nops["justify"] = 1; }
449 $n = strtolower( $ops["numberHeadings"] );
450 if ( "yes" == $n || "on" == $n ) { $nops["numberheadings"] = 1; }
451 $h = strtolower( $ops["hideMinor"] );
452 if ( "yes" == $h || "on" == $h ) { $nops["hideminor"] = 1; }
453 $r = strtolower( $ops["rememberPassword"] );
454 if ( "yes" == $r || "on" == $r ) { $nops["rememberpassword"] = 1; }
455 $s = strtolower( $ops["showHover"] );
456 if ( "yes" == $s || "on" == $s ) { $nops["hover"] = 1; }
457
458 $c = $ops["cols"];
459 if ( $c < 20 || c > 200 ) { $nops["cols"] = 80; }
460 else { $nops["cols"] = $c; }
461 $r = $ops["rows"];
462 if ( $r < 5 || $r > 100 ) { $nops["rows"] = 20; }
463 else { $nops["rows"] = $r; }
464 $r = $ops["resultsPerPage"];
465 if ( $r < 3 || $r > 500 ) { $nops["searchlimit"] = 20; }
466 else { $nops["searchlimit"] = $r; }
467 $r = $ops["viewRecentChanges"];
468 if ( $r < 10 || $r > 1000 ) { $nops["rclimit"] = 50; }
469 else { $nops["rclimit"] = $r; }
470 $nops["rcdays"] = 3;
471
472 $a = array();
473 foreach ( $nops as $oname => $oval ) {
474 array_push( $a, "$oname=$oval" );
475 }
476 $s = implode( "\n", $a );
477 return $s;
478 }
479
480 function fixUserRights( $in )
481 {
482 $a = explode( ",", $in );
483 $b = array();
484 foreach ( $a as $r ) {
485 if ( "is_developer" == strtolower( trim( $r ) ) ) {
486 array_push( $b, "developer" );
487 } else if ( "is_sysop" == strtolower( trim( $r ) ) ) {
488 array_push( $b, "sysop" );
489 }
490 }
491 $out = implode( ",", $b );
492 return $out;
493 }
494
495 function fixUserName( $in )
496 {
497 $lc = "-,.()' _0-9A-Za-z\\/:\\xA0-\\xFF";
498 $out = preg_replace( "/[^{$lc}]/", "", $in );
499 $out = ucfirst( trim( str_replace( "_", " ", $out ) ) );
500 return $out;
501 }
502
503 function indexTitle( $in )
504 {
505 $lc = "A-Za-z_'0-9&#;\\x90-\\xFF\\-";
506 $t = preg_replace( "/[^{$lc}]+/", " ", $in );
507 # $t = preg_replace( "/\\b[{$lc}][{$lc}]\\b/", " ", $t );
508 $t = preg_replace( "/\\b[{$lc}]\\b/", " ", $t );
509 $t = preg_replace( "/\\s+/", " ", $t );
510 return $t;
511 }
512
513 function indexText( $text, $ititle )
514 {
515 global $wgLang;
516 $lc = SearchEngine::legalSearchChars() . "&#;";
517
518 $text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
519 " ", strtolower( " " . $text . " " ) ); # Strip HTML markup
520 $text = preg_replace( "/(^|\\n)\\s*==\\s+([^\\n]+)\\s+==\\s/sD",
521 "\\2 \\2 \\2 ", $text ); # Emphasize headings
522
523 # Strip external URLs
524 $uc = "A-Za-z0-9_\\/:.,~%\\-+&;#?!=()@\\xA0-\\xFF";
525 $protos = "http|https|ftp|mailto|news|gopher";
526 $pat = "/(^|[^\\[])({$protos}):[{$uc}]+([^{$uc}]|$)/";
527 $text = preg_replace( $pat, "\\1 \\3", $text );
528
529 $p1 = "/([^\\[])\\[({$protos}):[{$uc}]+]/";
530 $p2 = "/([^\\[])\\[({$protos}):[{$uc}]+\\s+([^\\]]+)]/";
531 $text = preg_replace( $p1, "\\1 ", $text );
532 $text = preg_replace( $p2, "\\1 \\3 ", $text );
533
534 # Internal image links
535 $ins = $wgLang->getNsText( Namespace::getImage() );
536 $pat2 = "/\\[\\[$ins:([{$uc}]+)\\.(gif|png|jpg|jpeg)([^{$uc}])/i";
537 $text = preg_replace( $pat2, " \\1 \\3", $text );
538
539 $text = preg_replace( "/([^{$lc}])([{$lc}]+)]]([a-z]+)/",
540 "\\1\\2 \\2\\3", $text ); # Handle [[game]]s
541
542 # Strip all remaining non-search characters
543 $text = preg_replace( "/[^{$lc}]+/", " ", $text );
544
545 # Handle 's, s'
546 $text = preg_replace( "/([{$lc}]+)'s /", "\\1 \\1's ", $text );
547 $text = preg_replace( "/([{$lc}]+)s' /", "\\1s ", $text );
548
549 # Strip wiki '' and '''
550 $text = preg_replace( "/''[']*/", " ", $text );
551
552 # Strip 1- and 2-letter words
553 # $text = preg_replace( "/\\s[{$lc}][{$lc}]\\s/", " ", $text );
554 # $text = preg_replace( "/\\s[{$lc}][{$lc}]\\s/", " ", $text );
555 $text = preg_replace( "/\\s[{$lc}]\\s/", " ", $text );
556 $text = preg_replace( "/\\s[{$lc}]\\s/", " ", $text );
557
558 return $text;
559 }
560
561 function refillRandom()
562 {
563 $sql = "INSERT INTO random(ra_current,ra_title) SELECT 0,cur_title " .
564 "FROM cur WHERE cur_namespace=0 AND cur_is_redirect=0 " .
565 "ORDER BY RAND() LIMIT 1000";
566 wfQuery( $sql, DB_MASTER, $fname );
567
568 $sql = "UPDATE random SET ra_current=(ra_current+1)";
569 wfQuery( $sql, DB_MASTER, $fname );
570
571 $sql = "DELETE FROM random WHERE ra_current>1";
572 wfQuery( $sql, DB_MASTER, $fname );
573 }
574
575 function renameOldTables()
576 {
577 $sql = "ALTER TABLE user RENAME TO old_user";
578 wfQuery( $sql, DB_MASTER );
579 $sql = "ALTER TABLE cur RENAME TO old_cur";
580 wfQuery( $sql, DB_MASTER );
581 $sql = "ALTER TABLE old RENAME TO old_old";
582 wfQuery( $sql, DB_MASTER );
583 $sql = "DROP TABLE IF EXISTS linked";
584 wfQuery( $sql, DB_MASTER );
585 $sql = "DROP TABLE IF EXISTS unlinked";
586 wfQuery( $sql, DB_MASTER );
587 }
588
589 function removeOldTables()
590 {
591 wfQuery( "DROP TABLE IF EXISTS old_user", DB_MASTER );
592 wfQuery( "DROP TABLE IF EXISTS old_linked", DB_MASTER );
593 wfQuery( "DROP TABLE IF EXISTS old_unlinked", DB_MASTER );
594 wfQuery( "DROP TABLE IF EXISTS old_cur", DB_MASTER );
595 wfQuery( "DROP TABLE IF EXISTS old_old", DB_MASTER );
596 }
597
598 ?>