Index: trunk/extensions/TranslateSvg/TranslateSvg.php |
— | — | @@ -11,11 +11,11 @@ |
12 | 12 | */ |
13 | 13 | |
14 | 14 | $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', |
20 | 20 | ); |
21 | 21 | |
22 | 22 | $dir = dirname( __FILE__ ) . '/'; |
— | — | @@ -31,4 +31,5 @@ |
32 | 32 | 'messages' => array( 'translatesvg-add', 'translatesvg-addlink', 'translatesvg-specify' ), |
33 | 33 | 'localBasePath' => dirname( __FILE__ ), |
34 | 34 | 'remoteExtPath' => 'translateSvg' |
35 | | -); |
\ No newline at end of file |
| 35 | +); |
| 36 | + |
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php |
— | — | @@ -1,12 +1,16 @@ |
2 | 2 | <?php |
3 | 3 | class SpecialTranslateSvg extends SpecialPage { |
| 4 | + |
| 5 | + /** |
| 6 | + * @var SimpleXMLElement |
| 7 | + */ |
4 | 8 | private $svg = ''; |
5 | 9 | private $translations = array(); |
6 | 10 | private $number = 0; |
7 | 11 | private $num = 0; //iterator |
8 | 12 | private $added = array(); |
9 | 13 | private $modified = array(); |
10 | | - |
| 14 | + |
11 | 15 | function __construct() { |
12 | 16 | parent::__construct( 'TranslateSvg' ); |
13 | 17 | } |
— | — | @@ -25,8 +29,8 @@ |
26 | 30 | } else { |
27 | 31 | $file = wfFindFile( $title ); |
28 | 32 | |
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 ); |
31 | 35 | $this->svg->registerXPathNamespace( 'svg', 'http://www.w3.org/2000/svg' ); |
32 | 36 | $this->makeTranslationReady(); |
33 | 37 | $this->extractTranslations(); |
— | — | @@ -67,6 +71,7 @@ |
68 | 72 | Html::closeElement( 'form' ) |
69 | 73 | ); |
70 | 74 | } |
| 75 | + |
71 | 76 | function makeTranslationReady() { |
72 | 77 | $result = $this->svg->xpath("//svg:text"); |
73 | 78 | foreach( $result as &$text ){ |
— | — | @@ -86,6 +91,7 @@ |
87 | 92 | } |
88 | 93 | } |
89 | 94 | } |
| 95 | + |
90 | 96 | function extractTranslations(){ |
91 | 97 | $result = $this->svg->xpath("//svg:switch"); |
92 | 98 | $this->number = count( $result ); |
— | — | @@ -107,8 +113,9 @@ |
108 | 114 | } |
109 | 115 | $this->translations [ $i ][] = array_merge( $attr, array( 'text'=>$text) ); |
110 | 116 | } |
111 | | - } |
| 117 | + } |
112 | 118 | } |
| 119 | + |
113 | 120 | function tidyTranslations(){ |
114 | 121 | $new = array(); |
115 | 122 | foreach( $this->translations as $number=>$translations ){ |
— | — | @@ -127,20 +134,19 @@ |
128 | 135 | } |
129 | 136 | $this->translations = $new; |
130 | 137 | } |
131 | | - |
132 | | - function printTranslations( $filename ){ |
| 138 | + |
| 139 | + function printTranslations( $filename ){ |
133 | 140 | global $wgScript; |
134 | 141 | $this->getOutput()->addModules( 'ext.translateSvg' ); |
135 | 142 | $html = Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialtranslatesvg' ) ) . |
136 | 143 | Html::hidden( 'file', $filename ) . |
137 | 144 | Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
138 | | - |
139 | | - $groups = array(); |
| 145 | + |
140 | 146 | foreach( $this->translations as $language=>$translations ){ |
141 | 147 | $languages = Language::getLanguageNames(); |
142 | 148 | $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc'); |
143 | 149 | $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' ); |
144 | | - |
| 150 | + |
145 | 151 | $html .= Html::openElement( 'fieldset', array( 'id' => $language ) ) . |
146 | 152 | Html::element( 'legend', null, $languages[$language] ); |
147 | 153 | $groups = array(); |
— | — | @@ -152,7 +158,7 @@ |
153 | 159 | $grouphtml = $label . $desc . '   ' . $input; |
154 | 160 | if( $language !== 'qqq' ){ |
155 | 161 | $grouphtml .= Html::element( 'br' ) . |
156 | | - "   " . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) . |
| 162 | + "   " . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) . |
157 | 163 | "   " . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $existing['y'] ); |
158 | 164 | } |
159 | 165 | $groups[] = $grouphtml; |
— | — | @@ -164,7 +170,7 @@ |
165 | 171 | Html::closeElement( 'form' ); |
166 | 172 | $this->getOutput()->addHTML( $html ); |
167 | 173 | } |
168 | | - |
| 174 | + |
169 | 175 | function getFallback( $num ){ |
170 | 176 | if( isset( $this->translations['fallback'][$num] ) ){ |
171 | 177 | return $this->translations['fallback'][$num]; |
— | — | @@ -172,7 +178,7 @@ |
173 | 179 | //TODO |
174 | 180 | } |
175 | 181 | } |
176 | | - |
| 182 | + |
177 | 183 | /* |
178 | 184 | Return the existing translation of a text: the starting point that the translator works with. |
179 | 185 | Autofill is annoying at best, but it's useful for numbers. Hence scrub all non-numeric text (but |
— | — | @@ -193,7 +199,7 @@ |
194 | 200 | } |
195 | 201 | } |
196 | 202 | } |
197 | | - |
| 203 | + |
198 | 204 | function getDescriptor( $num ){ |
199 | 205 | $qqq = ''; |
200 | 206 | if( isset( $this->translations['qqq'][$num]['text'] ) ){ |
— | — | @@ -204,7 +210,7 @@ |
205 | 211 | } |
206 | 212 | return $qqq; |
207 | 213 | } |
208 | | - |
| 214 | + |
209 | 215 | function updateTranslations( $params ){ |
210 | 216 | foreach( $params as $name=>$value ){ |
211 | 217 | list( $lang, $num, $param ) = explode( '-', $name ); |
— | — | @@ -213,7 +219,7 @@ |
214 | 220 | } |
215 | 221 | $this->translations[ $lang ][ $num ][$param] = $value; |
216 | 222 | } |
217 | | - |
| 223 | + |
218 | 224 | $reverse = array(); |
219 | 225 | foreach( $this->translations as $language=>$translations ){ |
220 | 226 | if( $language == 'fallback' ) continue; //We'll come back for it. |
— | — | @@ -226,11 +232,12 @@ |
227 | 233 | } |
228 | 234 | $this->translations = $reverse; |
229 | 235 | } |
| 236 | + |
230 | 237 | function updateSVG(){ |
231 | 238 | $result = $this->svg->xpath("//svg:switch"); |
232 | 239 | for( $i = 0; $i < $this->number; $i++ ){ |
233 | 240 | $switch = $result[$i]; |
234 | | - $switch->registerXPathNamespace( 'svg', 'http://www.w3.org/2000/svg' ); |
| 241 | + $switch->registerXPathNamespace( 'svg', 'http://www.w3.org/2000/svg' ); |
235 | 242 | foreach( $this->translations[$i] as $translation ){ |
236 | 243 | $language = $translation['systemLanguage']; |
237 | 244 | if( $language === 'fallback' ){ |
— | — | @@ -238,7 +245,7 @@ |
239 | 246 | } else { |
240 | 247 | $path = "svg:text[@systemLanguage='$language']"; |
241 | 248 | } |
242 | | - $existing = $switch->xpath( $path ); |
| 249 | + $existing = $switch->xpath( $path ); |
243 | 250 | if( count( $existing ) == 1 ){ |
244 | 251 | // Update of existing translation |
245 | 252 | $old = array( (string)$existing[0][0], (string)$existing[0]['x'], (string)$existing[0]['y']); |
— | — | @@ -271,8 +278,9 @@ |
272 | 279 | } |
273 | 280 | } |
274 | 281 | } |
| 282 | + |
275 | 283 | function saveSVG( $filepath, $filename ){ |
276 | | - |
| 284 | + |
277 | 285 | $mUpload = new TranslateSvgUpload(); |
278 | 286 | $temp = tempnam( wfTempDir(), 'trans' ); |
279 | 287 | $dom = new DOMDocument('1.0'); |
— | — | @@ -281,9 +289,9 @@ |
282 | 290 | $dom->loadXML($this->svg->asXML()); |
283 | 291 | $dom->save( $temp ); |
284 | 292 | unset( $dom ); |
285 | | - |
| 293 | + |
286 | 294 | $mUpload->initializePathInfo( $filename, $temp, filesize( $filepath ), true ); |
287 | | - |
| 295 | + |
288 | 296 | $details = $mUpload->verifyUpload(); |
289 | 297 | if ( $details['status'] != UploadBase::OK ) { |
290 | 298 | //TODO |
— | — | @@ -322,6 +330,6 @@ |
323 | 331 | |
324 | 332 | class TranslateSvgUpload extends UploadBase { |
325 | 333 | public function initializeFromRequest( &$request ) { |
326 | | - |
| 334 | + |
327 | 335 | } |
328 | 336 | } |