jenkins-bot has submitted this change and it was merged. Change subject: Update languageeditstats.php to use Maintenance class ......................................................................
Update languageeditstats.php to use Maintenance class Change-Id: I33886d9987571235da2a77baca135bd0e1d57f12 --- M scripts/languageeditstats.php 1 file changed, 89 insertions(+), 91 deletions(-) Approvals: Nikerabbit: Looks good to me, approved jenkins-bot: Verified diff --git a/scripts/languageeditstats.php b/scripts/languageeditstats.php index 5a21728..5ef33db 100644 --- a/scripts/languageeditstats.php +++ b/scripts/languageeditstats.php @@ -10,104 +10,102 @@ * @ingroup Script Stats */ -$optionsWithArgs = array( 'top', 'days', 'bots', 'ns' ); -require __DIR__ . '/cli.inc'; - -function showUsage() { - STDERR( <<<EOT -Language statistics. -Shows number of edits per language for all message groups. - -Usage: php languageeditstats.php [options...] - -Options: - --top Show given number of language codes (default: 10) - --days Calculate for given number of days (default: 7) - --bots Include bot edits (default: false) - --ns Comma separated list of Namespace IDs (default: all) - -EOT - ); - exit( 1 ); -} - -/** - * Process command line parameters - */ -if ( isset( $options['help'] ) ) { - showUsage(); -} - -if ( isset( $options['days'] ) ) { - $hours = intval( $options['days'] ) * 24; // no day change cutoff +// Standard boilerplate to define $IP +if ( getenv( 'MW_INSTALL_PATH' ) !== false ) { + $IP = getenv( 'MW_INSTALL_PATH' ); } else { - $hours = 7 * 24; + $dir = __DIR__; + $IP = "$dir/../../.."; } +require_once "$IP/maintenance/Maintenance.php"; -if ( isset( $options['top'] ) ) { - $top = intval( $options['top'] ); -} else { - $top = 10; -} +class LanguageEditStats extends Maintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = 'Script to show number of edits per language for all message groups'; + $this->addOption( + '(optional) Show given number of language codes (default: 10)', + 'top', + false, /*required*/ + true /*has arg*/ + ); + $this->addOption( + '(optional) Calculate for given number of days (default: 7)', + 'days', + false, /*required*/ + true /*has arg*/ + ); + $this->addOption( + '(optional) Include bot edits', + 'bots' + ); + $this->addOption( + '(optional) Comma separated list of namespace IDs', + 'ns', + false, /*required*/ + true /*has arg*/ + ); + } -if ( isset( $options['bots'] ) ) { - $bots = true; -} else { - $bots = false; -} + public function execute() { + $hours = (int)$this->getOption( 'days' ); + $hours = $hours ? $hours * 7 : 7 * 24; -$namespaces = array(); -if ( isset( $options['ns'] ) ) { - $input = explode( ',', $options['ns'] ); + $top = (int)$this->getOption( 'top' ); + $top = $top ? $top : 10; - foreach ( $input as $namespace ) { - if ( is_numeric( $namespace ) ) { - array_push( $namespaces, $namespace ); + $bots = $this->hasOption( 'bots' ); + + $namespaces = array(); + if ( $this->hasOption( 'ns' ) ) { + $input = explode( ',', $this->getOption( 'ns' ) ); + + foreach ( $input as $namespace ) { + if ( is_numeric( $namespace ) ) { + array_push( $namespaces, $namespace ); + } + } + } + + /** + * Select set of edits to report on + */ + $rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces ); + + /** + * Get counts for edits per language code after filtering out edits by FuzzyBot + */ + $codes = array(); + global $wgTranslateFuzzyBotName; + foreach ( $rows as $_ ) { + // Filter out edits by $wgTranslateFuzzyBotName + if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) { + continue; + } + + list( , $code ) = TranslateUtils::figureMessage( $_->rc_title ); + + if ( !isset( $codes[$code] ) ) { + $codes[$code] = 0; + } + + $codes[$code]++; + } + + /** + * Sort counts and report descending up to $top rows. + */ + arsort( $codes ); + $i = 0; + foreach ( $codes as $code => $num ) { + if ( $i++ === $top ) { + break; + } + + $this->output( "$code\t$num\n" ); } } } -function figureMessage( $text ) { - $pos = strrpos( $text, '/' ); - $code = substr( $text, $pos + 1 ); - $key = substr( $text, 0, $pos ); - - return array( $key, $code ); -} - -/** - * Select set of edits to report on - */ -$rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces ); - -/** - * Get counts for edits per language code after filtering out edits by FuzzyBot - */ -$codes = array(); -foreach ( $rows as $_ ) { - // Filter out edits by $wgTranslateFuzzyBotName - if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) { - continue; - } - - list( , $code ) = figureMessage( $_->rc_title ); - - if ( !isset( $codes[$code] ) ) { - $codes[$code] = 0; - } - - $codes[$code]++; -} - -/** - * Sort counts and report descending up to $top rows. - */ -arsort( $codes ); -$i = 0; -foreach ( $codes as $code => $num ) { - if ( $i++ === $top ) { - break; - } - - STDOUT( "$code\t$num" ); -} +$maintClass = 'LanguageEditStats'; +require_once RUN_MAINTENANCE_IF_MAIN; -- To view, visit https://gerrit.wikimedia.org/r/89344 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I33886d9987571235da2a77baca135bd0e1d57f12 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Translate Gerrit-Branch: master Gerrit-Owner: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com> Gerrit-Reviewer: Siebrand <siebr...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits