From 8da29ee8fccfd8d36ec11f597670a7dcd743449c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 19 Mar 2005 10:17:41 +0000 Subject: [PATCH] Update message initialiser to use Revision functions for backend-independence. No longer inserts new revisions if previous text was the same as the current text (in 1.3 it would overwrite without saving the prior value) --- includes/Article.php | 7 ++--- maintenance/InitialiseMessages.inc | 43 ++++++++++++++---------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index b89c3c2a9d..2d208073ff 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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(), diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc index 2973e518cc..ffa43b91f1 100755 --- a/maintenance/InitialiseMessages.inc +++ b/maintenance/InitialiseMessages.inc @@ -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 ); } } -- 2.20.1