Update message initialiser to use Revision functions for backend-independence. No...
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 19 Mar 2005 10:17:41 +0000 (10:17 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 19 Mar 2005 10:17:41 +0000 (10:17 +0000)
includes/Article.php
maintenance/InitialiseMessages.inc

index b89c3c2..2d20807 100644 (file)
@@ -767,10 +767,11 @@ class Article {
         * Best if all done inside a transaction.
         *
         * @param Database $dbw
-        * @return int The newly created page_id key
+        * @param string   $restrictions
+        * @return int     The newly created page_id key
         * @access private
         */
-       function insertOn( &$dbw ) {
+       function insertOn( &$dbw, $restrictions = '' ) {
                $fname = 'Article::insertOn';
                wfProfileIn( $fname );
                
@@ -780,7 +781,7 @@ class Article {
                        'page_namespace'    => $this->mTitle->getNamespace(),
                        'page_title'        => $this->mTitle->getDBkey(),
                        'page_counter'      => 0,
-                       'page_restrictions' => '',
+                       'page_restrictions' => $restrictions,
                        'page_is_redirect'  => 0, # Will set this shortly...
                        'page_is_new'       => 1,
                        'page_random'       => wfRandom(),
index 2973e51..ffa43b9 100755 (executable)
@@ -170,36 +170,33 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
                } else {
                        $message = wfMsgNoDBForContent( $key );
                }
-               $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
+               $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ), NS_MEDIAWIKI );
                $title = $titleObj->getDBkey();
 
                # Update messages which already exist
                if ( array_key_exists( $title, $existingTitles ) ) {
                        if ( $existingTitles[$title] == 'chuck' || $overwrite) {
-                               # print "$title\n";
-                               $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
-                               $article = new Article( $mwTitleObj );
-                               $article->quickEdit( $message );
+                               # Don't bother writing a new revision if we're the same
+                               # as the current text!
+                               $revision = Revision::newFromTitle( $titleObj );
+                               if( is_null( $revision ) || $revision->getText() != $message ) {
+                                       $article = new Article( $titleObj );
+                                       $article->quickEdit( $message );
+                               }
                        }
                } else {
-                       extract( $dbw->tableNames( 'text', 'page', 'revision' ) );
-                       $sql = "INSERT INTO $text (old_text, old_flags) VALUES ('" .
-                               wfStrencode( $message ) .
-                               "', '')";
-                       $dbw->query( $sql, $fname );
-                       $text_id = $dbw->insertID();
-
-                       $sql = "INSERT INTO $page (page_namespace, page_title, page_restrictions, page_counter, page_is_redirect,
-                               page_is_new, page_random, page_touched, page_latest) VALUES (
-                               {$ns}, '{$title}', 'sysop', 0, 0, 1, 0.5, '{$timestamp}', {$text_id} )";
-                       $dbw->query( $sql, $fname );
-                       $page_id = $dbw->insertID();
-
-                       $sql = "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text,
-                                                       rev_timestamp, rev_minor_edit)
-                                       VALUES ({$text_id}, {$page_id}, '', 0, '{$username}', '{$timestamp}', 0)";
-                       $dbw->query( $sql, $fname );
-
+                       $article = new Article( $titleObj );
+                       $newid = $article->insertOn( $dbw, 'sysop' );
+                       # FIXME: set restrictions
+                       $revision = new Revision( array(
+                               'page'      => $newid,
+                               'text'      => $message,
+                               'user'      => 0,
+                               'user_text' => $username,
+                               'comment'   => '',
+                               ) );
+                       $revid = $revision->insertOn( $dbw );
+                       $article->updateRevisionOn( $dbw, $revision );
                }
        }