MediaWiki REL1_33
SpecialGadgetUsage.php
Go to the documentation of this file.
1<?php
29
35 public function __construct( $name = 'GadgetUsage' ) {
36 parent::__construct( $name );
37 $this->limit = 1000; // Show all gadgets
38 $this->shownavigation = false;
39 $this->activeUsers = $this->getConfig()->get( 'SpecialGadgetUsageActiveUsers' );
40 }
41
48
49 public function isExpensive() {
50 return true;
51 }
52
72 public function getQueryInfo() {
74 if ( !$this->activeUsers ) {
75 return [
76 'tables' => [ 'user_properties' ],
77 'fields' => [
78 'title' => 'up_property',
79 'value' => 'SUM( up_value )',
80 'namespace' => NS_GADGET
81 ],
82 'conds' => [
83 'up_property' . $dbr->buildLike( 'gadget-', $dbr->anyString() )
84 ],
85 'options' => [
86 'GROUP BY' => [ 'up_property' ]
87 ]
88 ];
89 } else {
90 return [
91 'tables' => [ 'user_properties', 'user', 'querycachetwo' ],
92 'fields' => [
93 'title' => 'up_property',
94 'value' => 'SUM( up_value )',
95 // Need to pick fields existing in the querycache table so that the results are cachable
96 'namespace' => 'COUNT( qcc_title )'
97 ],
98 'conds' => [
99 'up_property' . $dbr->buildLike( 'gadget-', $dbr->anyString() )
100 ],
101 'options' => [
102 'GROUP BY' => [ 'up_property' ]
103 ],
104 'join_conds' => [
105 'user' => [
106 'LEFT JOIN', [
107 'up_user = user_id'
108 ]
109 ],
110 'querycachetwo' => [
111 'LEFT JOIN', [
112 'user_name = qcc_title',
113 'qcc_type = "activeusers"',
114 'up_value = 1'
115 ]
116 ]
117 ]
118 ];
119 }
120 }
121
122 public function getOrderFields() {
123 return [ 'value' ];
124 }
125
131 protected function outputTableStart() {
132 $html = Html::openElement( 'table', [ 'class' => [ 'sortable', 'wikitable' ] ] );
133 $html .= Html::openElement( 'thead', [] );
134 $html .= Html::openElement( 'tr', [] );
135 $headers = [ 'gadgetusage-gadget', 'gadgetusage-usercount' ];
136 if ( $this->activeUsers ) {
137 $headers[] = 'gadgetusage-activeusers';
138 }
139 foreach ( $headers as $h ) {
140 if ( $h == 'gadgetusage-gadget' ) {
141 $html .= Html::element( 'th', [], $this->msg( $h )->text() );
142 } else {
143 $html .= Html::element( 'th', [ 'data-sort-type' => 'number' ],
144 $this->msg( $h )->text() );
145 }
146 }
147 $html .= Html::closeElement( 'tr' );
148 $html .= Html::closeElement( 'thead' );
149 $html .= Html::openElement( 'tbody', [] );
150 $this->getOutput()->addHTML( $html );
151 }
152
157 protected function outputTableEnd() {
158 $this->getOutput()->addHTML(
159 Html::closeElement( 'tbody' ) .
160 Html::closeElement( 'table' )
161 );
162 }
163
169 public function formatResult( $skin, $result ) {
170 $gadgetTitle = substr( $result->title, 7 );
171 $gadgetUserCount = $this->getLanguage()->formatNum( $result->value );
172 if ( $gadgetTitle ) {
173 $html = Html::openElement( 'tr', [] );
174 $html .= Html::element( 'td', [], $gadgetTitle );
175 $html .= Html::element( 'td', [], $gadgetUserCount );
176 if ( $this->activeUsers == true ) {
177 $activeUserCount = $this->getLanguage()->formatNum( $result->namespace );
178 $html .= Html::element( 'td', [], $activeUserCount );
179 }
180 $html .= Html::closeElement( 'tr' );
181 return $html;
182 }
183 return false;
184 }
185
192 protected function getDefaultGadgets( $gadgetRepo, $gadgetIds ) {
193 $gadgetsList = [];
194 foreach ( $gadgetIds as $g ) {
195 $gadget = $gadgetRepo->getGadget( $g );
196 if ( $gadget->isOnByDefault() ) {
197 $gadgetsList[] = $gadget->getName();
198 }
199 }
200 asort( $gadgetsList, SORT_STRING | SORT_FLAG_CASE );
201 return $gadgetsList;
202 }
203
215 protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
216 $gadgetRepo = GadgetRepo::singleton();
217 $gadgetIds = $gadgetRepo->getGadgetIds();
218 $defaultGadgets = $this->getDefaultGadgets( $gadgetRepo, $gadgetIds );
219 if ( $this->activeUsers ) {
220 $out->addHtml(
221 $this->msg( 'gadgetusage-intro' )
222 ->numParams( $this->getConfig()->get( 'ActiveUserDays' ) )->parseAsBlock()
223 );
224 } else {
225 $out->addHtml(
226 $this->msg( 'gadgetusage-intro-noactive' )->parseAsBlock()
227 );
228 }
229 if ( $num > 0 ) {
230 $this->outputTableStart();
231 // Append default gadgets to the table with 'default' in the total and active user fields
232 foreach ( $defaultGadgets as $default ) {
233 $html = Html::openElement( 'tr', [] );
234 $html .= Html::element( 'td', [], $default );
235 $html .= Html::element( 'td', [ 'data-sort-value' => 'Infinity' ],
236 $this->msg( 'gadgetusage-default' )->text() );
237 if ( $this->activeUsers ) {
238 $html .= Html::element( 'td', [ 'data-sort-value' => 'Infinity' ],
239 $this->msg( 'gadgetusage-default' )->text() );
240 }
241 $html .= Html::closeElement( 'tr' );
242 $out->addHTML( $html );
243 }
244 foreach ( $res as $row ) {
245 // Remove the 'gadget-' part of the result string and compare if it's present
246 // in $defaultGadgets, if not we format it and add it to the output
247 if ( !in_array( substr( $row->title, 7 ), $defaultGadgets ) ) {
248 // Only pick gadgets which are in the list $gadgetIds to make sure they exist
249 if ( in_array( substr( $row->title, 7 ), $gadgetIds ) ) {
250 $line = $this->formatResult( $skin, $row );
251 if ( $line ) {
252 $out->addHTML( $line );
253 }
254 }
255 }
256 }
257 // Close table element
258 $this->outputTableEnd();
259 } else {
260 $out->addHtml(
261 $this->msg( 'gadgetusage-noresults' )->parseAsBlock()
262 );
263 }
264 }
265
266 protected function getGroupName() {
267 return 'wiki';
268 }
269}
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
$line
Definition cdb.php:59
static singleton()
Get the configured default GadgetRepo.
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Definition QueryPage.php:35
int $offset
The offset and limit in use, as passed to the query() function.
Definition QueryPage.php:40
Special:GadgetUsage - Lists all the gadgets on the wiki along with number of users.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
$activeUsers
Flag for holding the value of config variable SpecialGadgetUsageActiveUsers.
getQueryInfo()
Define the database query that is used to generate the stats table.
formatResult( $skin, $result)
getDefaultGadgets( $gadgetRepo, $gadgetIds)
Get a list of default gadgets.
outputTableStart()
Output the start of the table Including opening.
__construct( $name='GadgetUsage')
isExpensive()
Is this query expensive (for some definition of expensive)? Then we don't let it run in miser mode.
getOrderFields()
Subclasses return an array of fields to order by here.
outputResults( $out, $skin, $dbr, $res, $num, $offset)
Format and output report results using the given information plus OutputPage.
outputTableEnd()
Output the end of the table
getOutput()
Get the OutputPage being used for this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
$res
Definition database.txt:21
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:855
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2011
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
Result wrapper for grabbing data queried from an IDatabase object.
const DB_REPLICA
Definition defines.php:25