Page MenuHomePhabricator

Add-on_-_statistics_per_namespace.patch

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

Add-on_-_statistics_per_namespace.patch

Index: SpecialUserStats.i18n.php
===================================================================
--- SpecialUserStats.i18n.php (revision 53631)
+++ SpecialUserStats.i18n.php (working copy)
@@ -13,10 +13,12 @@
'usagestatistics-desc' => 'Show individual user and overall wiki usage statistics',
'usagestatisticsfor' => '<h2>Usage statistics for [[User:$1|$1]]</h2>',
'usagestatisticsforallusers' => '<h2>Usage statistics for all users</h2>',
- 'usagestatisticsinterval' => 'Interval',
- 'usagestatisticstype' => 'Type',
- 'usagestatisticsstart' => 'Start date',
- 'usagestatisticsend' => 'End date',
+ '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:',
'usagestatisticssubmit' => 'Generate statistics',
'usagestatisticsnostart' => 'Please specify a start date',
'usagestatisticsnoend' => 'Please specify an end date',
Index: SpecialUserStats_body.php
===================================================================
--- SpecialUserStats_body.php (revision 53631)
+++ 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,70 +359,76 @@
$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\">
-<table border='0'>
-<tr>
- <td align='right'>" . wfMsg( 'usagestatisticsinterval' ) . ":</td>
- <td align='left'>
- <select name='interval'>
- <option value='86400'>" . wfMsg( 'usagestatisticsintervalday' ) . "
- <option value='604800'>" . wfMsg( 'usagestatisticsintervalweek' ) . "
- <option value='2629744' selected>" . wfMsg( 'usagestatisticsintervalmonth' ) . "
- </select>
- </td>
-</tr>
-<tr>
- <td align='right'>" . wfMsg( 'usagestatisticstype' ) . ":</td>
- <td align='left'>
- <select name='type'>
- <option value='incremental'>" . wfMsg( 'usagestatisticsincremental' ) . "
- <option value='cumulative' selected>" . wfMsg( 'usagestatisticscumulative' ) . "
- </select>
- </td>
-</tr>
-<tr>
- <td align='right'>" . wfMsg( 'usagestatisticsstart' ) . ":</td>
- <td align='left'>
+<form id=\"userstats\" method=\"post\">");
+
+ $wgOut->addHTML(
+ Xml::label( wfMsg( 'usagestatisticsnamespace' ), 'namespace' ) . '&nbsp;' .
+ Xml::namespaceSelector( $this->namespace, 'all' ) .
+ Xml::openElement( 'table', array( 'border' => '0' ) ) .
+ Xml::openElement( 'tr' ) .
+ Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticsinterval' ) .
+ Xml::closeElement( 'td' ) .
+ Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) .
+ Xml::openElement( 'select', array( 'name' => 'interval' ) ) .
+ Xml::openElement( 'option', array( 'value' => '86400' ) ) . wfMsg( 'usagestatisticsintervalday' ) .
+ Xml::openElement( 'option', array( 'value' => '604800' ) ) . wfMsg( 'usagestatisticsintervalweek' ) .
+ Xml::openElement( 'option', array( 'value' => '2629744', 'selected' => 'selected' )) . wfMsg( 'usagestatisticsintervalmonth' ) .
+ Xml::closeElement( 'select' ) .
+ Xml::closeElement( 'td' ) .
+ Xml::closeElement( 'tr' ) .
+ Xml::openElement( 'tr' ) .
+ Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticstype' ) . Xml::closeElement( 'td' ) .
+ Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) .
+ Xml::openElement( 'select', array( 'name' => 'type' ) ) .
+ Xml::openElement( 'option', array( 'value' => 'incremental' ) ) . wfMsg( 'usagestatisticsincremental' ) .
+ Xml::openElement( 'option', array( 'value' => 'cumulative', 'selected' => 'selected' ) ) . wfMsg( 'usagestatisticscumulative' ) .
+ Xml::closeElement( 'select' ) .
+ Xml::closeElement( 'td' ) .
+ Xml::closeElement( 'tr' ) .
+ Xml::openElement( 'tr' ) .
+ Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticsstart' ) . Xml::closeElement( 'td' ) .
+"
+ <td class='mw-input'>
<input type='text' size='20' name='start' value='$start'/>
<script type='text/javascript'>
var cal1 = new CalendarPopup('testdiv1');
cal1.showNavigationDropdowns();
</SCRIPT>
- <A HREF='#' onClick=\"cal1.select(document.forms[0].start,'anchor1','MM/dd/yyyy'); return false;\" NAME='anchor1' ID='anchor1'>" . wfMsg( 'usagestatisticscalselect' ) . "</A>
- </td>
-</tr>
-<tr>
- <td align='right'>" . wfMsg( 'usagestatisticsend' ) . ":</td>
- <td align='left'>
+ <A HREF='#' onClick=\"cal1.select(document.forms[0].start,'anchor1','MM/dd/yyyy'); return false;\" NAME='anchor1' ID='anchor1'>" . wfMsg( 'usagestatisticscalselect' ) .
+ Xml::closeElement( 'a' ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) .
+ Xml::openElement( 'tr' ) .
+ Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticsend' ) . Xml::closeElement( 'td' ) .
+"
+ <td class='mw-input'>
<input type='text' size='20' name='end' value='$end'/>
<script type='text/javascript'>
var cal2 = new CalendarPopup('testdiv1');
cal2.showNavigationDropdowns();
</SCRIPT>
- <A HREF='#' onClick=\"cal2.select(document.forms[0].end,'anchor2','MM/dd/yyyy'); return false;\" NAME='anchor2' ID='anchor2'>" . wfMsg( 'usagestatisticscalselect' ) . "</A>
- </td>
-</tr>
-</table>
-<input type='submit' name=\"wpSend\" value=\"" . wfMsg( 'usagestatisticssubmit' ) . "\" />
-</form>
+ <A HREF='#' onClick=\"cal2.select(document.forms[0].end,'anchor2','MM/dd/yyyy'); return false;\" NAME='anchor2' ID='anchor2'>" . wfMsg( 'usagestatisticscalselect' ) .
+ Xml::closeElement( 'a' ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) .
+ Xml::closeElement( 'table' ) . "
+<input type='submit' name=\"wpSend\" value=\"" . wfMsg( 'usagestatisticssubmit' ) . "\" /> ".
+ Xml::closeElement( 'form' ) ."
+
<DIV ID=\"testdiv1\" STYLE=\"position:absolute;visibility:hidden;background-color:white;layer-background-color:white;\"></DIV>
" );
}

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5451
Default Alt Text
Add-on_-_statistics_per_namespace.patch (10 KB)

Event Timeline