* $this->clear => $this->clear()
[lhc/web/wiklou.git] / maintenance / archives / moveCustomMessages.inc
index abab1a5..83664dc 100644 (file)
@@ -1,13 +1,23 @@
 <?php
-
+#### FIXME THIS FILE IS BADLY BROKEN FOR NEW SCHEMA
+/**
+ * @deprecated
+ * @package MediaWiki
+ * @subpackage MaintenanceArchive
+ */
+
+/** */
 function isTemplateInitialised() {
-       $sql = "SELECT 1 FROM cur WHERE cur_namespace=" . NS_TEMPLATE . " LIMIT 1";
-       $res = wfQuery( $sql, DB_READ );
-       return wfNumRows( $res ) ? true : false;
+       global $wgAllMessagesEn;
+       $fname = 'isTemplateInitialised';
+
+       $dbw =& wfGetDB( DB_MASTER );
+       $n = $dbw->selectField( 'page', 'count(*)', array( 'page_namespace' => NS_MEDIAWIKI ) );
+       return $n > count( $wgAllMessagesEn ) ? false : true;
 }
 
 function moveCustomMessages( $phase ) {
-       global $wgUser, $wgAllMessagesEn, $wgDeferredUpdateList, $wgLang ;
+       global $wgUser, $wgAllMessagesEn, $wgDeferredUpdateList, $wgLang, $wgContLang;
        global $targets, $template, $replaceCount;
 
        $wgUser = new User;
@@ -15,25 +25,28 @@ function moveCustomMessages( $phase ) {
        $wgUser->setName( "Template namespace initialisation script" );
        $wgUser->addRight( "bot" );
 
+       $dbw =& wfGetDB( DB_MASTER );
+
+       $dbw->ignoreErrors( true );
+
        # Compose DB key array
        $dbkeys = array();
 
        foreach ( $wgAllMessagesEn as $key => $enValue ) {
-               $title = Title::newFromText( $key );
+               $title = Title::newFromText( $wgContLang->ucfirst( $key ) );
                $dbkeys[$title->getDBkey()] = 1;
        }
 
-       $sql = "SELECT cur_id, cur_title FROM cur WHERE cur_namespace= " . NS_MEDIAWIKI;
-       $res = wfQuery( $sql, DB_READ );
+       $res = $dbw->select( 'page', array( 'page_id', 'page_title' ), array( 'page_namespace' => NS_MEDIAWIKI ) );
 
        # Compile target array
        $targets = array();
-       while ( $row = wfFetchObject( $res ) ) {
+       while ( $row = $dbw->fetchObject( $res ) ) {
                if ( !array_key_exists( $row->cur_title, $dbkeys ) ) {
                        $targets[$row->cur_title] = 1;
                }
        }
-       wfFreeResult( $res );
+       $dbw->freeResult( $res );
 
        # Create redirects from destination to source
        if ( $phase == 0 || $phase == 1 ) {
@@ -59,6 +72,7 @@ function moveCustomMessages( $phase ) {
        if ( $phase == 0 || $phase == 2 ) {
                print "\nMoving pages...\n";
                foreach ( $targets as $partial => $dummy ) {
+                       $dbw->query( "BEGIN" );
                        $ot = Title::makeTitle( NS_MEDIAWIKI, $partial );
                        $nt = Title::makeTitle( NS_TEMPLATE, $partial );
                        print "$partial...";
@@ -73,6 +87,7 @@ function moveCustomMessages( $phase ) {
                                $up = array_pop( $wgDeferredUpdateList );
                                $up->doUpdate();
                        }
+                       $dbw->query( "COMMIT" );
                }
        }
 
@@ -93,11 +108,12 @@ function moveCustomMessages( $phase ) {
                        $dest = Title::makeTitle( NS_MEDIAWIKI, $partial );
                        $linksTo = $dest->getLinksTo();
                        foreach( $linksTo as $source ) {
+                               $dbw->query( "BEGIN" );
                                $pdbk = $source->getPrefixedDBkey();
                                if ( !array_key_exists( $pdbk, $completedTitles ) ) {   
                                        $completedTitles[$pdbk] = 1;
                                        $id = $source->getArticleID();
-                                       $row = wfGetArray( 'cur', array( 'cur_text' ), 
+                                       $row = $dbw->selectRow( 'cur', array( 'cur_text' ), 
                                                array( 'cur_id' => $source->getArticleID() ) );
                                        $parser->startExternalParse( $source, $options, OT_WIKI );
                                        $text = $parser->strip( $row->cur_text, $stripState, false );
@@ -110,11 +126,17 @@ function moveCustomMessages( $phase ) {
                                        if ( $text != $row->cur_text ) {
                                                print "$pdbk\n";
                                                $art = new Article( $source );
-                                               $art->quickEdit( $text );
+                                               $art->updateArticle( $text, "", false, false );
+                                               # Do deferred updates
+                                               while ( count( $wgDeferredUpdateList ) ) {
+                                                       $up = array_pop( $wgDeferredUpdateList );
+                                                       $up->doUpdate();
+                                               }
                                        } else {
                                                print "($pdbk)\n";
                                        }
                                } 
+                               $dbw->query( "COMMIT" );
                        }
                }
        }