Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Wikipedia: Mediawiki-CVS

SVN: [37611] trunk/extensions/Translate

 

 

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded


nikerabbit at svn

Jul 13, 2008, 6:14 AM

Post #1 of 1 (69 views)
Permalink
SVN: [37611] trunk/extensions/Translate

Revision: 37611
Author: nikerabbit
Date: 2008-07-13 13:14:54 +0000 (Sun, 13 Jul 2008)

Log Message:
-----------
* 2008-07-13:2 group filter for graphs

Modified Paths:
--------------
trunk/extensions/Translate/README
trunk/extensions/Translate/Stats.php
trunk/extensions/Translate/Translate.php

Modified: trunk/extensions/Translate/README
===================================================================
--- trunk/extensions/Translate/README 2008-07-13 13:08:33 UTC (rev 37610)
+++ trunk/extensions/Translate/README 2008-07-13 13:14:54 UTC (rev 37611)
@@ -34,6 +34,7 @@

== Changes in version 10 ==

+* 2008-07-13:2 group filter for graphs
* 2008-07-13:1 experimental alias-export for extensions
* 2008-07-08:1 simple edit stats with phplot
* 2008-07-05:1 fuzzy.php was ignoring the namespace

Modified: trunk/extensions/Translate/Stats.php
===================================================================
--- trunk/extensions/Translate/Stats.php 2008-07-13 13:08:33 UTC (rev 37610)
+++ trunk/extensions/Translate/Stats.php 2008-07-13 13:14:54 UTC (rev 37611)
@@ -13,11 +13,11 @@


$opts = new FormOptions();
- $opts->add( 'language', 'en' );
+ $opts->add( 'language', '' );
$opts->add( 'days', 30 );
$opts->add( 'width', 600 );
$opts->add( 'height', 400 );
- $opts->add( 'ts', 0 );
+ $opts->add( 'group', '' );
$opts->fetchValuesFromRequest( $wgRequest );

$pars = explode( ';', $par );
@@ -33,7 +33,7 @@
$opts->validateIntBounds( 'height', 200, 1000 );

$title = $this->getTitle();
- $cgiparams = wfArrayToCgi( array( 'ts' => time() ), $opts->getAllValues() );
+ $cgiparams = wfArrayToCgi( $opts->getAllValues() );
$href = $title->getLocalUrl( $cgiparams );


