Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | 'livetranslate-special-button' => 'Save', |
40 | 40 | 'livetranslate-special-type' => 'Type', |
41 | 41 | 'livetranslate-special-location' => 'Location', |
| 42 | + 'livetranslate-special-add-tm' => 'Add a new translation memory', |
42 | 43 | ); |
43 | 44 | |
44 | 45 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
Index: trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | * @param string $arg |
67 | 67 | */ |
68 | 68 | public function execute( $arg ) { |
69 | | - global $wgOut, $wgUser, $wgRequest, $egPushTargets; |
| 69 | + global $wgOut, $wgUser, $wgRequest; |
70 | 70 | |
71 | 71 | $this->setHeaders(); |
72 | 72 | $this->outputHeader(); |
— | — | @@ -74,14 +74,38 @@ |
75 | 75 | if ( !$this->userCanExecute( $wgUser ) ) { |
76 | 76 | $this->displayRestrictionError(); |
77 | 77 | return; |
78 | | - } |
| 78 | + } |
79 | 79 | |
80 | | - // TODO: handle submissions |
| 80 | + if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { |
| 81 | + $this->handleSubmission(); |
| 82 | + } |
81 | 83 | |
82 | 84 | $this->displayTMConfig(); |
83 | 85 | } |
84 | 86 | |
85 | 87 | /** |
| 88 | + * Handles the submission of the config form. |
| 89 | + * |
| 90 | + * @since 0.4 |
| 91 | + */ |
| 92 | + protected function handleSubmission() { |
| 93 | + global $wgRequest; |
| 94 | + |
| 95 | + $dbw = wfGetDB( DB_MASTER ); |
| 96 | + |
| 97 | + if ( $wgRequest->getText( 'newtm-location' ) != '' ) { |
| 98 | + $dbw->insert( |
| 99 | + 'live_translate_memories', |
| 100 | + array( |
| 101 | + 'memory_type' => $wgRequest->getVal( 'wpnewtm-type' ), |
| 102 | + 'memory_location' => $wgRequest->getText( 'newtm-location' ) |
| 103 | + ) |
| 104 | + ); |
| 105 | + } |
| 106 | + |
| 107 | + } |
| 108 | + |
| 109 | + /** |
86 | 110 | * Displays the translation memories config table. |
87 | 111 | * |
88 | 112 | * @since 0.4 |
— | — | @@ -110,7 +134,7 @@ |
111 | 135 | $wgOut->addHTML( Html::rawElement( |
112 | 136 | 'tr', |
113 | 137 | array(), |
114 | | - Html::element( 'th', array(), wfMsg( 'livetranslate-special-location' ) ), |
| 138 | + Html::element( 'th', array(), wfMsg( 'livetranslate-special-location' ) ) . |
115 | 139 | Html::element( 'th', array(), wfMsg( 'livetranslate-special-type' ) ) |
116 | 140 | ) ); |
117 | 141 | |
— | — | @@ -127,6 +151,7 @@ |
128 | 152 | $this->displayAddNewTM(); |
129 | 153 | |
130 | 154 | $wgOut->addHtml( |
| 155 | + '<br />' . |
131 | 156 | Html::input( |
132 | 157 | '', |
133 | 158 | wfMsg( 'livetranslate-special-button' ), |
— | — | @@ -179,8 +204,8 @@ |
180 | 205 | $wgOut->addHTML( Html::rawElement( |
181 | 206 | 'tr', |
182 | 207 | array(), |
183 | | - Html::element( 'td', array(), $tm->memory_location ), // TODO |
184 | | - Html::element( 'rd', array(), $tm->memory_type ) // TODO |
| 208 | + Html::element( 'td', array(), $tm->memory_location ) . // TODO |
| 209 | + Html::element( 'td', array(), $tm->memory_type ) // TODO |
185 | 210 | ) ); |
186 | 211 | } |
187 | 212 | |
— | — | @@ -190,7 +215,42 @@ |
191 | 216 | * @since 0.4 |
192 | 217 | */ |
193 | 218 | protected function displayAddNewTM() { |
194 | | - // TODO |
| 219 | + global $wgOut; |
| 220 | + |
| 221 | + $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'livetranslate-special-add-tm' ) ) . '</h3>' ); |
| 222 | + |
| 223 | + $wgOut->addHTML( |
| 224 | + '<table><tr>' . |
| 225 | + '<td><b>' . htmlspecialchars( wfMsg( 'livetranslate-special-location' ) ) . ': </b></td>' . |
| 226 | + '<td>' . Html::input( 'newtm-location', '', 'text', array( 'size' => 75 ) ) . '</td>' . |
| 227 | + '</tr><tr>' . |
| 228 | + '<td><b>' . htmlspecialchars( wfMsg( 'livetranslate-special-type' ) ) . ': </b></td>' . |
| 229 | + '<td>' . $this->getTypeSelector( 'newtm-type', '' ) . '</td>' . // TODO |
| 230 | + '</tr></table>' |
| 231 | + ); |
195 | 232 | } |
196 | 233 | |
| 234 | + protected function getTypeSelector( $name, $value ) { |
| 235 | + $typeSelector = new HTMLSelectField( array( |
| 236 | + 'fieldname' => $name, |
| 237 | + 'options' => $this->getTypeOptions() |
| 238 | + ) ); |
| 239 | + |
| 240 | + return $typeSelector->getInputHTML( $value ); |
| 241 | + } |
| 242 | + |
| 243 | + protected function getTypeOptions() { |
| 244 | + static $options = false; |
| 245 | + |
| 246 | + if ( $options === false ) { |
| 247 | + $options = array(); |
| 248 | + |
| 249 | + foreach ( self::$tmTypes as $dbValue => $msgKey ) { |
| 250 | + $options[wfMsg( 'livetranslate-tmtype-' . $msgKey )] = $dbValue; |
| 251 | + } |
| 252 | + } |
| 253 | + |
| 254 | + return $options; |
| 255 | + } |
| 256 | + |
197 | 257 | } |