r65873 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65872‎ | r65873 | r65874 >
Date:20:19, 3 May 2010
Author:kipcool
Status:deferred
Tags:
Comment:
New special page on statistics to replace util/stat.php
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialOWStatistics.php (added) (history)
  • /trunk/extensions/Wikidata/Wikidata.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/Wikidata.i18n.php
@@ -251,6 +251,8 @@
252252 'ow_needs_xlation_dest_lang' => 'Destination language:',
253253 'ow_needs_xlation_no_dest_lang' => 'Please specify a destination language.',
254254
 255+ 'ow_statistics' => 'Wikidata: Statistics',
 256+
255257 'ow_show' => 'Show',
256258 'ow_upload' => 'Upload',
257259 'ow_create' => 'Create',
Index: trunk/extensions/Wikidata/App.php
@@ -117,6 +117,7 @@
118118 require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialCopy.php" );
119119 require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialExportTSV.php" );
120120 require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialImportTSV.php" );
 121+require_once( "{$IP}/extensions/Wikidata/OmegaWiki/SpecialOWStatistics.php" );
121122
122123 require_once( "{$IP}/extensions/Wikidata/LocalApp.php" );
123124
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialOWStatistics.php
@@ -0,0 +1,262 @@
 2+<?php
 3+ if ( !defined( 'MEDIAWIKI' ) ) die();
 4+
 5+ $wgExtensionFunctions[] = 'wfSpecialOWStatistics';
 6+
 7+ require_once( "Wikidata.php" );
 8+ require_once( 'languages.php' );
 9+
 10+ function wfSpecialOWStatistics() {
 11+ class SpecialOWStatistics extends SpecialPage {
 12+ function SpecialOWStatistics() {
 13+ SpecialPage::SpecialPage( 'ow_statistics' );
 14+ }
 15+
 16+ function execute( $par ) {
 17+ global $wgOut, $wgRequest;
 18+
 19+ $wgOut->setPageTitle( wfMsg( 'ow_statistics' ) );
 20+
 21+ $showstat = array_key_exists( 'showstat', $_GET ) ? $_GET['showstat']:'';
 22+
 23+ $headerText = '<big><div style="text-align:center; background-color:#DDFFDD;">'
 24+ . $this->linkHeader ( wfMsg('ow_DefinedMeaning'), "dm", $showstat ) . " — "
 25+ . $this->linkHeader ( wfMsg('ow_Definition'), "def", $showstat ) . " — "
 26+ . $this->linkHeader ( wfMsg('ow_Expression'), "exp", $showstat ) . " — "
 27+ . $this->linkHeader ( "Syntrans", "syntrans", $showstat )
 28+ . "</big></div><br /><br />" ;
 29+
 30+ $wgOut->addHTML( $headerText ) ;
 31+
 32+ if ( $showstat == 'dm' )
 33+ $wgOut->addHTML( $this->getDefinedMeaningPerLanguage () );
 34+ else if ( $showstat == 'def' )
 35+ $wgOut->addHTML( $this->getDefinitionPerLanguage () );
 36+ else if ( $showstat == 'syntrans' )
 37+ $wgOut->addHTML( $this->getSyntransPerLanguage () );
 38+ else // exp by default
 39+ $wgOut->addHTML ( $this->getExpressionPerLanguage () ) ;
 40+ }
 41+
 42+ function linkHeader ( $text, $val , $showstat ) {
 43+ global $wgArticlePath;
 44+ if ( $showstat != $val ) {
 45+ $url = str_replace( "$1", 'Special:Ow_statistics' , $wgArticlePath );
 46+ return "<a href=\"$url&showstat=$val\">$text</a>" ;
 47+ } else {
 48+ return "<b>$text</b>" ;
 49+ }
 50+ }
 51+
 52+ function getNumberOfDM ( ) {
 53+ $dc = wdGetDataSetContext();
 54+ $dbr = wfGetDB( DB_SLAVE );
 55+
 56+ $sql = "SELECT COUNT(DISTINCT defined_meaning_id) as number " ;
 57+ $sql .= "FROM " . "{$dc}_syntrans" . " WHERE remove_transaction_id IS NULL" ;
 58+
 59+ $queryResult = $dbr->query( $sql );
 60+ $row = $dbr->fetchObject( $queryResult ) ;
 61+ $nbdm = $row->number ;
 62+
 63+ return "$nbdm";
 64+ }
 65+
 66+ function getDefinedMeaningPerLanguage () {
 67+ $dc = wdGetDataSetContext();
 68+ $dbr = wfGetDB( DB_SLAVE );
 69+ global $wgUploadPath ;
 70+
 71+ $languageNames = getOwLanguageNames();
 72+
 73+ // get number of DM with at least one translation for each language
 74+ $sql = "SELECT language_id, count(DISTINCT {$dc}_syntrans.defined_meaning_id) as tot ";
 75+ $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ;
 76+ $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ;
 77+ $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ;
 78+ $sql .= " AND {$dc}_expression.remove_transaction_id IS NULL " ;
 79+ $sql .= " group by language_id " ;
 80+
 81+ $queryResult = $dbr->query( $sql );
 82+ $nbDMArray = array () ;
 83+
 84+ while ( $row = $dbr->fetchObject( $queryResult ) ) {
 85+ $lang = $languageNames[$row->language_id] ;
 86+ $nbDMArray[$lang] = $row->tot ;
 87+ }
 88+ $nblang = count ( $nbDMArray ) ;
 89+ $nbdm = $this->getNumberOfDM() ;
 90+
 91+ $tableLang = "<center><table class=\"sortable\">" ;
 92+ $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_DefinedMeaning') . "</b></th></tr>\n";
 93+
 94+ arsort ( $nbDMArray ) ;
 95+ $max = max ( $nbDMArray ) ;
 96+
 97+ foreach ($nbDMArray as $lang => $dm) {
 98+ $wi = ceil( ( ( $dm / $max ) * 500 ) );
 99+ $per = ceil( ( ( $dm / $max ) * 100 ) );
 100+ $tableLang .= "<tr><td>$lang</td><td align=right>$dm</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ;
 101+ }
 102+
 103+ $tableLang .= "</table></center>" ;
 104+
 105+ $output = "<center><big><table><tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ;
 106+ $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ;
 107+
 108+ $output .= "<p>$tableLang</p>" ;
 109+
 110+ return $output ;
 111+ }
 112+
 113+
 114+ function getDefinitionPerLanguage () {
 115+ $dc = wdGetDataSetContext();
 116+ $dbr = wfGetDB( DB_SLAVE );
 117+ global $wgUploadPath ;
 118+
 119+ $languageNames = getOwLanguageNames();
 120+
 121+ // get number of definitions for each language (note : a definition is always unique )
 122+ $sql = "SELECT language_id, count(DISTINCT {$dc}_translated_content.text_id) as tot ";
 123+ $sql .= " FROM {$dc}_translated_content, {$dc}_defined_meaning" ;
 124+ $sql .= " WHERE {$dc}_translated_content.translated_content_id = {$dc}_defined_meaning.meaning_text_tcid " ;
 125+ $sql .= " AND {$dc}_translated_content.remove_transaction_id IS NULL " ;
 126+ $sql .= " AND {$dc}_defined_meaning.remove_transaction_id IS NULL " ;
 127+ $sql .= " group by language_id " ;
 128+
 129+ $queryResult = $dbr->query( $sql );
 130+ $nbDefArray = array () ;
 131+
 132+ while ( $row = $dbr->fetchObject( $queryResult ) ) {
 133+ $lang = $languageNames[$row->language_id] ;
 134+ $nbDefArray[$lang] = $row->tot ;
 135+ }
 136+ $nbDefTot = array_sum ( $nbDefArray ) ;
 137+ $nblang = count ( $nbDefArray ) ;
 138+ $nbdm = $this->getNumberOfDM() ;
 139+
 140+ $tableLang = "<center><table class=\"sortable\">" ;
 141+ $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_Definition') . "</b></th></tr>\n";
 142+
 143+ arsort ( $nbDefArray ) ;
 144+ $max = max ( $nbDefArray ) ;
 145+ foreach ($nbDefArray as $lang => $def) {
 146+ $wi = ceil( ( ( $def / $max ) * 500 ) );
 147+ $per = ceil( ( ( $def / $max ) * 100 ) );
 148+ $tableLang .= "<tr><td>$lang</td><td align=right>$def</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ;
 149+ }
 150+
 151+ $tableLang .= "</table></center>" ;
 152+
 153+ $output = "<center><big><table><tr><td>" . wfMsg('ow_Definition') . " : </td><td><b>$nbDefTot</b></td></tr>" ;
 154+ $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ;
 155+ $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ;
 156+
 157+ $output .= "<p>$tableLang</p>" ;
 158+
 159+ return $output ;
 160+ }
 161+
 162+
 163+ function getExpressionPerLanguage () {
 164+ $dc = wdGetDataSetContext();
 165+ $dbr = wfGetDB( DB_SLAVE );
 166+ global $wgUploadPath ;
 167+
 168+ $sql = "SELECT language_id, count(DISTINCT {$dc}_expression.expression_id) as tot ";
 169+ $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ;
 170+ $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ;
 171+ $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ;
 172+ $sql .= " AND {$dc}_expression.remove_transaction_id IS NULL " ;
 173+ $sql .= " group by language_id " ;
 174+
 175+ $queryResult = $dbr->query( $sql );
 176+
 177+ $languageNames = getOwLanguageNames();
 178+ $nbexpArray = array () ;
 179+
 180+ while ( $row = $dbr->fetchObject( $queryResult ) ) {
 181+ $lang = $languageNames[$row->language_id] ;
 182+ $nbexpArray[$lang] = $row->tot ;
 183+ }
 184+ $nbexptot = array_sum ( $nbexpArray ) ;
 185+ $nbdm = $this->getNumberOfDM() ;
 186+ $nblang = count ( $nbexpArray ) ;
 187+
 188+ $tableLang = "<center><table class=\"sortable\">" ;
 189+ $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>" . wfMsg('ow_Expression') . "</b></th></tr>\n";
 190+
 191+ arsort ( $nbexpArray ) ;
 192+ $max = max ( $nbexpArray ) ;
 193+ foreach ($nbexpArray as $lang => $exp) {
 194+ $wi = ceil( ( ( $exp / $max ) * 500 ) );
 195+ $per = ceil( ( ( $exp / $max ) * 100 ) );
 196+ $tableLang .= "<tr><td>$lang</td><td align=right>$exp</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ;
 197+ }
 198+
 199+ $tableLang .= "</table></center>" ;
 200+
 201+ $output = "<center><big><table><tr><td>" . wfMsg('ow_Expression') . " : </td><td><b>$nbexptot</b></td></tr>" ;
 202+ $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ;
 203+ $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ;
 204+
 205+ $output .= "<p>$tableLang</p>" ;
 206+ return $output ;
 207+ }
 208+
 209+
 210+ function getSyntransPerLanguage () {
 211+ $dc = wdGetDataSetContext();
 212+ $dbr = wfGetDB( DB_SLAVE );
 213+ global $wgUploadPath ;
 214+
 215+ $sql = "SELECT language_id, count(DISTINCT {$dc}_syntrans.syntrans_sid) as tot ";
 216+ $sql .= " FROM {$dc}_expression, {$dc}_syntrans" ;
 217+ $sql .= " WHERE {$dc}_expression.expression_id = {$dc}_syntrans.expression_id " ;
 218+ $sql .= " AND {$dc}_syntrans.remove_transaction_id IS NULL " ;
 219+ $sql .= " AND {$dc}_expression.remove_transaction_id IS NULL " ;
 220+ $sql .= " group by language_id " ;
 221+
 222+ $queryResult = $dbr->query( $sql );
 223+
 224+ $languageNames = getOwLanguageNames();
 225+
 226+ $nblang = 0 ;
 227+ $nbexptot = 0 ;
 228+ $nbSyntransArray = array () ;
 229+
 230+ while ( $row = $dbr->fetchObject( $queryResult ) ) {
 231+ $lang = $languageNames[$row->language_id] ;
 232+ $nbSyntransArray[$lang] = $row->tot ;
 233+ }
 234+ $nbSyntransTot = array_sum ( $nbSyntransArray ) ;
 235+ $nbdm = $this->getNumberOfDM() ;
 236+ $nblang = count ( $nbSyntransArray ) ;
 237+
 238+ $tableLang = "<center><table class=\"sortable\">" ;
 239+ $tableLang .= "<tr><th><b>" . wfMsg('ow_Language') . "</b></th><th><b>Syntrans</b></th></tr>\n";
 240+
 241+ arsort ( $nbSyntransArray ) ;
 242+ $max = max ( $nbSyntransArray ) ;
 243+ foreach ($nbSyntransArray as $lang => $syntrans) {
 244+ $wi = ceil( ( ( $syntrans / $max ) * 500 ) );
 245+ $per = ceil( ( ( $syntrans / $max ) * 100 ) );
 246+ $tableLang .= "<tr><td>$lang</td><td align=right>$syntrans</td><td><img src=\"$wgUploadPath/sc1.png\" width=\"$wi\" height=15> $per % </td></tr>\n" ;
 247+ }
 248+
 249+ $tableLang .= "</table></center>" ;
 250+
 251+ $output = "<center><big><table><tr><td>Syntrans : </td><td><b>$nbSyntransTot</b></td></tr>" ;
 252+ $output .= "<tr><td>" . wfMsg('ow_DefinedMeaning') . " : </td><td><b>$nbdm</b></td></tr>" ;
 253+ $output .= "<tr><td>" . wfMsg('ow_Language') . " : </td><td><b>$nblang</b></td></tr></table></big></center>" ;
 254+
 255+ $output .= "<p>$tableLang</p>" ;
 256+
 257+ return $output ;
 258+ }
 259+
 260+ }
 261+ SpecialPage::addPage( new SpecialOWStatistics );
 262+
 263+ }
Property changes on: trunk/extensions/Wikidata/OmegaWiki/SpecialOWStatistics.php
___________________________________________________________________
Name: svn:executable
1264 + *

Status & tagging log