r79943 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79942‎ | r79943 | r79944 >
Date:18:26, 10 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r79938
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.i18n.php (modified) (history)
  • /trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.i18n.php
@@ -38,6 +38,7 @@
3939 'livetranslate-special-button' => 'Save',
4040 'livetranslate-special-type' => 'Type',
4141 'livetranslate-special-location' => 'Location',
 42+ 'livetranslate-special-add-tm' => 'Add a new translation memory',
4243 );
4344
4445 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
Index: trunk/extensions/LiveTranslate/specials/SpecialLiveTranslate.php
@@ -65,7 +65,7 @@
6666 * @param string $arg
6767 */
6868 public function execute( $arg ) {
69 - global $wgOut, $wgUser, $wgRequest, $egPushTargets;
 69+ global $wgOut, $wgUser, $wgRequest;
7070
7171 $this->setHeaders();
7272 $this->outputHeader();
@@ -74,14 +74,38 @@
7575 if ( !$this->userCanExecute( $wgUser ) ) {
7676 $this->displayRestrictionError();
7777 return;
78 - }
 78+ }
7979
80 - // TODO: handle submissions
 80+ if ( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
 81+ $this->handleSubmission();
 82+ }
8183
8284 $this->displayTMConfig();
8385 }
8486
8587 /**
 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+ /**
86110 * Displays the translation memories config table.
87111 *
88112 * @since 0.4
@@ -110,7 +134,7 @@
111135 $wgOut->addHTML( Html::rawElement(
112136 'tr',
113137 array(),
114 - Html::element( 'th', array(), wfMsg( 'livetranslate-special-location' ) ),
 138+ Html::element( 'th', array(), wfMsg( 'livetranslate-special-location' ) ) .
115139 Html::element( 'th', array(), wfMsg( 'livetranslate-special-type' ) )
116140 ) );
117141
@@ -127,6 +151,7 @@
128152 $this->displayAddNewTM();
129153
130154 $wgOut->addHtml(
 155+ '<br />' .
131156 Html::input(
132157 '',
133158 wfMsg( 'livetranslate-special-button' ),
@@ -179,8 +204,8 @@
180205 $wgOut->addHTML( Html::rawElement(
181206 'tr',
182207 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
185210 ) );
186211 }
187212
@@ -190,7 +215,42 @@
191216 * @since 0.4
192217 */
193218 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+ );
195232 }
196233
 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+
197257 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79938Work on special pagejeroendedauw16:08, 10 January 2011

Status & tagging log