Project:WikiProject Extensions/Projects/Page Drive/Before

Purpose
The purpose of this extension is to enable conditional execution of a template.

The extension is especially useful if one relies on a complex 'stack' of templates to render a page and would rather make this as generic as possible. The conditional inclusion of a specified page enables, for example, definition of one master template which includes various 'header' / 'footer' pages depending on the namespace of inclusion.

Usage
To setup this other feature, add to your LocalSettings.php: $wgExample['enable'] = true;

Example
The above example serves no purpose than to be used for this before/after page.

Source Code
 "ConditionalTemplate ",  'version' => '$LastChangedRevision: 202 $',  'author'  => 'Jean-Lou Dupont ' );

$wgExtensionFunctions[]        = 'efCondTemplateSetup'; $wgHooks['LanguageGetMagic'][] = 'efCondTemplateGetMagic';

function efCondTemplateGetMagic( &$magicWords, $langCode ) { $magicWords['template'] = array( 0, 'template' ); return true; }

function efCondTemplateSetup { global $wgParser; $wgParser->setFunctionHook( 'template', 'efCondTemplateExec' ); }

function efCondTemplateExec(&$parser, $page, $cond = false ) { return ($cond ? efCondTemplateLoadPage($page) : '' ); }

function efCondTemplateLoadPage( $p ) { $title = Title::newFromText( $p ); if ( $title->getArticleID == 0 ) $text = "".$p.''; else {   $article = new Article( $title ); $text = $article->getContent; } return $text; } if ($wgExample['enable']) { $unique_sql = " AND rc_id=               (SELECT MAX(rc_id)                 FROM $recentchanges tmp                 WHERE tmp.rc_cur_id=rc.rc_cur_id) "; } $sql = "SELECT rc_id, rev_id AS revid, rev_page AS page, rev_user_text as user, rc_id AS rcid        FROM $recentchanges rc, $revision         WHERE rc_this_oldid=rev_id AND rev_deleted=0 $unique_sql        ORDER BY rev_id DESC LIMIT $count;";
 * 1) LoadPage function
 * 1) LoadPage function