2 # Move "custom messages" from the MediaWiki namespace to the Template namespace
3 # Usage: php moveCustomMessages.php [<lang>] [skipredir]
7 include_once( "commandLine.inc" );
9 if ( @$argv[2] == "1" ) {
12 } elseif ( @$argv[2] == "2" ) {
20 $wgUser = User
::newFromName( "Template namespace initialisation script" );
22 # Compose DB key array
23 global $wgAllMessagesEn;
26 foreach ( $wgAllMessagesEn as $key => $enValue ) {
27 $title = Title
::newFromText( $key );
28 $dbkeys[$title->getDBkey()] = 1;
31 $sql = "SELECT cur_id, cur_title FROM cur WHERE cur_namespace= " . NS_MEDIAWIKI
;
32 $res = wfQuery( $sql, DB_READ
);
34 # Compile target array
36 while ( $row = wfFetchObject( $res ) ) {
37 if ( !array_key_exists( $row->cur_title
, $dbkeys ) ) {
38 $targets[] = $row->cur_title
;
43 # Create redirects from destination to source
45 foreach ( $targets as $partial ) {
47 $nt = Title
::makeTitle( NS_TEMPLATE
, $partial );
48 $ot = Title
::makeTitle( NS_MEDIAWIKI
, $partial );
50 if ( $nt->createRedirect( $ot, "" ) ) {
53 print "not redirected\n";
57 print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n";
64 foreach ( $targets as $partial ) {
65 $ot = Title
::makeTitle( NS_MEDIAWIKI
, $partial );
66 $nt = Title
::makeTitle( NS_TEMPLATE
, $partial );
69 if ( $ot->moveNoAuth( $nt ) === true ) {
75 while ( count( $wgDeferredUpdateList ) ) {
76 $up = array_pop( $wgDeferredUpdateList );