protected function setup( $parameters ) { global $wgUser, $wgRequest; $defaults = array( /* str */ 'task' => 'untranslated', /* str */ 'sort' => 'normal', /* str */ 'language' => $wgUser->getOption( 'language' ), /* str */ 'group' => '', /* int */ 'offset' => 0, /* int */ 'limit' => 100, ); // Dump everything here $nondefaults = array(); $parameters = array_map( 'trim', explode( ';', $parameters ) ); $pars = array(); foreach ( $parameters as $_ ) { if ( $_ === '' ) { continue; } if ( strpos( $_, '=' ) !== false ) { list( $key, $value ) = array_map( 'trim', explode( '=', $_, 2 ) ); } else { $key = 'group'; $value = $_; } $pars[$key] = $value; } foreach ( $defaults as $v => $t ) { if ( is_bool( $t ) ) { $r = isset( $pars[$v] ) ? (bool) $pars[$v] : $defaults[$v]; $r = $wgRequest->getBool( $v, $r ); } elseif ( is_int( $t ) ) { $r = isset( $pars[$v] ) ? (int) $pars[$v] : $defaults[$v]; $r = $wgRequest->getInt( $v, $r ); } elseif ( is_string( $t ) ) { $r = isset( $pars[$v] ) ? (string) $pars[$v] : $defaults[$v]; $r = $wgRequest->getText( $v, $r ); } wfAppendToArrayIfNotDefault( $v, $r, $defaults, $nondefaults ); } $this->defaults = $defaults; $this->nondefaults = $nondefaults; $this->options = $nondefaults + $defaults; $this->group = MessageGroups::getGroup( $this->options['group'] ); $this->task = TranslateTasks::getTask( $this->options['task'] ); if ( $this->group instanceof RecentMessageGroup ) { $this->group->setLanguage( $this->options['language'] ); } }
protected function setup($parameters) { $request = $this->getRequest(); $isBeta = self::isBeta($request); $defaults = array('taction' => 'translate', 'task' => $isBeta ? 'custom' : 'untranslated', 'language' => $this->getLanguage()->getCode(), 'group' => $isBeta ? '!additions' : '', 'offset' => '', 'limit' => $isBeta ? 0 : 100, 'optional' => '0'); // Dump everything here $nondefaults = array(); $parameters = array_map('trim', explode(';', $parameters)); $pars = array(); foreach ($parameters as $_) { if ($_ === '') { continue; } if (strpos($_, '=') !== false) { list($key, $value) = array_map('trim', explode('=', $_, 2)); } else { $key = 'group'; $value = $_; } $pars[$key] = $value; } foreach ($defaults as $v => $t) { if (is_bool($t)) { $r = isset($pars[$v]) ? (bool) $pars[$v] : $defaults[$v]; $r = $request->getBool($v, $r); } elseif (is_int($t)) { $r = isset($pars[$v]) ? (int) $pars[$v] : $defaults[$v]; $r = $request->getInt($v, $r); } elseif (is_string($t)) { $r = isset($pars[$v]) ? (string) $pars[$v] : $defaults[$v]; $r = $request->getText($v, $r); } if (!isset($r)) { throw new MWException('$r was not set'); } wfAppendToArrayIfNotDefault($v, $r, $defaults, $nondefaults); } // Fix defaults based on what we got if (isset($nondefaults['taction'])) { if ($nondefaults['taction'] === 'proofread') { if ($this->getUser()->isAllowed('translate-messagereview')) { $defaults['task'] = 'acceptqueue'; } else { $defaults['task'] = 'reviewall'; } } elseif ($nondefaults['taction'] === 'export') { $defaults['task'] = ''; } } if ($isBeta) { /* @todo fix all the places in Translate to create correct links. * The least effort way is to change them once we totally drop the * old UI. The penalty is only http redirect in some cases. More * effort would be to create utilities like makeTranslationLink * and makeProofreadLink. */ $this->rewriteLegacyUrls($nondefaults); } $this->defaults = $defaults; $this->nondefaults = $nondefaults; Hooks::run('TranslateGetSpecialTranslateOptions', array(&$defaults, &$nondefaults)); $this->options = $nondefaults + $defaults; $this->group = MessageGroups::getGroup($this->options['group']); if ($this->group) { $this->options['group'] = $this->group->getId(); } $this->task = TranslateTasks::getTask($this->options['task']); if ($this->group && MessageGroups::isDynamic($this->group)) { $this->group->setLanguage($this->options['language']); } }