r99258 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99257‎ | r99258 | r99259 >
Date:21:12, 7 October 2011
Author:nikerabbit
Status:deferred (Comments)
Tags:
Comment:
Cleanup to SpecialTranslate
Modified paths:
  • /trunk/extensions/Translate/specials/SpecialTranslate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/specials/SpecialTranslate.php
@@ -5,7 +5,7 @@
66 * @file
77 * @author Niklas Laxström
88 * @author Siebrand Mazeland
9 - * @copyright Copyright © 2006-2010 Niklas Laxström, Siebrand Mazeland
 9+ * @copyright Copyright © 2006-2011 Niklas Laxström, Siebrand Mazeland
1010 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1111 */
1212
@@ -45,6 +45,7 @@
4646
4747 $this->setHeaders();
4848
 49+ //@todo Move to api or so
4950 if ( $parameters === 'editpage' ) {
5051 $editpage = TranslationEditPage::newFromRequest( $wgRequest );
5152
@@ -80,9 +81,7 @@
8182 $this->options['group'] = $this->defaults['group'];
8283 }
8384
84 - /**
85 - * Show errors nicely.
86 - */
 85+ // Show errors nicely.
8786 $wgOut->addHTML( $this->settingsForm( $errors ) );
8887
8988 if ( count( $errors ) ) {
@@ -103,9 +102,7 @@
104103 }
105104 }
106105
107 - /**
108 - * Proceed.
109 - */
 106+ // Proceed.
110107 $taskOptions = new TaskOptions(
111108 $this->options['language'],
112109 $this->options['limit'],
@@ -113,9 +110,7 @@
114111 array( $this, 'cbAddPagingNumbers' )
115112 );
116113
117 - /**
118 - * Initialise and get output.
119 - */
 114+ // Initialise and get output.
120115 $this->task->init( $this->group, $taskOptions );
121116 $output = $this->task->execute();
122117
@@ -217,39 +212,40 @@
218213 }
219214
220215 $form =
221 - Xml::openElement( 'fieldset', array( 'class' => 'mw-sp-translate-settings' ) ) .
222 - Xml::element( 'legend', null, wfMsg( 'translate-page-settings-legend' ) ) .
223 - Xml::openElement( 'form', array( 'action' => $wgScript, 'method' => 'get' ) ) .
 216+ Html::openElement( 'fieldset', array( 'class' => 'mw-sp-translate-settings' ) ) .
 217+ Html::element( 'legend', null, wfMsg( 'translate-page-settings-legend' ) ) .
 218+ Html::openElement( 'form', array( 'action' => $wgScript, 'method' => 'get' ) ) .
224219 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
225 - Xml::openElement( 'table' ) .
 220+ Html::openElement( 'table' ) .
226221 implode( "", $options ) .
227222 self::optionRow( $button, ' ' ) .
228 - Xml::closeElement( 'table' ) .
229 - Xml::closeElement( 'form' ) .
230 - Xml::closeElement( 'fieldset' );
 223+ Html::closeElement( 'table' ) .
 224+ Html::closeElement( 'form' ) .
 225+ Html::closeElement( 'fieldset' );
