type = $type;
$this->language = $language;
}
/**
* @since 1.9
*
* @param string|int $type
* @param string|null $language
*
* @return Highlighter
*/
public static function factory( $type, $language = null ) {
if ( $type === '' || !is_int( $type ) ) {
$type = self::getTypeId( $type );
}
return new Highlighter( $type, $language );
}
/**
* @since 3.0
*
* @param string $text
* @param string|null $type
*
* @return bool
*/
public static function hasHighlighterClass( $text, $type = null ) {
if ( strpos( $text, 'smw-highlighter' ) === false ) {
return false;
}
if ( $type !== null ) {
return strpos( $text, 'data-type="' . self::getTypeId( $type ) . '"' ) !== false;
}
return true;
}
/**
* @since 3.0
*
* @param string $text
*
* @return string
*/
public static function decode( $text ) {
// #2347, '[' is handled by the MediaWiki parser/sanitizer itself
return str_replace(
[ '&', '<', '>', ' ', '
elements etc.) // hence encode the identifying > and decode it within the // tooltip str_replace( [ "\n", '<', '>' ], [ '', '<', '>' ], htmlspecialchars_decode( $this->options['content'] ?? '' ) ) ) ); return $html; } /** * Returns initial configuration settings * * @note You could create a class per entity type but does this * really make sense just to get some configuration parameters? * * @since 1.9 * * @param string $type * * @return array */ private function getTypeConfiguration( $type ) { $settings = []; $settings['type'] = $type; $settings['caption'] = ''; $settings['content'] = ''; switch ( $type ) { case self::TYPE_PROPERTY: $settings['state'] = 'inline'; $settings['title'] = 'smw-ui-tooltip-title-property'; $settings['captionclass'] = 'smwbuiltin'; break; case self::TYPE_TEXT: $settings['state'] = 'persistent'; $settings['title'] = 'smw-ui-tooltip-title-info'; $settings['captionclass'] = 'smwtext'; break; case self::TYPE_QUANTITY: $settings['state'] = 'inline'; $settings['title'] = 'smw-ui-tooltip-title-quantity'; $settings['captionclass'] = 'smwtext'; break; case self::TYPE_NOTE: $settings['state'] = 'inline'; $settings['title'] = 'smw-ui-tooltip-title-note'; $settings['captionclass'] = 'smwtticon note'; break; case self::TYPE_WARNING: $settings['state'] = 'inline'; $settings['title'] = 'smw-ui-tooltip-title-warning'; $settings['captionclass'] = 'smwtticon warning'; break; case self::TYPE_ERROR: $settings['state'] = 'inline'; $settings['title'] = 'smw-ui-tooltip-title-error'; $settings['captionclass'] = 'smwtticon error'; break; case self::TYPE_SERVICE: $settings['state'] = 'persistent'; $settings['title'] = 'smw-ui-tooltip-title-service'; $settings['captionclass'] = 'smwtticon service'; break; case self::TYPE_REFERENCE: $settings['state'] = 'persistent'; $settings['title'] = 'smw-ui-tooltip-title-reference'; $settings['captionclass'] = 'smwtext'; break; case self::TYPE_HELP: case self::TYPE_INFO: $settings['state'] = 'persistent'; $settings['title'] = 'smw-ui-tooltip-title-info'; $settings['captionclass'] = 'smwtticon info'; break; case self::TYPE_NOTYPE: default: $settings['state'] = 'persistent'; $settings['title'] = 'smw-ui-tooltip-title-info'; $settings['captionclass'] = 'smwbuiltin'; } return $settings; } private function title( $content, $language ) { // Pre-process the content when used as title to avoid breaking elements // (URLs etc.) $content = $content ?? ''; if ( strpos( $content, '[' ) !== false || strpos( $content, '//' ) !== false ) { $content = Message::get( [ 'smw-parse', $content ], Message::PARSE, $language ); } return strip_tags( htmlspecialchars_decode( str_replace( [ "[", ' ', " ", "\n", "'", "'" ], [ "[", ' ', '', '', '' ], $content ?? '' ), ) ); } }