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.
64 lines
2.4 KiB
PHTML
64 lines
2.4 KiB
PHTML
2 years ago
|
<?php
|
||
|
|
||
|
namespace Isekai\UserPoints;
|
||
|
|
||
|
use DatabaseUpdater;
|
||
|
use MediaWiki\MediaWikiServices;
|
||
|
use OutputPage;
|
||
|
use Skin;
|
||
|
use User;
|
||
|
|
||
|
class Hooks {
|
||
|
/**
|
||
|
* Implements LoadExtensionSchemaUpdates hook.
|
||
|
*
|
||
|
* @param \DatabaseUpdater $updater
|
||
|
*/
|
||
|
public static function onLoadExtensionSchemaUpdates($updater) {
|
||
|
$dir = dirname(__DIR__) . '/sql/';
|
||
|
$type = $updater->getDB()->getType();
|
||
|
$updater->addExtensionTable('isekai_user_daily_sign', $dir . $type . '/isekai_user_daily_sign.sql');
|
||
|
$updater->addExtensionTable('isekai_user_daily_sign_log', $dir . $type . '/isekai_user_daily_sign_log.sql');
|
||
|
$updater->addExtensionTable('isekai_user_points', $dir . $type . '/isekai_user_points.sql');
|
||
|
$updater->addExtensionTable('isekai_user_points_log', $dir . $type . '/isekai_user_points_log.sql');
|
||
|
}
|
||
|
|
||
|
public static function onBeforePageDisplay(OutputPage $out, Skin $skin) {
|
||
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
||
|
|
||
|
$out->addModuleStyles(['ext.isekai.userpoints.base']);
|
||
|
|
||
|
$dailySignConfig = $config->get('IsekaiUserDailySignConfig');
|
||
|
if ($dailySignConfig) {
|
||
|
$out->addModules(['ext.isekai.userpoints.dailysign']);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static function onGetPreferences(User $user, &$preferences) {
|
||
|
$config = MediaWikiServices::getInstance()->getMainConfig();
|
||
|
if ($config->get('IsekaiUserPointShowOnUserPerferences')) {
|
||
|
$userPointConfig = $config->get('IsekaiUserPointConfig');
|
||
|
|
||
|
/** @var \Isekai\UserPoints\Service\IsekaiUserPointsFactory */
|
||
|
$userPointsFactory = MediaWikiServices::getInstance()->getService('IsekaiUserPoints');
|
||
|
|
||
|
foreach ($userPointConfig as $pointType => $pointConfig) {
|
||
|
$userPoints = $userPointsFactory->newFromUser($user, $pointType);
|
||
|
|
||
|
$icon = Utils::getPointIcon($pointType);
|
||
|
$name = Utils::getPointName($pointType);
|
||
|
|
||
|
$language = MediaWikiServices::getInstance()->getContentLanguage();
|
||
|
|
||
|
$preferences['isekai-userpoints-' . $pointType] = [
|
||
|
'type' => 'text',
|
||
|
'label-raw' => $icon . ' ' . $name,
|
||
|
'default' => $language->formatNum($userPoints->points),
|
||
|
'section' => 'personal/info',
|
||
|
'raw' => true,
|
||
|
];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|