r87300 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87299‎ | r87300 | r87301 >
Date:21:34, 2 May 2011
Author:preilly
Status:deferred (Comments)
Tags:
Comment:
added basic Internationalization support
Modified paths:
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.i18n.php (added) (history)
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.i18n.php
@@ -0,0 +1,8 @@
 2+<?php
 3+
 4+$messages = array();
 5+$messages['en'] = array(
 6+ 'patch_output_mobile_show' => 'show',
 7+ 'patch_output_mobile_hide' => 'hide',
 8+ 'patch_output_mobile_back_to_top' => 'Jump Back A Section',
 9+);
\ No newline at end of file
Property changes on: trunk/extensions/PatchOutputMobile/PatchOutputMobile.i18n.php
___________________________________________________________________
Added: svn:eol-style
110 + native
Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php
@@ -18,15 +18,20 @@
1919 'url' => 'http://www.mediawiki.org/wiki/Extension:PatchOutputMobile',
2020 );
2121
 22+$dir = dirname(__FILE__) . '/';
 23+$wgExtensionMessagesFiles['PatchOutputMobile'] = $dir . 'PatchOutputMobile.i18n.php';
 24+
2225 $wgExtPatchOutputMobile = new ExtPatchOutputMobile();
2326
2427 $wgHooks['OutputPageBeforeHTML'][] = array( &$wgExtPatchOutputMobile,
2528 'onOutputPageBeforeHTML' );
2629
2730 class ExtPatchOutputMobile {
28 - const VERSION = '0.2.3';
 31+ const VERSION = '0.2.4';
2932
3033 private $doc;
 34+
 35+ public static $messages = array();
3136
3237 public $items_to_remove = array(
3338 '#contentSub', # redirection notice
@@ -61,15 +66,21 @@
6267 );
6368
6469 public function onOutputPageBeforeHTML( &$out, &$text ) {
 70+ // Need to stash the results of the "wfMsg" call before the Output Buffering handler
 71+ // because at this point the database connection is shut down, etc.
 72+ ExtPatchOutputMobile::$messages['patch_output_mobile_show'] = wfMsg('patch_output_mobile_show');
 73+ ExtPatchOutputMobile::$messages['patch_output_mobile_hide'] = wfMsg('patch_output_mobile_hide');
 74+ ExtPatchOutputMobile::$messages['patch_output_mobile_back_to_top'] = wfMsg('patch_output_mobile_back_to_top');
 75+
6576 ob_start( array( $this, 'parse' ) );
6677 return true;
6778 }
6879
6980 private function showHideCallback( $matches ) {
7081 static $headings = 0;
71 - $show = 'Show';
72 - $hide = 'Hide';
73 - $back_to_top = 'Jump Back A Section';
 82+ $show = ExtPatchOutputMobile::$messages['patch_output_mobile_show'];
 83+ $hide = ExtPatchOutputMobile::$messages['patch_output_mobile_hide'];
 84+ $back_to_top = ExtPatchOutputMobile::$messages['patch_output_mobile_back_to_top'];
7485 ++$headings;
7586 // Back to top link
7687 $base = "<div class='section_anchors' id='anchor_" . intval( $headings - 1 ) .
@@ -137,6 +148,12 @@
138149
139150 $item_to_remove_records = $this->parseItemsToRemove();
140151
 152+ $title_node = $this->doc->getElementsByTagName( 'title' );
 153+
 154+ if ( $title_node->length > 0 ) {
 155+ $title = $title_node->item( 0 )->nodeValue;
 156+ }
 157+
141158 // Tags
142159
143160 // You can't remove DOMNodes from a DOMNodeList as you're iterating
@@ -144,12 +161,7 @@
145162 // iterator on the foreach out of wack and results will be quite
146163 // strange. Though, making a queue of items to remove seems to work.
147164 // For example:
148 - $title_node = $this->doc->getElementsByTagName( 'title' );
149165
150 - if ( $title_node->length > 0 ) {
151 - $title = $title_node->item( 0 )->nodeValue;
152 - }
153 -
154166 $domElemsToRemove = array();
155167 foreach ( $item_to_remove_records['TAG'] as $tag_to_remove ) {
156168 $tag_to_remove_nodes = $this->doc->getElementsByTagName( $tag_to_remove );

Comments

#Comment by Reedy (talk | contribs)   14:05, 3 May 2011

I'm guessing

+		ExtPatchOutputMobile::$messages['patch_output_mobile_show'] = wfMsg('patch_output_mobile_show');
+		ExtPatchOutputMobile::$messages['patch_output_mobile_hide'] = wfMsg('patch_output_mobile_hide');
+		ExtPatchOutputMobile::$messages['patch_output_mobile_back_to_top'] = wfMsg('patch_output_mobile_back_to_top');

is some type of optimisation? But we don't do that anywhere, just use the calls inline, and IIRC we have the caching inplace for messages in calling

#Comment by Krinkle (talk | contribs)   16:59, 3 May 2011

Although it's not enforced in extensions as much as in core, using $camelCaseNames for variables and dash-seperated-message-keys is the convention.

Status & tagging log