r106727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106726‎ | r106727 | r106728 >
Date:23:47, 19 December 2011
Author:reedy
Status:ok
Tags:
Comment:
Fix spaces to tabs

Trim trailing whitespace
Modified paths:
  • /trunk/extensions/TranslateSvg/SpecialTranslateSvg.php (modified) (history)
  • /trunk/extensions/TranslateSvg/TranslateSvg.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TranslateSvg/TranslateSvg.php
@@ -11,11 +11,11 @@
1212 */
1313
1414 $wgExtensionCredits['specialpage'][] = array(
15 - 'name' => 'TranslateSVG',
16 - 'author' => 'Harry Burt',
17 - 'url' => 'http://www.mediawiki.org/wiki/Extension:TranslateSvg',
18 - 'descriptionmsg' => 'translatesvg-desc',
19 - 'version' => '1.0.0',
 15+ 'name' => 'TranslateSVG',
 16+ 'author' => 'Harry Burt',
 17+ 'url' => 'http://www.mediawiki.org/wiki/Extension:TranslateSvg',
 18+ 'descriptionmsg' => 'translatesvg-desc',
 19+ 'version' => '1.0.0',
2020 );
2121
2222 $dir = dirname( __FILE__ ) . '/';
@@ -31,4 +31,5 @@
3232 'messages' => array( 'translatesvg-add', 'translatesvg-addlink', 'translatesvg-specify' ),
3333 'localBasePath' => dirname( __FILE__ ),
3434 'remoteExtPath' => 'translateSvg'
35 -);
\ No newline at end of file
 35+);
 36+
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php
@@ -1,12 +1,16 @@
22 <?php
33 class SpecialTranslateSvg extends SpecialPage {
 4+
 5+ /**
 6+ * @var SimpleXMLElement
 7+ */
48 private $svg = '';
59 private $translations = array();
610 private $number = 0;
711 private $num = 0; //iterator
812 private $added = array();
913 private $modified = array();
10 -
 14+
1115 function __construct() {
1216 parent::__construct( 'TranslateSvg' );
1317 }
@@ -25,8 +29,8 @@
2630 } else {
2731 $file = wfFindFile( $title );
2832
29 - if ( $file && $file->exists() ){
30 - $this->svg = new SimpleXMLElement( $file->getPath(), 0, true );
 33+ if ( $file && $file->exists() ){
 34+ $this->svg = new SimpleXMLElement( $file->getPath(), 0, true );
3135 $this->svg->registerXPathNamespace( 'svg', 'http://www.w3.org/2000/svg' );
3236 $this->makeTranslationReady();
3337 $this->extractTranslations();
@@ -67,6 +71,7 @@
6872 Html::closeElement( 'form' )
6973 );
7074 }
 75+
7176 function makeTranslationReady() {
7277 $result = $this->svg->xpath("//svg:text");
7378 foreach( $result as &$text ){
@@ -86,6 +91,7 @@
8792 }
8893 }
8994 }
 95+
9096 function extractTranslations(){
9197 $result = $this->svg->xpath("//svg:switch");
9298 $this->number = count( $result );
@@ -107,8 +113,9 @@
108114 }
109115 $this->translations [ $i ][] = array_merge( $attr, array( 'text'=>$text) );
110116 }
111 - }
 117+ }
112118 }
 119+
113120 function tidyTranslations(){
114121 $new = array();
115122 foreach( $this->translations as $number=>$translations ){
@@ -127,20 +134,19 @@
128135 }
129136 $this->translations = $new;
130137 }
131 -
132 - function printTranslations( $filename ){
 138+
 139+ function printTranslations( $filename ){
133140 global $wgScript;
134141 $this->getOutput()->addModules( 'ext.translateSvg' );
135142 $html = Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialtranslatesvg' ) ) .
136143 Html::hidden( 'file', $filename ) .
137144 Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
138 -
139 - $groups = array();
 145+
140146 foreach( $this->translations as $language=>$translations ){
141147 $languages = Language::getLanguageNames();
142148 $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc');
143149 $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' );
144 -
 150+
145151 $html .= Html::openElement( 'fieldset', array( 'id' => $language ) ) .
146152 Html::element( 'legend', null, $languages[$language] );
147153 $groups = array();
@@ -152,7 +158,7 @@
153159 $grouphtml = $label . $desc . '&#160;&#160;&#160;' . $input;
154160 if( $language !== 'qqq' ){
155161 $grouphtml .= Html::element( 'br' ) .
156 - "&#160;&#160;&#160;" . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) .
 162+ "&#160;&#160;&#160;" . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) .
157163 "&#160;&#160;&#160;" . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $existing['y'] );
158164 }
159165 $groups[] = $grouphtml;
@@ -164,7 +170,7 @@
165171 Html::closeElement( 'form' );
166172 $this->getOutput()->addHTML( $html );
167173 }
168 -
 174+
