From a5f5619b4d92d564a7d5b14efa869ca44decdd7f Mon Sep 17 00:00:00 2001 From: Luqgreg Date: Sat, 22 Sep 2018 15:31:32 +0200 Subject: [PATCH] Add an option to use divs instead of headings in PI output --- extension.json | 1 + .../Helpers/PortableInfoboxTemplateEngine.php | 15 ++++++++++++--- templates/PortableInfoboxItemData.hbs | 2 +- templates/PortableInfoboxItemHeader.hbs | 2 +- templates/PortableInfoboxItemSmartGroup.hbs | 2 +- templates/PortableInfoboxItemTitle.hbs | 2 +- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/extension.json b/extension.json index 28425a7..35a8667 100644 --- a/extension.json +++ b/extension.json @@ -16,6 +16,7 @@ "AllInfoboxesMiserMode": true, "AllInfoboxesSubpagesBlacklist": [ "doc", "draft", "test" ], "PortableInfoboxCustomImageWidth": 300, + "PortableInfoboxUseHeadings": true, "PortableInfoboxUseTidy": true }, "MessagesDirs": { diff --git a/includes/services/Helpers/PortableInfoboxTemplateEngine.php b/includes/services/Helpers/PortableInfoboxTemplateEngine.php index 696bdc8..e2c660e 100644 --- a/includes/services/Helpers/PortableInfoboxTemplateEngine.php +++ b/includes/services/Helpers/PortableInfoboxTemplateEngine.php @@ -40,6 +40,9 @@ class PortableInfoboxTemplateEngine { } public function render( $type, array $data ) { + global $wgPortableInfoboxUseHeadings; + $data['useHeadings'] = $wgPortableInfoboxUseHeadings; + $renderer = $this->getRenderer( $type ); return $renderer( $data ); } @@ -55,7 +58,11 @@ class PortableInfoboxTemplateEngine { return self::$cache[$type]; } - $cachekey = self::$memcache->makeKey( __CLASS__, \PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type ); + global $wgPortableInfoboxUseHeadings; + + $cachekey = self::$memcache->makeKey( + __CLASS__, \PortableInfoboxParserTagController::PARSER_TAG_VERSION, $type + ); // @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy $renderer = \LightnCandy::prepare( @@ -63,7 +70,7 @@ class PortableInfoboxTemplateEngine { $path = self::getTemplatesDir() . DIRECTORY_SEPARATOR . static::getTemplates()[$type]; return \LightnCandy::compile( file_get_contents( $path ), [ - 'flags' => \LightnCandy::FLAG_BESTPERFORMANCE + 'flags' => \LightnCandy::FLAG_BESTPERFORMANCE | \LightnCandy::FLAG_PARENT ] ); } ) ); @@ -83,7 +90,9 @@ class PortableInfoboxTemplateEngine { public static function isSupportedType( $type ) { $result = isset( static::getTemplates()[$type] ); if ( !$result ) { - LoggerFactory::getInstance( 'PortableInfobox' )->info( self::TYPE_NOT_SUPPORTED_MESSAGE, [ 'type' => $type ] ); + LoggerFactory::getInstance( 'PortableInfobox' )->info( + self::TYPE_NOT_SUPPORTED_MESSAGE, [ 'type' => $type ] + ); } return $result; } diff --git a/templates/PortableInfoboxItemData.hbs b/templates/PortableInfoboxItemData.hbs index 2f69242..0e8ca05 100644 --- a/templates/PortableInfoboxItemData.hbs +++ b/templates/PortableInfoboxItemData.hbs @@ -1,6 +1,6 @@
{{#if label}} -

{{{label}}}

+ <{{#if useHeadings}}h3{{else}}div{{/if}} class="pi-data-label pi-secondary-font">{{{label}}} {{/if}}
{{{value}}}
\ No newline at end of file diff --git a/templates/PortableInfoboxItemHeader.hbs b/templates/PortableInfoboxItemHeader.hbs index 6d6935c..1b6cb70 100644 --- a/templates/PortableInfoboxItemHeader.hbs +++ b/templates/PortableInfoboxItemHeader.hbs @@ -1 +1 @@ -

{{{value}}}

\ No newline at end of file +<{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}} \ No newline at end of file diff --git a/templates/PortableInfoboxItemSmartGroup.hbs b/templates/PortableInfoboxItemSmartGroup.hbs index ceb19ad..d28d39a 100644 --- a/templates/PortableInfoboxItemSmartGroup.hbs +++ b/templates/PortableInfoboxItemSmartGroup.hbs @@ -2,7 +2,7 @@ {{#if renderLabels}}
{{#each labels}} -

{{{value}}}

+ <{{#if ../useHeadings}}h3{{else}}div{{/if}} class="pi-smart-data-label pi-data-label pi-secondary-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}} {{/each}}
{{/if}} diff --git a/templates/PortableInfoboxItemTitle.hbs b/templates/PortableInfoboxItemTitle.hbs index 6f3f27c..8df25c8 100644 --- a/templates/PortableInfoboxItemTitle.hbs +++ b/templates/PortableInfoboxItemTitle.hbs @@ -1 +1 @@ -

{{{value}}}

\ No newline at end of file +<{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-item-spacing pi-title"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}} \ No newline at end of file