Index: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php |
— | — | @@ -0,0 +1,195 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Contains logic for special page Special:MessageGroupStats. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @author Niklas Laxström |
| 8 | + * @copyright Copyright © 2011 Niklas Laxström |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Implements includable special page Special:MessageGroupStats which provides |
| 14 | + * translation statistics for all languages for a group. |
| 15 | + * |
| 16 | + * @ingroup SpecialPage TranslateSpecialPage Stats |
| 17 | + */ |
| 18 | +class SpecialMessageGroupStats extends SpecialLanguageStats { |
| 19 | + /// Overwritten from SpecialLanguageStats |
| 20 | + protected $targetValueName = 'group'; |
| 21 | + /// Overwritten from SpecialLanguageStats |
| 22 | + protected $noComplete = false; |
| 23 | + /// Overwritten from SpecialLanguageStats |
| 24 | + protected $noEmpty = true; |
| 25 | + |
| 26 | + public function __construct() { |
| 27 | + SpecialPage::__construct( 'MessageGroupStats' ); |
| 28 | + } |
| 29 | + |
| 30 | + /// Overwritten from SpecialPage |
| 31 | + public function getDescription() { |
| 32 | + return wfMessage( 'translate-mgs-pagename' )->text(); |
| 33 | + } |
| 34 | + |
| 35 | + /// Overwritten from SpecialLanguageStats |
| 36 | + protected function getAllowedValues() { |
| 37 | + $groups = MessageGroups::getAllGroups(); |
| 38 | + return array_keys( $groups ); |
| 39 | + } |
| 40 | + |
| 41 | + /// Overwritten from SpecialLanguageStats |
| 42 | + protected function invalidTarget() { |
| 43 | + global $wgOut; |
| 44 | + $wgOut->wrapWikiMsg( "<div class='error'>$1</div>", 'translate-mgs-invalid-group', $this->target ); |
| 45 | + } |
| 46 | + |
| 47 | + /// Overwritten from SpecialLanguageStats |
| 48 | + protected function outputIntroduction() { |
| 49 | + return ''; |
| 50 | + } |
| 51 | + |
| 52 | + /// @todo duplicated code |
| 53 | + protected function groupSelector( $default ) { |
| 54 | + $groups = MessageGroups::getAllGroups(); |
| 55 | + $selector = new HTMLSelector( 'group', 'group', $default ); |
| 56 | + |
| 57 | + foreach ( $groups as $id => $class ) { |
| 58 | + if ( MessageGroups::getGroup( $id )->exists() ) { |
| 59 | + $selector->addOption( $class->getLabel(), $id ); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return $selector->getHTML(); |
| 64 | + } |
| 65 | + |
| 66 | + /// Overwriten from SpecialLanguageStats |
| 67 | + function getform() { |
| 68 | + global $wgScript; |
| 69 | + |
| 70 | + $out = Html::openElement( 'div' ); |
| 71 | + $out .= Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ); |
| 72 | + $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
| 73 | + $out .= Html::hidden( 'x', 'D' ); // To detect submission |
| 74 | + $out .= Html::openElement( 'fieldset' ); |
| 75 | + $out .= Html::element( 'legend', null, wfMsg( 'translate-mgs-fieldset' ) ); |
| 76 | + $out .= Html::openElement( 'table' ); |
| 77 | + |
| 78 | + $out .= Html::openElement( 'tr' ); |
| 79 | + $out .= Html::openElement( 'td', array( 'class' => 'mw-label' ) ); |
| 80 | + $out .= Xml::label( wfMsg( 'translate-mgs-group' ), 'group' ); |
| 81 | + $out .= Html::closeElement( 'td' ); |
| 82 | + $out .= Html::openElement( 'td', array( 'class' => 'mw-input' ) ); |
| 83 | + $out .= $this->groupSelector( $this->target ); |
| 84 | + $out .= Html::closeElement( 'td' ); |
| 85 | + $out .= Html::closeElement( 'tr' ); |
| 86 | + |
| 87 | + $out .= Html::openElement( 'tr' ); |
| 88 | + $out .= Html::openElement( 'td', array( 'colspan' => 2 ) ); |
| 89 | + $out .= Xml::checkLabel( wfMsg( 'translate-mgs-nocomplete' ), 'suppresscomplete', 'suppresscomplete', $this->noComplete ); |
| 90 | + $out .= Html::closeElement( 'td' ); |
| 91 | + $out .= Html::closeElement( 'tr' ); |
| 92 | + |
| 93 | + $out .= Html::openElement( 'tr' ); |
| 94 | + $out .= Html::openElement( 'td', array( 'colspan' => 2 ) ); |
| 95 | + $out .= Xml::checkLabel( wfMsg( 'translate-mgs-noempty' ), 'suppressempty', 'suppressempty', $this->noEmpty ); |
| 96 | + $out .= Html::closeElement( 'td' ); |
| 97 | + $out .= Html::closeElement( 'tr' ); |
| 98 | + |
| 99 | + $out .= Html::openElement( 'tr' ); |
| 100 | + $out .= Html::openElement( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ) ); |
| 101 | + $out .= Xml::submitButton( wfMsg( 'translate-mgs-submit' ) ); |
| 102 | + $out .= Html::closeElement( 'td' ); |
| 103 | + $out .= Html::closeElement( 'tr' ); |
| 104 | + |
| 105 | + $out .= Html::closeElement( 'table' ); |
| 106 | + $out .= Html::closeElement( 'fieldset' ); |
| 107 | + $out .= Html::closeElement( 'form' ); |
| 108 | + $out .= Html::closeElement( 'div' ); |
| 109 | + |
| 110 | + return $out; |
| 111 | + } |
| 112 | + |
| 113 | + /// Overwriten from SpecialLanguageStats |
| 114 | + function getTable() { |
| 115 | + $table = $this->table; |
| 116 | + $out = ''; |
| 117 | + |
| 118 | + if ( $this->purge ) { |
| 119 | + MessageGroupStats::clearGroup( $this->target ); |
| 120 | + } |
| 121 | + |
| 122 | + MessageGroupStats::setTimeLimit( $this->timelimit ); |
| 123 | + $cache = MessageGroupStats::forGroup( $this->target ); |
| 124 | + |
| 125 | + $languages = array_keys( Language::getLanguageNames( false ) ); |
| 126 | + sort( $languages ); |
| 127 | + |
| 128 | + foreach ( $languages as $code ) { |
| 129 | + if ( $table->isBlacklisted( $this->target, $code ) !== null ) { |
| 130 | + continue; |
| 131 | + } |
| 132 | + $out .= $this->makeRow( $code, $cache ); |
| 133 | + } |
| 134 | + |
| 135 | + if ( $out ) { |
| 136 | + $table->setMainColumnHeader( wfMessage( 'translate-mgs-column-language' ) ); |
| 137 | + $out = $table->createHeader() . "\n" . $out; |
| 138 | + $out .= $table->makeTotalRow( wfMessage( 'translate-mgs-totals' ), $this->totals ); |
| 139 | + $out .= Html::closeElement( 'tbody' ); |
| 140 | + $out .= Html::closeElement( 'table' ); |
| 141 | + return $out; |
| 142 | + } else { |
| 143 | + $this->nothing = true; |
| 144 | + return ''; |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + protected function makeRow( $code, $cache ) { |
| 149 | + $stats = $cache[$code]; |
| 150 | + $this->totals = MessageGroupStats::multiAdd( $this->totals, $stats ); |
| 151 | + |
| 152 | + list( $total, $translated, $fuzzy ) = $stats; |
| 153 | + if ( $total === null ) { |
| 154 | + $this->incomplete = true; |
| 155 | + $extra = array(); |
| 156 | + } else { |
| 157 | + if ( $this->noComplete && $fuzzy === 0 && $translated === $total ) { |
| 158 | + return ''; |
| 159 | + } |
| 160 | + |
| 161 | + if ( $this->noEmpty && $translated === 0 && $fuzzy === 0 ) { |
| 162 | + return ''; |
| 163 | + } |
| 164 | + |
| 165 | + if ( $translated === $total ) { |
| 166 | + $extra = array( 'task' => 'reviewall' ); |
| 167 | + } else { |
| 168 | + $extra = array(); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + $out = "\t" . Html::openElement( 'tr' ); |
| 173 | + $out .= "\n\t\t" . $this->getMainColumnCell( $code, $extra ); |
| 174 | + $out .= $this->table->makeNumberColumns( $fuzzy, $translated, $total ); |
| 175 | + return $out; |
| 176 | + } |
| 177 | + |
| 178 | + protected function getMainColumnCell( $code, $params ) { |
| 179 | + if ( !isset( $this->names ) ) { |
| 180 | + global $wgLang; |
| 181 | + $this->names = Language::getTranslatedLanguageNames( $wgLang->getCode() ); |
| 182 | + $this->translate = SpecialPage::getTitleFor( 'Translate' ); |
| 183 | + } |
| 184 | + |
| 185 | + $queryParameters = $params + array( |
| 186 | + 'group' => $this->target, |
| 187 | + 'language' => $code |
| 188 | + ); |
| 189 | + |
| 190 | + $text = htmlspecialchars( "$code: {$this->names[$code]}" ); |
| 191 | + $linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker; |
| 192 | + $link = $linker->link( $this->translate, $text, array(), $queryParameters ); |
| 193 | + return Html::rawElement( 'td', array(), $link ); |
| 194 | + } |
| 195 | + |
| 196 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Translate/specials/SpecialMessageGroupStats.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 197 | + native |