Modification to moveCustomMessages.php to create redirects, related modifications...
[lhc/web/wiklou.git] / maintenance / archives / moveCustomMessages.php
1 <?php
2 # Move "custom messages" from the MediaWiki namespace to the Template namespace
3 # Usage: php moveCustomMessages.php [<lang>] [skipredir]
4
5
6 chdir( ".." );
7 include_once( "commandLine.inc" );
8
9 if ( @$argv[2] == "1" ) {
10 $doRedirects = true;
11 $doMove = false;
12 } elseif ( @$argv[2] == "2" ) {
13 $doRedirects = false;
14 $doMove = true;
15 } else {
16 $doRedirects = true;
17 $doMove = true;
18 }
19
20 $wgUser = User::newFromName( "Template namespace initialisation script" );
21
22 # Compose DB key array
23 global $wgAllMessagesEn;
24 $dbkeys = array();
25
26 foreach ( $wgAllMessagesEn as $key => $enValue ) {
27 $title = Title::newFromText( $key );
28 $dbkeys[$title->getDBkey()] = 1;
29 }
30
31 $sql = "SELECT cur_id, cur_title FROM cur WHERE cur_namespace= " . NS_MEDIAWIKI;
32 $res = wfQuery( $sql, DB_READ );
33
34 # Compile target array
35 $targets = array();
36 while ( $row = wfFetchObject( $res ) ) {
37 if ( !array_key_exists( $row->cur_title, $dbkeys ) ) {
38 $targets[] = $row->cur_title;
39 }
40 }
41 wfFreeResult( $res );
42
43 # Create redirects from destination to source
44 if ( $doRedirects ) {
45 foreach ( $targets as $partial ) {
46 print "$partial...";
47 $nt = Title::makeTitle( NS_TEMPLATE, $partial );
48 $ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
49
50 if ( $nt->createRedirect( $ot, "" ) ) {
51 print "redirected\n";
52 } else {
53 print "not redirected\n";
54 }
55 }
56 if ( $doMove ) {
57 print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n";
58 readconsole();
59 }
60 }
61
62 # Move pages
63 if ( $doMove ) {
64 foreach ( $targets as $partial ) {
65 $ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
66 $nt = Title::makeTitle( NS_TEMPLATE, $partial );
67 print "$partial...";
68
69 if ( $ot->moveNoAuth( $nt ) === true ) {
70 print "moved\n";
71 } else {
72 print "not moved\n";
73 }
74 # Do deferred updates
75 while ( count( $wgDeferredUpdateList ) ) {
76 $up = array_pop( $wgDeferredUpdateList );
77 $up->doUpdate();
78 }
79 }
80 }
81
82 ?>