Project:WikiProject Extensions/Projects/Page Drive/Before
This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date. WikiProject Extensions is not active anymore. See Manual:Extensions instead. For questions and help, see Communication. |
Example Fake Extension Release status: experimental |
|
---|---|
Description | Used as an example for page drive. |
Author(s) | user:example |
MediaWiki | tested on 1.15 - 1.18 |
License | GNU General Public License 2.0 |
Download | No link |
Translate the WikiProject Extensions/Projects/Page Drive/Before extension if it is available at translatewiki.net |
Purpose
editThe 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
edit{{#fakearticle:test article|condition}}
To setup this other feature, add to your LocalSettings.php:
$wgExample['enable'] = true;
Example
edit{{#fakearticle:Lorem ipsum|condition}}
The above example serves no purpose than to be used for this before/after page.
Source Code
edit<?php
/**
* Sample Fake Extension
* @package MediaWiki
* @subpackage Extensions
*
* This extension does nothing
*/
$wgExtensionCredits['parserhook'][] = array(
'name' => "ConditionalTemplate [http://www.bluecortex.com]",
'version' => '$LastChangedRevision: 202 $',
'author' => 'Jean-Lou Dupont [http://www.bluecortex.com]'
);
$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) : '' );
}
#
# LoadPage function
#
function efCondTemplateLoadPage( $p )
{
$title = Title::newFromText( $p );
if ( $title->getArticleID() == 0 )
$text = "<b>[[".$p.']]</b>';
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;";