From c23335fe5ea4b244428363337d2fdd9ec2de8c20 Mon Sep 17 00:00:00 2001 From: niharika29 Date: Thu, 29 Oct 2015 21:24:49 +0000 Subject: [PATCH] Remove default gadgets from Special:GadgetUsage The numbers for default gadgets are inconsistent and can be misleading. Change-Id: Ib46084d617a536e4e25da80424ad70cec2a09f5a --- SpecialGadgetUsage.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/SpecialGadgetUsage.php b/SpecialGadgetUsage.php index 8356d7e9..88205d22 100644 --- a/SpecialGadgetUsage.php +++ b/SpecialGadgetUsage.php @@ -95,6 +95,23 @@ class SpecialGadgetUsage extends QueryPage { return false; } + /** + * Get a list of default gadgets + * @return list + */ + protected function getDefaultGadgets() { + $gadgetRepo = GadgetRepo::singleton(); + $gadgetIds = $gadgetRepo->getGadgetIds(); + $gadgetsList = array(); + foreach ( $gadgetIds as $g ) { + $gadget = $gadgetRepo->getGadget( $g ); + if ( $gadget->isOnByDefault() ) { + $gadgetsList[] = $gadget->getName(); + } + } + return $gadgetsList; + } + /** * Format and output report results using the given information plus * OutputPage @@ -107,13 +124,17 @@ class SpecialGadgetUsage extends QueryPage { * @param int $offset Paging offset */ protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) { + $defaultGadgets = $this->getDefaultGadgets(); if ( $num > 0 ) { $this->outputTableStart(); - foreach ( $res as $row ) { - $line = $this->formatResult( $skin, $row ); - if ( $line ) { - $out->addHTML( $line ); + // Remove the 'gadget-' part of the result string and compare if it's present + // in $defaultGadgets, if not we format it and add it to the output + if ( !in_array( substr( $row->title, 7 ), $defaultGadgets ) ) { + $line = $this->formatResult( $skin, $row ); + if ( $line ) { + $out->addHTML( $line ); + } } } // Close table element