diff --git a/README.md b/README.md index a8f74da..6c2257d 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,40 @@ -# Extension:PickSome +# Extension: Deliberation -The PickSome extension all users to pick pages that show up in a global -PickSome list on the Special:PickSome page. +The Deliberation extension all users to pick pages that show up in a global +Deliberatiion list on the Special:Deliberation page. ## Installation -* Download and place the file(s) in a directory called PickSome in your extensions/ folder +* Download and place the file(s) in a directory called Deliberation in your extensions/ folder * Add the following line to your LocalSettings.php ``` -wfLoadExtension('PickSome'); +wfLoadExtension('Deliberation'); ``` * Run the update script `php /maintenance/update.php` to create the DB tables ## Usage -For logged in users, can enable PickSome by clicking "Start Picking" on the -sidebar menu. Then each valid page (see `$wgPickSomePage` below) will have +For logged in users, can enable Deliberation by clicking "Start Picking" on the +sidebar menu. Then each valid page (see `$wgDeliberationPage` below) will have a special banner that allows the user to pick this page. They can pick up to -`` proposals. All picked proposals will be viewable on the Special:PickSome page. +`` proposals. All picked proposals will be viewable on the Special:Deliberation page. ## Parameters -* `$wgPickSomeNumberOfPicks` - The number of picks (defaulted to 2) each user can choose -* `$wgPickSomePage` - Determines if a page can be removed or added. +* `$wgDeliberationNumberOfPicks` - The number of picks (defaulted to 2) each user can choose +* `$wgDeliberationPage` - Determines if a page can be removed or added. * If a string, matches as a regex for titles of pages that are pickable - * If a function, gets passed a Title and a permission (PickSome::ADD and PickSome::REMOVE) and needs to return a boolean -* `$wgPickSomeSortFunction` - A function that's handed two Title objects, + * If a function, gets passed a Title and a permission (Deliberation::ADD and Deliberation::REMOVE) and needs to return a boolean +* `$wgDeliberationSortFunction` - A function that's handed two Title objects, and returns values that php's `usort` function would expect (negative, zero, or positive for less than, equal to, or greater than). - This is used to sort the Special PickSome page that has the global list. + This is used to sort the Special Deliberation page that has the global list. -As an example of a `$wgPickSomePage` function, the following would allow someone to not remove picks, and add only if the page is a linked page in a marker page ("Eligible Picks"): +As an example of a `$wgDeliberationPage` function, the following would allow someone to not remove picks, and add only if the page is a linked page in a marker page ("Eligible Picks"): ``` -$wgPickSomePage = function($title) { - if($permission == PickSome::REMOVE) { +$wgDeliberationPage = function($title) { + if($permission == Deliberation::REMOVE) { return false; } $eligibleWildCardsTitle = Title::newFromText("Eligible Picks"); @@ -60,7 +60,7 @@ $wgPickSomePage = function($title) { Example to sort the global page alphabetically: ```php -$wgPickSomeSortFunction = function($t1, $t2) { +$wgDeliberationSortFunction = function($t1, $t2) { $text1 = $t1->getText(); $text2 = $t2->getText(); @@ -72,22 +72,22 @@ $wgPickSomeSortFunction = function($t1, $t2) { ## Special Page -This extension creates a new special page called "Special:PickSome". This is +This extension creates a new special page called "Special:Deliberation". This is the place that most actions are taken through via actions, but also where -users can view the global PickSome list where all user selections are displayed. -This is also where `picksome-admin` users can delete other picks. +users can view the global Deliberation list where all user selections are displayed. +This is also where `deliberation-admin` users can delete other picks. ## Rights -* `'picksome'` - Accounts who have the rights to use PickSome can access the interface.: -* `'picksome-write'` - Accounts that can add/remove choices (after clearing $wgPickSomePage) above. Accounts that have `'picksome'` but not `'picksome-write`' will be able to view picks, but not make them -* `'picksome-admin'` - Accounts that can remove other user picks (from the global pick page) +* `'deliberation'` - Accounts who have the rights to use Deliberation can access the interface.: +* `'deliberation-write'` - Accounts that can add/remove choices (after clearing $wgDeliberationPage) above. Accounts that have `'deliberation'` but not `'deliberation-write`' will be able to view picks, but not make them +* `'deliberation-admin'` - Accounts that can remove other user picks (from the global pick page) To enable for everyone, the following to lines should be added: ``` -$wgGroupPermissions['*']['picksome'] = true; -$wgGroupPermissions['*']['picksome-write'] = true; +$wgGroupPermissions['*']['deliberation'] = true; +$wgGroupPermissions['*']['deliberation-write'] = true; ``` ## Internationalization diff --git a/extension.json b/extension.json index 9cfc312..9e8dbc8 100644 --- a/extension.json +++ b/extension.json @@ -1,59 +1,59 @@ { - "name": "PickSome", - "version": "0.0.1", + "name": "Deliberation", + "version": "0.1.0", "author": [ "Open Tech Strategies" ], "license-name": "GPL-2.0-or-later", "url": "https://github.com/OpenTechStrategies/torque", - "descriptionmsg": "picksome-desc", + "descriptionmsg": "deliberation-desc", "type": "specialpages", "requires": { "MediaWiki": ">= 1.31.0" }, "LogHeaders": { - "picksome": "picksomelogpagetext" + "deliberation": "deliberationlogpagetext" }, "LogNames": { - "picksome": "picksomelogpage" + "deliberation": "deliberationlogpage" }, "LogActionsHandlers": { - "picksome/*": "LogFormatter" + "deliberation/*": "LogFormatter" }, "LogTypes": [ - "picksome" + "deliberation" ], "SpecialPages": { - "PickSome": "PickSome" + "Deliberation": "Deliberation" }, "MessagesDirs": { - "PickSome": [ + "Deliberation": [ "i18n" ] }, "AvailableRights": [ - "picksome", - "picksome-write", - "picksome-admin" + "deliberation", + "deliberation-write", + "deliberation-admin" ], "AutoloadClasses": { - "PickSome": "includes/specials/PickSome.php", - "PickSomeHooks": "includes/PickSomeHooks.php", - "PickSomeGlobalTemplate": "includes/templates/PickSomeGlobalTemplate.php", - "PickSomeSession": "includes/PickSomeSession.php" + "Deliberation": "includes/specials/Deliberation.php", + "DeliberationHooks": "includes/DeliberationHooks.php", + "DeliberationGlobalTemplate": "includes/templates/DeliberationGlobalTemplate.php", + "DeliberationSession": "includes/DeliberationSession.php" }, "ResourceFileModulePaths": { "localBasePath": "" }, "Hooks": { - "LoadExtensionSchemaUpdates": "PickSomeHooks::onLoadExtensionSchemaUpdates", - "SiteNoticeAfter": "PickSomeHooks::siteNoticeAfter", - "SidebarBeforeOutput": "PickSomeHooks::onSidebarBeforeOutput" + "LoadExtensionSchemaUpdates": "DeliberationHooks::onLoadExtensionSchemaUpdates", + "SiteNoticeAfter": "DeliberationHooks::siteNoticeAfter", + "SidebarBeforeOutput": "DeliberationHooks::onSidebarBeforeOutput" }, "config": { - "PickSomeNumberOfPicks": 2, - "PickSomePage": false, - "PickSomeSortFunction": false + "DeliberationNumberOfPicks": 2, + "DeliberationPage": false, + "DeliberationSortFunction": false }, "manifest_version": 1 } diff --git a/i18n/en.json b/i18n/en.json index 6ac5719..4fa441b 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -4,25 +4,25 @@ "Open Tech Strategies" ] }, - "picksome": "PickSome", - "picksome-desc": "Specialized Extension to pick some pages for purposes of voting", - "picksome-title": "PickSome", - "picksome-all": "Everyone's Picks", - "action-picksome-all": "Everyone's Picks", - "picksome-choices": "PickSome Choices", - "picksome-my-picks": "My Picks", - "picksome-unpick": "Unpick", - "picksome-pick": "Pick this page", - "picksome-no-picks": "No Picks", - "picksome-current": "Current Page", - "picksome-view-all": "View Everyone's Picks", - "picksome-global-list": "PickSome Global List", - "picksome-remove-below": "To pick the current page, remove one below", - "picksome-stop": "Stop Picking", - "picksome-close-window": "Close Window", - "picksome-start": "Start Picking", - "picksomelogpage": "PickSome log", - "picksomelogpagetext": "This is a log of PickSome choices made by users", - "logentry-picksome-pick": "$1 Picked $3 in PickSome", - "logentry-picksome-remove": "$1 Removed $3 in PickSome" + "deliberation": "Deliberation", + "deliberation-desc": "Specialized Extension to choose pages for purposes of voting", + "deliberation-title": "Deliberation", + "deliberation-all": "Everyone's Choices", + "action-deliberation-all": "Everyone's Choices", + "deliberation-choices": "Deliberation Choices", + "deliberation-my-picks": "My Choices", + "deliberation-unpick": "Remove Choice", + "deliberation-pick": "Pick this page", + "deliberation-no-picks": "No Choices", + "deliberation-current": "Current Page", + "deliberation-view-all": "View Everyone's Picks", + "deliberation-global-list": "Deliberation Global List", + "deliberation-remove-below": "To choose the current page, remove one below", + "deliberation-stop": "Stop Deliberating", + "deliberation-close-window": "Close Window", + "deliberation-start": "Start Deliberating", + "deliberationlogpage": "Deliberation log", + "deliberationlogpagetext": "This is a log of Deliberation choices made by users", + "logentry-deliberation-pick": "$1 Picked $3 in Deliberation", + "logentry-deliberation-remove": "$1 Removed $3 in Deliberation" } diff --git a/includes/PickSomeHooks.php b/includes/DeliberationHooks.php similarity index 55% rename from includes/PickSomeHooks.php rename to includes/DeliberationHooks.php index 6343a5d..76d92fc 100644 --- a/includes/PickSomeHooks.php +++ b/includes/DeliberationHooks.php @@ -1,14 +1,14 @@ getUser()->isLoggedIn()) { return true; } - if (!$skin->getUser()->isAllowed("picksome")) { + if (!$skin->getUser()->isAllowed("deliberation")) { return true; } @@ -17,45 +17,45 @@ public static function onSidebarBeforeOutput(Skin $skin, &$bar) { $page_url = $skin->getTitle()->getFullText(); } - $picksome_links = []; + $deliberation_links = []; $title = $skin->getTitle(); - if ($skin->getUser()->isAllowed("picksome-write")) { - if(PickSomeSession::isEnabled()) { - $picksome_links[] = [ - "msg" => "picksome-stop", - "href" => SpecialPage::getTitleFor('PickSome')->getLocalUrl( + if ($skin->getUser()->isAllowed("deliberation-write")) { + if(DeliberationSession::isEnabled()) { + $deliberation_links[] = [ + "msg" => "deliberation-stop", + "href" => SpecialPage::getTitleFor('Deliberation')->getLocalUrl( ['cmd' => 'stop', 'returnto' => $page_url] ) ]; } else { - $picksome_links[] = [ - "msg" => "picksome-start", - "href" => SpecialPage::getTitleFor('PickSome')->getLocalUrl( + $deliberation_links[] = [ + "msg" => "deliberation-start", + "href" => SpecialPage::getTitleFor('Deliberation')->getLocalUrl( ['cmd' => 'start', 'returnto' => $page_url] ) ]; } } - $picksome_links[] = [ - "msg" => "picksome-all", - "href" => SpecialPage::getTitleFor('PickSome')->getLocalUrl() + $deliberation_links[] = [ + "msg" => "deliberation-all", + "href" => SpecialPage::getTitleFor('Deliberation')->getLocalUrl() ]; - $bar['picksome-title'] = $picksome_links; + $bar['deliberation-title'] = $deliberation_links; return true; } public static function siteNoticeAfter( &$siteNotice, $skin ) { - global $wgPickSomePage; + global $wgDeliberationPage; - if(!PickSomeSession::isEnabled()) { + if(!DeliberationSession::isEnabled()) { return true; } - if (!($skin->getUser()->isAllowed("picksome") && $skin->getUser()->isAllowed("picksome-write"))) { + if (!($skin->getUser()->isAllowed("deliberation") && $skin->getUser()->isAllowed("deliberation-write"))) { return true; } @@ -71,13 +71,13 @@ public static function siteNoticeAfter( &$siteNotice, $skin ) { $dbw = wfGetDB(DB_MASTER); $res = $dbw->select( - 'PickSome', + 'Deliberation', ['page_id'], 'user_id = ' . $skin->getUser()->getId() ); - $can_add = PickSome::canAdd($title); - $can_remove = PickSome::canRemove($title); + $can_add = Deliberation::canAdd($title); + $can_remove = Deliberation::canRemove($title); if(!($can_add || $can_remove)) { return true; @@ -89,39 +89,39 @@ public static function siteNoticeAfter( &$siteNotice, $skin ) { $selected_pages[$row->page_id] = WikiPage::newFromID($row->page_id); } - $siteNotice .= self::renderPickSomeBox($title, $selected_pages, $page_id, $can_add, $can_remove); + $siteNotice .= self::renderDeliberationBox($title, $selected_pages, $page_id, $can_add, $can_remove); return true; } # Rendering via string concatenation is not ideal, but how to # delegate to the mediawiki templating system deserves more # discussion. - public static function renderPickSomeBox($title, $selected_pages, $page_id, $can_add, $can_remove) { - global $wgPickSomeNumberOfPicks; + public static function renderDeliberationBox($title, $selected_pages, $page_id, $can_add, $can_remove) { + global $wgDeliberationNumberOfPicks; $html = ""; $html .= "
"; $html .= "

