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.
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' ) );
}
}
# 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';
}
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.
# 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() );
}
}
}
$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 ) )
);
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() );
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.
# 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" );
}
* @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;
}
/**
* @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;
}
}
}
protected function msg( $str ) {
- $out = wfMsg( $str );
- return wfEmptyMsg( $str, $out ) ? $str : $out;
+ $msg = wfMessage( $str );
+ return $msg->exists() ? $msg->text() : $str;
}
/**#@-*/
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];
}
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 );
}
# 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 );
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>";
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 );
}
}
// 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
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]
: '-';
} 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 );
}
* @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();
}
/**
* @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();
}
/**
* @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;
}
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();
}
/**
$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;
}
}
}
- $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 ) );
? '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 ) );
}
}
? '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
$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 );
*/
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
$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 );
$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;
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, '* ' );
*/
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 );