X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FInitialiseMessages.inc;h=3976d1864d66bb0556965c4042dedb7aa5b5e0f8;hb=739cab780c0fd0265da048f709688eca0b0edd72;hp=d625d7d8afbe4d97e44ce538580dec41923c6d91;hpb=3d6bb721af126155c6f3db827b504574763164af;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc index d625d7d8af..3976d1864d 100755 --- a/maintenance/InitialiseMessages.inc +++ b/maintenance/InitialiseMessages.inc @@ -2,8 +2,6 @@ /** * Script to initialise the MediaWiki namespace * - * $Id$ - * * This script is included from update.php and install.php. Do not run it * by itself. * @@ -12,19 +10,18 @@ * @subpackage Maintenance */ - - +/** */ function initialiseMessages( $overwrite = false, $messageArray = false ) { global $wgContLang, $wgContLanguageCode; global $wgContLangClass, $wgAllMessagesEn; + global $wgDisableLangConversion; + global $wgForceUIMsgAsContentMsg; + global $wgLanguageNames; global $IP; - - $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) ); - require_once("$IP/languages/$langclass.php"); - $variants = $wgContLang->getVariants(); - if(!in_array($wgContLanguageCode, $variants)) - $variants[]=$wgContLanguageCode; + # overwrite language conversion option so that all variants + # of the messages are initialised + $wgDisableLangConversion = false; if ( $messageArray ) { $sortedArray = $messageArray; @@ -33,14 +30,19 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) { } ksort( $sortedArray ); - $messages=array(); + + $variants = $wgContLang->getVariants(); + if(!in_array($wgContLanguageCode, $variants)) + $variants[]=$wgContLanguageCode; + foreach ($variants as $v) { $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) ); - $lang = new $langclass; - if(!is_object($lang)) { + if( !class_exists($langclass) ) { die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?"); } + $lang = new $langclass; + if($v==$wgContLanguageCode) $suffix=''; else @@ -48,17 +50,28 @@ function initialiseMessages( $overwrite = false, $messageArray = false ) { foreach ($sortedArray as $key => $msg) { $messages[$key.$suffix] = $lang->getMessage($key); } - } + } + require_once('languages/Names.php'); + + /* + initialize all messages in $wgForceUIMsgAsContentMsg for all + languages in Names.php + */ + if( is_array( $wgForceUIMsgAsContentMsg ) ) { + foreach( $wgForceUIMsgAsContentMsg as $uikey ) { + foreach( $wgLanguageNames as $code => $name) { + if( $code == $wgContLanguageCode ) + continue; + $msg = $wgContLang->getMessage( $uikey ); + if( $msg ) + $messages[$uikey. '/' . $code] = $msg; + } + } + } initialiseMessagesReal( $overwrite, $messages ); } - - - - - - /** */ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) { global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn; @@ -89,12 +102,14 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) { $dbr =& wfGetDB( DB_SLAVE ); $dbw =& wfGetDB( DB_MASTER ); - $cur = $dbr->tableName( 'cur' ); + $page = $dbr->tableName( 'page' ); + $revision = $dbr->tableName( 'revision' ); $timestamp = wfTimestampNow(); - $invTimestamp = wfInvertTimestamp( $timestamp ); - $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN("; + #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN("; + $sql = "SELECT page_title,page_is_new,rev_user_text FROM $page, $revision WHERE + page_namespace=$ns AND rev_page=page_id AND page_title IN("; # Get keys from $wgAllMessagesEn, which is more complete than the local language $first = true; @@ -117,7 +132,7 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) { } else { $sql .= ','; } - $titleObj = Title::newFromText( $key ); + $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) ); $enctitle = $dbr->strencode($titleObj->getDBkey()); $sql .= "'$enctitle'"; } @@ -129,10 +144,10 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) { # Decide whether or not each one needs to be overwritten $existingTitles = array(); while ( $row ) { - if ( $row->cur_user_text != $username ) { - $existingTitles[$row->cur_title] = 'keep'; + if ( $row->rev_user_text != $username && $row->rev_user_text != 'Template namespace initialisation script' ) { + $existingTitles[$row->page_title] = 'keep'; } else { - $existingTitles[$row->cur_title] = 'chuck'; + $existingTitles[$row->page_title] = 'chuck'; } $row = $dbr->fetchObject( $res ); @@ -155,43 +170,44 @@ function initialiseMessagesReal( $overwrite = false, $messageArray = false ) { } else { $message = wfMsgNoDBForContent( $key ); } - $titleObj = Title::newFromText( $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 ); + } } - $doInsert = false; } else { - array_push( $arr, array( - 'cur_namespace' => $ns, - 'cur_title' => $title, - 'cur_text' => $message, - 'cur_user' => 0, - 'cur_user_text' => $username, - 'cur_timestamp' => $dbw->timestamp( $timestamp ), - 'cur_restrictions' => 'sysop', - 'cur_is_new' => 1, - 'inverse_timestamp' => $invTimestamp, - 'cur_touched' => $dbw->timestamp( $timestamp ) ) ); + $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 ); } } - $dbw->insert( $cur, $arr, $fname ); - # Clear the relevant memcached key print 'Clearing message cache...'; $wgMessageCache->clear(); print "Done.\n"; } -function loadLanguageFile( $filename ) -{ +/** */ +function loadLanguageFile( $filename ) { $contents = file_get_contents( $filename ); # Remove header line $p = strpos( $contents, "\n" ) + 1; @@ -200,9 +216,9 @@ function loadLanguageFile( $filename ) return unserialize( $contents ); } +/** */ function doUpdates() { global $wgDeferredUpdateList; foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); } } - ?>