Extension:PagesOnDemand/ArticleOnDemand

From Linux Web Expert

Revision as of 15:38, 8 May 2020 by imported>Dexbot (Deprecating <source> tag: phab:T237267)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<?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 &lt;wilson.jim.r@gmail.com&gt;',
    '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;
        }
}