21 public function __construct() {
22 parent::__construct();
23 $this->addDescription(
'Script to show number of edits per language for all message groups.' );
26 '(optional) Show given number of language codes (default: 10)',
32 '(optional) Calculate for given number of days (default: 7)',
38 '(optional) Include bot edits'
42 '(optional) Comma separated list of namespace IDs',
46 $this->requireExtension(
'Translate' );
49 public function execute():
void {
50 $days = (int)$this->getOption(
'days' ) ?: 7;
51 $top = (int)$this->getOption(
'top' ) ?: 10;
52 $bots = $this->hasOption(
'bots' );
55 if ( $this->hasOption(
'ns' ) ) {
56 $input = explode(
',', $this->getOption(
'ns' ) );
58 foreach ( $input as $namespace ) {
59 if ( is_numeric( $namespace ) ) {
60 $namespaces[] = $namespace;
66 $rows = $this->translationChanges( $days, $bots, $namespaces );
70 foreach ( $rows as $row ) {
73 if ( !isset( $codes[$code] ) ) {
83 foreach ( $codes as $code => $num ) {
84 if ( $i++ === $top ) {
88 $this->output(
"$code\t$num\n" );
100 private function translationChanges(
int $days,
bool $bots, array $ns ): array {
101 global $wgTranslateMessageNamespaces;
102 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
104 $cutoff = $dbr->timestamp( time() - ( $days * 24 * 3600 ) );
107 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff ),
108 'rc_namespace' => $ns ?: $wgTranslateMessageNamespaces,
109 'actor_name <> ' . $dbr->addQuotes( FuzzyBot::getName() )
112 $conds[
'rc_bot'] = 0;
115 return $dbr->newSelectQueryBuilder()
116 ->select( [
'rc_title' ] )
117 ->from(
'recentchanges' )
118 ->join(
'actor',
null,
'actor_id=rc_actor' )
120 ->caller( __METHOD__ )
121 ->fetchFieldValues();