"; - $html .= "" . wfMessage("picksome-choices") . ""; + $html .= "" . wfMessage("deliberation-choices") . ""; $html .= " (getLocalUrl( + $html .= SpecialPage::getTitleFor('Deliberation')->getLocalUrl( ['cmd' => 'stop', 'returnto' => $title->getFullText()] ); - $html .= "'>" . wfMessage("picksome-close-window") . ")"; + $html .= "'>" . wfMessage("deliberation-close-window") . ")"; $html .= "

"; $page_already_selected = false; $html .= ""; $html .= "
"; @@ -159,7 +159,7 @@ public static function renderPickSomeBox($title, $selected_pages, $page_id, $can } public static function onLoadExtensionSchemaUpdates( $updater ) { - $updater->addExtensionTable("PickSome", __DIR__ . "/../sql/picksome.sql"); + $updater->addExtensionTable("Deliberation", __DIR__ . "/../sql/deliberation.sql"); } } ?> diff --git a/includes/PickSomeSession.php b/includes/DeliberationSession.php similarity index 57% rename from includes/PickSomeSession.php rename to includes/DeliberationSession.php index 3de830f..7dfe03f 100644 --- a/includes/PickSomeSession.php +++ b/includes/DeliberationSession.php @@ -2,38 +2,38 @@ use MediaWiki\Session\SessionManager; -class PickSomeSession { +class DeliberationSession { public static function touchSession() { $session = SessionManager::getGlobalSession(); - $collection = $session['wsPickSome']; + $collection = $session['wsDeliberation']; $collection['timestamp'] = wfTimestampNow(); - $session['wsPickSome'] = $collection; + $session['wsDeliberation'] = $collection; } public static function enable() { $session = SessionManager::getGlobalSession(); $session->persist(); - $session['wsPickSome']['enabled'] = true; + $session['wsDeliberation']['enabled'] = true; self::touchSession(); } public static function disable() { $session = SessionManager::getGlobalSession(); - if ( !isset( $session['wsPickSome'] ) ) { + if ( !isset( $session['wsDeliberation'] ) ) { return; } - $session['wsPickSome']['enabled'] = false; + $session['wsDeliberation']['enabled'] = false; self::touchSession(); } public static function isEnabled() { $session = SessionManager::getGlobalSession(); - return isset( $session['wsPickSome'] ) && - isset( $session['wsPickSome']['enabled'] ) && - $session['wsPickSome']['enabled']; + return isset( $session['wsDeliberation'] ) && + isset( $session['wsDeliberation']['enabled'] ) && + $session['wsDeliberation']['enabled']; } } diff --git a/includes/specials/PickSome.php b/includes/specials/Deliberation.php similarity index 68% rename from includes/specials/PickSome.php rename to includes/specials/Deliberation.php index 0d9412c..93a29f9 100644 --- a/includes/specials/PickSome.php +++ b/includes/specials/Deliberation.php @@ -1,23 +1,23 @@ getUser()->isAllowed('picksome')) { - throw new PermissionsError('picksome-all'); + if(!$this->getUser()->isAllowed('deliberation')) { + throw new PermissionsError('deliberation-all'); } switch ($this->getRequest()->getVal('cmd')) { case 'pick': $page_picked = WikiPage::newFromID($this->getRequest()->getVal('page'))->getTitle(); - if(!$this->getUser()->isAllowed('picksome-write')) { - throw new PermissionsError('picksome-all'); + if(!$this->getUser()->isAllowed('deliberation-write')) { + throw new PermissionsError('deliberation-all'); } $this->addPickToDb(); $this-> @@ -28,7 +28,7 @@ public function execute( $subPage ) { $this->log("pick", $page_picked); return; case 'start': - PickSomeSession::enable(); + DeliberationSession::enable(); $this-> getOutput()-> redirect( @@ -36,7 +36,7 @@ public function execute( $subPage ) { ); return; case 'stop': - PickSomeSession::disable(); + DeliberationSession::disable(); $this-> getOutput()-> redirect( @@ -44,19 +44,19 @@ public function execute( $subPage ) { ); return; case 'adminremove': - if(!$this->getUser()->isAllowed('picksome-admin')) { - throw new PermissionsError('picksome-all'); + if(!$this->getUser()->isAllowed('deliberation-admin')) { + throw new PermissionsError('deliberation-all'); } $this->adminremovePickFromDb(); $this-> getOutput()-> redirect( - SpecialPage::getTitleFor('PickSome')->getLocalUrl() + SpecialPage::getTitleFor('Deliberation')->getLocalUrl() ); return; case 'remove': - if(!$this->getUser()->isAllowed('picksome-write')) { - throw new PermissionsError('picksome-all'); + if(!$this->getUser()->isAllowed('deliberation-write')) { + throw new PermissionsError('deliberation-all'); } $this->removePickFromDb(); $this-> @@ -68,24 +68,24 @@ public function execute( $subPage ) { $this->log("remove", $page_removed); return; } - $this->renderPickSomePage(); + $this->renderDeliberationPage(); } public static function canAdd($title) { - return PickSome::can($title, PickSome::ADD); + return Deliberation::can($title, Deliberation::ADD); } public static function canRemove($title) { - return PickSome::can($title, PickSome::REMOVE); + return Deliberation::can($title, Deliberation::REMOVE); } private static function can($title, $permission) { - global $wgPickSomePage; + global $wgDeliberationPage; - if ($wgPickSomePage) { - if(is_string($wgPickSomePage) && !preg_match($wgPickSomePage, $title->getPrefixedText())) { + if ($wgDeliberationPage) { + if(is_string($wgDeliberationPage) && !preg_match($wgDeliberationPage, $title->getPrefixedText())) { return false; - } else if(is_callable($wgPickSomePage) && !call_user_func($wgPickSomePage, $title, $permission)) { + } else if(is_callable($wgDeliberationPage) && !call_user_func($wgDeliberationPage, $title, $permission)) { return false; } // If it's not a string, and it's not callable, we'll default to true @@ -94,12 +94,12 @@ private static function can($title, $permission) { return true; } - private function renderPickSomePage() { + private function renderDeliberationPage() { $out = $this->getOutput(); $this->setHeaders(); - $out->setPageTitle(wfMessage("picksome-global-list")); - $template = new PickSomeGlobalTemplate(); + $out->setPageTitle(wfMessage("deliberation-global-list")); + $template = new DeliberationGlobalTemplate(); $template->set('users_picked_pages', $this->usersPickedPages()); $template->set('picked_pages', $this->allPickedPages()); $out->addTemplate($template); @@ -113,7 +113,7 @@ private function addPickToDb() { !$this->alreadyPickedTwoPages($user_id, $dbw)) { $dbw->insert( - "PickSome", + "Deliberation", [ "page_id" => $page, "user_id" => $user_id @@ -125,7 +125,7 @@ private function alreadyPickedPage($page, $user_id, $dbw) { return ($dbw->numRows( $dbw->select( - "PickSome", + "Deliberation", ["page_id"], [ "page_id" => $this->getRequest()->getVal('page'), @@ -135,14 +135,14 @@ private function alreadyPickedPage($page, $user_id, $dbw) { } private function alreadyPickedTwoPages($user_id, $dbw) { - global $wgPickSomeNumberOfPicks; - return (count($this->usersPickedPages()) >= $wgPickSomeNumberOfPicks); + global $wgDeliberationNumberOfPicks; + return (count($this->usersPickedPages()) >= $wgDeliberationNumberOfPicks); } private function removePickFromDb() { $dbw = wfGetDB(DB_MASTER); $dbw->delete( - "PickSome", + "Deliberation", [ "page_id" => $this->getRequest()->getVal('page'), "user_id" => $this->getUser()->getId() @@ -152,7 +152,7 @@ private function removePickFromDb() { private function adminremovePickFromDb() { $dbw = wfGetDB(DB_MASTER); $dbw->delete( - "PickSome", + "Deliberation", [ "page_id" => $this->getRequest()->getVal('page'), "user_id" => $this->getRequest()->getVal('user') @@ -160,10 +160,10 @@ private function adminremovePickFromDb() { } private function allPickedPages() { - global $wgPickSomeSortFunction; + global $wgDeliberationSortFunction; $dbw = wfGetDB(DB_MASTER); - $res = $dbw->select("PickSome", ["page_id", "user_id"]); + $res = $dbw->select("Deliberation", ["page_id", "user_id"]); $picked_pages = []; foreach($res as $row) { $page_id = $row->page_id; @@ -174,10 +174,10 @@ private function allPickedPages() { array_push($picked_pages[$page_id][1], User::newFromID($row->user_id)); } - if($wgPickSomeSortFunction) { + if($wgDeliberationSortFunction) { $cmp_page = function($p1, $p2) { - global $wgPickSomeSortFunction; - return call_user_func($wgPickSomeSortFunction, $p1[0]->getTitle(), $p2[0]->getTitle()); + global $wgDeliberationSortFunction; + return call_user_func($wgDeliberationSortFunction, $p1[0]->getTitle(), $p2[0]->getTitle()); }; usort($picked_pages, $cmp_page); } @@ -188,7 +188,7 @@ private function allPickedPages() { private function usersPickedPages() { $dbw = wfGetDB(DB_MASTER); $res = $dbw->select( - "PickSome", + "Deliberation", ["page_id"], ["user_id" => $this->getUser()->getId()]); $picked_pages = []; @@ -199,7 +199,7 @@ private function usersPickedPages() { } private function log($action, $page) { - $log = new LogPage('picksome', false); + $log = new LogPage('deliberation', false); $log->addEntry($action, $page, $page->getText()); } diff --git a/includes/templates/PickSomeGlobalTemplate.php b/includes/templates/DeliberationGlobalTemplate.php similarity index 77% rename from includes/templates/PickSomeGlobalTemplate.php rename to includes/templates/DeliberationGlobalTemplate.php index 1d5bcc6..5efcefb 100644 --- a/includes/templates/PickSomeGlobalTemplate.php +++ b/includes/templates/DeliberationGlobalTemplate.php @@ -1,13 +1,13 @@ -

+

data['users_picked_pages']) == 0) { - echo wfMessage("picksome-no-picks"); + echo wfMessage("deliberation-no-picks"); } else { ?>
    @@ -22,7 +22,7 @@ public function execute() { } ?>
-

+