45 private int $activeUsers;
53 parent::__construct(
'Statistics' );
54 $this->userGroupManager = $userGroupManager;
60 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
62 $this->edits = SiteStats::edits();
63 $this->good = SiteStats::articles();
64 $this->images = SiteStats::images();
65 $this->total = SiteStats::pages();
66 $this->users = SiteStats::users();
67 $this->activeUsers = SiteStats::activeUsers();
69 $text =
Xml::openElement(
'table', [
'class' =>
'wikitable mw-statistics-table' ] );
72 $text .= $this->getPageStats();
75 $text .= $this->getEditStats();
78 $text .= $this->getUserStats();
80 # Statistic - usergroups
81 $text .= $this->getGroupStats();
88 $text .= $this->getOtherStats( $extraStats );
96 $text .=
"\n" .
$footer->parse();
111 private function formatRow( $text, $number, $trExtraParams = [],
112 $descMsg =
'', $descMsgParam =
''
115 $msg = $this->
msg( $descMsg, $descMsgParam );
116 if ( !$msg->isDisabled() ) {
117 $descriptionHtml = $this->
msg(
'parentheses' )->rawParams( $msg->parse() )
119 $text .=
"<br />" . Html::rawElement(
121 [
'class' =>
'mw-statistic-desc' ],
127 return Html::rawElement(
'tr', $trExtraParams,
128 Html::rawElement(
'td', [], $text ) .
129 Html::rawElement(
'td', [
'class' =>
'mw-statistics-numbers' ], $number )
138 private function getPageStats() {
142 $pageStatsHtml = Html::rawElement(
'tr', [],
143 Xml::tags(
'th', [
'colspan' =>
'2' ],
144 $this->
msg(
'statistics-header-pages' )->parse()
148 ? $this->
msg(
'statistics-articles' )->escaped()
149 : $linkRenderer->makeKnownLink(
150 $specialAllPagesTitle,
151 $this->
msg(
'statistics-articles' )->text(),
152 [], [
'hideredirects' => 1 ] ),
154 [
'class' =>
'mw-statistics-articles' ],
155 'statistics-articles-desc' ) .
156 $this->formatRow( $linkRenderer->makeKnownLink( $specialAllPagesTitle,
157 $this->
msg(
'statistics-pages' )->text() ),
159 [
'class' =>
'mw-statistics-pages' ],
160 'statistics-pages-desc' );
164 $pageStatsHtml .= $this->formatRow(
166 $this->msg(
'statistics-files' )->text() ),
167 $this->getLanguage()->formatNum( $this->images ),
168 [
'class' =>
'mw-statistics-files' ],
'statistics-files-desc' );
171 return $pageStatsHtml;
174 private function getEditStats() {
175 return Html::rawElement(
'tr', [],
176 Xml::tags(
'th', [
'colspan' =>
'2' ],
177 $this->
msg(
'statistics-header-edits' )->parse()
179 $this->formatRow( $this->
msg(
'statistics-edits' )->parse(),
181 [
'class' =>
'mw-statistics-edits' ]
183 $this->formatRow( $this->
msg(
'statistics-edits-average' )->parse(),
185 sprintf(
'%.2f', $this->total ? $this->edits / $this->total : 0 )
186 ), [
'class' =>
'mw-statistics-edits-average' ]
190 private function getUserStats() {
191 return Html::rawElement(
'tr', [],
192 Xml::tags(
'th', [
'colspan' =>
'2' ],
193 $this->
msg(
'statistics-header-users' )->parse()
195 $this->formatRow( $this->
msg(
'statistics-users' )->parse() .
' ' .
198 $this->
msg(
'listgrouprights-members' )->text()
201 [
'class' =>
'mw-statistics-users' ]
203 $this->formatRow( $this->
msg(
'statistics-users-active' )->parse() .
' ' .
206 $this->
msg(
'listgrouprights-members' )->text()
208 $this->
getLanguage()->formatNum( $this->activeUsers ),
209 [
'class' =>
'mw-statistics-users-active' ],
210 'statistics-users-active-desc',
216 private function getGroupStats() {
220 foreach ( $this->userGroupManager->listAllGroups() as $group ) {
221 $groupnameLocalized = $lang->getGroupName( $group );
222 $linkTarget = UserGroupMembership::getGroupPage( $group )
223 ?: Title::makeTitleSafe(
NS_PROJECT, $group );
226 $grouppage = $linkRenderer->makeLink(
231 $grouppage = htmlspecialchars( $groupnameLocalized );
234 $grouplink = $linkRenderer->makeKnownLink(
236 $this->
msg(
'listgrouprights-members' )->text(),
238 [
'group' => $group ]
240 # Add a class when a usergroup contains no members to allow hiding these rows
242 $countUsers = SiteStats::numberingroup( $group );
243 if ( $countUsers == 0 ) {
244 $classZero =
' statistics-group-zero';
246 $text .= $this->formatRow( $grouppage .
' ' . $grouplink,
248 [
'class' =>
'statistics-group-' . Sanitizer::escapeClass( $group ) .
262 private function getOtherStats( array $stats ) {
265 foreach ( $stats as
$header => $items ) {
267 if ( is_array( $items ) ) {
269 if (
$header !==
'statistics-header-hooks' ) {
270 $return .= $this->formatRowHeader(
$header );
274 foreach ( $items as $key => $value ) {
275 if ( is_array( $value ) ) {
276 $name = $value[
'name'];
277 $number = $value[
'number'];
279 $name = $this->
msg( $key )->parse();
283 $return .= $this->formatRow(
285 $this->
getLanguage()->formatNum( htmlspecialchars( $number ) ),
286 [
'class' =>
'mw-statistics-hook',
'id' =>
'mw-' . $key ]
291 if ( $return ===
'' ) {
292 $return .= $this->formatRowHeader(
'statistics-header-hooks' );
296 $return .= $this->getOtherStats( [
'statistics-header-hooks' =>
310 private function formatRowHeader(
$header ) {
311 return Html::rawElement(
'tr', [],
312 Xml::tags(
'th', [
'colspan' =>
'2' ], $this->
msg(
$header )->parse() )