Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249453
Change subject: Implement <icon> tag in wikitext for OOjs UI icons
......................................................................
Implement <icon> tag in wikitext for OOjs UI icons
Bug: T101666
Change-Id: I29e876c768819413bf31499f067d545732e591b0
---
M includes/parser/CoreTagHooks.php
1 file changed, 45 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/53/249453/1
diff --git a/includes/parser/CoreTagHooks.php b/includes/parser/CoreTagHooks.php
index 59b4391..497c852 100644
--- a/includes/parser/CoreTagHooks.php
+++ b/includes/parser/CoreTagHooks.php
@@ -37,6 +37,7 @@
$parser->setHook( 'gallery', array( __CLASS__, 'gallery' ) );
$parser->setHook( 'indicator', array( __CLASS__, 'indicator' )
);
$parser->setHook( 'button', array( __CLASS__, 'button' ) );
+ $parser->setHook( 'icon', array( __CLASS__, 'icon' ) );
if ( $wgRawHtml ) {
$parser->setHook( 'html', array( __CLASS__, 'html' ) );
}
@@ -239,4 +240,48 @@
// Prevent further parsing
return array( $button, 'markerType' => 'nowiki' );
}
+
+ /**
+ * XML-style tag for OOjs UI icons.
+ *
+ * @param string $content Icon name
+ * @param array $attributes
+ * - `title`: icon tooltip for accessibility
+ * - `size`: size multiplier
+ * @param Parser $parser
+ * @param PPFrame $frame
+ * @return string
+ * @since 1.27
+ */
+public static function icon( $content, array $attributes, Parser $parser,
PPFrame $frame ) {
+ $parser->enableOOUI();
+
+ $config = array();
+
+ if ( $content ) {
+ // TODO Validate and load required additional modules
+ $config['icon'] = $content;
+ } else {
+ return '<span class="error">' .
+ wfMessage( 'tag-icon-must-have-content'
)->inContentLanguage()->parse() .
+ '</span>';
+ }
+
+ if ( isset( $attributes['title'] ) ) {
+ $config['title'] = $attributes['title'];
+ }
+
+ $icon = new OOUI\IconWidget( $config );
+ $icon = $icon->toString();
+ // Prevent Tidy from removing empty <span> tags (used to
display the icon)
+ $icon = str_replace( '></span>', '><!-- --></span>', $icon );
+
+ if ( isset( $attributes['size'] ) ) {
+ $size = floatval( $attributes['size'] ) * 100;
+ $icon = "<span style=\"font-size:
$size%;\">$icon</span>";
+ }
+
+ // Prevent further parsing
+ return array( $icon, 'markerType' => 'nowiki' );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/249453
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I29e876c768819413bf31499f067d545732e591b0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits