http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95970

Revision: 95970
Author:   catrope
Date:     2011-09-01 12:19:21 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
RL2: Rename getTitleMsg() to getTitleMessageKey(), and introduce 
getTitleMessage() which returns the contents of the title message or the name 
of the gadget if the message doesn't exist. Did a similar thing for 
getDescriptionMsg()

Modified Paths:
--------------
    branches/RL2/extensions/Gadgets/GadgetHooks.php
    branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php
    branches/RL2/extensions/Gadgets/backend/Gadget.php

Modified: branches/RL2/extensions/Gadgets/GadgetHooks.php
===================================================================
--- branches/RL2/extensions/Gadgets/GadgetHooks.php     2011-09-01 12:17:27 UTC 
(rev 95969)
+++ branches/RL2/extensions/Gadgets/GadgetHooks.php     2011-09-01 12:19:21 UTC 
(rev 95970)
@@ -207,7 +207,7 @@
                        $category = $gadget->getCategory();
                        
                        // Add the Gadget to the right category
-                       $description = wfMessage( $gadget->getDescriptionMsg() 
)->parse();
+                       $description = $gadget->getDescriptionMessage();
                        $categories[$category][$description] = $name;
                        // Add the Gadget to the default list if enabled
                        if ( $gadget->isEnabledForUser( $user ) ) {

Modified: branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php
===================================================================
--- branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php     2011-09-01 
12:17:27 UTC (rev 95969)
+++ branches/RL2/extensions/Gadgets/api/ApiQueryGadgets.php     2011-09-01 
12:19:21 UTC (rev 95970)
@@ -90,10 +90,10 @@
                                $row['definitiontimestamp'] = wfTimestamp( 
TS_ISO_8601, $g->getTimestamp() );
                        }
                        if ( isset( $this->props['desc'] ) ) {
-                               $row['desc'] = wfMessage( 
$g->getDescriptionMsg() )->parse();
+                               $row['desc'] = $g->getDescriptionMessage();
                        }
                        if ( isset( $this->props['desc-raw'] ) ) {
-                               $row['desc-raw'] = $row['desc'] = wfMessage( 
$g->getDescriptionMsg() )->plain();
+                               $row['desc-raw'] = $row['desc'] = wfMessage( 
$g->getDescriptionMessageKey() )->plain();
                        }
                        if ( isset( $this->props['category'] ) ) {
                                $row['category'] = $g->getCategory();

Modified: branches/RL2/extensions/Gadgets/backend/Gadget.php
===================================================================
--- branches/RL2/extensions/Gadgets/backend/Gadget.php  2011-09-01 12:17:27 UTC 
(rev 95969)
+++ branches/RL2/extensions/Gadgets/backend/Gadget.php  2011-09-01 12:19:21 UTC 
(rev 95970)
@@ -111,23 +111,59 @@
        }
        
        /**
-        * Get the title message for this gadget. This is the interface message 
that controls the name of the
-        * gadget as shown to the user.
+        * Get the key of the title message for this gadget. This is the 
interface message that
+        * controls the name of the gadget as shown to the user.
         * @return string Message key
         */
-       public function getTitleMsg() {
+       public function getTitleMessageKey() {
                return "gadget-{$this->name}-title";
        }
        
        /**
-        * Get the description message for this gadget.
+        * Get the title message for this gadget
+        * @param $langcode string Language code. If null, user language is used
+        * @return The title message in the given language, or the name of the 
gadget if the message doesn't exist
+        */
+       public function getTitleMessage( $langcode = null ) {
+               $msg = wfMessage( $this->getTitleMessageKey() );
+               if ( !$msg->exists() ) {
+                       // Fallback: return the name of the gadget
+                       $lang = Language::factory( $langcode );
+                       return $lang->ucfirst( $this->name );
+               }
+               if ( $langcode !== null ) {
+                       $msg->inLanguage( $langcode );
+               }
+               return $msg->plain();
+               
+       }
+       
+       /**
+        * Get the key of the description message for this gadget.
         * @return string Message key
         */
-       public function getDescriptionMsg() {
+       public function getDescriptionMessageKey() {
                return "gadget-{$this->name}-desc";
        }
        
        /**
+        * Get the description message for this gadget
+        * @param $langcode string Language code. If null, user language is used
+        * @return The description message HTML in the given language, or an 
empty string if the message doesn't exist
+        */
+       public function getDescriptionMessage( $langcode = null ) {
+               $msg = wfMessage( $this->getDescriptionMessageKey() );
+               if ( !$msg->exists() ) {
+                       // Fallback: return empty string
+                       return '';
+               }
+               if ( $langcode !== null ) {
+                       $msg->inLanguage( $langcode );
+               }
+               return $msg->parse();
+       }
+       
+       /**
         * Get the name of the category this gadget is in.
         * @return string Category key or empty string if not in any category
         */


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to