enhanced wfMsg: minor improvements
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 30 Aug 2003 07:12:38 +0000 (07:12 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 30 Aug 2003 07:12:38 +0000 (07:12 +0000)
includes/GlobalFunctions.php
includes/SpecialRecentchanges.php
languages/Language.php

index a1021e2..845cba1 100644 (file)
@@ -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 "&lt;$key&gt;";
        }
-       return $ret;
+       return $message;
 }
 
 function wfCleanFormFields( $fields )
index bdc75ad..70ea460 100644 (file)
@@ -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 ) {
index 58743cd..eb5699d 100644 (file)
@@ -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 ) {