Extension:PurgeParentPage
![]() | This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
![]() | This extension is currently not actively maintained! Although it may still work, any bug reports or feature requests will more than likely be ignored. |
PurgeParentPage Release status: unmaintained |
|
---|---|
Implementation | Page action |
Description | Purges parent page's cache on sub-page insert or delete |
Author(s) | Dforestertalk |
Latest version | 0.1 |
License | GPL |
Download | Here |
What can this extension do?[edit]
PurgeParentPage is a basic extension used to purge the cache of a parent page whenever a new subpage is added, or an existing subpage is deleted. This would typically be used in conjunction with other extensions in which parent-page content needs to refresh based on subpages (e.g. User:Karora/ListSubPages). Such extensions would otherwise dynamically refresh based on subpages; however, due to the cache - the new version of the parent page is unavailable until purged.
PurgeParentPage currently replicates Article::doPurge().
Usage[edit]
Once the extension is installed, it will check every article creation and article delete. If the given article is a subpage, the parent page's cache will be purged.
Download instructions[edit]
Please cut and paste the code found below and place it in $IP/extensions/ExtensionName/ExtensionName.php
. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
Installation[edit]
To install this extension, add the following to LocalSettings.php:
require_once( $IP . "/extensions/PurgeParentPage.php" )
Configuration parameters[edit]
User rights[edit]
Normal "purge rights" are not followed; e.g. a non-logged-in-user could cause a page to be purged directly without the typical confirmation as described in Manual:Purge.
Code[edit]
<?php
/*
PurgeParentPage v0.1 -- Purges parent page on subpage create/delete
Author: Daniel Forester
http://www.mediawiki.org/wiki/User:Dforester
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
http://www.gnu.org/copyleft/gpl.html
To install, add following to LocalSettings.php
require_once( $IP . "/extensions/PurgeParentPage.php" )
*/
if ( !defined( 'MEDIAWIKI' ) ) {
echo "This file is part of MediaWiki, it is not a valid entry point.\n";
exit( 1 );
}
$wgHooks['ArticleInsertComplete'][] = 'wfPurgeParentPage';
$wgHooks['ArticleDeleteComplete'][] = 'wfPurgeParentPage';
$wgExtensionCredits['other'][] = array(
'name' => 'Purge Parent Page',
'url' => 'http://www.mediawiki.org/wiki/Extension:PurgeParentPage',
'description' => 'Purge parent page cache on subpage create/delete',
'author' => 'Daniel Forester',
'version' => '0.1'
);
function wfPurgeParentPage(&$article, &$user) {
// create subpage title object from subpage article...
if (!is_object($title)) $title = $article->getTitle();
if ($title->isSubpage()) {
// create parent title object from subpage title; create an article object; purge it
$parentTitle = Title::newFromText($title->getBaseText());
$parentArticle = new Article($parentTitle);
// below modified from Article::doPurge()
// http://svn.wikimedia.org/doc/Article_8php-source.html#l01036
// unsure why $parentArticle->purge() or doPurge() doesn't work quite the same
global $wgUseSquid;
// Invalidate the cache
$parentArticle->mTitle->invalidateCache();
if ( $wgUseSquid ) {
// Commit the transaction before the purge is sent
$dbw = wfGetDB( DB_MASTER );
$dbw->immediateCommit();
// Send purge
$update = SquidUpdate::newSimplePurge( $parentArticle->mTitle );
$update->doUpdate();
}
if ( $parentArticle->mTitle->getNamespace() == NS_MEDIAWIKI ) {
global $wgMessageCache;
if ( $parentArticle->getID() == 0 ) {
$text = false;
} else {
$text = $parentArticle->getContent();
}
$wgMessageCache->replace( $parentArticle->mTitle->getDBkey(), $text );
}
} // if isSubpage
return true;
}