48 private int $activeUsers;
56 parent::__construct(
'Statistics' );
57 $this->userGroupManager = $userGroupManager;
63 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
65 $this->edits = SiteStats::edits();
66 $this->good = SiteStats::articles();
67 $this->images = SiteStats::images();
68 $this->total = SiteStats::pages();
69 $this->users = SiteStats::users();
70 $this->activeUsers = SiteStats::activeUsers();
72 $text = Xml::openElement(
'table', [
'class' =>
'wikitable mw-statistics-table' ] );
75 $text .= $this->getPageStats();
78 $text .= $this->getEditStats();
81 $text .= $this->getUserStats();
83 # Statistic - usergroups
84 $text .= $this->getGroupStats();
91 $text .= $this->getOtherStats( $extraStats );
94 $text .= Xml::closeElement(
'table' );
99 $text .=
"\n" .
$footer->parse();
114 private function formatRow( $text, $number, $trExtraParams = [],
115 $descMsg =
'', $descMsgParam =
''
118 $msg = $this->
msg( $descMsg, $descMsgParam );
119 if ( !$msg->isDisabled() ) {
120 $descriptionHtml = $this->
msg(
'parentheses' )->rawParams( $msg->parse() )
122 $text .=
"<br />" . Html::rawElement(
124 [
'class' =>
'mw-statistic-desc' ],
130 return Html::rawElement(
'tr', $trExtraParams,
131 Html::rawElement(
'td', [], $text ) .
132 Html::rawElement(
'td', [
'class' =>
'mw-statistics-numbers' ], $number )
141 private function getPageStats() {
146 Xml::tags(
'th', [
'colspan' =>
'2' ], $this->
msg(
'statistics-header-pages' )
151 ? $this->
msg(
'statistics-articles' )->escaped()
152 : $linkRenderer->makeKnownLink(
153 $specialAllPagesTitle,
154 $this->
msg(
'statistics-articles' )->text(),
155 [], [
'hideredirects' => 1 ] ),
157 [
'class' =>
'mw-statistics-articles' ],
158 'statistics-articles-desc' ) .
159 $this->formatRow( $linkRenderer->makeKnownLink( $specialAllPagesTitle,
160 $this->
msg(
'statistics-pages' )->text() ),
162 [
'class' =>
'mw-statistics-pages' ],
163 'statistics-pages-desc' );
167 $pageStatsHtml .= $this->formatRow(
169 $this->msg(
'statistics-files' )->text() ),
170 $this->getLanguage()->formatNum( $this->images ),
171 [
'class' =>
'mw-statistics-files' ],
'statistics-files-desc' );
174 return $pageStatsHtml;
177 private function getEditStats() {
180 $this->
msg(
'statistics-header-edits' )->parse() ) .
182 $this->formatRow( $this->
msg(
'statistics-edits' )->parse(),
184 [
'class' =>
'mw-statistics-edits' ]
186 $this->formatRow( $this->
msg(
'statistics-edits-average' )->parse(),
188 sprintf(
'%.2f', $this->total ? $this->edits / $this->total : 0 )
189 ), [
'class' =>
'mw-statistics-edits-average' ]
193 private function getUserStats() {
196 $this->
msg(
'statistics-header-users' )->parse() ) .
198 $this->formatRow( $this->
msg(
'statistics-users' )->parse() .
' ' .
201 $this->
msg(
'listgrouprights-members' )->text()
204 [
'class' =>
'mw-statistics-users' ]
206 $this->formatRow( $this->
msg(
'statistics-users-active' )->parse() .
' ' .
209 $this->
msg(
'listgrouprights-members' )->text()
211 $this->
getLanguage()->formatNum( $this->activeUsers ),
212 [
'class' =>
'mw-statistics-users-active' ],
213 'statistics-users-active-desc',
219 private function getGroupStats() {
223 foreach ( $this->userGroupManager->listAllGroups() as $group ) {
224 $groupnameLocalized = $lang->getGroupName( $group );
225 $linkTarget = UserGroupMembership::getGroupPage( $group )
226 ?: Title::makeTitleSafe(
NS_PROJECT, $group );
229 $grouppage = $linkRenderer->makeLink(
234 $grouppage = htmlspecialchars( $groupnameLocalized );
237 $grouplink = $linkRenderer->makeKnownLink(
239 $this->
msg(
'listgrouprights-members' )->text(),
241 [
'group' => $group ]
243 # Add a class when a usergroup contains no members to allow hiding these rows
245 $countUsers = SiteStats::numberingroup( $group );
246 if ( $countUsers == 0 ) {
247 $classZero =
' statistics-group-zero';
249 $text .= $this->formatRow( $grouppage .
' ' . $grouplink,
251 [
'class' =>
'statistics-group-' . Sanitizer::escapeClass( $group ) .
265 private function getOtherStats( array $stats ) {
268 foreach ( $stats as
$header => $items ) {
270 if ( is_array( $items ) ) {
272 if (
$header !==
'statistics-header-hooks' ) {
273 $return .= $this->formatRowHeader(
$header );
277 foreach ( $items as $key => $value ) {
278 if ( is_array( $value ) ) {
279 $name = $value[
'name'];
280 $number = $value[
'number'];
282 $name = $this->
msg( $key )->parse();
286 $return .= $this->formatRow(
288 $this->
getLanguage()->formatNum( htmlspecialchars( $number ) ),
289 [
'class' =>
'mw-statistics-hook',
'id' =>
'mw-' . $key ]
294 if ( $return ===
'' ) {
295 $return .= $this->formatRowHeader(
'statistics-header-hooks' );
299 $return .= $this->getOtherStats( [
'statistics-header-hooks' =>
313 private function formatRowHeader(
$header ) {
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.