3 function moveCustomMessages( $phase ) {
4 global $wgUser, $wgAllMessagesEn, $wgDeferredUpdateList, $wgLang ;
6 $wgUser->setLoaded( true ); # Don't load from DB
7 $wgUser->setName( "Template namespace initialisation script" );
8 $wgUser->addRight( "bot" );
10 # Compose DB key array
13 foreach ( $wgAllMessagesEn as $key => $enValue ) {
14 $title = Title::newFromText( $key );
15 $dbkeys[$title->getDBkey()] = 1;
18 $sql = "SELECT cur_id, cur_title FROM cur WHERE cur_namespace= " . NS_MEDIAWIKI;
19 $res = wfQuery( $sql, DB_READ );
21 # Compile target array
23 while ( $row = wfFetchObject( $res ) ) {
24 if ( !array_key_exists( $row->cur_title, $dbkeys ) ) {
25 $targets[$row->cur_title] = 1;
30 # Create redirects from destination to source
31 if ( $phase == 0 || $phase == 1 ) {
32 foreach ( $targets as $partial => $dummy ) {
34 $nt = Title::makeTitle( NS_TEMPLATE, $partial );
35 $ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
37 if ( $nt->createRedirect( $ot, "" ) ) {
40 print "not redirected\n";
44 print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n";
50 if ( $phase == 0 || $phase == 2 ) {
52 foreach ( $targets as $partial => $dummy ) {
53 $ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
54 $nt = Title::makeTitle( NS_TEMPLATE, $partial );
57 if ( $ot->moveNoAuth( $nt ) === true ) {
63 while ( count( $wgDeferredUpdateList ) ) {
64 $up = array_pop( $wgDeferredUpdateList );
71 if ( $phase == 0 || $phase == 3 ) {
75 $options = ParserOptions::newFromUser( $wgUser );
76 $completedTitles = array();
77 $titleChars = Title::legalChars();
78 $mediaWiki = $wgLang->getNsText( NS_MEDIAWIKI );
79 $template = $wgLang->getNsText( NS_TEMPLATE );
80 $linkRegex = "/\[\[$mediaWiki:([$titleChars]*?)\]\]/";
81 $msgRegex = "/{{msg:([$titleChars]*?)}}/";
83 foreach ( $targets as $partial => $dummy ) {
84 $dest = Title::makeTitle( NS_TEMPLATE, $partial );
85 $linksTo = $dest->getLinksTo();
86 foreach( $linksTo as $source ) {
87 $pdbk = $source->getPrefixedDBkey();
89 if ( !array_key_exists( $pdbk, $completedTitles ) ) {
90 $completedTitles[$pdbk] = 1;
91 $id = $source->getArticleID();
92 $row = wfGetArray( 'cur', array( 'cur_text' ),
93 array( 'cur_id' => $source->getArticleID() ) );
94 $parser->startExternalParse( $source, $options, OT_WIKI );
95 $text = $parser->strip( $row->cur_text, $stripState, false );
97 $text = preg_replace( $msgRegex, "{{\$1}}", $text );
98 # [[MediaWiki:]] -> [[Template:]]
99 $text = preg_replace_callback( $linkRegex, "wfReplaceMediaWiki", $text );
100 $text = $parser->unstrip( $text, $stripState );
101 if ( $text != $row->cur_text ) {
102 wfUpdateArray( 'cur', array( 'cur_text' => $text ), array( 'cur_id' => $id ) );
105 print "not modified\n";
114 #--------------------------------------------------------------------------------------------------------------
115 function wfReplaceMediaWiki( $m ) {
116 global $targets, $template, $replaceCount;
117 $title = Title::newFromText( $m[1] );
118 $partial = $title->getDBkey();
120 if ( array_key_exists( $partial, $targets ) ) {
121 $text = "[[$template:{$m[1]}]]";