r36506 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36505‎ | r36506 | r36507 >
Date:13:14, 20 June 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Some docu
Modified paths:
  • /trunk/extensions/Translate/ffs/Java.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/ffs/Java.php
@@ -9,8 +9,22 @@
1010 * @file
1111 */
1212
 13+/**
 14+ * Reader for java property files. Not completely general, as it excepts two
 15+ * comment sections at the top, separated by a blank line.
 16+ *
 17+ * Authors in the first section are detected, if prefixed with '# Author: '.
 18+ * Second section (if any) is returned verbatim.
 19+ */
1320 class JavaFormatReader extends SimpleFormatReader {
1421
 22+ /**
 23+ * Inherited from SimpleFormatReader, which parses whole header in one pass.
 24+ * Basically the same, with different author prefix and separator between
 25+ * headers and messages.
 26+ *
 27+ * FIXME: possible to refactor to reduce duplication?
 28+ */
1529 protected function parseHeader() {
1630 if ( $this->filename === false ) {
1731 return;
@@ -52,12 +66,20 @@
5367 $this->staticHeader = $staticHeader;
5468 }
5569
 70+ /**
 71+ * Parses messages from lines key=value. Whitespace is trimmer around key and
 72+ * values. New lines inside values have to be escaped as '\n'. Lines which do
 73+ * not have = are ignored. Comments are designated by # at the start of the
 74+ * line only. Values can have = characters, only the first one is considered
 75+ * separator.
 76+ */
5677 public function parseMessages( StringMangler $mangler ) {
5778 if ( !file_exists( $this->filename ) ) {
5879 return null;
5980 }
6081
61 - $lines = file( $this->filename );
 82+ # This format works nicely with line based parsing
 83+ $lines = array_map( 'trim', file( $this->filename ) );
6284 if ( !$lines ) { return null; }
6385
6486 $messages = array();
@@ -65,15 +87,20 @@
6688 foreach ( $lines as $line ) {
6789 if ( $line === '' || !strpos( $line, '=' ) || $line[0] === '#' ) { continue; }
6890 list( $key, $value ) = explode( '=', $line, 2 );
69 - $messages[$mangler->mangle($key)] = trim($value);
 91+ $messages[$mangler->mangle(trim($key))] = trim($value);
7092 }
7193 return $messages;
7294 }
7395 }
7496
75 -
 97+/**
 98+ * Very simple writer for exporting messages to Java property files from wiki.
 99+ */
76100 class JavaFormatWriter extends SimpleFormatWriter {
77101
 102+ /**
 103+ * Inherited. Very simplistic header with timestamp.
 104+ */
78105 public function makeHeader( $handle, $code ) {
79106 global $wgSitename;
80107 list( $name, $native ) = $this->getLanguageNames($code);
@@ -89,9 +116,14 @@
90117 );
91118 }
92119
 120+ /**
 121+ * Inherited. Exports messages as lines of format key=value.
 122+ */
93123 protected function exportMessages( $handle, array $messages ) {
94124 foreach ( $messages as $key => $value ) {
 125+ # Make sure we don't slip newlines trough... it would be fatal
95126 $value = str_replace( "\n", '\\n', $value );
 127+ # No pretty alignment here, sorry
96128 fwrite( $handle, "$key=$value\n" );
97129 }
98130 }

Status & tagging log