Lokal Profil has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/289314

Change subject: Add lang and project to statistic reports
......................................................................

Add lang and project to statistic reports

Also drops the empty fixEncoding() method in favour of stripping
wikitext using CommonFunctions.processWikitext().

Bug: T135502
Bug: T55688
Change-Id: I454a5a4822c85b95e11aec5ec478055cfa886983
---
M api/includes/Statistics.php
M api/includes/StatsBuilder.php
2 files changed, 22 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage 
refs/changes/14/289314/1

diff --git a/api/includes/Statistics.php b/api/includes/Statistics.php
index 2de8b3a..298fe13 100644
--- a/api/includes/Statistics.php
+++ b/api/includes/Statistics.php
@@ -17,7 +17,9 @@
        static $fieldPrefix = 'st_';
 
        var $lastDay = '';
-       static $aItems = array('address', 'address_pct', 'coordinates', 
'coordinates_pct', 'image', 'image_pct', 'municipality', 'municipality_pct', 
'name', 'name_pct', 'total' );
+       static $aItems = array(
+               'address', 'address_pct', 'coordinates', 'coordinates_pct', 
'image',
+               'image_pct', 'municipality', 'municipality_pct', 'name', 
'name_pct', 'total' );
 
 
        function getLatestDay() {
@@ -79,10 +81,11 @@
                        //var_dump($row);
                        $group[$row[$gc]] = 1;
                        $idxs[$row[$gi]] = 1;
-                       list($country,$municipality) = explode(':', $row[$gi], 
2);
+                       list($country,$municipality,$lang,$project) = 
explode(':', $row[$gi], 4);
                        $this->report[$row[$gi]]['country'] = $country;
-                       $this->report[$row[$gi]]['lang'] = $country == 'us' ? 
'en' : $country;
                        $this->report[$row[$gi]]['municipality'] = 
$municipality;
+                       $this->report[$row[$gi]]['lang'] = $lang;
+                       $this->report[$row[$gi]]['project'] = $project;
                        $this->report[$row[$gi]][$row[$gc]] = $row['value'];
                }
                //var_dump($this->report);
diff --git a/api/includes/StatsBuilder.php b/api/includes/StatsBuilder.php
index d90b653..bbb2b2c 100644
--- a/api/includes/StatsBuilder.php
+++ b/api/includes/StatsBuilder.php
@@ -7,7 +7,8 @@
  *
  * NOTE May be optimized by INSERTing in batches
  */
-
+//functions: processWikitext
+require_once('CommonFunctions.php');
 
 /*
 *
@@ -71,24 +72,19 @@
        }
 
 
-       /** Helper to fix encoding
-       */
-       static function fixEncoding($sString, $bToUTF8=true) {
-               /*
-               if ( $bToUTF8 ) {
-                       return utf8_encode($sString);
-               }
-               */
-               return $sString;
+       /** Helper to make idx identifier
+        */
+       static function makeIdx($row) {
+               return $row[0] . ':' . processWikitext($row[2], $row[1], False) 
. ':' .
+                       $row[2] . ':' . $row[3];
        }
-
 
        /** Calculate totals
         * @return false on error, true otherwise
         */
        private function getTotals() {
                $this->debug('Determining Totals');
-               $sql = 'SELECT country, municipality, COUNT(1) AS total
+               $sql = 'SELECT country, municipality, lang, project, COUNT(1) 
AS total
                        FROM '.Monuments::$dbTable.'
                        GROUP BY country, municipality';
                $wres = new ResultWrapper( $this->db, $this->db->query( $sql ) 
);
@@ -97,8 +93,9 @@
                }
 
                while ($row = $wres->fetchRow()) {
-                       $idx = 
$this->db->sanitize($row[0].':'.StatsBuilder::fixEncoding($row[1], true));
-                       $this->setReportItem(Statistics::$fieldPrefix.'total', 
$idx, $row[2]);
+                       $idx = $this->db->sanitize(StatsBuilder::makeIdx($row));
+                       $count = $row[4];  // update if makeIdx changes
+                       $this->setReportItem(Statistics::$fieldPrefix.'total', 
$idx, $count);
                }
                return true;
        }
@@ -133,7 +130,7 @@
                $sql = 'ALTER TABLE '.$tmp_table.' ADD UNIQUE INDEX 
idx1(country,municipality)';
                $this->db->query($sql);
 
-               $sql = 'SELECT m1.country, m1.municipality, IF(m2.non_blank IS 
NULL,0,m2.non_blank) AS non_blank
+               $sql = 'SELECT m1.country, m1.municipality, m1.lang, 
m1.project, IF(m2.non_blank IS NULL,0,m2.non_blank) AS non_blank
                  FROM '.Monuments::$dbTable.' m1
                  LEFT JOIN '.$tmp_table.' m2 ON m2.country = m1.country AND 
m2.municipality = m1.municipality
                  GROUP BY m1.country, m1.municipality';
@@ -144,9 +141,10 @@
                }
 
                while ( $row = $oRes->fetchRow() ) {
-                       $idx = 
$row[0].':'.$this->db->sanitize(StatsBuilder::fixEncoding($row[1],true));
-                       $this->setReportItem($report_as, $idx, $row[2]);
-                       $value_pct = sprintf("%.2f", 
100*$row[2]/$this->report[Statistics::$fieldPrefix.'total'][$idx]);
+                       $idx = $this->db->sanitize(StatsBuilder::makeIdx($row));
+                       $count = $row[4];  // update if makeIdx changes
+                       $this->setReportItem($report_as, $idx, $count);
+                       $value_pct = sprintf("%.2f", 
100*$count/$this->report[Statistics::$fieldPrefix.'total'][$idx]);
                        $this->setReportItem($report_as.'_pct', $idx, 
$value_pct);
                }
                return true;

-- 
To view, visit https://gerrit.wikimedia.org/r/289314
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I454a5a4822c85b95e11aec5ec478055cfa886983
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to