forked from sembrestels/mediawiki-bitid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpecialBitIdDashboard.php
138 lines (115 loc) · 3.7 KB
/
SpecialBitIdDashboard.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Implements Special:BitIdDashboard parameter settings and status information
*
* @ingroup SpecialPage
* @ingroup Extensions
* @author David Llop
* @author Thomas Gries
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
* @link http://www.mediawiki.org/wiki/Extension:BitId Documentation
*
*/
class SpecialBitIdDashboard extends SpecialPage {
/**
* Constructor - sets up the new special page
* required right: bitid-dashboard-access
*/
public function __construct() {
parent::__construct( 'BitIdDashboard', 'bitid-dashboard-access' );
}
/**
* Different description will be shown on Special:SpecialPage depending on
* whether the user has the 'bitiddashboard' right or not.
*/
function getDescription() {
global $wgUser;
if ( $wgUser->isAllowed( 'bitid-dashboard-admin' ) ) {
return wfMessage( 'bitid-dashboard-title-admin' )->text();
} else {
return wfMessage( 'bitid-dashboard-title' )->text() ;
}
}
/**
* @param $string string
* @param $value string
* @return string
*/
function show( $string, $value ) {
if ( $value === null ) {
$value = 'null';
} elseif ( is_bool( $value ) ) {
$value = wfBoolToStr( $value );
} else {
$value = htmlspecialchars( $value, ENT_QUOTES );
}
return Html::rawElement( 'tr',
array(),
Html::rawElement( 'td',
array(),
$string
) .
Html::rawElement( 'td',
array(),
$value
)
) . "\n";
}
/**
* Show the special page
*
* @param $par Mixed: parameter passed to the page or null
*/
function execute( $par ) {
global $wgOut, $wgUser,
$wgBitIdAllowExistingAccountSelection, $wgBitIdAllowNewAccountname,
$wgBitIdUseEmailAsNickname, $wgBitIdProposeUsernameFromSREG,
$wgBitIdLoginOnly, $wgBitIdAllowServingBitIdUserAccounts;
if ( !$this->userCanExecute( $wgUser ) ) {
$this->displayRestrictionError();
return;
}
$totalUsers = SiteStats::users();
$BitIddistinctUsers = $this->getBitIdUsers( 'distinctusers' );
$BitIdUsers = $this->getBitIdUsers();
$this->setHeaders();
$this->outputHeader();
$wgOut->addWikiMsg( 'bitid-dashboard-introduction', 'http://www.mediawiki.org/wiki/Extension:BitId' );
$wgOut->addHTML(
Html::openElement( 'table',
array(
'style' => 'width:50%;',
'class' => 'mw-bitiddashboard-table wikitable'
)
)
);
# Here we show some basic version infos. Retrieval of SVN revision number of BitId appears to be too difficult
$out = $this->show( 'BitId ' . wfMessage( 'version-software-version' )->text(), MEDIAWIKI_BITID_VERSION );
$out .= $this->show( 'MediaWiki ' . wfMessage( 'version-software-version' )->text(), SpecialVersion::getVersion() );
$out .= $this->show( '$wgBitIdLoginOnly', $wgBitIdLoginOnly );
$out .= $this->show( wfMessage( 'statistics-users' )->parse(), $totalUsers );
$out .= $this->show( wfMessage( 'bitid-dashboard-number-bitid-users' )->text(), $BitIddistinctUsers );
$out .= $this->show( wfMessage( 'bitid-dashboard-number-bitids-in-database' )->text(), $BitIdUsers );
$out .= $this->show( wfMessage( 'bitid-dashboard-number-users-without-bitid' )->text(), $totalUsers - $BitIddistinctUsers );
$wgOut->addHTML( $out . Html::closeElement( 'table' ) . "\n" );
}
function error() {
global $wgOut;
$args = func_get_args();
$wgOut->wrapWikiMsg( "<p class='error'>$1</p>", $args );
}
function getBitIdUsers ( $distinctusers = '' ) {
wfProfileIn( __METHOD__ );
$distinct = ( $distinctusers == 'distinctusers' ) ? 'COUNT(DISTINCT uoi_user)' : 'COUNT(*)' ;
$dbr = wfGetDB( DB_SLAVE );
$BitIdUserCount = (int)$dbr->selectField(
'bitid_users',
$distinct,
null,
__METHOD__,
null
);
wfProfileOut( __METHOD__ );
return $BitIdUserCount;
}
}