Difference between revisions of "Extension:MakePage.php"
($title is not a string use $v for return message) |
(just use strtolower rather than testing "name", "Name", "NAME" etc) |
||
(One intermediate revision by the same user not shown) | |||
Line 17: | Line 17: | ||
define('MAKEPAGE_VERSION', '0.0.1, 2009-02-17'); | define('MAKEPAGE_VERSION', '0.0.1, 2009-02-17'); | ||
− | $egMakePageTag | + | $egMakePageTag = "makepage"; |
$wgExtensionCredits['parserhook'][] = array( | $wgExtensionCredits['parserhook'][] = array( | ||
'name' => 'MakePage', | 'name' => 'MakePage', | ||
'author' => '[http://www.mediawiki.org/wiki/User:Jacknz User:Jack Henderson]', | 'author' => '[http://www.mediawiki.org/wiki/User:Jacknz User:Jack Henderson]', | ||
− | 'description' => 'An extension which allows the title and text of a wiki page to be created | + | 'description' => 'An extension which allows the title and text of a wiki page to be created without leaving the current one', |
− | without leaving the current one | ||
'url' => 'http://www.organicdesign.co.nz/Extension:MakePage', | 'url' => 'http://www.organicdesign.co.nz/Extension:MakePage', | ||
'version' => MAKEPAGE_VERSION | 'version' => MAKEPAGE_VERSION | ||
− | + | ); | |
#Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 | #Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980 | ||
Line 36: | Line 35: | ||
function efMakePageParserInit() { | function efMakePageParserInit() { | ||
− | global $wgParser; | + | global $wgParser, $egMakePageTag; |
− | $wgParser->setHook( | + | $wgParser->setHook( $egMakePageTag, 'efMakePageRender' ); |
return true; | return true; | ||
} | } | ||
Line 43: | Line 42: | ||
function efMakePageRender( $input, $args, $parser ) { | function efMakePageRender( $input, $args, $parser ) { | ||
− | + | foreach ($args as $k => $v) { | |
− | + | $k = htmlspecialchars($k); | |
− | + | $v = htmlspecialchars($v); | |
− | + | if (strtolower($k) == "name") $title = Title::newFromText($v); | |
− | + | } | |
− | + | $article = new Article($title); | |
− | + | $input = htmlspecialchars($input); | |
− | + | $article->doEdit($input,EDIT_UPDATE|EDIT_MINOR); | |
− | + | return "$v has been created"; | |
− | |||
− | |||
} | } |
Latest revision as of 20:35, 16 February 2009
<?php /**
Template:PhpCategory:Extensions created with Template:Extension
/**
* MakePage extension - An extension which allows the title and text of a wiki page to be created
by a simple tag, made with Template:Extension
* * See http://www.mediawiki.org/wiki/Extension:MakePage for installation and usage details * * @package MediaWiki * @subpackage Extensions * @author User:Jack Henderson * @copyright © 2007 User:Jack Henderson * @licence GNU General Public Licence 2.0 or later */
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('MAKEPAGE_VERSION', '0.0.1, 2009-02-17');
$egMakePageTag = "makepage";
$wgExtensionCredits['parserhook'][] = array( 'name' => 'MakePage', 'author' => 'User:Jack Henderson', 'description' => 'An extension which allows the title and text of a wiki page to be created without leaving the current one', 'url' => 'http://www.organicdesign.co.nz/Extension:MakePage', 'version' => MAKEPAGE_VERSION );
- Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { $wgHooks['ParserFirstCallInit'][] = 'efMakePageParserInit'; } else { # Otherwise do things the old fashioned way $wgExtensionFunctions[] = 'efMakePageParserInit'; }
function efMakePageParserInit() { global $wgParser, $egMakePageTag; $wgParser->setHook( $egMakePageTag, 'efMakePageRender' ); return true; }
function efMakePageRender( $input, $args, $parser ) {
foreach ($args as $k => $v) { $k = htmlspecialchars($k); $v = htmlspecialchars($v); if (strtolower($k) == "name") $title = Title::newFromText($v); } $article = new Article($title); $input = htmlspecialchars($input); $article->doEdit($input,EDIT_UPDATE|EDIT_MINOR); return "$v has been created"; }