Niharika29 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/247559

Change subject: Add a special page to show number of users for each gadget on 
the wiki
......................................................................

Add a special page to show number of users for each gadget on the wiki

Bug:T115152
Change-Id: Id1e245f8fdb2fc6a764682ae34937f35af24bd7c
---
A SpecialGadgetUsage.php
M extension.json
M i18n/en.json
M i18n/qqq.json
4 files changed, 137 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gadgets 
refs/changes/59/247559/1

diff --git a/SpecialGadgetUsage.php b/SpecialGadgetUsage.php
new file mode 100644
index 0000000..f23a102
--- /dev/null
+++ b/SpecialGadgetUsage.php
@@ -0,0 +1,126 @@
+<?php
+/**
+ * Implements Special:GadgetUsage
+ *
+ * Copyright © 2006 Rob Church
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ * @author Rob Church <[email protected]>
+ */
+
+/**
+ * Special:Listredirects - Lists all the redirects on the wiki.
+ * @ingroup SpecialPage
+ */
+class SpecialGadgetUsage extends QueryPage {
+       function __construct( $name = 'GadgetUsage' ) {
+               parent::__construct( $name );
+               $this->limit = 1000;    // Show all gadgets
+               $this->shownavigation = false;
+       }
+
+       public function isExpensive() {
+               return false;
+       }
+
+       public function getQueryInfo() {
+               return array(
+                       'tables' => array( 'user_properties_anon' ),
+                       'fields' => array(
+                               'title' => 'up_property',
+                               'value' => 'COUNT(*)'
+                       ),
+                       'conds' => array(
+                               "up_property LIKE 'gadget-%'"
+                       ),
+                       'options' => array(
+                               'GROUP BY' => array('up_property')
+                       )
+               );
+       }
+
+       function getOrderFields() {
+               return array( 'up_property' );
+       }
+
+       /**
+        * Output the start of the table
+        * Including opening <table>, and first <tr> with column headers.
+        */
+       protected function outputTableStart() {
+               $html = Html::openElement( 'table', array( 'class' => array( 
'sortable', 'wikitable' ) ) );
+               $html .= Html::openElement( 'tr', array() );
+               
+               $headers = array( 'gadgetusage-gadget', 'gadgetusage-usercount' 
);
+               foreach( $headers as $h ) {
+                       $html .= Html::rawElement( 'th', array(), $this->msg( 
$h ) );
+               }
+               $html .= Html::closeElement( 'tr' );
+               $this->getOutput()->addHTML( $html );
+       }
+
+       /**
+        * @param Skin $skin
+        * @param object $result Result row
+        * @return string
+        */
+       function formatResult( $skin, $result ) {
+               $gadget_title = substr( $result->title, 7 );
+               $gadget_usercount = $result->value;
+               if ( $gadget_title ) {
+                       $html = Html::openElement( 'tr', array() );
+                       $html .=  Html::rawElement( 'td', array(), 
$gadget_title );
+                       $html .= Html::rawElement( 'td', array(), 
$gadget_usercount );
+                       $html .= Html::closeElement( 'tr' );
+                       return $html;
+               }
+       }
+
+       /**
+        * Format and output report results using the given information plus
+        * OutputPage
+        *
+        * @param OutputPage $out OutputPage to print to
+        * @param Skin $skin User skin to use
+        * @param IDatabase $dbr Database (read) connection to use
+        * @param ResultWrapper $res Result pointer
+        * @param int $num Number of available result rows
+        * @param int $offset Paging offset
+        */
+       protected function outputResults( $out, $skin, $dbr, $res, $num, 
$offset ) {
+               $this->getOutput()->addHTML( $this->msg( 'gadgetusage-intro' ) 
);
+               if ( $num > 0 ) {
+                       $html = array();
+                       $this->outputTableStart();
+                       
+                       for ( $i = 0; $i < $num && $row = $res->fetchObject(); 
$i++ ) {
+                               $line = $this->formatResult( $skin, $row );
+                               if ( $line ) {
+                                       $this->getOutput()->addHTML( $line );
+                               }
+                       }
+                       // Close table element
+                       $this->getOutput()->addHtml( Html::closeElement( 
'table' ) );
+               }
+       }
+
+       protected function getGroupName() {
+               return 'wiki';
+       }
+}
diff --git a/extension.json b/extension.json
index 423861d..6b330d7 100644
--- a/extension.json
+++ b/extension.json
@@ -38,7 +38,8 @@
                "gadgets-definition-edit"
        ],
        "SpecialPages": {
-               "Gadgets": "SpecialGadgets"
+               "Gadgets": "SpecialGadgets",
+               "GadgetUsage": "SpecialGadgetUsage"
        },
        "APIListModules": {
                "gadgetcategories": "ApiQueryGadgetCategories",
@@ -60,6 +61,7 @@
                "GadgetHooks": "GadgetHooks.php",
                "GadgetResourceLoaderModule": 
"includes/GadgetResourceLoaderModule.php",
                "SpecialGadgets": "SpecialGadgets.php",
+               "SpecialGadgetUsage": "SpecialGadgetUsage.php",
                "GadgetRepo": "includes/GadgetRepo.php",
                "MediaWikiGadgetsDefinitionRepo": 
"includes/MediaWikiGadgetsDefinitionRepo.php"
        },
diff --git a/i18n/en.json b/i18n/en.json
index 7b8170b..ae8d4a6 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -8,6 +8,10 @@
        "prefs-gadgets": "Gadgets",
        "gadgets-prefstext": "Below is a list of special gadgets you can enable 
for your account.\nThese gadgets are mostly based on JavaScript, so JavaScript 
has to be enabled in your browser for them to work.\nNote that these gadgets 
will have no effect on this preferences page.\n\nAlso note that these special 
gadgets are not part of the MediaWiki software, and are usually developed and 
maintained by users on your local wiki.\nLocal administrators can edit the 
[[MediaWiki:Gadgets-definition|definitions]] and 
[[Special:Gadgets|descriptions]] of available gadgets.",
        "gadgets": "Gadgets",
+       "gadgetusage": "Gadget usage statistics",
+       "gadgetusage-gadget": "Gadget",
+       "gadgetusage-usercount": "Number of users",
+       "gadgetusage-intro": "This table indicates the number of users who have 
enabled the gadget for each gadget on this wiki.",
        "gadgets-definition": "",
        "gadgets-title": "Gadgets",
        "gadgets-pagetext": "Below is a list of special gadgets users can 
enable on their [[Special:Preferences#mw-prefsection-gadgets|preferences 
page]], as defined by the [[MediaWiki:Gadgets-definition|definitions]].\nThis 
overview provides easy access to the system message pages that define each 
gadget's description and code.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 011bba6..2e9cc24 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -19,6 +19,10 @@
        "prefs-gadgets": "In Gadgets extension. The name of a tab in 
[[Special:Preferences#mw-prefsection-gadgets|Special:Preferences]] where user 
set their preferences for the extension.\n\n{{Identical|Gadgets}}",
        "gadgets-prefstext": "In Gadgets extension. This is the explanation 
text displayed under the Gadgets tab in 
[[Special:Preferences#mw-prefsection-gadgets|Special:Preferences]].",
        "gadgets": "{{doc-special|Gadgets}}\n{{Identical|Gadgets}}",
+       "gadgetusage": "{{doc-special|Gadget usage statistics}}",
+       "gadgetusage-gadget": "Table column header on [[Special:GadgetUsage]]",
+       "gadgetusage-usercount": "Table column header on 
[[Special:GadgetUsage]]",
+       "gadgetusage-intro": "Intro text on [[Special:GadgetUsage]]",
        "gadgets-definition": "{{notranslate}}",
        "gadgets-title": "{{Identical|Gadgets}}",
        "gadgets-pagetext": "Used as intro text in [[Special:Gadgets]].",

-- 
To view, visit https://gerrit.wikimedia.org/r/247559
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1e245f8fdb2fc6a764682ae34937f35af24bd7c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Gadgets
Gerrit-Branch: master
Gerrit-Owner: Niharika29 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to