http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97261
Revision: 97261 Author: nikerabbit Date: 2011-09-16 13:15:33 +0000 (Fri, 16 Sep 2011) Log Message: ----------- Actually add the file, missing from r97260 Added Paths: ----------- trunk/extensions/Translate/specials/SpecialMessageGroupStats.php Added: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php =================================================================== --- trunk/extensions/Translate/specials/SpecialMessageGroupStats.php (rev 0) +++ trunk/extensions/Translate/specials/SpecialMessageGroupStats.php 2011-09-16 13:15:33 UTC (rev 97261) @@ -0,0 +1,195 @@ +<?php +/** + * Contains logic for special page Special:MessageGroupStats. + * + * @file + * @author Niklas Laxström + * @copyright Copyright © 2011 Niklas Laxström + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ + +/** + * Implements includable special page Special:MessageGroupStats which provides + * translation statistics for all languages for a group. + * + * @ingroup SpecialPage TranslateSpecialPage Stats + */ +class SpecialMessageGroupStats extends SpecialLanguageStats { + /// Overwritten from SpecialLanguageStats + protected $targetValueName = 'group'; + /// Overwritten from SpecialLanguageStats + protected $noComplete = false; + /// Overwritten from SpecialLanguageStats + protected $noEmpty = true; + + public function __construct() { + SpecialPage::__construct( 'MessageGroupStats' ); + } + + /// Overwritten from SpecialPage + public function getDescription() { + return wfMessage( 'translate-mgs-pagename' )->text(); + } + + /// Overwritten from SpecialLanguageStats + protected function getAllowedValues() { + $groups = MessageGroups::getAllGroups(); + return array_keys( $groups ); + } + + /// Overwritten from SpecialLanguageStats + protected function invalidTarget() { + global $wgOut; + $wgOut->wrapWikiMsg( "<div class='error'>$1</div>", 'translate-mgs-invalid-group', $this->target ); + } + + /// Overwritten from SpecialLanguageStats + protected function outputIntroduction() { + return ''; + } + + /// @todo duplicated code + protected function groupSelector( $default ) { + $groups = MessageGroups::getAllGroups(); + $selector = new HTMLSelector( 'group', 'group', $default ); + + foreach ( $groups as $id => $class ) { + if ( MessageGroups::getGroup( $id )->exists() ) { + $selector->addOption( $class->getLabel(), $id ); + } + } + + return $selector->getHTML(); + } + + /// Overwriten from SpecialLanguageStats + function getform() { + global $wgScript; + + $out = Html::openElement( 'div' ); + $out .= Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); + $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); + $out .= Html::hidden( 'x', 'D' ); // To detect submission + $out .= Html::openElement( 'fieldset' ); + $out .= Html::element( 'legend', null, wfMsg( 'translate-mgs-fieldset' ) ); + $out .= Html::openElement( 'table' ); + + $out .= Html::openElement( 'tr' ); + $out .= Html::openElement( 'td', array( 'class' => 'mw-label' ) ); + $out .= Xml::label( wfMsg( 'translate-mgs-group' ), 'group' ); + $out .= Html::closeElement( 'td' ); + $out .= Html::openElement( 'td', array( 'class' => 'mw-input' ) ); + $out .= $this->groupSelector( $this->target ); + $out .= Html::closeElement( 'td' ); + $out .= Html::closeElement( 'tr' ); + + $out .= Html::openElement( 'tr' ); + $out .= Html::openElement( 'td', array( 'colspan' => 2 ) ); + $out .= Xml::checkLabel( wfMsg( 'translate-mgs-nocomplete' ), '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( wfMsg( 'translate-mgs-noempty' ), '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( wfMsg( 'translate-mgs-submit' ) ); + $out .= Html::closeElement( 'td' ); + $out .= Html::closeElement( 'tr' ); + + $out .= Html::closeElement( 'table' ); + $out .= Html::closeElement( 'fieldset' ); + $out .= Html::closeElement( 'form' ); + $out .= Html::closeElement( 'div' ); + + return $out; + } + + /// Overwriten from SpecialLanguageStats + function getTable() { + $table = $this->table; + $out = ''; + + if ( $this->purge ) { + MessageGroupStats::clearGroup( $this->target ); + } + + MessageGroupStats::setTimeLimit( $this->timelimit ); + $cache = MessageGroupStats::forGroup( $this->target ); + + $languages = array_keys( Language::getLanguageNames( false ) ); + sort( $languages ); + + foreach ( $languages as $code ) { + if ( $table->isBlacklisted( $this->target, $code ) !== null ) { + continue; + } + $out .= $this->makeRow( $code, $cache ); + } + + if ( $out ) { + $table->setMainColumnHeader( wfMessage( 'translate-mgs-column-language' ) ); + $out = $table->createHeader() . "\n" . $out; + $out .= $table->makeTotalRow( wfMessage( 'translate-mgs-totals' ), $this->totals ); + $out .= Html::closeElement( 'tbody' ); + $out .= Html::closeElement( 'table' ); + return $out; + } else { + $this->nothing = true; + return ''; + } + } + + protected function makeRow( $code, $cache ) { + $stats = $cache[$code]; + $this->totals = MessageGroupStats::multiAdd( $this->totals, $stats ); + + list( $total, $translated, $fuzzy ) = $stats; + if ( $total === null ) { + $this->incomplete = true; + $extra = array(); + } else { + if ( $this->noComplete && $fuzzy === 0 && $translated === $total ) { + return ''; + } + + if ( $this->noEmpty && $translated === 0 && $fuzzy === 0 ) { + return ''; + } + + if ( $translated === $total ) { + $extra = array( 'task' => 'reviewall' ); + } else { + $extra = array(); + } + } + + $out = "\t" . Html::openElement( 'tr' ); + $out .= "\n\t\t" . $this->getMainColumnCell( $code, $extra ); + $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total ); + return $out; + } + + protected function getMainColumnCell( $code, $params ) { + if ( !isset( $this->names ) ) { + global $wgLang; + $this->names = Language::getTranslatedLanguageNames( $wgLang->getCode() ); + $this->translate = SpecialPage::getTitleFor( 'Translate' ); + } + + $queryParameters = $params + array( + 'group' => $this->target, + 'language' => $code + ); + + $text = htmlspecialchars( "$code: {$this->names[$code]}" ); + $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker; + $link = $linker->link( $this->translate, $text, array(), $queryParameters ); + return Html::rawElement( 'td', array(), $link ); + } + +} \ No newline at end of file Property changes on: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs