Extension:PagesOnDemand

Rationale and Features
We wanted an easy way to force certain pages to use defined templates based on the structure of the page title. With PagesOnDemand, pages are created from templates when users follow links if the link matches a string comparison that tells the PagesOnDemand system that the desired page is of a desired type. For example, pages with titles that match the regular expression '/^PMID:\\d+$/' are recognized by PagesOnDemand.php+PMID_OnDemand.php as being about articles in the scientific literature. When the system recognizes this pattern, it creates a page based on a template for wiki articles about the scientific literature and then forwards the user to the newly created page, instead of to an edit page. PagesOnDemand effectively makes some "red links" behave like "blue links".

Installing this extension by itself won't affect the wiki in and of itself, instead offloading the real work to modules capable of performing the article insertion. PagesOnDemand hooks at ArticleFromTitle and does the following when a link is clicked: Two examples of such modules are provided with the distribution. We hope others will write additional modules.
 * short circuits and returns true if the article already exists
 * provides a hook, PagesOnDemand, that passes the title and article objects to any extensions/modules that hook there
 * on return, ensures that the user will be forwarded to the article view after any other extensions hooking at ArticleFromTitle have had a chance to run

What the modules do
Modules should be written to examine the title using a string comparison function to determine whether a page should be created or not. If not, return true. If the module finds a match to the page title, it should generate the desired prepopulation text somehow and create the article. This is demonstated by the DemoOnDemand code: 'DemoOnDemand',    'author'=>'Jim Wilson &lt;wilson.jim.r@gmail.com&gt;',    'description'=>'Demo for PagesOnDemand mechanism for generating wiki articles on demand.',    'version'=>'0.1' );
 * 1) Credits

$wgHooks['PagesOnDemand'][] = 'wfLoadDemoPageOnDemand';
 * 1) Register hooks ('PagesOnDemand' hook is provided by the PagesOnDemand extension).

/** function wfLoadDemoPageOnDemand( $title, $article ){
 * Loads a demo page if the title matches a particular pattern.
 * @param Title title The Title to check or create.

# Short-circuit if $title isn't in the MAIN namespace or doesn't match the DEMO pattern. if ( $title->getNamespace != NS_MAIN || !preg_match('/^DEMO:/', $title->getDBkey ) ) { return true; }

# Create the Article's new text - could be more complicated, but this is just a demo $text = 'Wow, we just created a page called '. $title->getDBkey;

# Create the Article, supplying the new text $article = new Article($title); $article->doEdit( $text, 'Brand New Demo Page!', EDIT_NEW | EDIT_FORCE_BOT );

# All done (returning false to kill PoD's wfRunHooks stack) return false; } ?>

Status
Tested with MediaWiki 1.8.3 and 1.9.3. Help testing this extension on other versions will be appreciated!

Installation

 * Download pagesondemand.tgz
 * unpack in your extensions directory. Files included:
 * PagesOnDemand.php - the main extension
 * DemoOnDemand - a demo of how to write new extensions that hook into PagesOnDemand
 * Extension:PMID_OnDemand - an extension to create pages for papers in the National Library of Medicine PubMed system, using a template page and PubMed's E-utilities
 * add require_once("extensions/PagesOnDemand.php");
 * to LocalSettings.php, along with require statements for any additional extensions that use PagesOnDemand

Alternatives
Inputbox can be used to prepopulate a new page, but it takes you to an edit page, not the page itself.