Difference between revisions of "Extension:MakePage.php"

From Organic Design wiki
(replace weird way of creating title object)
($title is not a string use $v for return message)
Line 50: Line 50:
 
}
 
}
 
}
 
}
$article = new Article($title);
+
$article = new Article($title);
$input = htmlspecialchars($input);
+
$input = htmlspecialchars($input);
 
$article->doEdit($input,EDIT_UPDATE|EDIT_MINOR);
 
$article->doEdit($input,EDIT_UPDATE|EDIT_MINOR);
return $title . " has been created";
+
return "$v has been created";
 
}
 
}

Revision as of 20:31, 16 February 2009

<?php /**

Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.

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, made with Template:Extension', 'url' => 'http://www.organicdesign.co.nz/Extension:MakePage', 'version' => MAKEPAGE_VERSION );

  1. 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; $wgParser->setHook( 'makepage', 'efMakePageRender' ); return true; }

function efMakePageRender( $input, $args, $parser ) {

foreach ($args as $k => $v) { $k = htmlspecialchars($k); $v = htmlspecialchars($v); if ($k == "name" || $k == "Name" || $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"; }