Add an option to use divs instead of headings in PI output

This commit is contained in:
Luqgreg 2018-09-22 15:31:32 +02:00
parent 9ba2e5e971
commit a5f5619b4d
6 changed files with 17 additions and 7 deletions

View file

@ -16,6 +16,7 @@
"AllInfoboxesMiserMode": true, "AllInfoboxesMiserMode": true,
"AllInfoboxesSubpagesBlacklist": [ "doc", "draft", "test" ], "AllInfoboxesSubpagesBlacklist": [ "doc", "draft", "test" ],
"PortableInfoboxCustomImageWidth": 300, "PortableInfoboxCustomImageWidth": 300,
"PortableInfoboxUseHeadings": true,
"PortableInfoboxUseTidy": true "PortableInfoboxUseTidy": true
}, },
"MessagesDirs": { "MessagesDirs": {

View file

@ -40,6 +40,9 @@ class PortableInfoboxTemplateEngine {
} }
public function render( $type, array $data ) { public function render( $type, array $data ) {
global $wgPortableInfoboxUseHeadings;
$data['useHeadings'] = $wgPortableInfoboxUseHeadings;
$renderer = $this->getRenderer( $type ); $renderer = $this->getRenderer( $type );
return $renderer( $data ); return $renderer( $data );
} }
@ -55,7 +58,11 @@ class PortableInfoboxTemplateEngine {
return self::$cache[$type]; 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 // @see https://github.com/wikimedia/mediawiki-vendor/tree/master/zordius/lightncandy
$renderer = \LightnCandy::prepare( $renderer = \LightnCandy::prepare(
@ -63,7 +70,7 @@ class PortableInfoboxTemplateEngine {
$path = self::getTemplatesDir() . DIRECTORY_SEPARATOR . static::getTemplates()[$type]; $path = self::getTemplatesDir() . DIRECTORY_SEPARATOR . static::getTemplates()[$type];
return \LightnCandy::compile( file_get_contents( $path ), [ 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 ) { public static function isSupportedType( $type ) {
$result = isset( static::getTemplates()[$type] ); $result = isset( static::getTemplates()[$type] );
if ( !$result ) { 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; return $result;
} }

View file

@ -1,6 +1,6 @@
<div class="pi-item pi-data pi-item-spacing pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}> <div class="pi-item pi-data pi-item-spacing pi-border-color{{#if cssClasses}} {{{cssClasses}}}{{/if}}"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>
{{#if label}} {{#if label}}
<h3 class="pi-data-label pi-secondary-font">{{{label}}}</h3> <{{#if useHeadings}}h3{{else}}div{{/if}} class="pi-data-label pi-secondary-font">{{{label}}}</{{#if useHeadings}}h3{{else}}div{{/if}}>
{{/if}} {{/if}}
<div class="pi-data-value pi-font">{{{value}}}</div> <div class="pi-data-value pi-font">{{{value}}}</div>
</div> </div>

View file

@ -1 +1 @@
<h2 class="pi-item pi-header pi-secondary-font pi-item-spacing pi-secondary-background"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</h2> <{{#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}}}</{{#if useHeadings}}h2{{else}}div{{/if}}>

View file

@ -2,7 +2,7 @@
{{#if renderLabels}} {{#if renderLabels}}
<section class="pi-smart-group-head"> <section class="pi-smart-group-head">
{{#each labels}} {{#each labels}}
<h3 class="pi-smart-data-label pi-data-label pi-secondary-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}}</h3> <{{#if ../useHeadings}}h3{{else}}div{{/if}} class="pi-smart-data-label pi-data-label pi-secondary-font pi-item-spacing" style="{{{inlineStyles}}}">{{{value}}}</{{#if ../useHeadings}}h3{{else}}div{{/if}}>
{{/each}} {{/each}}
</section> </section>
{{/if}} {{/if}}

View file

@ -1 +1 @@
<h2 class="pi-item pi-item-spacing pi-title"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</h2> <{{#if useHeadings}}h2{{else}}div{{/if}} class="pi-item pi-item-spacing pi-title"{{#if inlineStyles}} style="{{inlineStyles}}"{{/if}}>{{{value}}}</{{#if useHeadings}}h2{{else}}div{{/if}}>