You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
<?php
|
|
namespace Isekai\Widgets;
|
|
|
|
use MediaWiki\Title\Title;
|
|
use MediaWiki\Parser\Parser;
|
|
use MediaWiki\Html\Html;
|
|
use PPFrame;
|
|
|
|
class ButtonLinkWidget {
|
|
/**
|
|
* @param string $text
|
|
* @param array $params
|
|
* @param Parser $parser
|
|
* @param PPFrame $frame
|
|
* @return string|string[]
|
|
*/
|
|
public static function create($text, $params, Parser $parser, PPFrame $frame) {
|
|
$out = $parser->getOutput();
|
|
$out->addModules([
|
|
"oojs-ui-core"
|
|
]);
|
|
|
|
if (!empty($params['page'])) {
|
|
$title = Title::newFromText($params['page']);
|
|
if ($title) {
|
|
$params['href'] = $title->getLocalURL();
|
|
}
|
|
}
|
|
|
|
$framed = true;
|
|
if (!empty($params['frameless']) && $params['frameless']) {
|
|
$framed = false;
|
|
}
|
|
|
|
$flags = [];
|
|
|
|
$primary = true;
|
|
$type = 'progressive';
|
|
|
|
if (!empty($params['type'])) {
|
|
switch ($params['type']) {
|
|
case 'progressive':
|
|
// default style
|
|
break;
|
|
case 'default':
|
|
$primary = false;
|
|
$type = null;
|
|
break;
|
|
case 'secondary':
|
|
$primary = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!empty($params['destructive']) && $params['destructive']) {
|
|
$flags[] = 'destructive';
|
|
}
|
|
|
|
if ($primary) {
|
|
$flags[] = 'primary';
|
|
}
|
|
if ($type) {
|
|
$flags[] = $type;
|
|
}
|
|
|
|
$classList = ['oo-ui-widget', 'oo-ui-widget-enabled', 'oo-ui-buttonElement', 'oo-ui-labelElement', 'oo-ui-buttonWidget'];
|
|
|
|
if ($framed) {
|
|
$classList[] = 'oo-ui-buttonElement-framed';
|
|
} else {
|
|
$classList[] = 'oo-ui-buttonElement-frameless';
|
|
}
|
|
|
|
foreach ($flags as $flag) {
|
|
$classList[] = 'oo-ui-flaggedElement-' . $flag;
|
|
}
|
|
|
|
$html = Html::rawElement('span', ['class' => implode(' ', $classList)],
|
|
Html::rawElement('a', [
|
|
'class' => 'oo-ui-buttonElement-button',
|
|
'role' => 'button',
|
|
'tabindex' => '0',
|
|
'href' => $params['href'] ?? '#',
|
|
'target' => $params['target'] ?? '_self',
|
|
'rel' => 'nofollow'
|
|
],
|
|
Html::element('span', ['class' => 'oo-ui-iconElement-icon oo-ui-iconElement-noIcon']) .
|
|
Html::element('span', ['class' => 'oo-ui-labelElement-label'], $text) .
|
|
Html::element('span', ['class' => 'oo-ui-indicatorElement-indicator oo-ui-indicatorElement-noIndicator'])
|
|
)
|
|
);
|
|
|
|
return [$html, "markerType" => 'nowiki'];
|
|
}
|
|
} |