From 64c23f52f5dd23ebc19df77d9653746cfacf7df2 Mon Sep 17 00:00:00 2001 From: Tom Hutchison Date: Thu, 11 Jun 2020 12:58:07 -0400 Subject: [PATCH] Registration (#26) * Add extension registration This change: * adds extension.json (with backwards compatible loading from Purge.php); * fixes a possible conflict with a message name; * removes installation instructions etc. from README and points instead to the mediawiki.org page; and * removes the global variables from the navigation links hook. Bug: GH #3 * Some tweaks to @samwilson PR to prep for merge * Bumps to version b/c will need MW 1.31+ * Manifest version back to 2 and requires MW >= 1.31.0 Co-authored-by: Sam Wilson --- CHANGELOG.md | 5 ++++ Purge.i18n.php | 35 -------------------------- Purge.php | 62 ---------------------------------------------- README.md | 16 ++---------- extension.json | 42 +++++++++++++++++++++++++++++++ i18n/en.json | 2 +- i18n/qqq.json | 2 +- includes/Hooks.php | 33 ++++++++++++++++++++++++ 8 files changed, 84 insertions(+), 113 deletions(-) delete mode 100644 Purge.i18n.php delete mode 100644 Purge.php create mode 100644 extension.json create mode 100644 includes/Hooks.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a641b2..1498a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Version 2.0.0 + +* Add extension registration. +* Bump major version as it will require MW 1.31+ + ## Version 1.0.2 * POST purge link to avoid confirmation diff --git a/Purge.i18n.php b/Purge.i18n.php deleted file mode 100644 index 9f1289b..0000000 --- a/Purge.i18n.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later - * - * This is a fork of the original see https://www.mediawiki.org/wiki/Extension:Purge - * Updated by Tom Hutchison to use proper i18n json files - * Changed extension hook to SkinTemplateNavigation - * Fixed ExtensionCredits to use the preferred descriptionmg - * version 1.0.1 - */ - -if( !defined( 'MEDIAWIKI' ) ) { - echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" ); - die( 1 ); -} - -$wgExtensionCredits['other'][] = array( - 'path' => __FILE__, - 'name' => 'Purge', - 'author' => 'Tom Hutchison', - 'url' => 'https://www.mediawiki.org/wiki/Extension:Purge', - 'descriptionmsg' => 'descriptionmsg', - 'version' => '1.0.2', - 'license-name' => "GPL-2.0+", -); - -$wgMessagesDirs['Purge'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['Purge'] = __DIR__ . '/Purge.i18n.php'; - -$wgHooks['SkinTemplateNavigation'][] = 'PurgeActionExtension::contentHook'; - -$wgResourceModules['ext.purge'] = [ - 'localBasePath' => __DIR__, - 'remoteExtPath' => 'Purge', - 'scripts' => [ 'resources/ext.purge.js' ], - 'messages' => [ 'purge-failed', ], -]; - -class PurgeActionExtension{ - public static function contentHook( $skin, array &$content_actions ) { - global $wgRequest, $wgUser; - // Use getRelevantTitle if present so that this will work on some special pages - $title = method_exists( $skin, 'getRelevantTitle' ) ? - $skin->getRelevantTitle() : $skin->getTitle(); - if ( $title->getNamespace() !== NS_SPECIAL && $wgUser->isAllowed( 'purge' ) ) { - $skin->getOutput()->addModules( 'ext.purge' ); - $action = $wgRequest->getText( 'action' ); - - $content_actions['actions']['purge'] = array( - 'class' => $action === 'purge' ? 'selected' : false, - 'text' => wfMessage( 'purge' )->text(), - 'href' => $title->getLocalUrl( 'action=purge' ) - ); - } - - return true; - } -} diff --git a/README.md b/README.md index c06e1b1..65a0679 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,3 @@ -## MediaWiki Purge Extension +# MediaWiki Purge Extension -Adds a Purge `&action=purge` link tab of regular articles to your MediaWiki Skin allowing quick purging of page caches. - -### Installation - -Download and upload the zip file to `/extensions` and extract. Rename directory folder `/Purge-#-#-#` to `/Purge` and add the following to `LocalSettings.php` to enable this extension. - -`require_once "$IP/extensions/Purge/Purge.php";` - -Control the ability by user group to purge content. eg `['*']` would allow anyone, `['user']` allows only users or `['sysop']` would only allow sysops. - -`$wgGroupPermissions['{a user group}']['purge'] = true; # delete the cache of a page` - -See https://www.mediawiki.org/wiki/Manual:Purge for more information about purging a page's cache. +For more information, see [mediawiki.org/wiki/Extension:Purge](https://www.mediawiki.org/wiki/Extension:Purge). diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..531c701 --- /dev/null +++ b/extension.json @@ -0,0 +1,42 @@ +{ + "name": "Purge", + "version": "2.0.0", + "author": [ + "[https://www.mediawiki.org/wiki/User:Ævar_Arnfjörð_Bjarmason Ævar Arnfjörð Bjarmason]", + "[https://www.mediawiki.org/wiki/User:Hutchy68 Tom Hutchison]", + "[https://www.mediawiki.org/wiki/User:Samwilson Sam Wilson]" + ], + "url": "https://www.mediawiki.org/wiki/Extension:Purge", + "descriptionmsg": "purge-descriptionmsg", + "license-name": "GPL-2.0+", + "type": "other", + "requires": { + "MediaWiki": ">= 1.31.0" + }, + "MessagesDirs": { + "Purge": [ + "i18n" + ] + }, + "ResourceModules": { + "ext.purge": { + "scripts": [ + "resources/ext.purge.js" + ], + "messages": [ + "purge-failed" + ] + } + }, + "ResourceFileModulePaths": { + "localBasePath": "", + "remoteExtPath": "Purge" + }, + "AutoloadClasses": { + "MediaWiki\\Extension\\Purge\\Hooks": "includes/Hooks.php" + }, + "Hooks": { + "SkinTemplateNavigation": "MediaWiki\\Extension\\Purge\\Hooks::onSkinTemplateNavigation" + }, + "manifest_version": 2 +} diff --git a/i18n/en.json b/i18n/en.json index a8e947c..6a94c31 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,6 +5,6 @@ ] }, "purge": "Purge", - "descriptionmsg": "Adds a purge tab on all normal pages allowing for quick purging of the cache", + "purge-descriptionmsg": "Adds a purge tab on all normal pages allowing for quick purging of the cache", "purge-failed": "Purge failed" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 3dbd277..e6e835c 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -9,6 +9,6 @@ ] }, "purge": "Displayed as a label in the action menu.\n{{Identical|Purge}}", - "descriptionmsg": "{{desc|name=Purge|url=https://www.mediawiki.org/wiki/Extension:Purge}}\n\"purge\" refers to {{msg-mw|purge}}.", + "purge-descriptionmsg": "{{desc|name=Purge|url=https://www.mediawiki.org/wiki/Extension:Purge}}\n\"purge\" refers to {{msg-mw|purge}}.", "purge-failed": "Displayed when the POST request to purge did not succeed." } diff --git a/includes/Hooks.php b/includes/Hooks.php new file mode 100644 index 0000000..72d5d81 --- /dev/null +++ b/includes/Hooks.php @@ -0,0 +1,33 @@ +getRelevantTitle() + : $sktemplate->getTitle(); + if ( $title->getNamespace() !== NS_SPECIAL && $sktemplate->getUser()->isAllowed( 'purge' ) ) { + $sktemplate->getOutput()->addModules( 'ext.purge' ); + $action = $sktemplate->getRequest()->getText( 'action' ); + + $links['actions']['purge'] = [ + 'class' => $action === 'purge' ? 'selected' : false, + 'text' => wfMessage( 'purge' )->text(), + 'href' => $title->getLocalUrl( 'action=purge' ) + ]; + } + + return true; + } +}