Extension:ParentPageLink

The ParentPageLink extension add a boilerplate page-link to the parent page upon editing a new page.

For example, creating a new article on the Main_Page will produce the following code at the bottom.

=Internal Links= Parent Article: Main_Page

Articles created in the new article will have the new article as the parent and so on down. This allows traceability from any article to the Main_Page (root) and provides some context for the article's creation.

Changes
Version 0.05 supports Namespaces and subpages. Talk Pages are ignored.

Installation
require_once( "$IP/extensions/ParentPageLink.php" );
 * 1) To install the ParentPageLink extension, put the following line in LocalSettings.php

Code


* */ if (!defined('MEDIAWIKI')) { echo << 'ParentPageLink',	'author' => 'Jesse B. Dooley',	'url' => 'http://www.mediawiki.org/wiki/Extension:ParentPageLink',	'description' => 'Adds a Parent Article Link',	'descriptionmsg' => 'Adds a Parent Article Link as boilerplate',	'version' => '0.051', );

function parentpagelink($editpage) { // EditFormPreloadText global $wgOut; global $wgEnableAPI; global $wgEnableWriteAPI; $wgOut->enableClientCache(false); $wgEnableAPI = true; # Check for no preview and blank page if (!$editpage->preview       && !$editpage->mArticle->mContentLoaded) { $parentID = ""; $parentName = ""; $title_name = ""; $category_name = ""; $parent_namespace = ""; $parent_Nick = ""; # Displayed in the link

$title = $editpage->getTitle;

# Test for Talk Page and skip if( $title->isTalkPage ) { return true; }

# replace ' ' with '_' because getTitle doesn't		$title_name = str_replace( ' ', '_', $title);

# Parse title_name for category $pieces = explode(':', $title_name); # test if the article has a category if ( count( $pieces ) > 1 ) { $category_name = $pieces[0]; $title_name = $pieces[1]; }		$dbr = wfGetDB( DB_MASTER ); # select to grab parent id		$res = $dbr->select(				'pagelinks',				array( 'pl_from' ),				array( 'pl_title' => $title_name),				__METHOD__,				array( 'ORDER BY' => 'pl_from ASC' )		);

# get the $parentID foreach( $res as $row ) { $parentID = $row->pl_from; break; }

# get the parent title $res = $dbr->select(				'page',				array( 'page_title', 'page_namespace' ),				array('page_id' => $parentID),				__METHOD__		); foreach( $res as $row ) { $parentName = $row->page_title; $parent_namespace = MWNamespace::getCanonicalName( $row->page_namespace ); break; }

$parentSlice = explode("/", $parentName);

# Check for Category if( $parent_namespace ) { # Add Namespace $parent_Nick = $parent_namespace. ":" . $parentName. " | " . $parentName; } elseif ( count( $parentSlice ) > 1 ){	# Check for subpage $parent_Nick = $parentName. " | " . end( $parentSlice ); } else { $parent_Nick = $parentName; }		# Check for subpage

# Add the parent link, modify the string as needed $editpage->textbox1= "\n\n\n\n\n\n\n\n=Internal Links=\nParent Article: " . $parent_Nick ." "; $editpage->textbox2=$editpage->textbox1; } // end if

return true; } // function parentpagelink($editpage) ?>