231226 return $form;
232227 }
233228
234229 /**
235 - * @param $label
236 - * @param $option
237 - * @param $error null
 230+ * @param $label string
 231+ * @param $option string
 232+ * @param $error string Html
238233 * @return string
239234 */
240235 private static function optionRow( $label, $option, $error = null ) {
241236 return
242 - Xml::openElement( 'tr' ) .
243 - Xml::tags( 'td', null, $label ) .
244 - Xml::tags( 'td', null, $option ) .
245 - ( $error ? Xml::tags( 'td', array( 'class' => 'mw-sp-translate-error' ), $error ) : '' ) .
246 - Xml::closeElement( 'tr' );
 237+ Html::openElement( 'tr' ) .
 238+ Html::rawElement( 'td', null, $label ) .
 239+ Html::rawElement( 'td', null, $option ) .
 240+ ( $error ? Html::rawElement( 'td', array( 'class' => 'mw-sp-translate-error' ), $error ) : '' ) .
 241+ Html::closeElement( 'tr' );
247242 }
248243
249244 /* Selectors ahead */
250245
251246 protected function groupSelector() {
252247 $groups = MessageGroups::getAllGroups();
253 - $selector = new HTMLSelector( 'group', 'group', $this->options['group'] );
 248+ $selector = new XmlSelect( 'group', 'group' );
 249+ $selector->setDefault( $this->options['group'] );
254250
255251 foreach ( $groups as $id => $class ) {
256252 if ( MessageGroups::getGroup( $id )->exists() ) {
@@ -261,7 +257,8 @@
262258 }
263259
264260 protected function taskSelector( $pageTranslation = false ) {
265 - $selector = new HTMLSelector( 'task', 'task', $this->options['task'] );
 261+ $selector = new XmlSelect( 'task', 'task' );
 262+ $selector->setDefault( $this->options['task'] );
266263
267264 $isPageTranslation = $this->group instanceof WikiPageMessageGroup;
268265 foreach ( TranslateTasks::getTasks( $isPageTranslation ) as $id ) {
@@ -285,7 +282,8 @@
286283 global $wgLang;
287284
288285 $items = array( 100, 1000, 5000 );
289 - $selector = new HTMLSelector( 'limit', 'limit', $this->options['limit'] );
 286+ $selector = new XmlSelect( 'limit', 'limit' );
 287+ $selector->setDefault( $this->options['limit'] );
290288
291289 foreach ( $items as $count ) {
292290 $selector->addOption( wfMsgExt( 'translate-page-limit-option', 'parsemag', $wgLang->formatNum( $count ) ), $count );
@@ -318,13 +316,9 @@
319317 $allInThisPage = $start === 1 && $total <= $this->options['limit'];
320318
321319 if ( $this->paging['count'] === 0 ) {
322 - $navigation = wfMsgExt( 'translate-page-showing-none', array( 'parseinline' ) );
 320+ $navigation = wfMessage( 'translate-page-showing-none' )->parse();
323321 } elseif ( $allInThisPage ) {
324 - $navigation = wfMsgExt(
325 - 'translate-page-showing-all',
326 - array( 'parseinline' ),
327 - $wgLang->formatNum( $total )
328 - );
 322+ $navigation = wfMessage( 'translate-page-showing-all', $wgLang->formatNum( $total ) )->parse();
329323 } else {
330324 $previous = wfMsg( 'translate-prev' );
331325 if ( $this->options['offset'] > 0 ) {
@@ -362,23 +356,21 @@
363357 }
364358
365359 return
366 - Xml::openElement( 'fieldset' ) .
367 - Xml::element( 'legend', null, wfMsg( 'translate-page-navigation-legend' ) ) .
 360+ Html::openElement( 'fieldset' ) .
 361+ Html::element( 'legend', null, wfMsg( 'translate-page-navigation-legend' ) ) .
368362 $navigation .
369 - Xml::closeElement( 'fieldset' );
 363+ Html::closeElement( 'fieldset' );
370364 }
371365
372366 private function makeOffsetLink( $label, $offset ) {
373 - global $wgUser;
 367+ $linker = $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
374368
375 - $skin = $wgUser->getSkin();
376 -
377369 $query = array_merge(
378370 $this->nondefaults,
379371 array( 'offset' => $offset )
380372 );
381373
382 - $link = $skin->link(
 374+ $link = $linker->link(
383375 $this->getTitle(),
384376 $label,
385377 array(),
@@ -389,17 +381,13 @@
390382 }
391383
392384 protected function getGroupDescription( MessageGroup $group ) {
393 - global $wgOut;
394 -
395385 $description = $group->getDescription();
396 -
397 - if ( $description === null ) {
398 - return null;
 386+ if ( $description !== null ) {
 387+ global $wgOut;
 388+ return $wgOut->parse( $description, false );
399389 }
400390
401 - $description = $wgOut->parse( $description, false );
402 -
403 - return $description;
 391+ return '';
404392 }
405393
406394 public function groupInformation() {
@@ -415,7 +403,7 @@
416404 }
417405
418406 public function formatGroupInformation( $blocks, $level = 2 ) {
419 - global $wgUser, $wgLang;
 407+ global $wgLang;
420408
421409 if ( is_array( $blocks ) ) {
422410 $block = array_shift( $blocks );
@@ -433,7 +421,9 @@
434422 'language' => $code
435423 );
436424
437 - $label = $wgUser->getSkin()->link(
 425+ $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
 426+
 427+ $label = $linker->link(
438428 $title,
439429 htmlspecialchars( $block->getLabel() ),
440430 array(),
@@ -446,7 +436,7 @@
447437 $subid = Sanitizer::escapeId( "mw-subgroup-$id" );
448438
449439 if ( $hasSubblocks ) {
450 - $msg = wfMsgExt( 'translate-showsub', 'parsemag', $wgLang->formatNum( count( $blocks ) ) );
 440+ $msg = wfMessage( 'translate-showsub', $wgLang->formatNum( count( $blocks ) ) )->text();
451441 $target = TranslationHelpers::jQueryPathId( $subid );
452442 $desc .= Html::element( 'a', array( 'onclick' => "jQuery($target).toggle()", 'class' => 'mw-sp-showmore' ), $msg );
453443 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r99303Fix r99258: removed double assignmentnikerabbit11:16, 8 October 2011

Comments

#Comment by Siebrand (talk | contribs)   21:37, 7 October 2011

Around line 370:

+        $linker = $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;

Linker = linker?

Status & tagging log