From b1a944009dd51eb8ee7c0bb573964551c0234ea1 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 23 Mar 2004 12:05:40 +0000 Subject: [PATCH] Modification to moveCustomMessages.php to create redirects, related modifications in other files --- includes/Title.php | 44 ++++++++++++++ maintenance/archives/moveCustomMessages.php | 63 ++++++++++++++++----- maintenance/commandLine.inc | 2 +- 3 files changed, 95 insertions(+), 14 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 3de57d4924..86a3f7d240 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1043,5 +1043,49 @@ class Title { # Return true if there was no history return $row === false; } + + # Create a redirect, fails if the title already exists, does not notify RC + # Returns success + function createRedirect( $dest, $comment ) { + global $wgUser; + if ( $this->getArticleID() ) { + return false; + } + + $now = wfTimestampNow(); + $won = wfInvertTimestamp( $now ); + + wfInsertArray( 'cur', array( + 'cur_namespace' => $this->getNamespace(), + 'cur_title' => $this->getDBkey(), + 'cur_comment' => $comment, + 'cur_user' => $wgUser->getID(), + 'cur_user_text' => $wgUser->getName(), + 'cur_timestamp' => $now, + 'inverse_timestamp' => $won, + 'cur_touched' => $now, + 'cur_is_redirect' => 1, + 'cur_is_new' => 1, + 'cur_text' => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n" + )); + $newid = wfInsertId(); + $this->resetArticleID( $newid ); + + # Link table + if ( $dest->getArticleID() ) { + wfInsertArray( 'links', array( + 'l_to' => $dest->getArticleID(), + 'l_from' => $newid + )); + } else { + wfInsertArray( 'brokenlinks', array( + 'bl_to' => $dest->getPrefixedDBkey(), + 'bl_from' => $newid + )); + } + + Article::onArticleCreate( $this ); + return true; + } } ?> diff --git a/maintenance/archives/moveCustomMessages.php b/maintenance/archives/moveCustomMessages.php index 02c2421f6c..e87ae2cfb3 100644 --- a/maintenance/archives/moveCustomMessages.php +++ b/maintenance/archives/moveCustomMessages.php @@ -1,45 +1,82 @@ ] [skipredir] + chdir( ".." ); include_once( "commandLine.inc" ); +if ( @$argv[2] == "1" ) { + $doRedirects = true; + $doMove = false; +} elseif ( @$argv[2] == "2" ) { + $doRedirects = false; + $doMove = true; +} else { + $doRedirects = true; + $doMove = true; +} + +$wgUser = User::newFromName( "Template namespace initialisation script" ); + # Compose DB key array global $wgAllMessagesEn; $dbkeys = array(); -foreach ( $wgAllMessagesEn as $key => $enValue ) -{ +foreach ( $wgAllMessagesEn as $key => $enValue ) { $title = Title::newFromText( $key ); $dbkeys[$title->getDBkey()] = 1; } $sql = "SELECT cur_id, cur_title FROM cur WHERE cur_namespace= " . NS_MEDIAWIKI; $res = wfQuery( $sql, DB_READ ); -$first = true; + +# Compile target array +$targets = array(); while ( $row = wfFetchObject( $res ) ) { - $partial = $row->cur_title; - print "$partial..."; - if ( !array_key_exists( $partial, $dbkeys ) ) { + if ( !array_key_exists( $row->cur_title, $dbkeys ) ) { + $targets[] = $row->cur_title; + } +} +wfFreeResult( $res ); + +# Create redirects from destination to source +if ( $doRedirects ) { + foreach ( $targets as $partial ) { + print "$partial..."; + $nt = Title::makeTitle( NS_TEMPLATE, $partial ); + $ot = Title::makeTitle( NS_MEDIAWIKI, $partial ); + + if ( $nt->createRedirect( $ot, "" ) ) { + print "redirected\n"; + } else { + print "not redirected\n"; + } + } + if ( $doMove ) { + print "\nRedirects created. Update live script files now.\nPress ENTER to continue.\n\n"; + readconsole(); + } +} + +# Move pages +if ( $doMove ) { + foreach ( $targets as $partial ) { $ot = Title::makeTitle( NS_MEDIAWIKI, $partial ); $nt = Title::makeTitle( NS_TEMPLATE, $partial ); + print "$partial..."; + if ( $ot->moveNoAuth( $nt ) === true ) { print "moved\n"; } else { print "not moved\n"; } - # Clear deferred updates + # Do deferred updates while ( count( $wgDeferredUpdateList ) ) { $up = array_pop( $wgDeferredUpdateList ); $up->doUpdate(); } - $first = false; - } else { - print "internal\n"; } } -if ( $first ) { - print "Nothing to move\n"; -} ?> diff --git a/maintenance/commandLine.inc b/maintenance/commandLine.inc index 216ee9c068..a103d11755 100644 --- a/maintenance/commandLine.inc +++ b/maintenance/commandLine.inc @@ -8,7 +8,7 @@ if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) { $wgCommandLineMode = true; $sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":"; -if ( @$argv[1] ) { +if ( @$argv[1] && @$argv[1] != "-" ) { $lang = $argv[1]; putenv( "wikilang=$lang"); $settingsFile = "/apache/htdocs/{$argv[1]}/w/LocalSettings.php"; -- 2.20.1