Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
languageeditstats.php
Go to the documentation of this file.
1<?php
13// Standard boilerplate to define $IP
15
16if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
17 $IP = getenv( 'MW_INSTALL_PATH' );
18} else {
19 $dir = __DIR__;
20 $IP = "$dir/../../..";
21}
22require_once "$IP/maintenance/Maintenance.php";
23
24class Languageeditstats extends Maintenance {
25 public function __construct() {
26 parent::__construct();
27 $this->addDescription( 'Script to show number of edits per language for all message groups.' );
28 $this->addOption(
29 'top',
30 '(optional) Show given number of language codes (default: 10)',
31 false, /*required*/
32 true /*has arg*/
33 );
34 $this->addOption(
35 'days',
36 '(optional) Calculate for given number of days (default: 7)',
37 false, /*required*/
38 true /*has arg*/
39 );
40 $this->addOption(
41 'bots',
42 '(optional) Include bot edits'
43 );
44 $this->addOption(
45 'ns',
46 '(optional) Comma separated list of namespace IDs',
47 false, /*required*/
48 true /*has arg*/
49 );
50 $this->requireExtension( 'Translate' );
51 }
52
53 public function execute() {
54 $hours = ( $this->getOption( 'days' ) ?: 7 ) * 24;
55 $top = (int)$this->getOption( 'top' ) ?: 10;
56 $bots = $this->hasOption( 'bots' );
57
58 $namespaces = [];
59 if ( $this->hasOption( 'ns' ) ) {
60 $input = explode( ',', $this->getOption( 'ns' ) );
61
62 foreach ( $input as $namespace ) {
63 if ( is_numeric( $namespace ) ) {
64 $namespaces[] = $namespace;
65 }
66 }
67 }
68
72 $rows = TranslateUtils::translationChanges( $hours, $bots, $namespaces );
73
77 $codes = [];
78 foreach ( $rows as $_ ) {
79 // Filter out edits by FuzzyBot
80 if ( $_->rc_user_text === FuzzyBot::getName() ) {
81 continue;
82 }
83
84 [ , $code ] = TranslateUtils::figureMessage( $_->rc_title );
85
86 if ( !isset( $codes[$code] ) ) {
87 $codes[$code] = 0;
88 }
89
90 $codes[$code]++;
91 }
92
96 arsort( $codes );
97 $i = 0;
98 foreach ( $codes as $code => $num ) {
99 if ( $i++ === $top ) {
100 break;
101 }
102
103 $this->output( "$code\t$num\n" );
104 }
105 }
106}
107
108$maintClass = Languageeditstats::class;
109require_once RUN_MAINTENANCE_IF_MAIN;
FuzzyBot - the misunderstood workhorse.
Definition FuzzyBot.php:15