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.
80 lines
3.1 KiB
PHP
80 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Isekai\UserPoints\Quests;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\Session\SessionManager;
|
|
use OutputPage;
|
|
|
|
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_quests_record', $dir . $type . '/isekai_user_quests_record.sql');
|
|
}
|
|
|
|
/**
|
|
* @param \WikiPage $wikiPage
|
|
* @param \MediaWiki\User\UserIdentity $user
|
|
* @param string $summary
|
|
* @param int $flags
|
|
* @param \MediaWiki\Revision\RevisionRecord $revisionRecord
|
|
* @param \MediaWiki\Storage\EditResult $editResult
|
|
*/
|
|
public static function onPageSaveComplete($wikiPage, $user, $summary, $flags, $revisionRecord, $editResult) {
|
|
wfDebugLog('IsekaiQuests', 'onPageSaveComplete');
|
|
$services = MediaWikiServices::getInstance();
|
|
$config = $services->getMainConfig();
|
|
|
|
$questsConfig = $config->get('IsekaiQuestsConfig');
|
|
|
|
$allowedNamespaces = [NS_MAIN, NS_CATEGORY, NS_TEMPLATE, NS_HELP];
|
|
|
|
if (in_array($wikiPage->getNamespace(), $allowedNamespaces)) {
|
|
if ($flags & EDIT_NEW && isset($questsConfig['new'])) {
|
|
// 新建页面
|
|
$questConfig = $questsConfig['new'];
|
|
|
|
$questRes = QuestsUtils::onQuestComplete($user, 'new', $questConfig);
|
|
wfDebugLog('IsekaiQuests', 'quest finished: ', var_export($questRes, true));
|
|
if ($questRes) {
|
|
QuestsUtils::setQuestCompleteNotification('new', $questRes['deltaPoints'], $questRes['completeNum'], $questConfig);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// 如果新建页面的任务次数已满,则作为编辑页面处理
|
|
if ($flags & EDIT_UPDATE && isset($questsConfig['edit'])) {
|
|
// 编辑页面
|
|
$questConfig = $questsConfig['edit'];
|
|
|
|
$questRes = QuestsUtils::onQuestComplete($user, 'edit', $questConfig);
|
|
wfDebugLog('IsekaiQuests', 'quest finished: ', var_export($questRes, true));
|
|
if ($questRes) {
|
|
QuestsUtils::setQuestCompleteNotification('edit', $questRes['deltaPoints'], $questRes['completeNum'], $questConfig);
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static function onBeforePageDisplay(OutputPage $out, $skin) {
|
|
$out->addModules(['ext.isekai.userpoints.quests.notification']);
|
|
|
|
$sessionManager = SessionManager::getGlobalSession();
|
|
if ($sessionManager->exists(QuestsUtils::SESSION_KEY_QUEST_COMPLETE_NOTIFICATION)) {
|
|
$out->addJsConfigVars([
|
|
'wgIsekaiQuestsCompleteNotification' => $sessionManager->get(QuestsUtils::SESSION_KEY_QUEST_COMPLETE_NOTIFICATION),
|
|
]);
|
|
$sessionManager->remove(QuestsUtils::SESSION_KEY_QUEST_COMPLETE_NOTIFICATION);
|
|
}
|
|
}
|
|
}
|