Deprecated wfMsgWeirdKey(), use wfMessage() instead. Moved getDefaultMessageText() from Article to Title so that it can be used there instead of duplicating code. No usage in extensions.

This commit is contained in:
Alexandre Emsenhuber 2011-02-05 15:11:52 +00:00
parent 35f83153c0
commit 136f4c06fa
5 changed files with 32 additions and 38 deletions

View file

@ -257,7 +257,7 @@ class Article {
# If this is a MediaWiki:x message, then load the messages
# and return the message value for x.
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
$text = $this->getDefaultMessageText();
$text = $this->mTitle->getDefaultMessageText();
if ( $text === false ) {
$text = '';
}
@ -275,28 +275,6 @@ class Article {
}
}
/**
* Get the default message text or false if the message doesn't exist
*
* @return String or false
*/
public function getDefaultMessageText() {
global $wgContLang;
if ( $this->mTitle->getNamespace() != NS_MEDIAWIKI ) { // Just in case
return false;
}
list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
$message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
if ( $message->exists() ) {
return $message->plain();
} else {
return false;
}
}
/**
* Get the text of the current revision. No side-effects...
*
@ -1411,7 +1389,7 @@ class Article {
wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
} elseif ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) {
// Use the default message text
$text = $this->getDefaultMessageText();
$text = $this->mTitle->getDefaultMessageText();
} else {
$createErrors = $this->mTitle->getUserPermissionsErrors( 'create', $wgUser );
$editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
@ -4162,7 +4140,7 @@ class Article {
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
// This doesn't quite make sense; the user is asking for
// information about the _page_, not the message... -- RC
$wgOut->addHTML( htmlspecialchars( wfMsgWeirdKey( $this->mTitle->getText() ) ) );
$wgOut->addHTML( htmlspecialchars( $this->mTitle->getDefaultMessageText() ) );
} else {
$msg = $wgUser->isLoggedIn()
? 'noarticletext'

View file

@ -141,7 +141,7 @@ class EditPage {
if ( !$this->mTitle->exists() ) {
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
# If this is a system message, get the default text.
$text = $this->mArticle->getDefaultMessageText();
$text = $this->mTitle->getDefaultMessageText();
if( $text === false ) {
$text = $this->getPreloadedText( $preload );
}

View file

@ -607,7 +607,9 @@ function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform
/**
* This function provides the message source for messages to be edited which are *not* stored in the database.
* @param $key String:
*
* @deprecated in 1.18; use wfMessage()
* @param $key String
*/
function wfMsgWeirdKey( $key ) {
$source = wfMsgGetKey( $key, false, true, false );

View file

@ -3760,12 +3760,8 @@ class Title {
// selflink, possibly with fragment
return $this->mDbkeyform == '';
case NS_MEDIAWIKI:
// If the page is form Mediawiki:message/lang, calling wfMsgWeirdKey causes
// the full l10n of that language to be loaded. That takes much memory and
// isn't needed. So we strip the language part away.
list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
// known system message
return (bool)wfMsgWeirdKey( $basename );
return $this->getDefaultMessageText() !== false;
default:
return false;
}
@ -3796,16 +3792,34 @@ class Title {
if ( $this->mNamespace == NS_MEDIAWIKI ) {
// If the page doesn't exist but is a known system message, default
// message content will be displayed, same for language subpages
// Also, if the page is form Mediawiki:message/lang, calling wfMsgWeirdKey
// causes the full l10n of that language to be loaded. That takes much
// memory and isn't needed. So we strip the language part away.
list( $basename, /* rest */ ) = explode( '/', $this->mDbkeyform, 2 );
return (bool)wfMsgWeirdKey( $basename );
return $this->getDefaultMessageText() !== false;
}
return false;
}
/**
* Get the default message text or false if the message doesn't exist
*
* @return String or false
*/
public function getDefaultMessageText() {
global $wgContLang;
if ( $this->getNamespace() != NS_MEDIAWIKI ) { // Just in case
return false;
}
list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) );
$message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
if ( $message->exists() ) {
return $message->plain();
} else {
return false;
}
}
/**
* Is this in a namespace that allows actual pages?
*

View file

@ -129,7 +129,7 @@ class AddWiki extends Maintenance {
}
}
$title = Title::newFromText( wfMsgWeirdKey( "mainpage/$lang" ) );
$title = Title::newFromText( wfMessage( 'mainpage' )->inLanguage( $lang )->useDatabase( false )->plain() );
$this->output( "Writing main page to " . $title->getPrefixedDBkey() . "\n" );
$article = new Article( $title );
$ucsite = ucfirst( $site );