Extension:PagesOnDemand/ArticleOnDemand
From Linux Web Expert
<translate> This extension stores its source code on a wiki page.</translate> <translate> Please be aware that this code may be unreviewed or maliciously altered.</translate> <translate> They may contain security holes, outdated interfaces that are no longer compatible etc.</translate> <translate> Note:</translate> <translate> No [[<tvar name=localisation>Special:MyLanguage/Localisation#Translation resources</tvar>|localisation]] updates are provided for this extension by <tvar name=twn>translatewiki.net </tvar>.</translate> |
<?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->isLoggedIn() ) {
return true;
}
# Create the Article, supplying the new text
$article = new WikiPage($title);
$content = '{{article}}';
$article->doEditContent( ContentHandler::makeContent( $content, $title ), 'Auto creation', EDIT_NEW | EDIT_FORCE_BOT );
# All done (returning false to kill PoD's wfRunHooks stack)
return false;
}
}