-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpecialGlobalEditcount.php
120 lines (101 loc) · 2.67 KB
/
SpecialGlobalEditcount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
class SpecialGlobalEditcount extends Editcount {
public function __construct() {
IncludableSpecialPage::__construct( 'GlobalEditcount' );
}
/**
* main()
*/
public function execute( $par ) {
global $wgRequest, $wgOut, $wgContLang;
$target = isset( $par ) ? $par : $wgRequest->getText( 'username' );
list( $username, $namespace ) = $this->extractParamaters( $target );
$username = Title::newFromText( $username );
$username = is_object( $username ) ? $username->getText() : '';
$uid = User::idFromName( $username );
if ( $this->including() ) {
if ( $namespace === null ) {
if ( $uid != 0 ) {
$out = $wgContLang->formatNum( User::edits( $uid ) );
} else {
$out = '';
}
} else {
$out = $wgContLang->formatNum( $this->editsInNs( $uid, $namespace ) );
}
$wgOut->addHTML( $out );
} else {
if ( $uid != 0 ) {
$total = $this->getTotal( $nscount = $this->editsByNs( $uid ) );
}
$html = new GlobalEditcountHTML;
$html->outputHTML( $username, $uid, @$nscount, @$total );
}
}
/**
* Count the number of edits of a user by namespace
*
* @param int $uid The user ID to check
* @return array
*/
function editsByNs( $uid ) {
global $wgConf;
$nscount = array();
foreach ( $wgConf->wikis as $wiki ) {
$dbr = wfGetDB( DB_SLAVE, array(), $wiki );
$res = $dbr->select(
array( 'revision', 'page' ),
array( 'page_namespace', 'COUNT(*) AS count' ),
array(
'rev_user' => $uid,
'rev_page = page_id'
),
__METHOD__,
array( 'GROUP BY' => 'page_namespace' )
);
foreach ( $res as $row ) {
if ( isset( $nscount[$row->page_namespace] ) ) {
$nscount[$row->page_namespace] += intval( $row->count );
} else {
$nscount[$row->page_namespace] = intval( $row->count );
}
}
}
return $nscount;
}
/**
* Count the number of edits of a user in a given namespace
*
* @param int $uid The user ID to check
* @param int $ns The namespace to check
* @return string
*/
function editsInNs( $uid, $ns ) {
global $wgConf;
$i = 0;
foreach ( $wgConf->wikis as $wiki ) {
$dbr = wfGetDB( DB_SLAVE, array(), $wiki );
$res = $dbr->selectField(
array( 'revision', 'page' ),
array( 'COUNT(*) AS count' ),
array(
'page_namespace' => $ns,
'rev_user' => $uid,
'rev_page = page_id'
),
__METHOD__,
array( 'GROUP BY' => 'page_namespace' )
);
$i += intval( $res );
}
return strval( $i );
}
}
class GlobalEditcountHTML extends EditcountHTML {
/**
* Not ideal, but for calls to $this->getTitle() return Editcount (no global) otherwise
*/
function getPageTitle() {
return SpecialPage::getTitleFor( 'GlobalEditcount' );
}
}