43 private $edits, $good, $images, $total, $users,
52 parent::__construct(
'Statistics' );
53 $this->userGroupManager = $userGroupManager;
59 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
61 $this->edits = SiteStats::edits();
62 $this->good = SiteStats::articles();
63 $this->images = SiteStats::images();
64 $this->total = SiteStats::pages();
65 $this->users = SiteStats::users();
66 $this->activeUsers = SiteStats::activeUsers();
68 $text = Xml::openElement(
'table', [
'class' =>
'wikitable mw-statistics-table' ] );
71 $text .= $this->getPageStats();
74 $text .= $this->getEditStats();
77 $text .= $this->getUserStats();
79 # Statistic - usergroups
80 $text .= $this->getGroupStats();
87 $text .= $this->getOtherStats( $extraStats );
90 $text .= Xml::closeElement(
'table' );
95 $text .=
"\n" .
$footer->parse();
110 private function formatRow( $text, $number, $trExtraParams = [],
111 $descMsg =
'', $descMsgParam =
''
114 $msg = $this->
msg( $descMsg, $descMsgParam );
115 if ( !$msg->isDisabled() ) {
116 $descriptionHtml = $this->
msg(
'parentheses' )->rawParams( $msg->parse() )
118 $text .=
"<br />" . Html::rawElement(
120 [
'class' =>
'mw-statistic-desc' ],
126 return Html::rawElement(
'tr', $trExtraParams,
127 Html::rawElement(
'td', [], $text ) .
128 Html::rawElement(
'td', [
'class' =>
'mw-statistics-numbers' ], $number )
137 private function getPageStats() {
142 Xml::tags(
'th', [
'colspan' =>
'2' ], $this->
msg(
'statistics-header-pages' )
147 ? $this->
msg(
'statistics-articles' )->escaped()
148 : $linkRenderer->makeKnownLink(
149 $specialAllPagesTitle,
150 $this->
msg(
'statistics-articles' )->text(),
151 [], [
'hideredirects' => 1 ] ),
153 [
'class' =>
'mw-statistics-articles' ],
154 'statistics-articles-desc' ) .
155 $this->formatRow( $linkRenderer->makeKnownLink( $specialAllPagesTitle,
156 $this->
msg(
'statistics-pages' )->text() ),
158 [
'class' =>
'mw-statistics-pages' ],
159 'statistics-pages-desc' );
163 $pageStatsHtml .= $this->formatRow(
165 $this->msg(
'statistics-files' )->text() ),
166 $this->getLanguage()->formatNum( $this->images ),
167 [
'class' =>
'mw-statistics-files' ],
'statistics-files-desc' );
170 return $pageStatsHtml;
173 private function getEditStats() {
176 $this->
msg(
'statistics-header-edits' )->parse() ) .
178 $this->formatRow( $this->
msg(
'statistics-edits' )->parse(),
180 [
'class' =>
'mw-statistics-edits' ]
182 $this->formatRow( $this->
msg(
'statistics-edits-average' )->parse(),
184 sprintf(
'%.2f', $this->total ? $this->edits / $this->total : 0 )
185 ), [
'class' =>
'mw-statistics-edits-average' ]
189 private function getUserStats() {
192 $this->
msg(
'statistics-header-users' )->parse() ) .
194 $this->formatRow( $this->
msg(
'statistics-users' )->parse() .
' ' .
197 $this->
msg(
'listgrouprights-members' )->text()
200 [
'class' =>
'mw-statistics-users' ]
202 $this->formatRow( $this->
msg(
'statistics-users-active' )->parse() .
' ' .
205 $this->
msg(
'listgrouprights-members' )->text()
207 $this->
getLanguage()->formatNum( $this->activeUsers ),
208 [
'class' =>
'mw-statistics-users-active' ],
209 'statistics-users-active-desc',
215 private function getGroupStats() {
219 foreach ( $this->userGroupManager->listAllGroups() as $group ) {
220 $groupnameLocalized = $lang->getGroupName( $group );
221 $linkTarget = UserGroupMembership::getGroupPage( $group )
222 ?: Title::makeTitleSafe(
NS_PROJECT, $group );
225 $grouppage = $linkRenderer->makeLink(
230 $grouppage = htmlspecialchars( $groupnameLocalized );
233 $grouplink = $linkRenderer->makeKnownLink(
235 $this->
msg(
'listgrouprights-members' )->text(),
237 [
'group' => $group ]
239 # Add a class when a usergroup contains no members to allow hiding these rows
241 $countUsers = SiteStats::numberingroup( $group );
242 if ( $countUsers == 0 ) {
243 $classZero =
' statistics-group-zero';
245 $text .= $this->formatRow( $grouppage .
' ' . $grouplink,
247 [
'class' =>
'statistics-group-' . Sanitizer::escapeClass( $group ) .
261 private function getOtherStats( array $stats ) {
264 foreach ( $stats as
$header => $items ) {
266 if ( is_array( $items ) ) {
268 if (
$header !==
'statistics-header-hooks' ) {
269 $return .= $this->formatRowHeader(
$header );
273 foreach ( $items as $key => $value ) {
274 if ( is_array( $value ) ) {
275 $name = $value[
'name'];
276 $number = $value[
'number'];
278 $name = $this->
msg( $key )->parse();
282 $return .= $this->formatRow(
284 $this->
getLanguage()->formatNum( htmlspecialchars( $number ) ),
285 [
'class' =>
'mw-statistics-hook',
'id' =>
'mw-' . $key ]
290 if ( $return ===
'' ) {
291 $return .= $this->formatRowHeader(
'statistics-header-hooks' );
295 $return .= $this->getOtherStats( [
'statistics-header-hooks' =>
309 private function formatRowHeader(
$header ) {
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.