34 private $edits, $good, $images, $total, $users,
38 private $userGroupManager;
44 parent::__construct(
'Statistics' );
45 $this->userGroupManager = $userGroupManager;
51 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
60 $text = Xml::openElement(
'table', [
'class' =>
'wikitable mw-statistics-table' ] );
63 $text .= $this->getPageStats();
66 $text .= $this->getEditStats();
69 $text .= $this->getUserStats();
71 # Statistic - usergroups
72 $text .= $this->getGroupStats();
79 $text .= $this->getOtherStats( $extraStats );
82 $text .= Xml::closeElement(
'table' );
87 $text .=
"\n" .
$footer->parse();
102 private function formatRow( $text, $number, $trExtraParams = [],
103 $descMsg =
'', $descMsgParam =
''
106 $msg = $this->
msg( $descMsg, $descMsgParam );
107 if ( !$msg->isDisabled() ) {
108 $descriptionHtml = $this->
msg(
'parentheses' )->rawParams( $msg->parse() )
110 $text .=
"<br />" . Html::rawElement(
112 [
'class' =>
'mw-statistic-desc' ],
119 Html::rawElement(
'td', [], $text ) .
120 Html::rawElement(
'td', [
'class' =>
'mw-statistics-numbers' ], $number )
129 private function getPageStats() {
134 Xml::tags(
'th', [
'colspan' =>
'2' ], $this->
msg(
'statistics-header-pages' )
138 $this->
getConfig()->
get( MainConfigNames::MiserMode )
139 ? $this->
msg(
'statistics-articles' )->escaped()
140 : $linkRenderer->makeKnownLink(
141 $specialAllPagesTitle,
142 $this->
msg(
'statistics-articles' )->text(),
143 [], [
'hideredirects' => 1 ] ),
145 [
'class' =>
'mw-statistics-articles' ],
146 'statistics-articles-desc' ) .
147 $this->formatRow( $linkRenderer->makeKnownLink( $specialAllPagesTitle,
148 $this->
msg(
'statistics-pages' )->text() ),
150 [
'class' =>
'mw-statistics-pages' ],
151 'statistics-pages-desc' );
154 if ( $this->images !== 0 || $this->
getConfig()->
get( MainConfigNames::EnableUploads ) ) {
155 $pageStatsHtml .= $this->formatRow(
157 $this->msg(
'statistics-files' )->text() ),
158 $this->getLanguage()->formatNum( $this->images ),
159 [
'class' =>
'mw-statistics-files' ],
'statistics-files-desc' );
162 return $pageStatsHtml;
165 private function getEditStats() {
168 $this->
msg(
'statistics-header-edits' )->parse() ) .
170 $this->formatRow( $this->
msg(
'statistics-edits' )->parse(),
172 [
'class' =>
'mw-statistics-edits' ]
174 $this->formatRow( $this->
msg(
'statistics-edits-average' )->parse(),
176 sprintf(
'%.2f', $this->total ? $this->edits / $this->total : 0 )
177 ), [
'class' =>
'mw-statistics-edits-average' ]
181 private function getUserStats() {
184 $this->
msg(
'statistics-header-users' )->parse() ) .
186 $this->formatRow( $this->
msg(
'statistics-users' )->parse() .
' ' .
189 $this->
msg(
'listgrouprights-members' )->text()
192 [
'class' =>
'mw-statistics-users' ]
194 $this->formatRow( $this->
msg(
'statistics-users-active' )->parse() .
' ' .
197 $this->
msg(
'listgrouprights-members' )->text()
199 $this->
getLanguage()->formatNum( $this->activeUsers ),
200 [
'class' =>
'mw-statistics-users-active' ],
201 'statistics-users-active-desc',
203 $this->
getConfig()->
get( MainConfigNames::ActiveUserDays ) )
207 private function getGroupStats() {
211 foreach ( $this->userGroupManager->listAllGroups() as $group ) {
212 $groupnameLocalized =
$lang->getGroupName( $group );
217 $grouppage = $linkRenderer->makeLink(
222 $grouppage = htmlspecialchars( $groupnameLocalized );
225 $grouplink = $linkRenderer->makeKnownLink(
227 $this->
msg(
'listgrouprights-members' )->text(),
229 [
'group' => $group ]
231 # Add a class when a usergroup contains no members to allow hiding these rows
234 if ( $countUsers == 0 ) {
235 $classZero =
' statistics-group-zero';
237 $text .= $this->formatRow( $grouppage .
' ' . $grouplink,
239 [
'class' =>
'statistics-group-' . Sanitizer::escapeClass( $group ) .
253 private function getOtherStats( array $stats ) {
256 foreach ( $stats as
$header => $items ) {
258 if ( is_array( $items ) ) {
260 if (
$header !==
'statistics-header-hooks' ) {
261 $return .= $this->formatRowHeader(
$header );
265 foreach ( $items as $key => $value ) {
266 if ( is_array( $value ) ) {
267 $name = $value[
'name'];
268 $number = $value[
'number'];
270 $name = $this->
msg( $key )->parse();
274 $return .= $this->formatRow(
276 $this->
getLanguage()->formatNum( htmlspecialchars( $number ) ),
277 [
'class' =>
'mw-statistics-hook',
'id' =>
'mw-' . $key ]
282 if ( $return ===
'' ) {
283 $return .= $this->formatRowHeader(
'statistics-header-hooks' );
287 $return .= $this->getOtherStats( [
'statistics-header-hooks' =>
301 private function formatRowHeader(
$header ) {
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.