private function getList() { $data = array(); $result = $this->getResult(); $gadgets = GadgetRepo::singleton()->getStructuredList(); if ($gadgets) { foreach ($gadgets as $category => $list) { if (!$this->neededNames || isset($this->neededNames[$category])) { $row = array(); if (isset($this->props['name'])) { $row['name'] = $category; } if ($category !== "") { if (isset($this->props['title'])) { $row['desc'] = $this->msg("gadget-section-{$category}")->parse(); } } if (isset($this->props['members'])) { $row['members'] = count($list); } $data[] = $row; } } } $result->setIndexedTagName($data, 'category'); $result->addValue('query', $this->getModuleName(), $data); }
/** * @return array */ private function getList() { $gadgets = GadgetRepo::singleton()->getStructuredList(); if ($gadgets === false) { return array(); } $result = array(); foreach ($gadgets as $category => $list) { if ($this->categories && !isset($this->categories[$category])) { continue; } foreach ($list as $g) { if ($this->isNeeded($g)) { $result[] = $g; } } } return $result; }
/** * Exports a gadget with its dependencies in a serialized form * @param $gadget String Name of gadget to export */ public function showExportForm($gadget) { global $wgScript; $output = $this->getOutput(); try { $g = GadgetRepo::singleton()->getGadget($gadget); } catch (InvalidArgumentException $e) { $output->showErrorPage('error', 'gadgets-not-found', array($gadget)); return; } $this->setHeaders(); $output->setPagetitle($this->msg('gadgets-export-title')); $output->addWikiMsg('gadgets-export-text', $gadget, $g->getDefinition()); $exportList = "MediaWiki:gadget-{$gadget}\n"; foreach ($g->getScriptsAndStyles() as $page) { $exportList .= "MediaWiki:{$page}\n"; } $output->addHTML(Html::openElement('form', array('method' => 'get', 'action' => $wgScript)) . Html::hidden('title', SpecialPage::getTitleFor('Export')->getPrefixedDBKey()) . Html::hidden('pages', $exportList) . Html::hidden('wpDownload', '1') . Html::hidden('templates', '1') . Xml::submitButton($this->msg('gadgets-export-download')->text()) . Html::closeElement('form')); }
/** * Should only be used by unit tests * * @param GadgetRepo|null $repo */ public static function setSingleton($repo = null) { self::$instance = $repo; }
/** * BeforePageDisplay hook handler. * @param $out OutputPage * @return bool */ public static function beforePageDisplay($out) { $repo = GadgetRepo::singleton(); $ids = $repo->getGadgetIds(); if (!$ids) { return true; } $lb = new LinkBatch(); $lb->setCaller(__METHOD__); $enabledLegacyGadgets = array(); /** * @var $gadget Gadget */ $user = $out->getUser(); foreach ($ids as $id) { $gadget = $repo->getGadget($id); if ($gadget->isEnabled($user) && $gadget->isAllowed($user)) { if ($gadget->hasModule()) { $out->addModuleStyles($gadget->getModuleName()); $out->addModules($gadget->getModuleName()); } if ($gadget->getLegacyScripts()) { $enabledLegacyGadgets[] = $id; } } } $strings = array(); foreach ($enabledLegacyGadgets as $id) { $strings[] = self::makeLegacyWarning($id); } $out->addHTML(WrappedString::join("\n", $strings)); return true; }
public function tearDown() { GadgetRepo::setSingleton(); parent::tearDown(); }