From 369774f91ca0fedd1348773c3378479e3c26540a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 14 Jul 2005 17:53:27 +0000 Subject: [PATCH] * A new Special Page extension that displays edit counts. This page can be accessed from Special:Editcount[/user] as well as being included like {{Special:Editcount/user}} --- SpecialEditcount.php | 98 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 SpecialEditcount.php diff --git a/SpecialEditcount.php b/SpecialEditcount.php new file mode 100644 index 0000000..f9200e6 --- /dev/null +++ b/SpecialEditcount.php @@ -0,0 +1,98 @@ + + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + */ + +$wgExtensionFunctions[] = 'wfSpecialEditcount'; +$wgExtensionCredits['specialpage'][] = array( + 'name' => 'Editcount', + 'author' => 'Ævar Arnfjörð Bjarmason', +); + +function wfSpecialEditcount() { + global $IP, $wgMessageCache; + + $wgMessageCache->addMessages( + array( + 'editcount' => 'Edit count', + 'editcount_username' => 'User: ', + 'editcount_total' => 'Total', + ) + ); + + require_once( "$IP/includes/SpecialPage.php" ); + class Editcount extends SpecialPage { + function Editcount() { + // Includable + SpecialPage::SpecialPage( 'Editcount', '', true, false, 'default', true ); + } + + function execute( $par = null ) { + global $wgOut, $wgRequest, $wgContLang; + + $username = isset( $par ) ? $par : $wgRequest->getText( 'username' ); + $username = strtr( $wgContLang->ucfirst( $username ), '_', ' ' ); + + $total = 0; + $nscount = User::editsByNs( User::idFromName( $username ) ); + foreach ( $nscount as $ns => $edits ) + $total += $edits; + + if ( $this->including() ) { + $wgOut->addHTML( $wgContLang->formatNum( $total ) ); + } else { + global $wgLang, $wgTitle, $wgVersion; + + $this->setHeaders(); + if ($wgVersion != 1.5) { + $wgOut->versionRequired( 1.5 ); + return; + } + + $action = $wgTitle->escapeLocalUrl(); + $user = wfMsgHtml( 'editcount_username' ); + $go = wfMsgHtml( 'go' ); + $wgOut->addHTML( " +
+ + +
"); + if ($username == '') + return; + + $out = '

'; + $out .= ''; + foreach( $nscount as $ns => $edits ) { + $fns = $ns == NS_MAIN ? wfMsg( 'blanknamespace' ) : $wgLang->getFormattedNsText( $ns ); + $percent = $this->percent( $edits / $total * 100 , 2 ); + $out .= ""; + } + $out .= '
' . + wfMsg( 'editcount_total' ) . + "$total" . + $this->percent( $total / $total * 100 , 2 ) . + '
$fns$edits$percent

'; + $wgOut->addHTML( $out ); + } + } + + function percent( $nr, $acc ) { + return sprintf( "%.${acc}f%%", $nr ); + } + } + + SpecialPage::addPage( new Editcount ); +}