00001 <?php
00018 class SpecialMessageGroupStats extends SpecialLanguageStats {
00020 protected $targetValueName = array( 'group' );
00022 protected $noComplete = false;
00024 protected $noEmpty = true;
00025
00026 protected $names;
00027
00028 protected $translate;
00029
00030 public function __construct() {
00031 SpecialPage::__construct( 'MessageGroupStats' );
00032 $this->totals = MessageGroupStats::getEmptyStats();
00033 }
00034
00036 public function getDescription() {
00037 return $this->msg( 'translate-mgs-pagename' )->text();
00038 }
00039
00041 protected function isValidValue( $value ) {
00042 $group = MessageGroups::getGroup( $value );
00043 if ( $group ) {
00044 if ( MessageGroups::isDynamic( $group ) ) {
00045
00046
00047
00048
00049
00050 $group = false;
00051 } else {
00052 $this->target = $group->getId();
00053 }
00054 }
00055
00056 return (bool)$group;
00057 }
00058
00060 protected function invalidTarget() {
00061 $this->getOutput()->wrapWikiMsg(
00062 "<div class='error'>$1</div>",
00063 array( 'translate-mgs-invalid-group', $this->target )
00064 );
00065 }
00066
00068 protected function outputIntroduction() {
00069 $group = $this->getRequest()->getVal( 'group' );
00070 $priorityLangs = TranslateMetadata::get( $group, 'prioritylangs' );
00071 if ( $priorityLangs ) {
00072 $this->getOutput()->addWikiMsg( 'tpt-priority-languages', $priorityLangs );
00073 }
00074 }
00075
00077 function getform() {
00078 global $wgScript;
00079
00080 $out = Html::openElement( 'div' );
00081 $out .= Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) );
00082 $out .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
00083 $out .= Html::hidden( 'x', 'D' );
00084 $out .= Html::openElement( 'fieldset' );
00085 $out .= Html::element( 'legend', array(), $this->msg( 'translate-mgs-fieldset' )->text() );
00086 $out .= Html::openElement( 'table' );
00087
00088 $out .= Html::openElement( 'tr' );
00089 $out .= Html::openElement( 'td', array( 'class' => 'mw-label' ) );
00090 $out .= Xml::label( $this->msg( 'translate-mgs-group' )->text(), 'group' );
00091 $out .= Html::closeElement( 'td' );
00092 $out .= Html::openElement( 'td', array( 'class' => 'mw-input' ) );
00093 $out .= TranslateUtils::groupSelector( $this->target )->getHTML();
00094 $out .= Html::closeElement( 'td' );
00095 $out .= Html::closeElement( 'tr' );
00096
00097 $out .= Html::openElement( 'tr' );
00098 $out .= Html::openElement( 'td', array( 'colspan' => 2 ) );
00099 $out .= Xml::checkLabel(
00100 $this->msg( 'translate-mgs-nocomplete' )->text(),
00101 'suppresscomplete',
00102 'suppresscomplete',
00103 $this->noComplete
00104 );
00105 $out .= Html::closeElement( 'td' );
00106 $out .= Html::closeElement( 'tr' );
00107
00108 $out .= Html::openElement( 'tr' );
00109 $out .= Html::openElement( 'td', array( 'colspan' => 2 ) );
00110 $out .= Xml::checkLabel(
00111 $this->msg( 'translate-mgs-noempty' )->text(),
00112 'suppressempty',
00113 'suppressempty',
00114 $this->noEmpty
00115 );
00116 $out .= Html::closeElement( 'td' );
00117 $out .= Html::closeElement( 'tr' );
00118
00119 $out .= Html::openElement( 'tr' );
00120 $out .= Html::openElement( 'td', array( 'class' => 'mw-input', 'colspan' => 2 ) );
00121 $out .= Xml::submitButton( $this->msg( 'translate-mgs-submit' )->text() );
00122 $out .= Html::closeElement( 'td' );
00123 $out .= Html::closeElement( 'tr' );
00124
00125 $out .= Html::closeElement( 'table' );
00126 $out .= Html::closeElement( 'fieldset' );
00127
00128
00129
00130 $val = $this->getRequest()->getVal( 'language' );
00131 if ( $val !== null ) {
00132 $out .= Html::hidden( 'language', $val );
00133 }
00134 $out .= Html::closeElement( 'form' );
00135 $out .= Html::closeElement( 'div' );
00136
00137 return $out;
00138 }
00139
00145 function getTable() {
00146 $table = $this->table;
00147
00148 $this->addWorkflowStatesColumn();
00149 $out = '';
00150
00151 if ( $this->purge ) {
00152 MessageGroupStats::clearGroup( $this->target );
00153 }
00154
00155 MessageGroupStats::setTimeLimit( $this->timelimit );
00156 $cache = MessageGroupStats::forGroup( $this->target );
00157
00158 $languages = array_keys( Language::getLanguageNames( false ) );
00159 sort( $languages );
00160 $this->filterPriorityLangs( $languages, $this->target, $cache );
00161 foreach ( $languages as $code ) {
00162 if ( $table->isBlacklisted( $this->target, $code ) !== null ) {
00163 continue;
00164 }
00165 $out .= $this->makeRow( $code, $cache );
00166 }
00167
00168 if ( $out ) {
00169 $table->setMainColumnHeader( $this->msg( 'translate-mgs-column-language' ) );
00170 $out = $table->createHeader() . "\n" . $out;
00171 $out .= Html::closeElement( 'tbody' );
00172
00173 $out .= Html::openElement( 'tfoot' );
00174 $out .= $table->makeTotalRow( $this->msg( 'translate-mgs-totals' ), $this->totals );
00175 $out .= Html::closeElement( 'tfoot' );
00176
00177 $out .= Html::closeElement( 'table' );
00178
00179 return $out;
00180 } else {
00181 $this->nothing = true;
00182
00183 return '';
00184 }
00185 }
00186
00195 protected function filterPriorityLangs( &$languages, $group, $cache ) {
00196 $filterLangs = TranslateMetadata::get( $group, 'prioritylangs' );
00197 if ( strlen( $filterLangs ) === 0 ) {
00198
00199 return;
00200 }
00201 $filter = array_flip( explode( ',', $filterLangs ) );
00202 foreach ( $languages as $id => $code ) {
00203 if ( isset( $filter[$code] ) ) {
00204 continue;
00205 }
00206 $translated = $cache[$code][1];
00207 if ( $translated === 0 ) {
00208 unset( $languages[$id] );
00209 }
00210 }
00211 }
00212
00218 protected function makeRow( $code, $cache ) {
00219 $stats = $cache[$code];
00220 $total = $stats[MessageGroupStats::TOTAL];
00221 $translated = $stats[MessageGroupStats::TRANSLATED];
00222 $fuzzy = $stats[MessageGroupStats::FUZZY];
00223
00224 if ( $total === null ) {
00225 $this->incomplete = true;
00226 $extra = array();
00227 } else {
00228 if ( $this->noComplete && $fuzzy === 0 && $translated === $total ) {
00229 return '';
00230 }
00231
00232 if ( $this->noEmpty && $translated === 0 && $fuzzy === 0 ) {
00233 return '';
00234 }
00235
00236
00237 if ( $this->noEmpty && ( $translated / $total ) < 0.02 ) {
00238 return '';
00239 }
00240
00241 if ( $translated === $total ) {
00242 $extra = array( 'task' => 'reviewall' );
00243 } else {
00244 $extra = array();
00245 }
00246 }
00247
00248 $this->totals = MessageGroupStats::multiAdd( $this->totals, $stats );
00249
00250 $out = "\t" . Html::openElement( 'tr' );
00251 $out .= "\n\t\t" . $this->getMainColumnCell( $code, $extra );
00252 $out .= $this->table->makeNumberColumns( $stats );
00253 $state = $this->getWorkflowStateValue( $code );
00254 $out .= $this->getWorkflowStateCell( $code, $state );
00255
00256 $out .= "\n\t" . Html::closeElement( 'tr' ) . "\n";
00257
00258 return $out;
00259 }
00260
00266 protected function getMainColumnCell( $code, $params ) {
00267 if ( !isset( $this->names ) ) {
00268 $this->names = TranslateUtils::getLanguageNames( $this->getLanguage()->getCode() );
00269 $this->translate = SpecialPage::getTitleFor( 'Translate' );
00270 }
00271
00272 $queryParameters = $params + array(
00273 'group' => $this->target,
00274 'language' => $code
00275 );
00276
00277 $text = htmlspecialchars( "$code: {$this->names[$code]}" );
00278 $link = Linker::link( $this->translate, $text, array(), $queryParameters );
00279
00280 return Html::rawElement( 'td', array(), $link );
00281 }
00282
00283
00284
00290 protected function getWorkflowStates( $field = 'tgr_lang', $filter = 'tgr_group' ) {
00291 return parent::getWorkflowStates( $field, $filter );
00292 }
00293 }