From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
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
Translate the PurgeParentPage extension if it is available at translatewiki.net
Check usage and version matrix.

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().


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.


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.



 PurgeParentPage v0.1 -- Purges parent page on subpage create/delete

 Author: Daniel Forester

 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
 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.

 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

        if ( $wgUseSquid ) {
            // Commit the transaction before the purge is sent
            $dbw = wfGetDB( DB_MASTER );

            // Send purge
            $update = SquidUpdate::newSimplePurge( $parentArticle->mTitle );
        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;

See also[edit]