Skip to content

Commit

Permalink
Registration (#26)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Hutchy68 and samwilson authored Jun 11, 2020
1 parent c0fabc0 commit 64c23f5
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 113 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 0 additions & 35 deletions Purge.i18n.php

This file was deleted.

62 changes: 0 additions & 62 deletions Purge.php

This file was deleted.

16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
42 changes: 42 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
33 changes: 33 additions & 0 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace MediaWiki\Extension\Purge;

use SkinTemplate;

class Hooks {

/**
* @link https://www.mediawiki.org/wiki/Manual:Hooks/SkinTemplateNavigation
* @param SkinTemplate $sktemplate The skin template object.
* @param array $links The existing structured navigation links.
* @return bool
*/
public static function onSkinTemplateNavigation( SkinTemplate &$sktemplate, array &$links ) {
// Use getRelevantTitle if present so that this will work on some special pages
$title = method_exists( $sktemplate, 'getRelevantTitle' )
? $sktemplate->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;
}
}

0 comments on commit 64c23f5

Please sign in to comment.