Implement Message::isBlank and Message::isDisabled.
authorDaniel Friesen <dantman@users.mediawiki.org>
Fri, 14 Jan 2011 10:51:05 +0000 (10:51 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Fri, 14 Jan 2011 10:51:05 +0000 (10:51 +0000)
And while we're at it... update a random assortment of code using wfEmptyMsg to use the new wfMessage class and our exists/isBlank/isDisabled methods.

24 files changed:
includes/Article.php
includes/ChangeTags.php
includes/EditPage.php
includes/GlobalFunctions.php
includes/ImagePage.php
includes/Interwiki.php
includes/Licenses.php
includes/LogPage.php
includes/Message.php
includes/Preferences.php
includes/ProtectionForm.php
includes/RawPage.php
includes/SpecialPage.php
includes/User.php
includes/filerepo/FileRepo.php
includes/parser/Parser.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialListgrouprights.php
includes/specials/SpecialStatistics.php
includes/specials/SpecialTags.php
includes/specials/SpecialUpload.php
includes/specials/SpecialUserlogin.php
includes/upload/UploadBase.php

index b898549..adea10c 100644 (file)
@@ -1270,8 +1270,7 @@ class Article {
                global $wgOut;
 
                if ( $this->mTitle->isTalkPage() ) {
-                       $msg = wfMsgNoTrans( 'talkpageheader' );
-                       if ( $msg !== '-' && !wfEmptyMsg( 'talkpageheader', $msg ) ) {
+                       if ( !wfMessage( 'talkpageheader' )->isDisabled() ) {
                                $wgOut->wrapWikiMsg( "<div class=\"mw-talkpageheader\">\n$1\n</div>", array( 'talkpageheader' ) );
                        }
                }
@@ -3843,8 +3842,7 @@ class Article {
                # Show user links if allowed to see them. If hidden, then show them only if requested...
                $userlinks = $sk->revUserTools( $revision, !$unhide );
 
-               $m = wfMsg( 'revision-info-current' );
-               $infomsg = $current && !wfEmptyMsg( 'revision-info-current', $m ) && $m != '-'
+               $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled()
                        ? 'revision-info-current'
                        : 'revision-info';
 
index 4a1ad80..b893d30 100644 (file)
@@ -28,11 +28,8 @@ class ChangeTags {
        }
 
        static function tagDescription( $tag ) {
-               $msg = wfMsgExt( "tag-$tag", 'parseinline' );
-               if ( wfEmptyMsg( "tag-$tag", $msg ) ) {
-                       return htmlspecialchars( $tag );
-               }
-               return $msg;
+               $msg = wfMessage( "tag-$tag" );
+               return $msg->exists() ? $msg->parse() : htmlspecialchars( $tag ); 
        }
 
        ## Basic utility method to add tags to a particular change, given its rc_id, rev_id and/or log_id.
index bf5c2bf..775c5b6 100644 (file)
@@ -390,16 +390,18 @@ class EditPage {
 
                # Optional notices on a per-namespace and per-page basis
                $editnotice_ns   = 'editnotice-'.$this->mTitle->getNamespace();
-               if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
-                       $wgOut->addWikiText( wfMsgForContent( $editnotice_ns )  );
+               $editnotice_ns_message = wfMessage( $editnotice_ns )->inContentLanguage();
+               if ( !$editnotice_ns_message->empty() ) {
+                       $wgOut->addWikiText( $editnotice_ns_msg->plain() )  );
                }
                if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
                        $parts = explode( '/', $this->mTitle->getDBkey() );
                        $editnotice_base = $editnotice_ns;
                        while ( count( $parts ) > 0 ) {
                                $editnotice_base .= '-'.array_shift( $parts );
-                               if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
-                                       $wgOut->addWikiText( wfMsgForContent( $editnotice_base )  );
+                               $editnotice_base_msg = wfMessage( $editnotice_base )->inContentLanguage();
+                               if ( !$editnotice_base_msg->exists() ) {
+                                       $wgOut->addWikiText( $editnotice_base_msg->plain()  );
                                }
                        }
                }
@@ -1483,9 +1485,7 @@ HTML
                        $wgOut->wrapWikiMsg( "<div class='error' id='mw-edit-longpageerror'>\n$1\n</div>",
                                array( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) ) );
                } else {
-                       $msg = 'longpage-hint';
-                       $text = wfMsg( $msg );
-                       if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
+                       if( !wfMessage('longpage-hint')->isDisabled() ) {
                                $wgOut->wrapWikiMsg( "<div id='mw-edit-longpage-hint'>\n$1\n</div>",
                                        array( 'longpage-hint', $wgLang->formatSize( strlen( $this->textbox1 ) ), strlen( $this->textbox1 ) )
                                );
@@ -1741,8 +1741,7 @@ HTML
        protected function showTosSummary() {
                $msg = 'editpage-tos-summary';
                wfRunHooks( 'EditPageTosSummary', array( $this->mTitle, &$msg ) );
-               $text = wfMsg( $msg );
-               if( !wfEmptyMsg( $msg, $text ) && $text !== '-' ) {
+               if( !wfMessage( $msg )->isDisabled() ) {
                        global $wgOut;
                        $wgOut->addHTML( '<div class="mw-tos-summary">' );
                        $wgOut->addWikiMsgArray( $msg, array() );
index 1eef74b..d6d6a16 100644 (file)
@@ -2004,11 +2004,12 @@ function wfGetCachedNotice( $name ) {
                        return false;
                }
        } else {
-               $notice = wfMsgForContentNoTrans( $name );
-               if( wfEmptyMsg( $name, $notice ) || $notice == '-' ) {
+               $msg = wfMessage( $name )->inContentLanguage();
+               if( $msg->isDisabled() ) {
                        wfProfileOut( $fname );
                        return( false );
                }
+               $notice = $msg->plain();
        }
 
        // Use the extra hash appender to let eg SSL variants separately cache.
index bfae00b..bf903b7 100644 (file)
@@ -120,9 +120,9 @@ class ImagePage extends Article {
 
                # Show shared description, if needed
                if ( $this->mExtraDescription ) {
-                       $fol = wfMsgNoTrans( 'shareddescriptionfollows' );
-                       if ( $fol != '-' && !wfEmptyMsg( 'shareddescriptionfollows', $fol ) ) {
-                               $wgOut->addWikiText( $fol );
+                       $fol = wfMessage( 'shareddescriptionfollows' );
+                       if ( !$fol->isDisabled() ) {
+                               $wgOut->addWikiText( $fol->plain() );
                        }
                        $wgOut->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
                }
index 5a3b655..84f2686 100644 (file)
@@ -248,9 +248,8 @@ class Interwiki {
         * @return String
         */
        public function getName() {
-               $key = 'interwiki-name-' . $this->mPrefix;
-               $msg = wfMsgForContent( $key );
-               return wfEmptyMsg( $key, $msg ) ? '' : $msg;
+               $msg = wfMessage( 'interwiki-name-' . $this->mPrefix )->inContentLanguage();
+               return !$msg->exists() ? '' : $msg;
        }
 
        /**
@@ -259,8 +258,7 @@ class Interwiki {
         * @return String
         */
        public function getDescription() {
-               $key = 'interwiki-desc-' . $this->mPrefix;
-               $msg = wfMsgForContent( $key );
-               return wfEmptyMsg( $key, $msg ) ? '' : $msg;
+               $msg = wfMessage( 'interwiki-desc-' . $this->mPrefix )->inContentLanguage();
+               return !$msg->exists() ? '' : $msg;
        }
 }
index 45944c7..abf23ac 100644 (file)
@@ -111,8 +111,8 @@ class Licenses extends HTMLFormField {
        }
 
        protected function msg( $str ) {
-               $out = wfMsg( $str );
-               return wfEmptyMsg( $str, $out ) ? $str : $out;
+               $msg = wfMessage( $str );
+               return $msg->exists() ? $msg->text() : $str;
        }
 
        /**#@-*/
index fcd553e..8c47665 100644 (file)
@@ -514,13 +514,11 @@ class LogPage {
        public static function formatBlockFlag( $flag, $forContent = false ) {
                static $messages = array();
                if( !isset( $messages[$flag] ) ) {
-                       $k = 'block-log-flags-' . $flag;
-                       if( $forContent ) {
-                               $msg = wfMsgForContent( $k );
-                       } else {
-                               $msg = wfMsg( $k );
+                       $msg = wfMessage( 'block-log-flags-' . $flag );
+                       if ( $forContent ) {
+                               $msg = $msg->inContentLanguage();
                        }
-                       $messages[$flag] = htmlspecialchars( wfEmptyMsg( $k, $msg ) ? $flag : $msg );
+                       $messages[$flag] = htmlspecialchars( !$msg->exists() ? $flag : $msg );
                }
                return $messages[$flag];
        }
index 4b44ca5..4e2e153 100644 (file)
@@ -308,6 +308,24 @@ class Message {
                return $this->fetchMessage() !== false;
        }
 
+       /**
+        * Check whether a message does not exist, or is an empty string
+        * @return Bool: true if is is and false if not
+        */
+       public function isBlank() {
+               $message = $this->fetchMessage();
+               return $message === false || $message == '';
+       }
+
+       /**
+        * Check whether a message does not exist, is an empty string, or is "-"
+        * @return Bool: true if is is and false if not
+        */
+       public function isDisabled() {
+               $message = $this->fetchMessage();
+               return $message === false || $message == '' || $message == '-';
+       }
+
        public static function rawParam( $value ) {
                return array( 'raw' => $value );
        }
index 8cf1f44..9eb7d89 100644 (file)
@@ -1013,10 +1013,9 @@ class Preferences {
                # Sort by UI skin name. First though need to update validSkinNames as sometimes
                # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
                foreach ( $validSkinNames as $skinkey => &$skinname ) {
-                       $msgName = "skinname-{$skinkey}";
-                       $localisedSkinName = wfMsg( $msgName );
-                       if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) {
-                               $skinname = htmlspecialchars( $localisedSkinName );
+                       $msg = wfMessage( "skinname-{$skinkey}" );
+                       if ( $msg->exists() ) {
+                               $skinname = htmlspecialchars( $msg->text() );
                        }
                }
                asort( $validSkinNames );
index 2d95d80..9fb1337 100644 (file)
@@ -351,13 +351,10 @@ class ProtectionForm {
 
                foreach( $this->mRestrictions as $action => $selected ) {
                        /* Not all languages have V_x <-> N_x relation */
-                       $msg = wfMsg( 'restriction-' . $action );
-                       if( wfEmptyMsg( 'restriction-' . $action, $msg ) ) {
-                               $msg = $action;
-                       }
+                       $msg = wfMessage( 'restriction-' . $action );
                        $out .= "<tr><td>".
                        Xml::openElement( 'fieldset' ) .
-                       Xml::element( 'legend', null, $msg ) .
+                       Xml::element( 'legend', null, $msg->exists() ? $action : $msg->text() ) .
                        Xml::openElement( 'table', array( 'id' => "mw-protect-table-$action" ) ) .
                                "<tr><td>" . $this->buildSelector( $action, $selected ) . "</td></tr><tr><td>";
 
@@ -565,11 +562,11 @@ class ProtectionForm {
                if( $permission == '' ) {
                        return wfMsg( 'protect-default' );
                } else {
-                       $key = "protect-level-{$permission}";
-                       $msg = wfMsg( $key );
-                       if( wfEmptyMsg( $key, $msg ) )
-                               $msg = wfMsg( 'protect-fallback', $permission );
-                       return $msg;
+                       $msg = wfMessage( "protect-level-{$permission}" );
+                       if( !$msg->exists() ) {
+                               return $msg->text();
+                       }
+                       return wfMsg( 'protect-fallback', $permission );
                }
        }
        
index 1c99e5f..a4d5400 100644 (file)
@@ -189,11 +189,9 @@ class RawPage {
                        // If it's a MediaWiki message we can just hit the message cache
                        if( $this->mUseMessageCache && $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                                $key = $this->mTitle->getDBkey();
-                               $text = wfMsgForContentNoTrans( $key );
+                               $msg = wfMessage( $key )->inContentLanguage();
                                # If the message doesn't exist, return a blank
-                               if( wfEmptyMsg( $key, $text ) ) {
-                                       $text = '';
-                               }
+                               $text = !$msg->exists() ? '' : $msg->plain();
                                $found = true;
                        } else {
                                // Get it from the DB
index 558296a..e985f2b 100644 (file)
@@ -341,9 +341,10 @@ class SpecialPage {
                if( isset($specialPageGroupsCache[$page->mName]) ) {
                        return $specialPageGroupsCache[$page->mName];
                }
-               $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName));
-               if( $group == ''
-                || wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName), $group ) ) {
+               $msg = wfMessage('specialpages-specialpagegroup-'.strtolower($page->mName));
+               if ( !$msg->isBlank() ) {
+                       $group = $msg->text();
+               } else {
                        $group = isset($wgSpecialPageGroups[$page->mName])
                                ? $wgSpecialPageGroups[$page->mName]
                                : '-';
@@ -882,8 +883,7 @@ class SpecialPage {
                } else {
                        $msg = $summaryMessageKey;
                }
-               $out = wfMsgNoTrans( $msg );
-               if ( ! wfEmptyMsg( $msg, $out ) and  $out !== '' and ! $this->including() ) {
+               if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
                }
 
index 40a41ed..1e972a4 100644 (file)
@@ -3181,11 +3181,8 @@ class User {
         * @return String Localized descriptive group name
         */
        static function getGroupName( $group ) {
-               $key = "group-$group";
-               $name = wfMsg( $key );
-               return $name == '' || wfEmptyMsg( $key, $name )
-                       ? $group
-                       : $name;
+               $msg = wfMessage( "group-$group" );
+               return $msg->isBlank() ? $group : $msg->text();
        }
 
        /**
@@ -3195,11 +3192,8 @@ class User {
         * @return String Localized name for group member
         */
        static function getGroupMember( $group ) {
-               $key = "group-$group-member";
-               $name = wfMsg( $key );
-               return $name == '' || wfEmptyMsg( $key, $name )
-                       ? $group
-                       : $name;
+               $msg = wfMessage( "group-$group-member" );
+               return $msg->isBlank() ? $group : $msg->text();
        }
 
        /**
@@ -3251,9 +3245,9 @@ class User {
         * @return Title|Bool Title of the page if it exists, false otherwise
         */
        static function getGroupPage( $group ) {
-               $page = wfMsgForContent( 'grouppage-' . $group );
-               if( !wfEmptyMsg( 'grouppage-' . $group, $page ) ) {
-                       $title = Title::newFromText( $page );
+               $msg = wfMessage( 'grouppage-' . $group )->inContentLanguage();
+               if( !$msg->exists() ) {
+                       $title = Title::newFromText( $msg->text() );
                        if( is_object( $title ) )
                                return $title;
                }
index 6fd7790..a3931f2 100644 (file)
@@ -657,11 +657,7 @@ abstract class FileRepo {
                        return null;
                }
                // 'shared-repo-name-wikimediacommons' is used when $wgUseInstantCommons = true
-               $repoName = wfMsg( 'shared-repo-name-' . $this->name );
-               if ( !wfEmptyMsg( 'shared-repo-name-' . $this->name, $repoName ) ) {
-                       return $repoName;
-               }
-               return wfMsg( 'shared-repo' );
+               return wfMessageFallback( 'shared-repo-name-' . $this->name, 'shared-repo' )->text();
        }
 
        /**
index a14255b..5212920 100644 (file)
@@ -3355,12 +3355,12 @@ class Parser {
                                $text = $rev->getText();
                        } elseif ( $title->getNamespace() == NS_MEDIAWIKI ) {
                                global $wgContLang;
-                               $message = $wgContLang->lcfirst( $title->getText() );
-                               $text = wfMsgForContentNoTrans( $message );
-                               if ( wfEmptyMsg( $message, $text ) ) {
+                               $message = wfMessage( $wgContLang->lcfirst( $title->getText() ) )->inContentLanguage();
+                               if ( !$message->exists() ) {
                                        $text = false;
                                        break;
                                }
+                               $text = $message->plain();
                        } else {
                                break;
                        }
index 2db53ca..ea4d26d 100644 (file)
@@ -161,8 +161,7 @@ class SpecialContributions extends SpecialPage {
                                        }
                                }
 
-                               $text = wfMsgNoTrans( $message, $target );
-                               if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
+                               if( !wfMessage( $message, $target )->isDisabled() ) {
                                        $wgOut->wrapWikiMsg(
                                                "<div class='mw-contributions-footer'>\n$1\n</div>",
                                                array( $message, $target ) );
index 92e2258..0e2215f 100644 (file)
@@ -340,9 +340,7 @@ class DeletedContributionsPage extends SpecialPage {
                                ? 'sp-contributions-footer-anon'
                                : 'sp-contributions-footer';
 
-
-                       $text = wfMsgNoTrans( $message, $target );
-                       if( !wfEmptyMsg( $message, $text ) && $text != '-' ) {
+                       if( !wfMessage( $message )->isDisabled() ) {
                                $wgOut->wrapWikiMsg( "<div class='mw-contributions-footer'>\n$1\n</div>", array( $message, $target ) );
                        }
                }
index 910ffd0..e351729 100644 (file)
@@ -78,19 +78,13 @@ class SpecialListGroupRights extends SpecialPage {
                                ? 'all' 
                                : $group; 
 
-                       $msg = wfMsg( 'group-' . $groupname );
-                       if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
-                               $groupnameLocalized = $groupname;
-                       } else {
-                               $groupnameLocalized = $msg;
-                       }
+                       $msg = wfMessage( 'group-' . $groupname );
+                       $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
 
-                       $msg = wfMsgForContent( 'grouppage-' . $groupname );
-                       if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
-                               $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
-                       } else {
-                               $grouppageLocalized = $msg;
-                       }
+                       $msg = wfMessage( 'grouppage-' . $groupname )->inContentLanguage();
+                       $grouppageLocalized = !$msg->isBlank() ?
+                               $msg->text() :
+                               MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
 
                        if( $group == '*' ) {
                                // Do not make a link for the generic * group
index b0d0246..733b48d 100644 (file)
@@ -98,9 +98,9 @@ class SpecialStatistics extends SpecialPage {
                $text .= Xml::closeElement( 'table' );
 
                # Customizable footer
-               $footer = wfMsgExt( 'statistics-footer', array('parseinline') );
-               if( !wfEmptyMsg( 'statistics-footer', $footer ) && $footer != '' ) {
-                       $text .= "\n" . $footer;
+               $footer = wfMessage( 'statistics-footer' );
+               if ( !$footer->isBlank() ) {
+                       $text .= "\n" . $footer->parse();
                }
 
                $wgOut->addHTML( $text );
@@ -117,11 +117,11 @@ class SpecialStatistics extends SpecialPage {
         */
        private function formatRow( $text, $number, $trExtraParams = array(), $descMsg = '', $descMsgParam = '' ) {
                if( $descMsg ) {
-                       $descriptionText = wfMsgExt( $descMsg, array( 'parseinline' ), $descMsgParam );
-                       if ( !wfEmptyMsg( $descMsg, $descriptionText ) ) {
-                               $descriptionText = " ($descriptionText)";
+                       $msg = wfMessage( $descMsg, $descMsgParam );
+                       if ( $msg->exists() ) {
+                               $descriptionText = $msg->parse();
                                $text .= "<br />" . Xml::element( 'small', array( 'class' => 'mw-statistic-desc'), 
-                                       $descriptionText );
+                                       " ($descriptionText)" );
                        }
                }
                return
index 164565c..cd15b21 100644 (file)
@@ -82,8 +82,8 @@ class SpecialTags extends SpecialPage {
                $disp .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag" ), wfMsgHtml( 'tags-edit' ) ) . ')';
                $newRow .= Xml::tags( 'td', null, $disp );
 
-               $desc = wfMsgExt( "tag-$tag-description", 'parseinline' );
-               $desc = wfEmptyMsg( "tag-$tag-description", $desc ) ? '' : $desc;
+               $msg = wfMessage( "tag-$tag-description" );
+               $desc = !$msg->exists() ? '' : $msg->parse();
                $desc .= ' (' . $sk->link( Title::makeTitle( NS_MEDIAWIKI, "Tag-$tag-description" ), wfMsgHtml( 'tags-edit' ) ) . ')';
                $newRow .= Xml::tags( 'td', null, $desc );
 
index 7021ef6..3dd13dc 100644 (file)
@@ -285,10 +285,10 @@ class SpecialUpload extends SpecialPage {
                $form->addPreText( $message );
 
                # Add footer to form
-               $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
-               if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
+               $uploadFooter = wfMessage( 'uploadfooter' );
+               if ( !$uploadFooter->isDisabled() ) {
                        $form->addPostText( '<div id="mw-upload-footer-message">'
-                               . $wgOut->parse( $uploadFooter ) . "</div>\n" );
+                               . $wgOut->parse( $uploadFooter->plain() ) . "</div>\n" );
                }
 
                return $form;
index bd8e7ca..26b9c94 100644 (file)
@@ -1186,9 +1186,9 @@ class LoginForm extends SpecialPage {
        function makeLanguageSelector() {
                global $wgLang;
 
-               $msg = wfMsgForContent( 'loginlanguagelinks' );
-               if( $msg != '' && !wfEmptyMsg( 'loginlanguagelinks', $msg ) ) {
-                       $langs = explode( "\n", $msg );
+               $msg = wfMessage( 'loginlanguagelinks' )->inContentLanguage();
+               if( !$msg->isBlank() ) {
+                       $langs = explode( "\n", $msg->text() );
                        $links = array();
                        foreach( $langs as $lang ) {
                                $lang = trim( $lang, '* ' );
index dd108ad..86da818 100644 (file)
@@ -1179,9 +1179,9 @@ abstract class UploadBase {
         */
        public static function getFilenamePrefixBlacklist() {
                $blacklist = array();
-               $message = wfMsgForContent( 'filename-prefix-blacklist' );
-               if( $message && !( wfEmptyMsg( 'filename-prefix-blacklist', $message ) || $message == '-' ) ) {
-                       $lines = explode( "\n", $message );
+               $message = wfMessage( 'filename-prefix-blacklist' )->inContentLanguage();
+               if( !$message->isDisabled() ) {
+                       $lines = explode( "\n", $message->plain() );
                        foreach( $lines as $line ) {
                                // Remove comment lines
                                $comment = substr( trim( $line ), 0, 1 );