r81456 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81455‎ | r81456 | r81457 >
Date:15:29, 3 February 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use wfMessage() instead of wfMsgGetKey() and wfEmptyMsg()
* Factorise common code
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -257,12 +257,10 @@
258258 # If this is a MediaWiki:x message, then load the messages
259259 # and return the message value for x.
260260 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
261 - # If this is a system message, get the default text.
262 - list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
263 - $text = wfMsgGetKey( $message, false, $lang, false );
264 -
265 - if ( wfEmptyMsg( $message, $text ) )
 261+ $text = $this->getDefaultMessageText();
 262+ if ( $text === false ) {
266263 $text = '';
 264+ }
267265 } else {
268266 $text = wfMsgExt( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon', 'parsemag' );
269267 }
@@ -278,6 +276,28 @@
279277 }
280278
281279 /**
 280+ * Get the default message text or false if the message doesn't exist
 281+ *
 282+ * @return String or false
 283+ */
 284+ public function getDefaultMessageText() {
 285+ global $wgContLang;
 286+
 287+ if ( $this->mTitle->getNamespace() != NS_MEDIAWIKI ) { // Just in case
 288+ return false;
 289+ }
 290+
 291+ list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
 292+ $message = wfMessage( $name )->inLanguage( $lang )->useDatabase( false );
 293+
 294+ if ( $message->exists() ) {
 295+ return $message->plain();
 296+ } else {
 297+ return false;
 298+ }
 299+ }
 300+
 301+ /**
282302 * Get the text of the current revision. No side-effects...
283303 *
284304 * @return Return the text of the current revision
@@ -1391,7 +1411,7 @@
13921412 wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
13931413 } elseif ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) {
13941414 // Use the default message text
1395 - $text = $this->getContent();
 1415+ $text = $this->getDefaultMessageText();
13961416 } else {
13971417 $createErrors = $this->mTitle->getUserPermissionsErrors( 'create', $wgUser );
13981418 $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
Index: trunk/phase3/includes/EditPage.php
@@ -141,10 +141,10 @@
142142 if ( !$this->mTitle->exists() ) {
143143 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
144144 # If this is a system message, get the default text.
145 - list( $message, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
146 - $text = wfMsgGetKey( $message, false, $lang, false );
147 - if( wfEmptyMsg( $message, $text ) )
 145+ $text = $this->mArticle->getDefaultMessageText();
 146+ if( $text === false ) {
148147 $text = $this->getPreloadedText( $preload );
 148+ }
149149 } else {
150150 # If requested, preload some text.
151151 $text = $this->getPreloadedText( $preload );

Follow-up revisions

RevisionCommit summaryAuthorDate
r81458Follow-up r81456: forgot to remove a global declarationialex15:31, 3 February 2011
r81789Remove unused $wgContLang globals after refactoring at r81456 and r81456platonides22:40, 8 February 2011

Status & tagging log