diff options
Diffstat (limited to 'www/wiki/extensions/Translate/specials/SpecialMessageGroupStats.php')
-rw-r--r-- | www/wiki/extensions/Translate/specials/SpecialMessageGroupStats.php | 189 |
1 files changed, 86 insertions, 103 deletions
diff --git a/www/wiki/extensions/Translate/specials/SpecialMessageGroupStats.php b/www/wiki/extensions/Translate/specials/SpecialMessageGroupStats.php index 518e0716..8698a7f9 100644 --- a/www/wiki/extensions/Translate/specials/SpecialMessageGroupStats.php +++ b/www/wiki/extensions/Translate/specials/SpecialMessageGroupStats.php @@ -5,7 +5,7 @@ * @file * @author Niklas Laxström * @author Siebrand Mazeland - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ /** @@ -16,7 +16,7 @@ */ class SpecialMessageGroupStats extends SpecialLanguageStats { /// Overwritten from SpecialLanguageStats - protected $targetValueName = array( 'group' ); + protected $targetValueName = [ 'group' ]; /// Overwritten from SpecialLanguageStats protected $noComplete = false; /// Overwritten from SpecialLanguageStats @@ -36,8 +36,14 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { return $this->msg( 'translate-mgs-pagename' )->text(); } - protected function getGroupName() { - return 'wiki'; + /// Overwritten from SpecialLanguageStats + protected function loadStatistics( $target, $flags = 0 ) { + return MessageGroupStats::forGroup( $target, $flags ); + } + + /// Overwritten from SpecialLanguageStats + protected function getCacheRebuildJobParameters( $target ) { + return [ 'groupid' => $target ]; } /// Overwritten from SpecialLanguageStats @@ -63,111 +69,82 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { protected function invalidTarget() { $this->getOutput()->wrapWikiMsg( "<div class='error'>$1</div>", - array( 'translate-mgs-invalid-group', $this->target ) + [ 'translate-mgs-invalid-group', $this->target ] ); } /// Overwritten from SpecialLanguageStats protected function outputIntroduction() { - $group = $this->getRequest()->getVal( 'group' ); - $priorityLangs = TranslateMetadata::get( $group, 'prioritylangs' ); + $priorityLangs = TranslateMetadata::get( $this->target, 'prioritylangs' ); if ( $priorityLangs ) { $this->getOutput()->addWikiMsg( 'tpt-priority-languages', $priorityLangs ); } } /// Overwriten from SpecialLanguageStats - protected function getform() { - global $wgScript; - - $out = Html::openElement( 'div' ); - $out .= Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); - $out .= Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ); - $out .= Html::hidden( 'x', 'D' ); // To detect submission - $out .= Html::openElement( 'fieldset' ); - $out .= Html::element( 'legend', array(), $this->msg( 'translate-mgs-fieldset' )->text() ); - $out .= Html::openElement( 'table' ); - - $out .= Html::openElement( 'tr' ); - $out .= Html::openElement( 'td', array( 'class' => 'mw-label' ) ); - $out .= Xml::label( $this->msg( 'translate-mgs-group' )->text(), 'group' ); - $out .= Html::closeElement( 'td' ); - $out .= Html::openElement( 'td', array( 'class' => 'mw-input' ) ); - $out .= $this->getGroupSelector( $this->target )->getHTML(); - $out .= Html::closeElement( 'td' ); - $out .= Html::closeElement( 'tr' ); - - $out .= Html::openElement( 'tr' ); - $out .= Html::openElement( 'td', array( 'colspan' => 2 ) ); - $out .= Xml::checkLabel( - $this->msg( 'translate-mgs-nocomplete' )->text(), - 'suppresscomplete', - 'suppresscomplete', - $this->noComplete - ); - $out .= Html::closeElement( 'td' ); - $out .= Html::closeElement( 'tr' ); - - $out .= Html::openElement( 'tr' ); - $out .= Html::openElement( 'td', array( 'colspan' => 2 ) ); - $out .= Xml::checkLabel( - $this->msg( 'translate-mgs-noempty' )->text(), - 'suppressempty', - 'suppressempty', - $this->noEmpty - ); - $out .= Html::closeElement( 'td' ); - $out .= Html::closeElement( 'tr' ); - - $out .= Html::openElement( 'tr' ); - $out .= Html::openElement( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ) ); - $out .= Xml::submitButton( $this->msg( 'translate-mgs-submit' )->text() ); - $out .= Html::closeElement( 'td' ); - $out .= Html::closeElement( 'tr' ); + protected function addForm() { + $formDescriptor = [ + 'select' => [ + 'type' => 'select', + 'name' => 'group', + 'id' => 'group', + 'label' => $this->msg( 'translate-mgs-group' )->text(), + 'options' => $this->getGroupOptions(), + 'default' => $this->target + ], + 'nocomplete-check' => [ + 'type' => 'check', + 'name' => 'suppresscomplete', + 'id' => 'suppresscomplete', + 'label' => $this->msg( 'translate-mgs-nocomplete' )->text(), + 'default' => $this->noComplete, + ], + 'noempty-check' => [ + 'type' => 'check', + 'name' => 'suppressempty', + 'id' => 'suppressempty', + 'label' => $this->msg( 'translate-mgs-noempty' )->text(), + 'default' => $this->noEmpty, + ] + ]; + + $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() ); - $out .= Html::closeElement( 'table' ); - $out .= Html::closeElement( 'fieldset' ); /* Since these pages are in the tabgroup with Special:Translate, * it makes sense to retain the selected group/language parameter * on post requests even when not relevant to the current page. */ $val = $this->getRequest()->getVal( 'language' ); if ( $val !== null ) { - $out .= Html::hidden( 'language', $val ); + $htmlForm->addHiddenField( 'language', $val ); } - $out .= Html::closeElement( 'form' ); - $out .= Html::closeElement( 'div' ); - return $out; + $htmlForm + ->addHiddenField( 'x', 'D' ) // To detect submission + ->setMethod( 'get' ) + ->setSubmitTextMsg( 'translate-mgs-submit' ) + ->setWrapperLegendMsg( 'translate-mgs-fieldset' ) + ->prepareForm() + ->displayForm( false ); } - /** - * Overwriten from SpecialLanguageStats - * - * @return string - */ - protected function getTable() { + /// Overwritten from SpecialLanguageStats + protected function getTable( $stats ) { $table = $this->table; $this->addWorkflowStatesColumn(); $out = ''; - if ( $this->purge ) { - MessageGroupStats::clearGroup( $this->target ); - } - - MessageGroupStats::setTimeLimit( $this->timelimit ); - $cache = MessageGroupStats::forGroup( $this->target ); - + $this->numberOfShownLanguages = 0; $languages = array_keys( TranslateUtils::getLanguageNames( $this->getLanguage()->getCode() ) ); sort( $languages ); - $this->filterPriorityLangs( $languages, $this->target, $cache ); + $this->filterPriorityLangs( $languages, $this->target, $stats ); foreach ( $languages as $code ) { if ( $table->isBlacklisted( $this->target, $code ) !== null ) { continue; } - $out .= $this->makeRow( $code, $cache ); + $out .= $this->makeRow( $code, $stats ); } if ( $out ) { @@ -176,7 +153,11 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { $out .= Html::closeElement( 'tbody' ); $out .= Html::openElement( 'tfoot' ); - $out .= $table->makeTotalRow( $this->msg( 'translate-mgs-totals' ), $this->totals ); + $out .= $table->makeTotalRow( + $this->msg( 'translate-mgs-totals' ) + ->numParams( $this->numberOfShownLanguages ), + $this->totals + ); $out .= Html::closeElement( 'tfoot' ); $out .= Html::closeElement( 'table' ); @@ -193,9 +174,9 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { * Filter an array of languages based on whether a priority set of * languages present for the passed group. If priority languages are * present, to that list add languages with more than 0% translation. - * @param $languages Array of Languages to be filtered - * @param $group - * @param $cache + * @param array &$languages Array of Languages to be filtered + * @param string $group + * @param array $cache */ protected function filterPriorityLangs( &$languages, $group, $cache ) { $filterLangs = TranslateMetadata::get( $group, 'prioritylangs' ); @@ -216,8 +197,8 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { } /** - * @param $code - * @param $cache + * @param string $code + * @param array $cache * @return string */ protected function makeRow( $code, $cache ) { @@ -228,7 +209,7 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { if ( $total === null ) { $this->incomplete = true; - $extra = array(); + $extra = []; } else { if ( $this->noComplete && $fuzzy === 0 && $translated === $total ) { return ''; @@ -244,12 +225,12 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { } if ( $translated === $total ) { - $extra = array( 'action' => 'proofread' ); + $extra = [ 'action' => 'proofread' ]; } else { - $extra = array(); + $extra = []; } } - + $this->numberOfShownLanguages += 1; $this->totals = MessageGroupStats::multiAdd( $this->totals, $stats ); $out = "\t" . Html::openElement( 'tr' ); @@ -264,8 +245,8 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { } /** - * @param $code - * @param $params + * @param string $code + * @param array $params * @return string */ protected function getMainColumnCell( $code, $params ) { @@ -274,23 +255,26 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { $this->translate = SpecialPage::getTitleFor( 'Translate' ); } - $queryParameters = $params + array( + $queryParameters = $params + [ 'group' => $this->target, 'language' => $code - ); + ]; if ( isset( $this->names[$code] ) ) { - $text = htmlspecialchars( "$code: {$this->names[$code]}" ); + $text = "$code: {$this->names[$code]}"; } else { - $text = htmlspecialchars( $code ); + $text = $code; } - $link = Linker::link( $this->translate, $text, array(), $queryParameters ); + $link = $this->getLinkRenderer()->makeKnownLink( + $this->translate, + $text, + [], + $queryParameters + ); - return Html::rawElement( 'td', array(), $link ); + return Html::rawElement( 'td', [], $link ); } - // @codingStandardsIgnoreStart PHP CodeSniffer warns "Useless method overriding - // detected", but that's not the case. /** * @param string $field * @param string $filter @@ -298,24 +282,23 @@ class SpecialMessageGroupStats extends SpecialLanguageStats { */ protected function getWorkflowStates( $field = 'tgr_lang', $filter = 'tgr_group' ) { return parent::getWorkflowStates( $field, $filter ); - } // @codingStandardsIgnoreEnd + } /** - * Creates a simple message group selector. + * Creates a simple message group options. * - * @param string|bool $default Group id of the group chosen by default. Optional. - * @return XmlSelect + * @return array $options */ - protected function getGroupSelector( $default = false ) { + protected function getGroupOptions() { + $options = []; $groups = MessageGroups::getAllGroups(); - $selector = new XmlSelect( 'group', 'group', $default ); foreach ( $groups as $id => $class ) { if ( MessageGroups::getGroup( $id )->exists() ) { - $selector->addOption( $class->getLabel(), $id ); + $options[$class->getLabel()] = $id; } } - return $selector; + return $options; } } |