Index: trunk/extensions/TranslateSvg/TranslateSvg.php |
— | — | @@ -31,6 +31,7 @@ |
32 | 32 | 'scripts' => array( 'ext.translateSvg.core.js' ), |
33 | 33 | // 'styles' => 'css/ext.translateSvg.css', |
34 | 34 | 'messages' => array( 'translatesvg-add', 'translatesvg-addlink', 'translatesvg-specify', 'translatesvg-remove' ), |
| 35 | + 'dependencies' => array( 'jquery.spinner', 'jquery.makeCollapsible' ), |
35 | 36 | 'localBasePath' => dirname( __FILE__ ), |
36 | 37 | 'remoteExtPath' => 'translateSvg' |
37 | | -); |
| 38 | +); |
\ No newline at end of file |
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php |
— | — | @@ -43,21 +43,20 @@ |
44 | 44 | $this->extractTranslations(); |
45 | 45 | $this->tidyTranslations(); |
46 | 46 | $params = $request->getQueryValues(); |
47 | | - if( count( $params ) > 2 && isset( $params['title'] ) && isset( $params['file'] ) ){ |
48 | | - unset( $params['title'] ); |
| 47 | + if( count( $params ) > 2 && isset( $params['title'] ) && isset( $params['file'] ) && isset( $params['step'] ) ){ |
49 | 48 | $filename = $params['file']; |
50 | | - unset( $params['file'] ); |
| 49 | + unset( $params['title'], $params['file'], $params['step'] ); |
51 | 50 | $this->updateTranslations( $params ); |
52 | 51 | $this->updateSVG(); |
53 | 52 | $this->saveSVG( $file->getLocalRefPath(), $filename ); |
54 | 53 | $file->purgeThumbnails(); |
55 | 54 | } else { |
56 | 55 | $this->thumb = Linker::makeThumbLinkObj( $title, $file, $label = '', '', |
57 | | - $align = 'right', array( 'width' => 250, 'height' => 250) ); |
| 56 | + $align = $this->getLanguage()->alignEnd(), array( 'width' => 250, 'height' => 250 ) ); |
58 | 57 | $this->printTranslations( $file->getName() ); |
59 | 58 | } |
60 | 59 | } else { |
61 | | - $this->getOutput()->addHTML( '<p>This file could not be translated, sorry.</p>' ); |
| 60 | + $this->getOutput()->addHTML( '<p>This file could not be translated, sorry.</p>' ); //TODO: internationalise |
62 | 61 | } |
63 | 62 | } else { |
64 | 63 | $this->getOutput()->setStatusCode( 404 ); |
— | — | @@ -116,23 +115,27 @@ |
117 | 116 | $attrs = ( $child->hasAttributes() ) ? $child->attributes : array(); |
118 | 117 | foreach ($attrs as $num => $attr){ |
119 | 118 | $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; |
| 119 | + if( trim( $parentattr ) === '' ){ |
| 120 | + $text->setAttribute( $attr->name, $attr->value ); //Simple upmerge |
| 121 | + } else { |
| 122 | + //Resolve conflict. the aim is to preserve the visuals. |
| 123 | + switch( $attr->name ){ |
| 124 | + case 'x': |
| 125 | + case 'y': |
| 126 | + $text->setAttribute( $attr->name, $attr->value ); //Overwrite |
| 127 | + break; |
| 128 | + case 'style': |
| 129 | + $merged = $parentattr; |
| 130 | + if( substr( $merged, -1 ) !== ';' ){ |
| 131 | + $merged .= ';'; |
| 132 | + } |
| 133 | + $merged .= $attr->value; |
| 134 | + break; |
| 135 | + case 'id': |
| 136 | + break; //Ignore |
| 137 | + default: |
| 138 | + return false; |
| 139 | + } |
137 | 140 | } |
138 | 141 | } |
139 | 142 | $text->appendChild( $child->childNodes->item( 0 ) ); |
— | — | @@ -197,33 +200,34 @@ |
198 | 201 | $html = $this->thumb . |
199 | 202 | Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialtranslatesvg' ) ) . |
200 | 203 | Html::hidden( 'file', $filename ) . |
| 204 | + Html::hidden( 'step', 'translated' ) . |
201 | 205 | Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
202 | 206 | |
| 207 | + $groups = array(); |
203 | 208 | foreach( $this->translations as $language=>$translations ){ |
204 | | - $languages = Language::getLanguageNames(); |
205 | | - $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc'); |
206 | | - $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' ); |
207 | | - |
208 | | - $html .= Html::openElement( 'fieldset', array( 'id' => $language ) ) . |
209 | | - Html::element( 'legend', null, $languages[$language] ); |
| 209 | + $html .= Html::openElement( 'fieldset', array( 'id' => "mw-translatesvg-fieldset-$language" ) ) . |
| 210 | + Html::element( 'legend', null, $languages[$language] ) . |
| 211 | + Html::openElement( 'div', array( 'class' => "mw-translatesvg-collapsible" ) ); |
210 | 212 | $groups = array(); |
211 | 213 | for( $i = 0; $i < $this->number; $i++ ){ |
212 | 214 | $fallback = $this->getFallback( $i ); |
213 | 215 | $existing = $this->getExisting( $i, $language ); |
214 | 216 | $desc = ( $language === 'qqq' ) ? '' : ' ' . Html::element( 'small', null, $this->getDescriptor( $i ) ); |
215 | | - list( $label, $input ) = Xml::inputLabelSep( $fallback['text'], $language.'-'.$i.'-text', $language.'-'.$i.'-text', 50, $existing['text'] ); |
| 217 | + list( $label, $input ) = Xml::inputLabelSep( $fallback['text'], "mw-translatesvg-$language-$i-text", "mw-translatesvg-$language-$i-text", 50, $existing['text'] ); |
216 | 218 | $grouphtml = $label . $desc . '   ' . $input; |
217 | 219 | if( $language !== 'qqq' ){ |
218 | 220 | $grouphtml .= Html::element( 'br' ) . |
219 | | - "   " . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) . |
220 | | - "   " . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $existing['y'] ); |
| 221 | + "   " . |
| 222 | + Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), "mw-translatesvg-$language-$i-x", "mw-translatesvg-$language-$i-x", 5, $existing['x'] ) . |
| 223 | + "   " . |
| 224 | + Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), "mw-translatesvg-$language-$i-y", "mw-translatesvg-$language-$i-y", 5, $existing['y'] ); |
221 | 225 | } |
222 | 226 | $groups[] = $grouphtml; |
223 | 227 | } |
224 | 228 | $html .= implode( Html::element( 'div', array( 'style' => 'height:10px' ) ), $groups ); |
225 | | - $html .= Html::closeElement( 'fieldset' ); |
| 229 | + $html .= Html::closeElement( 'div' ) . Html::closeElement( 'fieldset' ); |
226 | 230 | } |
227 | | - $html .= Xml::submitButton( 'Submit' ) . "\n" . |
| 231 | + $html .= Xml::submitButton( wfMsg( 'translatesvg-submit' ) ) . "\n" . |
228 | 232 | Html::closeElement( 'form' ); |
229 | 233 | $this->getOutput()->addHTML( $html ); |
230 | 234 | } |
Index: trunk/extensions/TranslateSvg/ext.translateSvg.core.js |
— | — | @@ -2,28 +2,29 @@ |
3 | 3 | var languages = { isset: false }; |
4 | 4 | |
5 | 5 | //Replace fake "add language" link with real one and add it |
6 | | - var paragraph = $( '<p id="newtrans"></p>' ).text( mw.msg( 'translatesvg-add' ) ); |
| 6 | + var paragraph = $( '<p id="mw-translatesvg-newtrans"></p>' ).text( mw.msg( 'translatesvg-add' ) ); |
7 | 7 | var match = paragraph.html().match( /\[\[#addlanguage\|(.*?)\]\]/ ); |
8 | | - paragraph.html( paragraph.html().replace( match[0], '<a id="newtranslink" href="#">' + match[1] + '</a>' ) ); |
| 8 | + paragraph.html( paragraph.html().replace( match[0], '<a id="mw-translatesvg-newtranslink" href="#">' + match[1] + '</a>' ) ); |
9 | 9 | $( 'div.mw-specialpage-summary' ).append( paragraph ); |
10 | 10 | |
11 | 11 | //Add in "remove" links |
12 | 12 | $( 'legend' ).each( function(){ |
13 | | - var langcode = $(this).parent().attr('id'); |
| 13 | + var langcode = $(this).parent().attr('id').substr( 25 ); //Trim "mw-translatesvg-fieldset-" |
14 | 14 | if( langcode !== 'qqq' && langcode !== 'fallback' ){ |
15 | 15 | $(this).append( ' ' ).append( getRemoveLink() ); |
16 | 16 | } |
17 | 17 | } ); |
18 | 18 | |
19 | | - $( '#newtranslink' ) |
| 19 | + |
| 20 | + $( '#mw-translatesvg-newtranslink' ) |
20 | 21 | .click( function() { |
21 | 22 | var langcode = prompt( mw.msg( 'translatesvg-specify' ) ); |
22 | 23 | if( langcode !== null ){ |
23 | | - if( !langcode.match( /^[a-z]+( ?:-[a-z]+ )?/ ) ){ |
| 24 | + if( !langcode.match( /^[a-z]+(?:-[a-z]+)?/ ) ){ |
24 | 25 | //Not valid language code |
25 | 26 | return false; //TODO: more helpful? |
26 | 27 | } |
27 | | - if( $( 'fieldset#'+langcode ).length !== 0 ){ |
| 28 | + if( $( '#mw-translatesvg-fieldset-'+langcode ).length !== 0 ){ |
28 | 29 | //Already exists |
29 | 30 | return false; //TODO: more helpful? |
30 | 31 | } |
— | — | @@ -32,10 +33,10 @@ |
33 | 34 | //Have already loaded valid languages and this ain't one of them |
34 | 35 | return false; //TODO: more helpful? |
35 | 36 | } |
36 | | - $( 'form#specialtranslatesvg' ).prepend( getNewFieldset( langcode, languages[langcode] ) ); |
| 37 | + $( '#specialtranslatesvg' ).prepend( getNewFieldset( langcode, languages[langcode] ) ); |
37 | 38 | } else { |
38 | | - var temp = $( '<fieldset id="temp"><br /></fieldset>' ).append( $.createSpinner() ); |
39 | | - $( 'form#specialtranslatesvg' ).prepend( temp ); |
| 39 | + var temp = $( '<fieldset class="mw-translatesvg-temp"><br /></fieldset>' ).append( $.createSpinner() ); |
| 40 | + $( '#specialtranslatesvg' ).prepend( temp ); |
40 | 41 | jQuery.getJSON( |
41 | 42 | mw.util.wikiScript( 'api' ), { |
42 | 43 | 'format': 'json', |
— | — | @@ -48,12 +49,12 @@ |
49 | 50 | languages[ data.query.languages[i]['code'] ] = data.query.languages[i]['*']; |
50 | 51 | } |
51 | 52 | if( ( langcode in languages ) ){ |
52 | | - $( 'form#specialtranslatesvg' ).prepend( getNewFieldset( langcode, languages[langcode] ) ); |
| 53 | + $( '#specialtranslatesvg' ).prepend( getNewFieldset( langcode, languages[langcode] ) ); |
53 | 54 | } else { |
54 | 55 | //Have now loaded valid languages and this ain't one of them |
55 | 56 | //TODO: more helpful? |
56 | 57 | } |
57 | | - $( 'fieldset#temp' ).remove(); |
| 58 | + $( '.mw-translatesvg-temp' ).remove(); |
58 | 59 | languages.isset = true; |
59 | 60 | } |
60 | 61 | ); |
— | — | @@ -64,7 +65,7 @@ |
65 | 66 | } ); |
66 | 67 | |
67 | 68 | function getNewFieldset( langcode, langname ){ |
68 | | - var newfieldset = $( 'fieldset#fallback' ).clone(); |
| 69 | + var newfieldset = $( 'fieldset#mw-translatesvg-fieldset-fallback' ).clone(); |
69 | 70 | newfieldset.find( 'input' ).each( function (){ |
70 | 71 | $( this ).attr( 'id', $( this ).attr( 'id' ).toString().replace( 'fallback', langcode ) ); |
71 | 72 | $( this ).attr( 'name', $( this ).attr( 'name' ).toString().replace( 'fallback', langcode ) ); |
— | — | @@ -73,7 +74,7 @@ |
74 | 75 | newfieldset.find( 'label' ).each( function (){ |
75 | 76 | $( this ).attr( 'for', $( this ).attr( 'for' ).toString().replace( 'fallback', langcode ) ); |
76 | 77 | } ); |
77 | | - newfieldset.attr( 'id', langcode ); |
| 78 | + newfieldset.attr( 'id', "mw-translatesvg-fieldset-" + langcode ); |
78 | 79 | newfieldset.find( 'legend' ).each( function (){ |
79 | 80 | $( this ).text( langname ); |
80 | 81 | $( this ).append( ' ' ).append( getRemoveLink() ); |
— | — | @@ -83,7 +84,7 @@ |
84 | 85 | |
85 | 86 | function getRemoveLink(){ |
86 | 87 | var removelink = $( '<a href="#"><abbr title="' |
87 | | - + mw.msg( 'translatesvg-remove' ) |
| 88 | + + mw.message('translatesvg-remove').escaped() |
88 | 89 | + '"><small>[x]</small></abbr></a>' ); |
89 | 90 | removelink.click( function(){ $(this).parent().parent().remove(); } ); |
90 | 91 | return removelink; |