Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php |
— | — | @@ -14,6 +14,7 @@ |
15 | 15 | private $number = 0; |
16 | 16 | private $added = array(); |
17 | 17 | private $modified = array(); |
| 18 | + private $thumb = null; |
18 | 19 | |
19 | 20 | function __construct() { |
20 | 21 | parent::__construct( 'TranslateSvg' ); |
— | — | @@ -33,27 +34,30 @@ |
34 | 35 | } else { |
35 | 36 | $file = wfFindFile( $title ); |
36 | 37 | |
37 | | - if ( $file && $file->exists() ){ |
| 38 | + if ( $file && $file->exists() ){ |
38 | 39 | $this->svg = new DOMDocument( '1.0' ); |
39 | | - $this->svg->load( $file->getPath() ); |
| 40 | + $this->svg->load( $file->getLocalRefPath() ); |
40 | 41 | $this->xpath = new DOMXpath( $this->svg ); |
41 | 42 | $this->xpath->registerNamespace( 'svg', 'http://www.w3.org/2000/svg' ); |
42 | | - if( !$this->makeTranslationReady() ){ |
43 | | - die( "Could not be made translation ready." ); //TODO: internationalise. |
44 | | - } |
45 | | - $this->extractTranslations(); |
46 | | - $this->tidyTranslations(); |
47 | | - $params = $request->getQueryValues(); |
48 | | - if( count( $params ) > 2 && isset( $params['title'] ) && isset( $params['file'] ) ){ |
49 | | - unset( $params['title'] ); |
50 | | - $filename = $params['file']; |
51 | | - unset( $params['file'] ); |
52 | | - $this->updateTranslations( $params ); |
53 | | - $this->updateSVG(); |
54 | | - $this->saveSVG( $file->getPath(), $filename ); |
55 | | - $file->purgeThumbnails(); |
| 43 | + if( $this->makeTranslationReady() ){ |
| 44 | + $this->extractTranslations(); |
| 45 | + $this->tidyTranslations(); |
| 46 | + $params = $request->getQueryValues(); |
| 47 | + if( count( $params ) > 2 && isset( $params['title'] ) && isset( $params['file'] ) ){ |
| 48 | + unset( $params['title'] ); |
| 49 | + $filename = $params['file']; |
| 50 | + unset( $params['file'] ); |
| 51 | + $this->updateTranslations( $params ); |
| 52 | + $this->updateSVG(); |
| 53 | + $this->saveSVG( $file->getLocalRefPath(), $filename ); |
| 54 | + $file->purgeThumbnails(); |
| 55 | + } else { |
| 56 | + $this->thumb = Linker::makeThumbLinkObj( $title, $file, $label = '', '', |
| 57 | + $align = 'right', array( 'width' => 250, 'height' => 250) ); |
| 58 | + $this->printTranslations( $file->getName() ); |
| 59 | + } |
56 | 60 | } else { |
57 | | - $this->printTranslations( $file->getName() ); |
| 61 | + $this->getOutput()->addHTML( '<p>This file could not be translated, sorry.</p>' ); |
58 | 62 | } |
59 | 63 | } else { |
60 | 64 | $this->getOutput()->setStatusCode( 404 ); |
— | — | @@ -91,7 +95,7 @@ |
92 | 96 | $ancestorswitches = $this->xpath->query( "ancestor::svg:switch", $text ); |
93 | 97 | if( $ancestorswitches->length == 0 ){ |
94 | 98 | $switch = $this->svg->createElement( 'switch' ); |
95 | | - $text->parentNode->appendChild( $switch ); |
| 99 | + $text->parentNode->insertBefore( $switch, $text ); |
96 | 100 | $switch->appendChild( $text ); //Move node into sibling <switch> element |
97 | 101 | } else { |
98 | 102 | if( $text->parentNode->nodeName !== "switch" ){ |
— | — | @@ -111,7 +115,25 @@ |
112 | 116 | //Repair by trimming excess <tspan>s |
113 | 117 | $attrs = ( $child->hasAttributes() ) ? $child->attributes : array(); |
114 | 118 | foreach ($attrs as $num => $attr){ |
115 | | - $text->setAttribute( $attr->name, $attr->value ); |
| 119 | + $parentattr = trim( $text->getAttribute( $attr->name ) ); |
| 120 | + switch( $attr->name ){ |
| 121 | + case 'x': |
| 122 | + case 'y': |
| 123 | + case '': |
| 124 | + $text->setAttribute( $attr->name, $attr->value ); //Overwrite |
| 125 | + break; |
| 126 | + case 'style': |
| 127 | + $merged = $parentattr; |
| 128 | + if( substr( $merged, -1 ) !== ';' ){ |
| 129 | + $merged .= ';'; |
| 130 | + } |
| 131 | + $merged .= $attr->value; |
| 132 | + break; |
| 133 | + case 'id': |
| 134 | + break; //Ignore |
| 135 | + default: |
| 136 | + return false; |
| 137 | + } |
116 | 138 | } |
117 | 139 | $text->appendChild( $child->childNodes->item( 0 ) ); |
118 | 140 | $text->removeChild( $child ); |
— | — | @@ -166,8 +188,14 @@ |
167 | 189 | */ |
168 | 190 | function printTranslations( $filename ){ |
169 | 191 | global $wgScript; |
| 192 | + |
| 193 | + $languages = Language::getLanguageNames(); |
| 194 | + $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc'); |
| 195 | + $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' ); |
| 196 | + |
170 | 197 | $this->getOutput()->addModules( 'ext.translateSvg' ); |
171 | | - $html = Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialtranslatesvg' ) ) . |
| 198 | + $html = $this->thumb . |
| 199 | + Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialtranslatesvg' ) ) . |
172 | 200 | Html::hidden( 'file', $filename ) . |
173 | 201 | Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
174 | 202 | |
— | — | @@ -227,7 +255,7 @@ |
228 | 256 | return $this->translations[$language][$num]; |
229 | 257 | } else { |
230 | 258 | $fallback = $this->getFallback( $num ); |
231 | | - if( preg_match( '/^[0-9 .,]+$/', trim( $fallback['text'] ) ) ){ |
| 259 | + if( preg_match( '/^[0-9 .,-]+$/', trim( $fallback['text'] ) ) ){ |
232 | 260 | return $fallback; |
233 | 261 | } else { |
234 | 262 | return array( 'text' => '', $fallback['x'], $fallback['y'] ); |
— | — | @@ -257,9 +285,13 @@ |
258 | 286 | foreach( $params as $name=>$value ){ |
259 | 287 | list( $lang, $num, $param ) = explode( '-', $name ); |
260 | 288 | if( !isset( $this->translations[ $lang ][ $num ] ) ){ |
261 | | - $this->translations[ $lang ][ $num ] = $this->getFallback( $num ); |
| 289 | + if( $lang !== 'qqq' ){ |
| 290 | + $this->translations[ $lang ][ $num ] = $this->getFallback( $num ); |
| 291 | + } else { |
| 292 | + $this->translations[ $lang ][ $num ] = array(); |
| 293 | + } |
262 | 294 | } |
263 | | - $this->translations[ $lang ][ $num ][$param] = $value; |
| 295 | + $this->translations[ $lang ][ $num ][ $param ] = $value; |
264 | 296 | } |
265 | 297 | |
266 | 298 | $reverse = array(); |
Index: trunk/extensions/TranslateSvg/ext.translateSvg.core.js |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | |
93 | 93 | function getExisting( fallback ){ |
94 | 94 | //No need to check for an existing translation since we're creating a new language box |
95 | | - if( fallback.match( /^[0-9 .,]+$/ ) ){ |
| 95 | + if( fallback.match( /^[0-9 .,-]+$/ ) ){ |
96 | 96 | return fallback; |
97 | 97 | } else { |
98 | 98 | return ''; |