diff --git a/extension.json b/extension.json index b06198e..ddf7ab1 100644 --- a/extension.json +++ b/extension.json @@ -1,105 +1,105 @@ -{ - "name": "Isekai User Points", - "namemsg": "isekai-userpoints", - "author": "Hyperzlib", - "version": "1.0.0", - "url": "https://git.isekai.cn/Isekai-Project/mediawiki-extension-IsekaiUserPoints", - "descriptionmsg": "isekai-userpoints-desc", - "license-name": "GPL-2.0-or-later", - "type": "api", - "requires": { - "MediaWiki": ">= 1.35.0" - }, - "MessagesDirs": { - "IsekaiUserPoints": [ - "i18n" - ] - }, - "ExtensionMessagesFiles": { - "IsekaiUserPointsAlias": "IsekaiUserPoints.alias.php" - }, - "AutoloadNamespaces": { - "Isekai\\UserPoints\\": "includes" - }, - "Hooks": { - "LoadExtensionSchemaUpdates": "Isekai\\UserPoints\\Hooks::onLoadExtensionSchemaUpdates", - "BeforePageDisplay": "Isekai\\UserPoints\\Hooks::onBeforePageDisplay", - "GetPreferences": "Isekai\\UserPoints\\Hooks::onGetPreferences" - }, - "APIModules": { - "userdailysign": "Isekai\\UserPoints\\Api\\ApiUserDailySign" - }, - "APIPropModules": { - "userpoints": "Isekai\\UserPoints\\Api\\ApiQueryUserPoints", - "pointinfo": "Isekai\\UserPoints\\Api\\ApiQueryPointInfo" - }, - "APIListModules": { - "userspoints": "Isekai\\UserPoints\\Api\\ApiQueryUsersPoints" - }, - "ServiceWiringFiles": [ - "IsekaiUserPoints.services.php" - ], - "GroupPermissions": { - "bureaucrat": { - "queryuserpoints": true, - "edituserpoints": true - }, - "suppress": { - "queryuserpoints": true, - "edituserpoints": true - }, - "sysop": { - "queryuserpoints": true, - "edituserpoints": true - } - }, - "GrantPermissions": { - "userpointsmanager": { - "queryuserpoints": true, - "edituserpoints": true - } - }, - "ResourceModules": { - "ext.isekai.userpoints.base": { - "styles": ["ext.isekai.userpoints.base.less"] - }, - "ext.isekai.userpoints.dailysign": { - "scripts": ["ext.isekai.userpoints.dailysign.js"], - "messages": [ - "comma-separator", - "isekai-userpoints-point-name-num", - "isekai-userpoints-dailysign-notify-title", - "isekai-userpoints-dailysign-notify-success" - ] - } - }, - "ResourceFileModulePaths": { - "localBasePath": "modules", - "remoteExtPath": "IsekaiUserPoints/modules" - }, - "config": { - "IsekaiUserPointConfig": { - "value": { - "exp": { - "name": "Exp.", - "namemsg": "isekai-userpoints-point-name-exp", - "icon": { - "normal": { - "image": "https://static.isekai.dev/isekaiwiki/isekaiwiki-exp.png" - }, - "invert": { - "image": "https://static.isekai.dev/isekaiwiki/isekaiwiki-exp-invert.png" - } - } - } - } - }, - "IsekaiUserPointShowOnUserPerferences": { - "value": true - }, - "IsekaiUserDailySignConfig": { - "value": null - } - }, - "manifest_version": 2 +{ + "name": "Isekai User Points", + "namemsg": "isekai-userpoints", + "author": "Hyperzlib", + "version": "1.0.0", + "url": "https://git.isekai.cn/Isekai-Project/mediawiki-extension-IsekaiUserPoints", + "descriptionmsg": "isekai-userpoints-desc", + "license-name": "GPL-2.0-or-later", + "type": "api", + "requires": { + "MediaWiki": ">= 1.35.0" + }, + "MessagesDirs": { + "IsekaiUserPoints": [ + "i18n" + ] + }, + "ExtensionMessagesFiles": { + "IsekaiUserPointsAlias": "IsekaiUserPoints.alias.php" + }, + "AutoloadNamespaces": { + "Isekai\\UserPoints\\": "includes" + }, + "Hooks": { + "LoadExtensionSchemaUpdates": "Isekai\\UserPoints\\Hooks::onLoadExtensionSchemaUpdates", + "BeforePageDisplay": "Isekai\\UserPoints\\Hooks::onBeforePageDisplay", + "GetPreferences": "Isekai\\UserPoints\\Hooks::onGetPreferences" + }, + "APIModules": { + "userdailysign": "Isekai\\UserPoints\\Api\\ApiUserDailySign" + }, + "APIPropModules": { + "userpoints": "Isekai\\UserPoints\\Api\\ApiQueryUserPoints", + "pointinfo": "Isekai\\UserPoints\\Api\\ApiQueryPointInfo" + }, + "APIListModules": { + "userspoints": "Isekai\\UserPoints\\Api\\ApiQueryUsersPoints" + }, + "ServiceWiringFiles": [ + "IsekaiUserPoints.services.php" + ], + "GroupPermissions": { + "bureaucrat": { + "queryuserpoints": true, + "edituserpoints": true + }, + "suppress": { + "queryuserpoints": true, + "edituserpoints": true + }, + "sysop": { + "queryuserpoints": true, + "edituserpoints": true + } + }, + "GrantPermissions": { + "userpointsmanager": { + "queryuserpoints": true, + "edituserpoints": true + } + }, + "ResourceModules": { + "ext.isekai.userpoints.base": { + "styles": ["ext.isekai.userpoints.base.less"] + }, + "ext.isekai.userpoints.dailysign": { + "scripts": ["ext.isekai.userpoints.dailysign.js"], + "messages": [ + "comma-separator", + "isekai-userpoints-point-name-num", + "isekai-userpoints-dailysign-notify-title", + "isekai-userpoints-dailysign-notify-success" + ] + } + }, + "ResourceFileModulePaths": { + "localBasePath": "modules", + "remoteExtPath": "IsekaiUserPoints/modules" + }, + "config": { + "IsekaiUserPointConfig": { + "value": { + "exp": { + "name": "Exp.", + "namemsg": "isekai-userpoints-point-name-exp", + "icon": { + "normal": { + "image": "https://static.isekai.dev/isekaiwiki/isekaiwiki-exp.png" + }, + "invert": { + "image": "https://static.isekai.dev/isekaiwiki/isekaiwiki-exp-invert.png" + } + } + } + } + }, + "IsekaiUserPointShowOnUserPerferences": { + "value": true + }, + "IsekaiUserDailySignConfig": { + "value": null + } + }, + "manifest_version": 2 } \ No newline at end of file diff --git a/includes/Hooks.php b/includes/Hooks.php index cfd33b8..5c2362b 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -24,10 +24,12 @@ class Hooks { } public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { + $user = $out->getUser(); + $config = MediaWikiServices::getInstance()->getMainConfig(); $out->addModuleStyles(['ext.isekai.userpoints.base']); - + $dailySignConfig = $config->get('IsekaiUserDailySignConfig'); if ($dailySignConfig) { $out->addModules(['ext.isekai.userpoints.dailysign']); diff --git a/includes/Service/IsekaiUserPoints.php b/includes/Service/IsekaiUserPoints.php index ed10953..dd64cce 100644 --- a/includes/Service/IsekaiUserPoints.php +++ b/includes/Service/IsekaiUserPoints.php @@ -1,6 +1,7 @@ Utils::getPointName($this->type), + 'icon' => Utils::getPointIcon($this->type), + ]; + } + /** * Save point data */ diff --git a/modules/ext.isekai.userpoints.dailysign.js b/modules/ext.isekai.userpoints.dailysign.js index c25f6c6..0bfef71 100644 --- a/modules/ext.isekai.userpoints.dailysign.js +++ b/modules/ext.isekai.userpoints.dailysign.js @@ -1,43 +1,45 @@ $(function() { - const storeKey = 'isekai-userpoints-dailysign-lastSignDate'; - const lastSignDate = localStorage.getItem(storeKey); - const today = new Date().toLocaleDateString(); - if (lastSignDate !== today) { - let mwApi = new mw.Api(); - mwApi.postWithToken('csrf', { - action: 'userdailysign', - }).done(function(data) { - if (data.userdailysign && data.userdailysign.success) { - if (Array.isArray(data.userdailysign.point_delta)) { - const pointDelta = data.userdailysign.point_delta; - let pointMsgList = []; - pointDelta.forEach(function (pointDeltaInfo) { - let msg = mw.msg('isekai-userpoints-point-name-num', pointDeltaInfo.name, pointDeltaInfo.icon, pointDeltaInfo.points); - pointMsgList.push(msg); - }); - let separator = mw.msg('comma-separator'); - let pointMsg = pointMsgList.join(separator); + if (!mw.user.isAnon()) { + const storeKey = 'isekai-userpoints-dailysign-lastSignDate'; + const lastSignDate = localStorage.getItem(storeKey); + const today = new Date().toLocaleDateString(); + if (lastSignDate !== today) { + let mwApi = new mw.Api(); + mwApi.postWithToken('csrf', { + action: 'userdailysign', + }).done(function(data) { + if (data.userdailysign && data.userdailysign.success) { + if (Array.isArray(data.userdailysign.point_delta)) { + const pointDelta = data.userdailysign.point_delta; + let pointMsgList = []; + pointDelta.forEach(function (pointDeltaInfo) { + let msg = mw.msg('isekai-userpoints-point-name-num', pointDeltaInfo.name, pointDeltaInfo.icon, pointDeltaInfo.points); + pointMsgList.push(msg); + }); + let separator = mw.msg('comma-separator'); + let pointMsg = pointMsgList.join(separator); - let notificationMsg = mw.msg('isekai-userpoints-dailysign-notify-success', pointMsg); - mw.notify('', { - title: mw.msg('isekai-userpoints-dailysign-notify-title'), - tag: 'isekai-userpoints-dailysign', - id: 'isekai-userpoints-dailysign-notify', - }); + let notificationMsg = mw.msg('isekai-userpoints-dailysign-notify-success', pointMsg); + mw.notify('', { + title: mw.msg('isekai-userpoints-dailysign-notify-title'), + tag: 'isekai-userpoints-dailysign', + id: 'isekai-userpoints-dailysign-notify', + }); - function changeNotifyContent() { - let notifyDom = document.querySelector('#isekai-userpoints-dailysign-notify'); - if (notifyDom) { - notifyDom.querySelector('.mw-notification-content').innerHTML = notificationMsg; - } else { - requestAnimationFrame(changeNotifyContent); + function changeNotifyContent() { + let notifyDom = document.querySelector('#isekai-userpoints-dailysign-notify'); + if (notifyDom) { + notifyDom.querySelector('.mw-notification-content').innerHTML = notificationMsg; + } else { + requestAnimationFrame(changeNotifyContent); + } } - } - changeNotifyContent(); + changeNotifyContent(); + } + localStorage.setItem(storeKey, today); } - localStorage.setItem(storeKey, today); - } - }); + }); + } } }); \ No newline at end of file diff --git a/sql/mysql/isekai_user_daily_sign_log.sql b/sql/mysql/isekai_user_daily_sign_log.sql index 34417d7..620a3c6 100644 --- a/sql/mysql/isekai_user_daily_sign_log.sql +++ b/sql/mysql/isekai_user_daily_sign_log.sql @@ -4,7 +4,7 @@ CREATE TABLE /*_*/isekai_user_daily_sign_log ( `month` INT UNSIGNED NOT NULL, `sign_log` LONGTEXT NOT NULL ) /*$wgDBTableOptions*/; -ALTER TABLE /*_*/isekai_user_daily_sign_log ADD PRIMARY KEY (`user_id`); -ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`user_id`, `year`, `month`); +ALTER TABLE /*_*/isekai_user_daily_sign_log ADD PRIMARY KEY (`user_id`, `year`, `month`); +ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`user_id`); ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`year`); ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`month`); \ No newline at end of file diff --git a/sql/postgres/isekai_user_daily_sign_log.sql b/sql/postgres/isekai_user_daily_sign_log.sql index a17120d..32ce960 100644 --- a/sql/postgres/isekai_user_daily_sign_log.sql +++ b/sql/postgres/isekai_user_daily_sign_log.sql @@ -4,7 +4,7 @@ CREATE TABLE isekai_user_daily_sign_log ( month INT NOT NULL, sign_log JSON NOT NULL ); -ALTER TABLE isekai_user_daily_sign_log ADD PRIMARY KEY (user_id); -ALTER TABLE isekai_user_daily_sign_log ADD INDEX(user_id, year, month); +ALTER TABLE isekai_user_daily_sign_log ADD PRIMARY KEY (user_id, year, month); +ALTER TABLE isekai_user_daily_sign_log ADD INDEX(user_id); ALTER TABLE isekai_user_daily_sign_log ADD INDEX(year); ALTER TABLE isekai_user_daily_sign_log ADD INDEX(month); \ No newline at end of file