@@ -48,16 +48,10 @@
)
);
} else {
- if ( $opts['ts'] === 0 ) {
- $wgOut->redirect( $href );
- return;
- }
+ // Cache for two hours
+ $lastMod = $wgOut->checkLastModified( wfTimestamp( TS_MW, time() - 2*3600 ) );
+ if ( $lastMod ) return;

- if ( time() - $opts['ts'] < 3600*2 ) {
- $lastMod = $wgOut->checkLastModified( wfTimestamp( TS_MW, $opts['ts'] ) );
- if ( $lastMod ) return;
- }
-
$wgOut->disable();

if ( !class_exists('PHPlot') ) {
@@ -78,36 +72,55 @@
$cutoff = $now - ( 3600 * 24 * $opts->getValue('days') -1 );
$cutoff -= ($cutoff % 86400);
$cutoffDb = $dbr->timestamp( $cutoff );
- $code = $dbr->escapeLike( $opts->getValue('language') );

- $res = $dbr->select(
- 'recentchanges',
- 'rc_timestamp',
- array(
- "rc_timestamp >= '$cutoffDb'",
- 'rc_namespace' => $wgTranslateMessageNamespaces,
- "rc_title like '%%/$code'",
- 'rc_bot' => 0
- ),
- __METHOD__,
- array( 'ORDER BY' => 'rc_timestamp' )
+ $so = new TranslatePerLanguageStats( $opts );
+
+
+ $tables = array( 'recentchanges' );
+ $fields = array( 'rc_timestamp' );
+
+ $conds = array(
+ "rc_timestamp >= '$cutoffDb'",
+ 'rc_namespace' => $wgTranslateMessageNamespaces,
+ 'rc_bot' => 0
);

+ $type = __METHOD__;
+ $options = array( 'ORDER BY' => 'rc_timestamp' );
+
+ $so->preQuery( $tables, $fields, $conds, $type, $options );
+ $res = $dbr->select( $tables, $fields, $conds, $type, $options );
+
+
+ // Initialisations
+ $so->postQuery( $res );
+
$data = array();
while ( $cutoff < $now ) {
$date = $wgLang->sprintfDate( 'Y-m-d', wfTimestamp( TS_MW, $cutoff ) );
- $data[$date] = 0;
+ $so->preProcess( $data[$date] );
$cutoff += 24 * 3600;
}

+ // Processing
foreach ( $res as $row ) {
$date = $wgLang->sprintfDate( 'Y-m-d', $row->rc_timestamp );
- if ( !isset($data[$date]) ) $data[$date] = 0;
- $data[$date]++;
+ $index = $so->indexOf( $row );
+ if ( $index < 0 ) continue;
+
+ if ( !isset($data[$date][$index]) ) $data[$date][$index] = 0;
+ $data[$date][$index]++;
}

- return $data;
+ $labels = null;
+ if ( $opts['type'] === 'userlang' ) {
+ $labels = @array_keys($usercache);
+ }
+ $so->labels( $labels );

+ //var_dump( $data );
+ return array($labels, $data);
+
}

public function draw( FormOptions $opts ) {
@@ -118,9 +131,8 @@
$height = $opts->getValue( 'height' );
//Define the object
$plot = new PHPlot($width, $height);
- $code = 'nl';

- $resData = $this->getData($opts);
+ list( $legend, $resData ) = $this->getData($opts);
$count = count($resData);
$skip = intval($count / ($width/60) -1);
$i = $count;
@@ -128,13 +140,18 @@
if ( $skip > 0 ) {
if ( ($count-$i)%$skip !== 0 ) { $date = ''; }
}
- $data[] = array( $date, $edits );
+ array_unshift( $edits, $date );
+ $data[] = $edits;
$i--;
}

$plot->SetDefaultTTFont($wgTranslatePHPlotFont);

$plot->SetDataValues( $data );
+
+ if ( $legend !== null )
+ $plot->SetLegend($legend);
+
$plot->setFont( 'x_label', null, 8 );
$plot->setFont( 'y_label', null, 8 );

@@ -144,7 +161,7 @@
$plot->SetXTickPos('none');
$plot->SetXLabelAngle(45);

- $max = max( $resData );
+ $max = max( array_map( 'max', $resData ) );
$yTick = 5;
while ( $max / $yTick > $height/20 ) $yTick *= 2;

@@ -159,4 +176,90 @@

}

+}
+
+
+class TranslatePerLanguageStats {
+ protected $opts;
+ protected $cache;
+ protected $index;
+ protected $filters;
+
+ public function __construct( FormOptions $opts ) {
+ $this->opts = $opts;
+ }
+
+ public function preQuery( &$tables, &$fields, &$conds, &$type, &$options ) {
+ $db = wfGetDb();
+
+ $groups = array_map( 'trim', explode(',', $this->opts['group']) );
+ $codes = array_map( 'trim', explode(',', $this->opts['language']) );
+
+ $filters['language'] = trim($this->opts['language']) !== '';
+ $filters['group'] = trim($this->opts['group']) !== '';
+
+ foreach ( $groups as $group )
+ foreach ( $codes as $code )
+ $this->cache[$group . $code] = count($this->cache);
+
+ if ( $filters['language'] ) {
+ $myconds = array();
+ foreach( $codes as $code ) {
+ $myconds[] = 'rc_title like \'%%/' . $db->escapeLike( $code ) . "'";
+ }
+
+ $conds[] = $db->makeList( $myconds, LIST_OR );
+ }
+
+ if ( max($filters) ) $fields[] = 'rc_title';
+ if ( $filters['group'] ) $fields[] = 'rc_namespace';
+
+ $type .= '-perlang';
+
+ $this->filters = $filters;
+
+ }
+
+ public function postQuery( $rows ) {}
+
+ public function preProcess( &$initial ) {
+ $initial = array_pad( array(), max(1, count($this->cache)), 0 );
+ }
+
+ public function indexOf( $row ) {
+ global $wgContLang;
+
+ if ( max($this->filters) === 0 ) return 0;
+ if ( strpos( $row->rc_title, '/' ) === false ) return -1;
+
+ list( $key, $code ) = explode('/', $wgContLang->lcfirst($row->rc_title), 2);
+ $indexKey = '';
+
+ if ( $this->filters['group'] ) {
+ if ( $this->index === null ) $this->index = TranslateUtils::messageIndex();
+
+ $key = strtolower($row->rc_namespace. ':' . $key);
+ $group = @$this->index[$key];
+ if ( is_null($group) ) return -1;
+ $indexKey .= $group;
+ }
+
+ if ( $this->filters['language'] ) {
+ $indexKey .= $code;
+ }
+
+
+ if ( count($this->cache) > 1 ) {
+ return isset($this->cache[$indexKey]) ? $this->cache[$indexKey] : -1;
+ } else {
+ return 0;
+ }
+ }
+
+ public function labels( &$labels ) {
+ if ( count($this->cache) > 1 ) {
+ $labels = array_keys($this->cache);
+ }
+ }
+
}
\ No newline at end of file

Modified: trunk/extensions/Translate/Translate.php
===================================================================
--- trunk/extensions/Translate/Translate.php 2008-07-13 13:08:33 UTC (rev 37610)
+++ trunk/extensions/Translate/Translate.php 2008-07-13 13:14:54 UTC (rev 37611)
@@ -11,7 +11,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
*/

-define( 'TRANSLATE_VERSION', '9 (2008-07-13:1)' );
+define( 'TRANSLATE_VERSION', '9 (2008-07-13:2)' );

$wgExtensionCredits['specialpage'][] = array(
'name' => 'Translate',



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS [at] lists
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Wikipedia mediawiki-cvs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.