r10165 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10164‎ | r10165 | r10166 >
Date:22:04, 16 July 2005
Author:avar
Status:old
Tags:
Comment:
* The User class no longer includes editsByNs(), including it
* Using GlobalFunctions percent()
Modified paths:
  • /trunk/extensions/Editcount/SpecialEditcount.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Editcount/SpecialEditcount.php
@@ -44,7 +44,7 @@
4545 $username = strtr( $wgContLang->ucfirst( $username ), '_', ' ' );
4646
4747 $total = 0;
48 - $nscount = User::editsByNs( User::idFromName( $username ) );
 48+ $nscount = $this->editsByNs( User::idFromName( $username ) );
4949 foreach ( $nscount as $ns => $edits )
5050 $total += $edits;
5151
@@ -77,20 +77,46 @@
7878 $out .= '<tr><th>' .
7979 wfMsg( 'editcount_total' ) .
8080 "</th><th>$total</th><th>" .
81 - $this->percent( $total / $total * 100 , 2 ) .
 81+ percent( $total / $total * 100 , 2 ) .
8282 '</th></tr>';
8383 foreach( $nscount as $ns => $edits ) {
8484 $fns = $ns == NS_MAIN ? wfMsg( 'blanknamespace' ) : $wgLang->getFormattedNsText( $ns );
85 - $percent = $this->percent( $edits / $total * 100 , 2 );
 85+ $percent = percent( $edits / $total * 100 );
8686 $out .= "<tr><td>$fns</td><td>$edits</td><td>$percent</td></tr>";
8787 }
8888 $out .= '</table></p>';
8989 $wgOut->addHTML( $out );
9090 }
9191 }
 92+
 93+ /**
 94+ * Count the number of edits of a user by namespace
 95+ *
 96+ * @param int $uid The user ID to check
 97+ * @return array
 98+ */
 99+ function editsByNs( $uid ) {
 100+ $fname = 'Editcount::editsByNs';
 101+ $nscount = array();
92102
93 - function percent( $nr, $acc ) {
94 - return sprintf( "%.${acc}f%%", $nr );
 103+ $dbr =& wfGetDB( DB_SLAVE );
 104+ $res = $dbr->select(
 105+ array( 'user', 'revision', 'page' ),
 106+ array( 'page_namespace', 'COUNT(*) as count' ),
 107+ array(
 108+ 'user_id' => $uid,
 109+ 'rev_user = user_id',
 110+ 'rev_page = page_id'
 111+ ),
 112+ $fname,
 113+ array( 'GROUP BY' => 'page_namespace' )
 114+ );
 115+
 116+ while( $row = $dbr->fetchObject( $res ) ) {
 117+ $nscount[$row->page_namespace] = $row->count;
 118+ }
 119+
 120+ return $nscount;
95121 }
96122 }
97123

Status & tagging log