169175 function getFallback( $num ){
170176 if( isset( $this->translations['fallback'][$num] ) ){
171177 return $this->translations['fallback'][$num];
@@ -172,7 +178,7 @@
173179 //TODO
174180 }
175181 }
176 -
 182+
177183 /*
178184 Return the existing translation of a text: the starting point that the translator works with.
179185 Autofill is annoying at best, but it's useful for numbers. Hence scrub all non-numeric text (but
@@ -193,7 +199,7 @@
194200 }
195201 }
196202 }
197 -
 203+
198204 function getDescriptor( $num ){
199205 $qqq = '';
200206 if( isset( $this->translations['qqq'][$num]['text'] ) ){
@@ -204,7 +210,7 @@
205211 }
206212 return $qqq;
207213 }
208 -
 214+
209215 function updateTranslations( $params ){
210216 foreach( $params as $name=>$value ){
211217 list( $lang, $num, $param ) = explode( '-', $name );
@@ -213,7 +219,7 @@
214220 }
215221 $this->translations[ $lang ][ $num ][$param] = $value;
216222 }
217 -
 223+
218224 $reverse = array();
219225 foreach( $this->translations as $language=>$translations ){
220226 if( $language == 'fallback' ) continue; //We'll come back for it.
@@ -226,11 +232,12 @@
227233 }
228234 $this->translations = $reverse;
229235 }
 236+
230237 function updateSVG(){
231238 $result = $this->svg->xpath("//svg:switch");
232239 for( $i = 0; $i < $this->number; $i++ ){
233240 $switch = $result[$i];
234 - $switch->registerXPathNamespace( 'svg', 'http://www.w3.org/2000/svg' );
 241+ $switch->registerXPathNamespace( 'svg', 'http://www.w3.org/2000/svg' );
235242 foreach( $this->translations[$i] as $translation ){
236243 $language = $translation['systemLanguage'];
237244 if( $language === 'fallback' ){
@@ -238,7 +245,7 @@
239246 } else {
240247 $path = "svg:text[@systemLanguage='$language']";
241248 }
242 - $existing = $switch->xpath( $path );
 249+ $existing = $switch->xpath( $path );
243250 if( count( $existing ) == 1 ){
244251 // Update of existing translation
245252 $old = array( (string)$existing[0][0], (string)$existing[0]['x'], (string)$existing[0]['y']);
@@ -271,8 +278,9 @@
272279 }
273280 }
274281 }
 282+
275283 function saveSVG( $filepath, $filename ){
276 -
 284+
277285 $mUpload = new TranslateSvgUpload();
278286 $temp = tempnam( wfTempDir(), 'trans' );
279287 $dom = new DOMDocument('1.0');
@@ -281,9 +289,9 @@
282290 $dom->loadXML($this->svg->asXML());
283291 $dom->save( $temp );
284292 unset( $dom );
285 -
 293+
286294 $mUpload->initializePathInfo( $filename, $temp, filesize( $filepath ), true );
287 -
 295+
288296 $details = $mUpload->verifyUpload();
289297 if ( $details['status'] != UploadBase::OK ) {
290298 //TODO
@@ -322,6 +330,6 @@
323331
324332 class TranslateSvgUpload extends UploadBase {
325333 public function initializeFromRequest( &$request ) {
326 -
 334+
327335 }
328336 }

Status & tagging log