36 private $edits, $good, $images, $total, $users,
40 private $userGroupManager;
46 parent::__construct(
'Statistics' );
47 $this->userGroupManager = $userGroupManager;
53 $this->
getOutput()->addModuleStyles(
'mediawiki.special' );
62 $text = Xml::openElement(
'table', [
'class' =>
'wikitable mw-statistics-table' ] );
65 $text .= $this->getPageStats();
68 $text .= $this->getEditStats();
71 $text .= $this->getUserStats();
73 # Statistic - usergroups
74 $text .= $this->getGroupStats();
81 $text .= $this->getOtherStats( $extraStats );
84 $text .= Xml::closeElement(
'table' );
89 $text .=
"\n" .
$footer->parse();
104 private function formatRow( $text, $number, $trExtraParams = [],
105 $descMsg =
'', $descMsgParam =
''
108 $msg = $this->
msg( $descMsg, $descMsgParam );
109 if ( !$msg->isDisabled() ) {
110 $descriptionHtml = $this->
msg(
'parentheses' )->rawParams( $msg->parse() )
112 $text .=
"<br />" . Html::rawElement(
114 [
'class' =>
'mw-statistic-desc' ],
120 return Html::rawElement(
'tr', $trExtraParams,
121 Html::rawElement(
'td', [], $text ) .
122 Html::rawElement(
'td', [
'class' =>
'mw-statistics-numbers' ], $number )
131 private function getPageStats() {
136 Xml::tags(
'th', [
'colspan' =>
'2' ], $this->
msg(
'statistics-header-pages' )
140 $this->
getConfig()->
get( MainConfigNames::MiserMode )
141 ? $this->
msg(
'statistics-articles' )->escaped()
142 : $linkRenderer->makeKnownLink(
143 $specialAllPagesTitle,
144 $this->
msg(
'statistics-articles' )->text(),
145 [], [
'hideredirects' => 1 ] ),
147 [
'class' =>
'mw-statistics-articles' ],
148 'statistics-articles-desc' ) .
149 $this->formatRow( $linkRenderer->makeKnownLink( $specialAllPagesTitle,
150 $this->
msg(
'statistics-pages' )->text() ),
152 [
'class' =>
'mw-statistics-pages' ],
153 'statistics-pages-desc' );
156 if ( $this->images !== 0 || $this->
getConfig()->
get( MainConfigNames::EnableUploads ) ) {
157 $pageStatsHtml .= $this->formatRow(
159 $this->msg(
'statistics-files' )->text() ),
160 $this->getLanguage()->formatNum( $this->images ),
161 [
'class' =>
'mw-statistics-files' ],
'statistics-files-desc' );
164 return $pageStatsHtml;
167 private function getEditStats() {
170 $this->
msg(
'statistics-header-edits' )->parse() ) .
172 $this->formatRow( $this->
msg(
'statistics-edits' )->parse(),
174 [
'class' =>
'mw-statistics-edits' ]
176 $this->formatRow( $this->
msg(
'statistics-edits-average' )->parse(),
178 sprintf(
'%.2f', $this->total ? $this->edits / $this->total : 0 )
179 ), [
'class' =>
'mw-statistics-edits-average' ]
183 private function getUserStats() {
186 $this->
msg(
'statistics-header-users' )->parse() ) .
188 $this->formatRow( $this->
msg(
'statistics-users' )->parse() .
' ' .
191 $this->
msg(
'listgrouprights-members' )->text()
194 [
'class' =>
'mw-statistics-users' ]
196 $this->formatRow( $this->
msg(
'statistics-users-active' )->parse() .
' ' .
199 $this->
msg(
'listgrouprights-members' )->text()
201 $this->
getLanguage()->formatNum( $this->activeUsers ),
202 [
'class' =>
'mw-statistics-users-active' ],
203 'statistics-users-active-desc',
205 $this->
getConfig()->
get( MainConfigNames::ActiveUserDays ) )
209 private function getGroupStats() {
213 foreach ( $this->userGroupManager->listAllGroups() as $group ) {
214 $groupnameLocalized =
$lang->getGroupName( $group );
216 ?: Title::makeTitleSafe(
NS_PROJECT, $group );
219 $grouppage = $linkRenderer->makeLink(
224 $grouppage = htmlspecialchars( $groupnameLocalized );
227 $grouplink = $linkRenderer->makeKnownLink(
229 $this->
msg(
'listgrouprights-members' )->text(),
231 [
'group' => $group ]
233 # Add a class when a usergroup contains no members to allow hiding these rows
236 if ( $countUsers == 0 ) {
237 $classZero =
' statistics-group-zero';
239 $text .= $this->formatRow( $grouppage .
' ' . $grouplink,
241 [
'class' =>
'statistics-group-' . Sanitizer::escapeClass( $group ) .
255 private function getOtherStats( array $stats ) {
258 foreach ( $stats as
$header => $items ) {
260 if ( is_array( $items ) ) {
262 if (
$header !==
'statistics-header-hooks' ) {
263 $return .= $this->formatRowHeader(
$header );
267 foreach ( $items as $key => $value ) {
268 if ( is_array( $value ) ) {
269 $name = $value[
'name'];
270 $number = $value[
'number'];
272 $name = $this->
msg( $key )->parse();
276 $return .= $this->formatRow(
278 $this->
getLanguage()->formatNum( htmlspecialchars( $number ) ),
279 [
'class' =>
'mw-statistics-hook',
'id' =>
'mw-' . $key ]
284 if ( $return ===
'' ) {
285 $return .= $this->formatRowHeader(
'statistics-header-hooks' );
289 $return .= $this->getOtherStats( [
'statistics-header-hooks' =>
303 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.