Page MenuHomePhabricator

Add-on_-_statistics_per_namespace_-_v0.1.patch

Authored By
bzimport
Nov 21 2014, 10:43 PM
Size
6 KB
Referenced Files
None
Subscribers
None

Add-on_-_statistics_per_namespace_-_v0.1.patch

Index: SpecialUserStats.i18n.php
===================================================================
--- SpecialUserStats.i18n.php (revision 53467)
+++ SpecialUserStats.i18n.php (working copy)
@@ -14,6 +14,8 @@
'usagestatisticsfor' => '<h2>Usage statistics for [[User:$1|$1]]</h2>',
'usagestatisticsforallusers' => '<h2>Usage statistics for all users</h2>',
'usagestatisticsinterval' => 'Interval',
+ 'usagestatisticsnamespace' => 'Namespace',
+ 'usagestatistics-namespace-withoutredirects' => 'These are statistics on the [[Special:Allpages/$1:|$1]] namespace. [[Special:ListRedirects|Redirects]] are not taken into account.',
'usagestatisticstype' => 'Type',
'usagestatisticsstart' => 'Start date',
'usagestatisticsend' => 'End date',
Index: SpecialUserStats_body.php
===================================================================
--- SpecialUserStats_body.php (revision 53467)
+++ SpecialUserStats_body.php (working copy)
@@ -1,8 +1,10 @@
<?php
-class SpecialUserStats extends SpecialPage
-{
+class SpecialUserStats extends SpecialPage {
+
+ var $namespace = NULL;
+
function SpecialUserStats() {
- SpecialPage::SpecialPage( "SpecialUserStats" );
+ parent::SpecialPage( "SpecialUserStats" );
# the standard method for LoadingExtensionMessages was apparently broken in several versions of MW
# so, to make this work with multiple versions of MediaWiki, let's load the messages nicely
@@ -35,9 +37,10 @@
$wgOut->setPagetitle( wfMsg( 'usagestatistics' ) );
$user = $wgUser->getName();
- $wgOut->addWikiText( wfMsg( 'usagestatisticsfor', $user ) );
+ $wgOut->addWikiMsg( 'usagestatisticsfor', $user );
$interval = $wgRequest->getVal( 'interval', '' );
+ $namespace = $wgRequest->getVal('namespace', '');
$type = $wgRequest->getVal( 'type', '' );
$start = $wgRequest->getVal( 'start', '' );
$end = $wgRequest->getVal( 'end', '' );
@@ -53,10 +56,10 @@
// FIXME: ideally this would use a class for markup.
$wgOut->addWikiText( '* <font color=red>' . wfMsg( 'usagestatisticsnoend' ) . '</font>' );
}
- self::DisplayForm( $start, $end );
+ self::DisplayForm( $start, $end, $namespace );
} else {
$db = wfGetDB( DB_SLAVE );
- self::GetUserUsage( $db, $user, $start, $end, $interval, $type );
+ self::GetUserUsage( $db, $user, $start, $end, $interval, $namespace, $type );
}
}
@@ -128,8 +131,8 @@
return $new_ary;
}
- function GetUserUsage( $db, $user, $start, $end, $interval, $type ) {
- global $wgOut, $wgUser, $wgUserStatsGlobalRight, $wgUserStatsGoogleCharts;
+ function GetUserUsage( $db, $user, $start, $end, $interval, $namespace, $type ) {
+ global $wgOut, $wgUser, $wgUserStatsGlobalRight, $wgUserStatsGoogleCharts, $wgContLang;
list( $start_m, $start_d, $start_y ) = split( '/', $start );
$start_t = mktime( 0, 0, 0, $start_m, $start_d, $start_y );
@@ -140,7 +143,11 @@
$wgOut->addHTML( wfMsg( 'usagestatisticsbadstartend' ) );
return;
}
-
+ if ($namespace != 'all') {
+ $nstext = $wgContLang->getNSText($namespace);
+ if ($nstext == '') $nstext = '(Main)';
+ $wgOut->addWikiMsg( 'usagestatistics-namespace-withoutredirects', $nstext );
+ }
$dates = array();
$csv = 'Username,';
$cur_t = $start_t;
@@ -149,13 +156,17 @@
$dates[$a_date] = array();
$cur_t += $interval;
}
-
# Let's process the edits that are recorded in the database
$u = array();
- $sql = "SELECT rev_user_text,rev_timestamp,page_id FROM " .
+ if ( $namespace == 'all' ) {
+ $sql = "SELECT rev_user_text,rev_timestamp,page_id FROM " .
$db->tableName( 'page' ) . "," . $db->tableName( 'revision' ) .
" WHERE rev_page=page_id";
-
+ } else {
+ $sql = "SELECT rev_user_text,rev_timestamp,page_id FROM " .
+ $db->tableName( 'page' ) . "," . $db->tableName( 'revision' ) .
+ " WHERE rev_page=page_id" . " AND page_is_redirect=0 AND page_namespace=" . $db->addQuotes($namespace);
+ }
$res = $db->query( $sql, __METHOD__ );
for ( $j = 0; $j < $db->numRows( $res ); $j++ ) {
@@ -240,7 +251,7 @@
return;
# plot overall usage statistics
- $wgOut->addWikiText( wfMsg( 'usagestatisticsforallusers' ) );
+ $wgOut->addWikiMsg( 'usagestatisticsforallusers' );
$gnuplot = "<gnuplot>
set xdata time
set xtics rotate by 90
@@ -348,28 +359,30 @@
$wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' );
$wgOut->addHTML( '<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">' );
- $wgOut->addWikiText( wfMsg ( 'usagestatistics-editindividual', $nature ) );
+ $wgOut->addWikiMsg ( 'usagestatistics-editindividual', $nature );
$wgOut->addHTML( '</div><div class="NavContent" style="display:none; font-size:normal; text-align:left">' );
- $wgOut->AddHtml( "<pre>$csv$csv_edits</pre></div></div><br />" );
+ $wgOut->addHTML( "<pre>$csv$csv_edits</pre></div></div><br />" );
$wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' );
$wgOut->addHTML( '<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">' );
- $wgOut->addWikiText( wfMsg ( 'usagestatistics-editpages', $nature ) );
+ $wgOut->addWikiMsg ( 'usagestatistics-editpages', $nature );
$wgOut->addHTML( '</div><div class="NavContent" style="display:none; font-size:normal; text-align:left">' );
- $wgOut->AddHtml( "<pre>$csv$csv_pages</pre></div></div>" );
+ $wgOut->addHTML( "<pre>$csv$csv_pages</pre></div></div>" );
return;
}
- function DisplayForm( $start, $end ) {
+ function DisplayForm( $start, $end, $namespace ) {
global $wgOut;
$wgOut->addHTML( "
<script type='text/javascript'>document.write(getCalendarStyles());</SCRIPT>
-<form id=\"userstats\" method=\"post\">
+<form id=\"userstats\" method=\"post\">");
+ $wgOut->addHTML( $this->makeNamespaceForm( $namespace ) );
+ $wgOut->addHTML( "
<table border='0'>
<tr>
- <td align='right'>" . wfMsg( 'usagestatisticsinterval' ) . ":</td>
+ <td align='left'>" . wfMsg( 'usagestatisticsinterval' ) . ":</td>
<td align='left'>
<select name='interval'>
<option value='86400'>" . wfMsg( 'usagestatisticsintervalday' ) . "
@@ -379,7 +392,7 @@
</td>
</tr>
<tr>
- <td align='right'>" . wfMsg( 'usagestatisticstype' ) . ":</td>
+ <td align='left'>" . wfMsg( 'usagestatisticstype' ) . ":</td>
<td align='left'>
<select name='type'>
<option value='incremental'>" . wfMsg( 'usagestatisticsincremental' ) . "
@@ -415,7 +428,13 @@
<DIV ID=\"testdiv1\" STYLE=\"position:absolute;visibility:hidden;background-color:white;layer-background-color:white;\"></DIV>
" );
}
-
+
+ function makeNamespaceForm( $namespace ) {
+ $form = Xml::label( wfMsg( 'usagestatisticsnamespace' ), 'namespace' ) . ':&nbsp;';
+ $form .= Xml::namespaceSelector( $this->namespace, 'all' );
+ return $form;
+ }
+
function AddCalendarJavascript() {
global $wgOut, $wgContLang;

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5450
Default Alt Text
Add-on_-_statistics_per_namespace_-_v0.1.patch (6 KB)

Event Timeline