diff options
author | Brian Evans <grknight@gentoo.org> | 2020-12-03 21:59:15 -0500 |
---|---|---|
committer | Brian Evans <grknight@gentoo.org> | 2020-12-03 21:59:15 -0500 |
commit | af77cced1619d9dfc9d75c78fbef2d79aaf2353c (patch) | |
tree | 54683e965457fffc4fbf219bcdf11bb95dffd694 | |
parent | GentooPackages: Attempt to cache the result of USE data (diff) | |
download | extensions-af77cced1619d9dfc9d75c78fbef2d79aaf2353c.tar.gz extensions-af77cced1619d9dfc9d75c78fbef2d79aaf2353c.tar.bz2 extensions-af77cced1619d9dfc9d75c78fbef2d79aaf2353c.zip |
GentooPackages: Use Parser hook interface
Signed-off-by: Brian Evans <grknight@gentoo.org>
-rw-r--r-- | GentooPackages/GentooPackages.php | 19 | ||||
-rw-r--r-- | GentooPackages/extension.json | 9 |
2 files changed, 14 insertions, 14 deletions
diff --git a/GentooPackages/GentooPackages.php b/GentooPackages/GentooPackages.php index 13ab7241..8bd8d576 100644 --- a/GentooPackages/GentooPackages.php +++ b/GentooPackages/GentooPackages.php @@ -1,7 +1,7 @@ <?php -class GentooPackages { - static function packageInfo($input, array $args, Parser $parser, PPFrame $frame) { +class GentooPackages implements MediaWiki\Hook\ParserFirstCallInitHook { + public static function packageInfo($input, array $args, Parser $parser, PPFrame $frame) { $atom = $args['atom']; $type = $args['type']; @@ -21,7 +21,7 @@ class GentooPackages { } } - static function fetchOrError($atom, $type) { + private static function fetchOrError($atom, $type) { global $wgVersion; $url = "https://packages.gentoo.org/packages/${atom}.json"; if ($type !== 'use') { @@ -48,7 +48,7 @@ class GentooPackages { } } - static function render($json) { + private static function render($json) { $use_flags = self::renderFlags($json); $updated_at = strftime('%Y-%m-%d %H:%M', strtotime($json['updated_at'])); $desc = htmlspecialchars($json['description']); @@ -80,7 +80,7 @@ class GentooPackages { HTML; } - static function renderFlags($json) { + private static function renderFlags($json) { $flags = self::sortFlags($json); $html = <<<HTML @@ -110,7 +110,7 @@ HTML; return $html; } - static function sortFlags($json) { + private static function sortFlags($json) { $merged_flags = []; foreach(array_merge($json['use']['global'], $json['use']['local']) as $flag) $merged_flags[$flag['name']] = $flag; @@ -118,10 +118,9 @@ HTML; return $merged_flags; } - static function initHooks($parser) { - global $wgOut; - + public function onParserFirstCallInit($parser) { $parser->setHook('package-info', 'GentooPackages::packageInfo'); - $wgOut->addModules('ext.gentooPackages'); + $output = $parser->getOutput(); + $output->addModules('ext.gentooPackages'); } } diff --git a/GentooPackages/extension.json b/GentooPackages/extension.json index 0fc88cde..e1f9b2ce 100644 --- a/GentooPackages/extension.json +++ b/GentooPackages/extension.json @@ -1,6 +1,6 @@ { "name": "GentooPackages", - "version": "0.0.2", + "version": "0.0.3", "author": [ "Alex Legler", "Brian Evans" @@ -9,6 +9,9 @@ "descriptionmsg": "gentoopackages-desc", "license-name": "AGPL", "type": "parserhook", + "requires": { + "MediaWiki": ">= 1.35.0" + }, "AutoloadClasses": { "GentooPackages": "GentooPackages.php" }, @@ -18,9 +21,7 @@ ] }, "Hooks": { - "ParserFirstCallInit": [ - "GentooPackages::initHooks" - ] + "ParserFirstCallInit": "GentooPackages" }, "ResourceModules": { "ext.gentooPackages": { |