r84248 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84247‎ | r84248 | r84249 >
Date:14:17, 18 March 2011
Author:purodha
Status:resolved (Comments)
Tags:
Comment:
Minor enhancements and fixes following up r84229, r84078, 84027, 84015.
Modified paths:
  • /trunk/extensions/Babel/Babel.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Babel/Babel.class.php
@@ -26,21 +26,20 @@
2727 self::mTemplateLinkBatch( $parameters );
2828
2929 $content = '';
30 - $templateParameters = array(); // collects name=value parameters to be passed to wiki templates.
 30+ $templateParameter[0] = '' ; // collects name=value parameters to be passed to wiki templates.
3131 foreach ( $parameters as $name ) {
3232 if (strpos($name, '=') !== false) {
3333 $templateParameters[] = $name;
3434 continue;
3535 }
3636 $components = self::mParseParameter( $name );
37 - $template = wfMsgForContent( 'babel-template', $name );
 37+ $template = wfMessage( 'babel-template', $name )->inContentLanguage()->text();
3838 if ( $name === '' ) {
3939 continue;
4040 } elseif ( self::mPageExists( $template ) ) {
4141 // Existent template page has precedence
42 - if ( count($templateParameters) ) {
43 - $template .= '|'.implode('|', $templateParameters);
44 - }
 42+ $templateParameters[0] = $template;
 43+ $template = implode('|', $templateParameters);
4544 $content .= self::mGenerateNotaBox( $parser->replaceVariables( "{{{$template}}}" ) );
4645 } elseif ( $components !== false ) {
4746 // Non-existent page and valid parameter syntax, babel box
@@ -100,7 +99,7 @@
101100 protected static function mTemplateLinkBatch( $parameters ) {
102101 $titles = array();
103102 foreach ( $parameters as $name ) {
104 - $title = Title::newFromText( wfMsgForContent( 'babel-template', $name ) );
 103+ $title = Title::newFromText( wfMessage( 'babel-template', $name )->inContentLanguage()->text() );
105104 if ( is_object( $title ) ) {
106105 $titles[] = $title;
107106 }
@@ -175,15 +174,15 @@
176175 }
177176
178177 /**
179 - * Generate an inner box which is not a babel box.
 178+ * Generate an inner item which is not a babel box.
180179 *
181 - * @param $coontent String: what's inside the box, in wikitext format.
 180+ * @param $content String: what's inside the box, in wikitext format.
182181 * @return String: A single non-babel box, in wikitext format.
183182 */
184183 protected static function mGenerateNotaBox( $content ) {
185 - $dir_content = wfMessage( 'babel-directionality' )->inContentLanguage()->text();
 184+ $dir_head = Babel::mHtmlAttrib( 'dir', 'babel-directionality' );
186185 $notabox = <<<EOT
187 -<div class="mw-babel-notabox" dir="$dir_content">$content</div>
 186+<div class="mw-babel-notabox"$dir_head>$content</div>
188187 EOT;
189188 return $notabox;
190189 }
@@ -196,8 +195,8 @@
197196 * @return String: A single babel box, in wikitext format.
198197 */
199198 protected static function mGenerateBox( $code, $level ) {
200 - $portal = wfMsgForContent( 'babel-portal', $code );
201199 $lang = wfBCP47( $code );
 200+ $portal = wfMsgForContent( 'babel-portal', $code );
202201 $header = "[[$portal|" . $lang . "]]<span class=\"mw-babel-box-level-$level\">-$level</span>";
203202
204203 $code = strtolower( $code );
@@ -205,17 +204,17 @@
206205 $code = BabelLanguageCodes::getCode( $code );
207206 $text = self::mGetText( $name, $code, $level );
208207
209 - $dir_content = wfMsgForContent( 'babel-directionality' );
210208 $dir_current = wfMsgExt( 'babel-directionality', array( 'language' => $code ) );
211209
212210 $cellspacing = Babel::mHtmlAttrib( 'cellspacing', 'babel-cellspacing' );
213211 $cellpadding = Babel::mHtmlAttrib( 'cellpadding', 'babel-cellpadding' );
 212+ $dir_head = Babel::mHtmlAttrib( 'dir', 'babel-directionality' );
214213
215214 $box = <<<EOT
216 -<div class="mw-babel-box mw-babel-box-$level" dir="$dir_content">
 215+<div class="mw-babel-box mw-babel-box-$level"$dir_head>
217216 {|$cellspacing$cellpadding
218 -! dir="$dir_content" | $header
219 -| dir="$dir_current" lang="$lang" xml:lang="$lang" | $text
 217+!$dir_head | $header
 218+| dir="$dir_current" lang="$lang" xml:lang="$lang" | $text
220219 |}
221220 </div>
222221 EOT;
@@ -314,7 +313,7 @@
315314 }
316315
317316 /**
318 - * Determine a HTML attribute, such as "cellspacing" or "cellpadding".
 317+ * Determine an HTML attribute, such as "cellspacing" or "title", from a localizeable message.
319318 *
320319 * @param $name String: name of HTML attribute.
321320 * @param $key String: Message key of attribute value.

Follow-up revisions

RevisionCommit summaryAuthorDate
r97717Follow-up r84248: revert initialising an unused variable to initialising a us...siebrand11:50, 21 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84015Allow name=value parameters in {{#babel: ... }} which are collected and passe...purodha13:14, 15 March 2011
r84027More systematic handling of cellspacing and cellpadding attributes.purodha15:56, 15 March 2011
r84078Fixing r84027.purodha03:21, 16 March 2011
r84229Wrap everything that is not a babel box into <div> 's as well, for consisten...purodha08:13, 18 March 2011

Comments

#Comment by SPQRobin (talk | contribs)   14:13, 18 September 2011

Why did you change $templateParameters = array(); to $templateParameter[0] = '' ; ? The second variable is not used.

Status & tagging log