Extension:Header Footer

Note on Caching
If your installation relies on parser caching, then one must wait until a full cache cycle is completed (i.e. $wgParserCacheExpireTime, default being 86400 seconds) or purge the parser cache in order for the extension to be fully operational.

HeaderFooter.php
<?php /* * HeaderFooter.php * * MediaWiki extension * @author: Jean-Lou Dupont (http://www.bluecortex.com) * * Purpose: insert an header and/or footer to an article *         upon a 'view' action. * * Features: * ********* * - Recursive (bottom-up) search for "Header" and "Footer" subpages * - section support * - Configurable per-namespace recursive level depth * - Configurable per-namespace enable/disable flag (all disable per default) * * DEPENDANCIES: * - ArticleCacheClass (for recursive search function) * * * Tested Compatibility: MW 1.8.2, 1.9.3 * * HISTORY: * -- Version 1.1:	added support for and * -- Version 1.11: changed interface to ArticleCacheClass: using singleton * -- Version 1.12: added check to ensure that the process is only performed once *                 i.e. the article requested in the transaction (and not other *                  articles fetched during the rendering process) *                 (helps with some other extensions that do fetch multiple pages *                   before returning the final render requested page). * -- Version 1.13: - Added support for '__NOHEADER__' and '__NOFOOTER__' magic words */ $wgExtensionCredits['other'][] = array( 	'name'   => 'HeaderFooter Extension', 	'version' => '1.13',	'author'  => 'Jean-Lou Dupont', 	'url'     => 'http://www.bluecortex.com', );

require_once("HeaderFooterClass.php"); $hfObj = &HeaderFooterClass::singleton; $wgHooks['ArticleAfterFetchContent'][] = array( $hfObj, 'hAddHeaderFooter' ); ?>

HeaderFooterClass.php
<?php /* * HeaderFooterClass.php * * MediaWiki extension * @author: Jean-Lou Dupont (http://www.bluecortex.com) * */

class HeaderFooterClass {	var $done; // v1.12 var $cache; var $level; var $inproc; var $nsPar = array;

public static function &singleton {		static $instance; if ( !isset( $instance ) ) $instance = new HeaderFooterClass; return $instance; }	// deprecated interface: use "singleton" functionality. static function getGlobalObjectName { return "hfObj";          } static function &getGlobalObject   { return $GLOBALS['hfObj']; } public function HeaderFooterClass {		$this->cache = &ArticleCacheClass::singleton; $this->level = 0 ; $this->done = false; }	/*	 *  Parameters: *  ==========	 *   Enable => true/false *  Level  => 0, 1, 2 etc.	 *             IF 0 THEN recurse to top of namespace (top:  NS:header, NS:footer) *            IF 1 THEN just check the current level e.g. NS:base/header, NS:base/footer */	public function setNsParams( $ns, $p ) { $this->nsPar[$ns] = $p; } public function hAddHeaderFooter( &$article ) {		global $action;

// only show up the header/footer on page views if ($action != 'view') return true;

if ( $this->done ) // v1.12 return; $this->done = true;

// check the per-namespace enable/disable attribute. $ns = $article->mTitle->getNamespace; if (!$this->nsPar[$ns]['enable']) return true;

// Re-entrancy check // If this function is called recursively, // that probably means a processor code page // is being fetched. Get out. if ($this->inproc) return true; $this->inproc= true;

$name = $article->mTitle->getPrefixedDBkey; // Check if the title name ends with either "header" or "footer" // and skip if true. $e = explode("/", $name); $t = $e[count($e)-1]; $u = strtolower($t); // take care of namespace prefix if present. $v=explode(":", $u); if (count($v)>1) $u = $v[1];

$hdisable=false; $fdisable=false; // check for disabling directives. if (strpos($content, " ")!==false) $hdisable=true; if (strpos($content, " ")!==false) $fdisable=true; if (strpos($content, "__NOHEADER__")!==false) $hdisable=true; // v1.13 if (strpos($content, "__NOFOOTER__")!==false) $fdisable=true; // v1.13 $content = preg_replace('//si','', $content); $content = preg_replace('//si','', $content); $content = preg_replace('/__NOHEADER__/si','', $content); // v1.13 $content = preg_replace('/__NOFOOTER__/si','', $content); // v1.13 if ($u<>"header" and $u<>"footer") {				if (!$hdisable) $h = $this->cache->recurseGetArticleContent($name, "Header", $this->nsPar[$ns]['level'] ); if (!$fdisable) $f = $this->cache->recurseGetArticleContent($name, "Footer", $this->nsPar[$ns]['level'] ); if (!empty($h)) $h = preg_replace( '/ .*<\/noinclude>/si', '', $h ); if (!empty($f)) $f = preg_replace( '/ .*<\/noinclude>/si', '', $f ); $content = $ht.$content.$ft; }				// RESET re-entrancy flag. $this->inproc= false; return true; } } // END CLASS DEFINITION ?>