r41813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41812‎ | r41813 | r41814 >
Date:18:10, 7 October 2008
Author:ialex
Status:old
Tags:
Comment:
* Display default extensions messages for language subpages when the page being edited doesn't exist
* Fix MessageCache::figureMessage() to allow slashes in message name
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MessageCache.php
@@ -25,7 +25,7 @@
2626 var $mKeys, $mParserOptions, $mParser;
2727 var $mExtensionMessages = array();
2828 var $mInitialised = false;
29 - var $mAllMessagesLoaded; // Extension messages
 29+ var $mAllMessagesLoaded = array(); // Extension messages
3030
3131 // Variable for tracking which variables are loaded
3232 var $mLoadedLanguages = array();
@@ -766,12 +766,13 @@
767767 }
768768 }
769769
770 - function loadAllMessages() {
 770+ function loadAllMessages( $lang = false ) {
771771 global $wgExtensionMessagesFiles;
772 - if ( $this->mAllMessagesLoaded ) {
 772+ $key = $lang === false ? '*' : $lang;
 773+ if ( isset( $this->mAllMessagesLoaded[$key] ) ) {
773774 return;
774775 }
775 - $this->mAllMessagesLoaded = true;
 776+ $this->mAllMessagesLoaded[$key] = true;
776777
777778 # Some extensions will load their messages when you load their class file
778779 wfLoadAllExtensions();
@@ -779,7 +780,7 @@
780781 wfRunHooks( 'LoadAllMessages' );
781782 # Some register their messages in $wgExtensionMessagesFiles
782783 foreach ( $wgExtensionMessagesFiles as $name => $file ) {
783 - wfLoadExtensionMessages( $name );
 784+ wfLoadExtensionMessages( $name, $lang );
784785 }
785786 # Still others will respond to neither, they are EVIL. We sometimes need to know!
786787 }
@@ -840,13 +841,17 @@
841842
842843 public function figureMessage( $key ) {
843844 global $wgContLanguageCode;
844 - $pieces = explode('/', $key, 2);
 845+ $pieces = explode( '/', $key );
 846+ if( count( $pieces ) < 2 )
 847+ return array( $key, $wgContLanguageCode );
845848
846 - $key = $pieces[0];
 849+ $lang = array_pop( $pieces );
 850+ $validCodes = Language::getLanguageNames();
 851+ if( !array_key_exists( $lang, $validCodes ) )
 852+ return array( $key, $wgContLanguageCode );
847853
848 - # Language the user is translating to
849 - $langCode = isset($pieces[1]) ? $pieces[1] : $wgContLanguageCode;
850 - return array( $key, $langCode );
 854+ $message = implode( '/', $pieces );
 855+ return array( $message, $lang );
851856 }
852857
853858 }
Index: trunk/phase3/includes/EditPage.php
@@ -110,7 +110,7 @@
111111 * @private
112112 */
113113 function getContent( $def_text = '' ) {
114 - global $wgOut, $wgRequest, $wgParser, $wgMessageCache;
 114+ global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
115115
116116 wfProfileIn( __METHOD__ );
117117 # Get variables from query string :P
@@ -124,9 +124,12 @@
125125 // For other non-existent articles, use preload text if any.
126126 if ( !$this->mTitle->exists() ) {
127127 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
128 - $wgMessageCache->loadAllMessages();
129128 # If this is a system message, get the default text.
130 - $text = wfMsgWeirdKey( $this->mTitle->getText() ) ;
 129+ list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
 130+ $wgMessageCache->loadAllMessages( $lang );
 131+ $text = wfMsgGetKey( $message, false, $lang, false );
 132+ if( wfEmptyMsg( $message, $text ) )
 133+ $text = '';
131134 } else {
132135 # If requested, preload some text.
133136 $text = $this->getPreloadedText( $preload );
@@ -1044,11 +1047,8 @@
10451048 */
10461049 function initialiseForm() {
10471050 $this->edittime = $this->mArticle->getTimestamp();
1048 - $this->textbox1 = $this->getContent(false);
1049 - if ( $this->textbox1 === false) return false;
1050 -
1051 - if ( !$this->mArticle->exists() && $this->mTitle->getNamespace() == NS_MEDIAWIKI )
1052 - $this->textbox1 = wfMsgWeirdKey( $this->mTitle->getText() );
 1051+ $this->textbox1 = $this->getContent( false );
 1052+ if ( $this->textbox1 === false ) return false;
10531053 wfProxyCheck();
10541054 return true;
10551055 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r44024Do the same as r41813, but for non-edit page: Display default extensions mess...ialex18:37, 28 November 2008

Status & tagging log