languageeditstats.php
Go to the documentation of this file.00001 <?php
00013
00014 if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
00015 $IP = getenv( 'MW_INSTALL_PATH' );
00016 } else {
00017 $dir = __DIR__;
00018 $IP = "$dir/../../..";
00019 }
00020 require_once "$IP/maintenance/Maintenance.php";
00021
00022 class LanguageEditStats extends Maintenance {
00023 public function __construct() {
00024 parent::__construct();
00025 $this->mDescription = 'Script to show number of edits per language for all message groups.';
00026 $this->addOption(
00027 '(optional) Show given number of language codes (default: 10)',
00028 'top',
00029 false,
00030 true
00031 );
00032 $this->addOption(
00033 '(optional) Calculate for given number of days (default: 7)',
00034 'days',
00035 false,
00036 true
00037 );
00038 $this->addOption(
00039 '(optional) Include bot edits',
00040 'bots'
00041 );
00042 $this->addOption(
00043 '(optional) Comma separated list of namespace IDs',
00044 'ns',
00045 false,
00046 true
00047 );
00048 }
00049
00050 public function execute() {
00051 $hours = (int)$this->getOption( 'days' );
00052 $hours = $hours ? $hours * 7 : 7 * 24;
00053
00054 $top = (int)$this->getOption( 'top' );
00055 $top = $top ? $top : 10;
00056
00057 $bots = $this->hasOption( 'bots' );
00058
00059 $namespaces = array();
00060 if ( $this->hasOption( 'ns' ) ) {
00061 $input = explode( ',', $this->getOption( 'ns' ) );
00062
00063 foreach ( $input as $namespace ) {
00064 if ( is_numeric( $namespace ) ) {
00065 array_push( $namespaces, $namespace );
00066 }
00067 }
00068 }
00069
00073 $rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces );
00074
00078 $codes = array();
00079 global $wgTranslateFuzzyBotName;
00080 foreach ( $rows as $_ ) {
00081
00082 if ( $_->rc_user_text === $wgTranslateFuzzyBotName ) {
00083 continue;
00084 }
00085
00086 list( , $code ) = TranslateUtils::figureMessage( $_->rc_title );
00087
00088 if ( !isset( $codes[$code] ) ) {
00089 $codes[$code] = 0;
00090 }
00091
00092 $codes[$code]++;
00093 }
00094
00098 arsort( $codes );
00099 $i = 0;
00100 foreach ( $codes as $code => $num ) {
00101 if ( $i++ === $top ) {
00102 break;
00103 }
00104
00105 $this->output( "$code\t$num\n" );
00106 }
00107 }
00108 }
00109
00110 $maintClass = 'LanguageEditStats';
00111 require_once RUN_MAINTENANCE_IF_MAIN;