From 3d042077f86c69a193d7beb6982b2f0846cbd70a Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 30 Aug 2003 07:12:38 +0000 Subject: [PATCH] enhanced wfMsg: minor improvements --- includes/GlobalFunctions.php | 30 ++++++++++++++++++++++++++---- includes/SpecialRecentchanges.php | 3 +++ languages/Language.php | 22 +++------------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a1021e2842..845cba124a 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -176,19 +176,41 @@ $wgReplacementKeys = array( "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9" function wfMsg( $key ) { global $wgLang, $wgReplacementKeys; - $ret = $wgLang->getMessage( $key ); + $message = $wgLang->getMessage( $key ); + if ( $message{0} == ":" ) { + # Get message from the database + $message = substr( $message, 1 ); + $title = Title::newFromText( $message ); + $dbKey = $title->getDBkey(); + $ns = $title->getNamespace(); + $sql = "SELECT cur_text FROM cur WHERE cur_namespace=$ns AND cur_title='$dbKey'"; + $res = wfQuery( $sql, $fname ); + if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) { + $message = $s->cur_text; + # filter out a comment at the top if there is one + $commentPos = strpos( $message, "__START__" ); + if ( $commentPos !== false ) { + $message = substr( $message, $commentPos + strlen( "__START__" ) ); + wfDebug( "Comment filtered at pos $commentPos, \"$message\"\n" ); + } + } else { + # if the page doesn't exist, just make a link to where it should be + $message = "[[$message]]"; + } + wfFreeResult( $res ); + } if( func_num_args() > 1 ) { $reps = func_get_args(); array_shift( $reps ); - $ret = str_replace( $wgReplacementKeys, $reps, $ret ); + $message = str_replace( $wgReplacementKeys, $reps, $message ); } - if ( "" == $ret ) { + if ( "" == $message ) { # Let's at least _try_ to be graceful about this. return "<$key>"; } - return $ret; + return $message; } function wfCleanFormFields( $fields ) diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index bdc75ad1bf..70ea460f1d 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -20,11 +20,14 @@ function wfSpecialRecentchanges( $par ) $wgOut->checkLastModified( $s->lastmod ); $rctext = wfMsg( "recentchangestext" ); + + # The next few lines can probably be commented out now that wfMsg can get text from the DB $sql = "SELECT cur_text FROM cur WHERE cur_namespace=4 AND cur_title='Recentchanges'"; $res = wfQuery( $sql, $fname ); if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) { $rctext = $s->cur_text; } + $wgOut->addWikiText( $rctext ); if ( ! $days ) { diff --git a/languages/Language.php b/languages/Language.php index 58743cddf4..eb5699d6fa 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -677,7 +677,8 @@ from server time (UTC).", # "changes" => "changes", "recentchanges" => "Recent changes", -"recentchangestext" => "Track the most recent changes to Wikipedia on this page. +"recentchangestext" => +"Track the most recent changes to Wikipedia on this page. [[Wikipedia:Welcome,_newcomers|Welcome, newcomers]]! Please have a look at these pages: [[wikipedia:FAQ|Wikipedia FAQ]], [[Wikipedia:Policies and guidelines|Wikipedia policy]] @@ -1337,24 +1338,7 @@ class Language { function getMessage( $key ) { global $wgAllMessagesEn; - $message = $wgAllMessagesEn[$key]; - if ( $message{0} == ":" ) { - # Get message from the database - $message = substr( $message, 1 ); - $title = Title::newFromText( $message ); - $dbKey = $title->getDBkey(); - $ns = $title->getNamespace(); - $sql = "SELECT cur_text FROM cur WHERE cur_namespace=$ns AND cur_title='$dbKey'"; - $res = wfQuery( $sql, $fname ); - if( ( $s = wfFetchObject( $res ) ) and ( $s->cur_text != "" ) ) { - $message = $s->cur_text; - } else { - # Similar behaviour on fail to ordinary missing messages - $message = "<$message>"; - } - wfFreeResult( $res ); - } - return $message; + return $wgAllMessagesEn[$key]; } function iconv( $in, $out, $string ) { -- 2.20.1