Project:WikiProject Extensions/Projects/Page Drive/After
Appearance
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. |
This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net . |
Warning: The code or configuration described here poses a major security risk. Site administrators: You are advised against using it until this security issue is resolved. Problem: Vulnerable to SQL injection attacks, because it passes user input directly into SQL commands. This may lead to user accounts being hijacked, wiki content being compromised, private data being leaked, malware being injected, and the entire wiki content being erased, among other things. Solution: make proper use of MediaWiki's database class instead of concatenating raw sql |
Example Fake Extension Release status: experimental |
|
---|---|
Implementation | Parser function, Extended syntax |
Description | Used as an example for page drive. |
Author(s) | user:example |
MediaWiki | tested on 1.15, 1.16, 1.17, 1.18 |
License | GPLv2 |
Download | Code |
$wgExample['enable'] |
|
Translate the WikiProject Extensions/Projects/Page Drive/After extension if it is available at translatewiki.net |
Purpose
[edit]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
[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;";