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.

74 lines
2.7 KiB
PHTML

2 years ago
<?php
namespace Isekai\UserPoints;
use DatabaseUpdater;
use DateTime;
use DateTimeZone;
2 years ago
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) {
$user = $out->getUser();
2 years ago
$config = MediaWikiServices::getInstance()->getMainConfig();
$out->addModuleStyles(['ext.isekai.userpoints.base']);
2 years ago
$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' => 'info',
2 years ago
'label-raw' => $icon . ' ' . $name,
'default' => $language->formatNum($userPoints->points),
'section' => 'personal/info',
'raw' => true,
];
}
}
}
public static function onResourceLoaderGetConfigVars(array &$vars) {
$defaultTimezone = date_default_timezone_get();
$tzInfo = new DateTimeZone($defaultTimezone);
$vars['wgTimezoneOffsetMinutes'] = $tzInfo->getOffset(new DateTime()) / 60;
}
2 years ago
}