diff --git a/extension.json b/extension.json index 29bf838ea5b6c28cdc2f684d375154c20708c26e..2cf4bb736c195c70cec00b057f4c9c1652917a75 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "Deliberation", - "version": "0.2.0", + "version": "0.2.1", "author": [ "Open Tech Strategies" ], @@ -44,6 +44,7 @@ "DeliberationSummary": "includes/specials/DeliberationSummary.php", "DeliberationHooks": "includes/DeliberationHooks.php", "DeliberationWidgetTemplate": "includes/templates/DeliberationWidgetTemplate.php", + "DeliberationDelete": "includes/api/DeliberationDelete.php", "DeliberationWrite": "includes/api/DeliberationWrite.php" }, "ResourceFileModulePaths": { @@ -53,13 +54,11 @@ "ParserFirstCallInit": "DeliberationHooks::onParserFirstCallInit", "LoadExtensionSchemaUpdates": "DeliberationHooks::onLoadExtensionSchemaUpdates" }, - "DeliberationWrite": { - "deliberationwrite": "DeliberationWrite" - }, "config": { "DeliberationChoices": false }, "APIModules": { + "deliberationdelete": "DeliberationDelete", "deliberationwrite": "DeliberationWrite" }, "manifest_version": 1, diff --git a/i18n/en.json b/i18n/en.json index 8fe5f0e1421d5e26e6484e03151fbdddfd4c8fd7..1a6b4b8d75c63b993ef7be8d867482243e2bc59a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -8,6 +8,7 @@ "deliberation-desc": "Specialized Extension to choose pages for purposes of voting", "deliberation-choose": "Choose", "deliberation-reject": "Reject", + "deliberation-reset": "Reset", "deliberationsummary": "Deliberation Summary", "deliberationsummary-allpages": "All Pages" } diff --git a/includes/Deliberation.php b/includes/Deliberation.php index f8f53abeaa311a7e5abb294d8242a07a775f1996..10d6d9c2ad4f573bf17ea67bc6c782fbee29748b 100644 --- a/includes/Deliberation.php +++ b/includes/Deliberation.php @@ -15,6 +15,18 @@ class Deliberation { } } + public static function remove($user, $title) { + // No deliberation on special pages!! + if($title->getArticleID() != 0) { + $lb = \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancer(); + $dbw = $lb->getConnectionRef(DB_MASTER); + $dbw->delete("Deliberation", [ + 'page_id' => $title->getArticleID(), + 'user_id' => $user->getId(), + ]); + } + } + public static function limitHit($user, $value) { $limit = false; foreach(Self::getConfiguredChoices() as $choice) { diff --git a/includes/api/DeliberationDelete.php b/includes/api/DeliberationDelete.php new file mode 100644 index 0000000000000000000000000000000000000000..bf49e2de778f9bd10092a3ab908c2cb4a94b45f0 --- /dev/null +++ b/includes/api/DeliberationDelete.php @@ -0,0 +1,28 @@ +<?php +class DeliberationDelete extends APIBase { + public function __construct($main, $action) { + parent::__construct($main, $action); + } + + public function execute() { + parent::checkUserRightsAny(["deliberation-write"]); + $user = $this->getUser(); + $title = Title::newFromText($this->getParameter('title')); + + Deliberation::remove($user, $title); + } + + public function mustBePosted() { + return true; + } + + public function getAllowedParams() { + return [ + "title" => [ + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => 'true' + ] + ]; + } +} +?> diff --git a/includes/templates/DeliberationWidgetTemplate.php b/includes/templates/DeliberationWidgetTemplate.php index 1586b8b5f0a8089b5922bee19cc08583f50c3be6..c1f838c1f5433fa8384a240371e09f1c4c9bc275 100644 --- a/includes/templates/DeliberationWidgetTemplate.php +++ b/includes/templates/DeliberationWidgetTemplate.php @@ -27,6 +27,9 @@ class DeliberationWidgetTemplate extends QuickTemplate { } ?> </ul> +<div class="deliberation-reset"> +<a href="#" class="reset-link"><?php echo wfMessage("deliberation-reset");?></span> +</div> </div> <hr> <?php diff --git a/resources/js/deliberation.js b/resources/js/deliberation.js index a9aed087bcaff999cca9643a05a76346ab6b6fb5..554fe67852214d1433783ae3a8924a2b60dbb1ea 100644 --- a/resources/js/deliberation.js +++ b/resources/js/deliberation.js @@ -1,7 +1,7 @@ (function ($, mw) { $(function() { + var api = new mw.Api(); $(".deliberation input").change(function(e) { - var api = new mw.Api(); var elem = $(this); api.post({ action: "deliberationwrite", @@ -9,6 +9,14 @@ title: mw.config.values.wgTitle }); }); + $(".deliberation a.reset-link").click(function(e) { + $(".deliberation input").prop("checked", false); + api.post({ + action: "deliberationdelete", + title: mw.config.values.wgTitle + }); + return false; + }); }); }(jQuery, mediaWiki));