Index: trunk/extensions/Editcount/SpecialEditcount.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | $username = strtr( $wgContLang->ucfirst( $username ), '_', ' ' ); |
46 | 46 | |
47 | 47 | $total = 0; |
48 | | - $nscount = User::editsByNs( User::idFromName( $username ) ); |
| 48 | + $nscount = $this->editsByNs( User::idFromName( $username ) ); |
49 | 49 | foreach ( $nscount as $ns => $edits ) |
50 | 50 | $total += $edits; |
51 | 51 | |
— | — | @@ -77,20 +77,46 @@ |
78 | 78 | $out .= '<tr><th>' . |
79 | 79 | wfMsg( 'editcount_total' ) . |
80 | 80 | "</th><th>$total</th><th>" . |
81 | | - $this->percent( $total / $total * 100 , 2 ) . |
| 81 | + percent( $total / $total * 100 , 2 ) . |
82 | 82 | '</th></tr>'; |
83 | 83 | foreach( $nscount as $ns => $edits ) { |
84 | 84 | $fns = $ns == NS_MAIN ? wfMsg( 'blanknamespace' ) : $wgLang->getFormattedNsText( $ns ); |
85 | | - $percent = $this->percent( $edits / $total * 100 , 2 ); |
| 85 | + $percent = percent( $edits / $total * 100 ); |
86 | 86 | $out .= "<tr><td>$fns</td><td>$edits</td><td>$percent</td></tr>"; |
87 | 87 | } |
88 | 88 | $out .= '</table></p>'; |
89 | 89 | $wgOut->addHTML( $out ); |
90 | 90 | } |
91 | 91 | } |
| 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(); |
92 | 102 | |
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; |
95 | 121 | } |
96 | 122 | } |
97 | 123 | |