Index: trunk/extensions/Translate/SpecialTranslationStats.php |
— | — | @@ -52,8 +52,10 @@ |
53 | 53 | } elseif ( $opts['graphit'] ) { |
54 | 54 | |
55 | 55 | // Cache for two hours |
56 | | - $lastMod = $wgOut->checkLastModified( wfTimestamp( TS_MW, time() - 2 * 3600 ) ); |
57 | | - if ( $lastMod ) return; |
| 56 | + if ( !$opts['preview'] ) { |
| 57 | + $lastMod = $wgOut->checkLastModified( wfTimestamp( TS_MW, time() - 2 * 3600 ) ); |
| 58 | + if ( $lastMod ) return; |
| 59 | + } |
58 | 60 | |
59 | 61 | $wgOut->disable(); |
60 | 62 | |
— | — | @@ -279,7 +281,6 @@ |
280 | 282 | $so->preQuery( $tables, $fields, $conds, $type, $options ); |
281 | 283 | $res = $dbr->select( $tables, $fields, $conds, $type, $options ); |
282 | 284 | |
283 | | - |
284 | 285 | // Initialisations |
285 | 286 | $so->postQuery( $res ); |
286 | 287 | |
— | — | @@ -291,9 +292,9 @@ |
292 | 293 | |
293 | 294 | $data = array(); |
294 | 295 | while ( $cutoff < $now ) { |
295 | | - $date = $wgLang->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) ); |
296 | | - $so->preProcess( $data[$date] ); |
| 296 | + $date = $wgLang->sprintfDate( $dateFormat, wfTimestamp( TS_MW, $cutoff ) ); |
297 | 297 | $cutoff += $increment; |
| 298 | + $data[$date] = array(); |
298 | 299 | } |
299 | 300 | |
300 | 301 | // Processing |
— | — | @@ -301,7 +302,7 @@ |
302 | 303 | $date = $wgLang->sprintfDate( $dateFormat, $row->rc_timestamp ); |
303 | 304 | |
304 | 305 | $indexes = $so->indexOf( $row ); |
305 | | - if ( $indexes === -1 ) continue; |
| 306 | + if ( $indexes === false ) continue; |
306 | 307 | |
307 | 308 | foreach ( (array) $indexes as $index ) { |
308 | 309 | if ( !isset( $data[$date][$index] ) ) $data[$date][$index] = 0; |
— | — | @@ -309,9 +310,18 @@ |
310 | 311 | } |
311 | 312 | } |
312 | 313 | |
313 | | - $labels = null; |
314 | | - $so->labels( $labels ); |
| 314 | + $labels = $so->labels(); |
315 | 315 | |
| 316 | + /* Make sure there is empty entries for silent days, or otherwise |
| 317 | + * they will be skipped alltogether. */ |
| 318 | + foreach ( $data as &$date ) { |
| 319 | + foreach ( $labels as $label ) { |
| 320 | + if ( !isset( $date[$label] ) ) { |
| 321 | + $date[$label] = 0; |
| 322 | + } |
| 323 | + } |
| 324 | + } |
| 325 | + |
316 | 326 | return array( $labels, $data ); |
317 | 327 | } |
318 | 328 | |
— | — | @@ -378,9 +388,6 @@ |
379 | 389 | |
380 | 390 | class TranslatePerLanguageStats { |
381 | 391 | protected $opts; |
382 | | - protected $cache; |
383 | | - protected $index; |
384 | | - protected $filters; |
385 | 392 | protected $usercache; |
386 | 393 | |
387 | 394 | public function __construct( FormOptions $opts ) { |
— | — | @@ -390,55 +397,42 @@ |
391 | 398 | public function preQuery( &$tables, &$fields, &$conds, &$type, &$options ) { |
392 | 399 | $db = wfGetDB( DB_SLAVE ); |
393 | 400 | |
394 | | - $groups = array_map( 'trim', explode( ',', $this->opts['group'] ) ); |
395 | | - $codes = array_map( 'trim', explode( ',', $this->opts['language'] ) ); |
| 401 | + $this->groups = array_filter( array_map( 'trim', explode( ',', $this->opts['group'] ) ) ); |
| 402 | + $this->codes = array_filter( array_map( 'trim', explode( ',', $this->opts['language'] ) ) ); |
396 | 403 | |
397 | | - $filters['language'] = trim( $this->opts['language'] ) !== ''; |
398 | | - $filters['group'] = trim( $this->opts['group'] ) !== ''; |
399 | | - |
400 | 404 | $namespaces = array(); |
| 405 | + $languages = array(); |
401 | 406 | |
402 | | - foreach ( $groups as $group ) { |
403 | | - if ( $group === '' ) continue; |
404 | | - $ns = MessageGroups::getGroup( $group )->getNamespace(); |
405 | | - $namespaces[$ns] = true; |
406 | | - |
407 | | - foreach ( $codes as $code ) { |
408 | | - if ( $code !== '' ) $key = "$group ($code)"; |
409 | | - else $key = $group; |
410 | | - $this->cache[$key] = count( $this->cache ); |
| 407 | + foreach ( $this->groups as $id ) { |
| 408 | + $group = MessageGroups::getGroup( $id ); |
| 409 | + if ( $group ) { |
| 410 | + $namespaces[] = $group->getNamespace(); |
411 | 411 | } |
412 | 412 | } |
413 | 413 | |
| 414 | + foreach( $this->codes as $code ) { |
| 415 | + $languages[] = 'rc_title like \'%%/' . $db->escapeLike( $code ) . "'"; |
| 416 | + } |
| 417 | + |
414 | 418 | if ( count( $namespaces ) ) { |
415 | | - $conds['rc_namespace'] = array_keys( $namespaces ); |
| 419 | + $namespaces = array_unique( $namespaces ); |
| 420 | + $conds['rc_namespace'] = $namespaces; |
416 | 421 | } |
417 | 422 | |
418 | | - if ( $filters['language'] ) { |
419 | | - $myconds = array(); |
420 | | - foreach ( $codes as $code ) { |
421 | | - if ( $code === '' ) continue; |
422 | | - $myconds[] = 'rc_title like \'%%/' . $db->escapeLike( $code ) . "'"; |
423 | | - } |
424 | | - |
425 | | - $conds[] = $db->makeList( $myconds, LIST_OR ); |
| 423 | + if ( count( $languages ) ) { |
| 424 | + $languages = array_unique( $languages ); |
| 425 | + $conds[] = $db->makeList( $languages, LIST_OR ); |
426 | 426 | } |
427 | 427 | |
428 | | - if ( max( $filters ) ) $fields[] = 'rc_title'; |
429 | | - if ( $filters['group'] ) $fields[] = 'rc_namespace'; |
| 428 | + $fields[] = 'rc_title'; |
| 429 | + if ( $this->groups ) $fields[] = 'rc_namespace'; |
430 | 430 | if ( $this->opts['count'] === 'users' ) $fields[] = 'rc_user_text'; |
431 | 431 | |
432 | 432 | $type .= '-perlang'; |
433 | | - |
434 | | - $this->filters = $filters; |
435 | 433 | } |
436 | 434 | |
437 | 435 | public function postQuery( $rows ) { } |
438 | 436 | |
439 | | - public function preProcess( &$initial ) { |
440 | | - $initial = array_pad( array(), max( 1, count( $this->cache ) ), 0 ); |
441 | | - } |
442 | | - |
443 | 437 | public function indexOf( $row ) { |
444 | 438 | global $wgContLang; |
445 | 439 | |
— | — | @@ -454,41 +448,53 @@ |
455 | 449 | } |
456 | 450 | } |
457 | 451 | |
458 | | - if ( !max( $this->filters ) ) return 0; |
459 | | - if ( strpos( $row->rc_title, '/' ) === false ) return -1; |
460 | | - if ( !count( $this->cache ) ) return 0; |
| 452 | + // Don't consider language-less pages |
| 453 | + if ( strpos( $row->rc_title, '/' ) === false ) return false; |
461 | 454 | |
| 455 | + // No filters, just one key to track |
| 456 | + if ( !$this->groups && !$this->codes ) return 'all'; |
| 457 | + |
| 458 | + // The key-building needs to be in sync with ::labels() |
| 459 | + $keys = array(); |
| 460 | + |
462 | 461 | list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title ); |
463 | | - $indexKeys = array(); |
464 | 462 | |
465 | | - if ( $this->filters['group'] ) { |
| 463 | + if ( $this->groups ) { |
| 464 | + /* Get list of keys that the message belongs to, and filter |
| 465 | + * out those which are not requested */ |
466 | 466 | $groups = TranslateUtils::messageKeyToGroups( $row->rc_namespace, $key ); |
467 | | - if ( !count( $groups ) ) { |
468 | | - return -1; |
469 | | - } |
470 | | - foreach ( $groups as $group ) $indexKeys[] = $group; |
| 467 | + $keys = array_intersect( $this->groups, $groups ); |
| 468 | + } else { |
| 469 | + $keys[] = ''; |
471 | 470 | } |
472 | | - |
473 | | - if ( $this->filters['language'] ) { |
474 | | - foreach ( $indexKeys as &$value ) { |
475 | | - $value .= " ($code)"; |
| 471 | + if ( $this->codes ) { |
| 472 | + foreach ( $keys as &$value ) { |
| 473 | + if ( $value === '' ) { |
| 474 | + $value = $code; |
| 475 | + } else { |
| 476 | + $value .= " ($code)"; |
| 477 | + } |
476 | 478 | } |
477 | 479 | } |
| 480 | + return $keys; |
| 481 | + } |
478 | 482 | |
479 | | - $indexes = array(); |
480 | | - |
481 | | - foreach ( $indexKeys as $value ) { |
482 | | - if ( isset( $this->cache[$value] ) ) { |
483 | | - $indexes[] = $this->cache[$value]; |
| 483 | + public function labels() { |
| 484 | + $labels = array(); |
| 485 | + if ( $this->groups && $this->codes ) { |
| 486 | + foreach ( $this->codes as $code ) { |
| 487 | + foreach ( $this->groups as $group ) { |
| 488 | + $labels[] = "$group ($code)"; |
| 489 | + } |
484 | 490 | } |
| 491 | + } elseif ( $this->groups ) { |
| 492 | + $labels = $this->groups; |
| 493 | + } elseif ( $this->codes ) { |
| 494 | + $labels = $this->codes; |
| 495 | + } else { |
| 496 | + $labels = array(); |
485 | 497 | } |
486 | | - |
487 | | - return $indexes; |
| 498 | + return $labels; |
488 | 499 | } |
489 | 500 | |
490 | | - public function labels( &$labels ) { |
491 | | - if ( count( $this->cache ) > 1 ) { |
492 | | - $labels = array_keys( $this->cache ); |
493 | | - } |
494 | | - } |
495 | 501 | } |