Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 76 additions & 87 deletions SpecialWiretap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use MediaWiki\MediaWikiServices;

class SpecialWiretap extends SpecialPage {

public $mMode;
Expand All @@ -9,6 +12,9 @@ public function __construct() {
"", // rights required to view
true // show in Special:SpecialPages
);
$this->mediaWikiServices = MediaWikiServices::getInstance();
$this->loadBalancer = $this->mediaWikiServices->getDBLoadBalancer();
$this->databaseRead = $this->loadBalancer->getConnectionRef( DB_REPLICA );
}

function execute( $parser = null ) {
Expand Down Expand Up @@ -165,27 +171,24 @@ public function totals () {
// GROUP BY wiretap.hit_year, wiretap.hit_month, wiretap.hit_day
// ORDER BY wiretap.hit_year DESC, wiretap.hit_month DESC, wiretap.hit_day DESC
// LIMIT 100000;
$dbr = wfGetDB( DB_REPLICA );

$res = $dbr->select(
array('w' => 'wiretap'),
array(
"w.hit_year AS year",
"w.hit_month AS month",
"w.hit_day AS day",
"count(*) AS num_hits",
),
null, // CONDITIONS? 'wiretap.hit_timestamp>20131001000000',
__METHOD__,
array(
"DISTINCT",
"GROUP BY" => "w.hit_year, w.hit_month, w.hit_day",
"ORDER BY" => "w.hit_year DESC, w.hit_month DESC, w.hit_day DESC",
"LIMIT" => "100000",
),
null // join conditions
);
while( $row = $dbr->fetchRow( $res ) ) {
//

$res = $this->databaseRead->newSelectQueryBuilder()
->select( [
"w.hit_year AS year",
"w.hit_month AS month",
"w.hit_day AS day",
"count(*) AS num_hits",
] )
->distinct()
->from( 'wiretap', 'w' )
->groupBy( 'w.hit_year, w.hit_month, w.hit_day' )
->orderBy( 'w.hit_year DESC, w.hit_month DESC, w.hit_day DESC' )
->limit( 10000 )
->caller( __METHOD__ )
->fetchResultSet();

while( $row = $res->fetchRow() ) {

list($year, $month, $day, $hits) = array($row['year'], $row['month'], $row['day'], $row['num_hits']);
$html .= "<tr><td>$year-$month-$day</td><td>$hits</td></tr>";
Expand All @@ -205,29 +208,24 @@ public function totalsChart () {

$html = '<canvas id="wiretapChart" width="400" height="400"></canvas>';

$dbr = wfGetDB( DB_REPLICA );
$res = $db->newSelectQueryBuilder()
->select( [
"w.hit_year AS year",
"w.hit_month AS month",
"w.hit_day AS day",
"count(*) AS num_hits",
] )
->from( 'wiretap', 'w' )
->distinct()
->groupBy( 'w.hit_year, w.hit_month, w.hit_day' )
->orderBy( 'w.hit_year DESC, w.hit_month DESC, w.hit_day DESC' )
->limit( 10000 )
->caller( __METHOD__ )
->fetchResultSet();

$res = $dbr->select(
array('w' => 'wiretap'),
array(
"w.hit_year AS year",
"w.hit_month AS month",
"w.hit_day AS day",
"count(*) AS num_hits",
),
null, //'w.hit_timestamp > 20140801000000', //null, // CONDITIONS? 'wiretap.hit_timestamp>20131001000000',
__METHOD__,
array(
"DISTINCT",
"GROUP BY" => "w.hit_year, w.hit_month, w.hit_day",
"ORDER BY" => "w.hit_year ASC, w.hit_month ASC, w.hit_day ASC",
"LIMIT" => "100000",
),
null // join conditions
);
$previous = null;

while( $row = $dbr->fetchRow( $res ) ) {
while( $row = $res->fetchRow() ) {

list($year, $month, $day, $hits) = array($row['year'], $row['month'], $row['day'], $row['num_hits']);

Expand All @@ -252,8 +250,6 @@ public function totalsChart () {

protected function getUniqueRows ( $uniquePageHits = true, $order = "DESC" ) {

$dbr = wfGetDB( DB_REPLICA );

$fields = array(
"CONCAT(w.hit_year, '-', w.hit_month, '-', w.hit_day) AS date",
);
Expand All @@ -265,22 +261,19 @@ protected function getUniqueRows ( $uniquePageHits = true, $order = "DESC" ) {
$fields[] = "COUNT(DISTINCT(w.user_name)) as hits";
}

$res = $dbr->select(
array('w' => 'wiretap'),
$fields,
null, // CONDITIONS? 'wiretap.hit_timestamp>20131001000000',
__METHOD__,
array(
// "DISTINCT",
"GROUP BY" => "w.hit_year, w.hit_month, w.hit_day",
"ORDER BY" => "w.hit_timestamp $order",
"LIMIT" => "100000",
),
null // join conditions
);
$res = $this->databaseRead->newSelectQueryBuilder()
->select( $fields )
->from( 'wiretap', 'w' )
->distinct()
->groupBy( 'w.hit_year, w.hit_month, w.hit_day' )
->orderBy( 'w.hit_timestamp ' . $order )
->limit( 10000 )
->caller( __METHOD__ )
->fetchResultSet();

$output = array();
while( $row = $dbr->fetchRow( $res ) ) {

while( $row = $res->fetchRow() ) {

// list($year, $month, $day, $hits) = array($row['year'], $row['month'], $row['day'], $row['hits']);

Expand Down Expand Up @@ -380,49 +373,45 @@ public function totalsChart2 () {

$html = '<div id="wiretap-chart"><svg height="400px"></svg></div>';

$dbr = wfGetDB( DB_REPLICA );

$res = $dbr->select(
array('w' => 'wiretap'),
array(
"w.hit_year AS year",
"w.hit_month AS month",
"w.hit_day AS day",
"count(*) AS num_hits",
),
null, //'w.hit_timestamp > 20140801000000', //null, // CONDITIONS? 'wiretap.hit_timestamp>20131001000000',
__METHOD__,
array(
"DISTINCT",
"GROUP BY" => "w.hit_year, w.hit_month, w.hit_day",
"ORDER BY" => "w.hit_year ASC, w.hit_month ASC, w.hit_day ASC",
"LIMIT" => "100000",
),
null // join conditions
);

$previous = null;

while( $row = $dbr->fetchRow( $res ) ) {
$res = $this->databaseRead->newSelectQueryBuilder()
->select( [
"w.hit_year AS year",
"w.hit_month AS month",
"w.hit_day AS day",
"count(*) AS num_hits",
] )
->from( 'wiretap', 'w' )
->distinct()
->groupBy( 'w.hit_year, w.hit_month, w.hit_day' )
->orderBy( 'w.hit_year DESC, w.hit_month DESC, w.hit_day DESC' )
->limit( 10000 )
->caller( __METHOD__ )
->fetchResultSet();

while( $row = $res->fetchRow() ) {

list($year, $month, $day, $hits) = array($row['year'], $row['month'], $row['day'], $row['num_hits']);

$currentDateString = "$year-$month-$day";
$current = new DateTime( $currentDateString );

while ( $previous && $previous->modify( '+1 day' )->format( 'Y-m-d') !== $currentDateString ) {
$data[] = array(
'x' => $previous->getTimestamp() * 1000, // x value timestamp in milliseconds
'y' => 0, // y value = zero hits for this day
);
}
// Not sure what this code is doing but it is causing memory issues in PHP 8.1
// Commenting out. If you know what this does, please email github@rechenberg.net
//
//while ( $previous && $previous->modify( '+1 day' )->format( 'Y-m-d') !== $currentDateString ) {
// $data[] = array(
// 'x' => $previous->getTimestamp() * 1000, // x value timestamp in milliseconds
// 'y' => 0, // y value = zero hits for this day
// );
//}

$data[] = array(
'x' => strtotime( $currentDateString ) * 1000, // x value time in milliseconds
'y' => intval( $hits ),
);

$previous = new DateTime( $currentDateString );

}

$data = array(
Expand Down
2 changes: 1 addition & 1 deletion Wiretap.body.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Wiretap {
**/
public static function updateTable( &$title, &$article, &$output, &$user, $request, $mediaWiki ) {

$output->enableClientCache( false );
$output->disableClientCache();
$output->addMeta( 'http:Pragma', 'no-cache' );

global $wgRequestTime, $egWiretapCurrentHit;
Expand Down