Extension:PagesOnDemand/ArticleOnDemand
Appearance
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 . |
<?php
/*
* ArticleOnDemand.php - An extension 'module' for the PagesOnDemand extension.
* @author Joe Beaudoin Jr. (webmaster@battlestarwiki.org)
* @version 0.3
* @copyright Copyright (C) 2007 Jim R. Wilson, 2020 Joe Beaudoin Jr.
* @license The MIT License - http://www.opensource.org/licenses/mit-license.php
version 0.3 MW 1.3x Updates by Joe Beaudoin Jr.
version 0.2 convert to OO by Jim Hu
version 0.1 Demo by Jim Wilson
*/
if ( ! defined( 'MEDIAWIKI' ) ) die();
# Credits
$wgExtensionCredits['other'][] = array(
'name'=>'ArticleOnDemand',
'author'=>'Modified by Joe Beaudoin Jr - Original Code by Jim Wilson <wilson.jim.r@gmail.com>',
'description'=>'Adds article template for PagesOnDemand mechanism for generating wiki articles on demand.',
'version'=>'0.2'
);
# Register hooks ('PagesOnDemand' hook is provided by the PagesOnDemand extension).
$wgHooks['PagesOnDemand'][] = 'ArticleOnDemand::wfLoadArticlePageOnDemand';
/**
* Loads a demo page if the title matches a particular pattern.
* @param Title title The Title to check or create.
*/
class ArticleOnDemand{
public static function wfLoadArticlePageOnDemand( $title, $article ){
global $wgUser;
# Short-circuit if $title isn't in the MAIN namespace.
if ( $title->getNamespace() != NS_MAIN ) {
return true;
}
# Kill this if the user isn't logged in.
if ( !$wgUser->isRegistered() ) {
return true;
}
# Create the Article, supplying the new text
$article = new WikiPage($title);
$content = '{{article}}';
$article->doUserEditContent( ContentHandler::makeContent( $content, $title ), $wgUser, 'Auto creation', EDIT_NEW | EDIT_FORCE_BOT );
# All done (returning false to kill PoD's wfRunHooks stack)
return false;
}
}