From mediawiki.org
MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
Implementation Hook , Page action
Description Extension to create new pages when links are followed
Author(s) Jim Wilson, JimHu
Latest version 0.2 (2014-10-8)
MediaWiki 1.18+
License MIT License
Example EcoliWiki

Rationale and Features[edit]

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 (and subsequently 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:

  • short circuits and returns true if the article already exists
  • provides a hook, PagesOnDemand, that passes the title and article objects to any extensions that hook there (modules).
  • 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

Two examples of such modules are provided with the distribution. We hope others will write additional modules.

What the modules do[edit]

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 (included from DemoOnDemand):


 * DemoOnDemand.php - An extension 'module' for the PagesOnDemand
 * extension.  @author Jim R. Wilson (wilson.jim.r@gmail.com)
 * @version 0.1
 * @copyright Copyright (C) 2007 Jim R. Wilson
 * @license The MIT License -
 * http://www.opensource.org/licenses/mit-license.php

if ( ! defined( 'MEDIAWIKI' ) ) die();

// Extension credits
$wgExtensionCredits['other'][] = array(
  'author'=>'Jim Wilson &lt;wilson.jim.r@gmail.com&gt;',
    'Demo for PagesOnDemand mechanism for generating wiki articles on demand.',

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

 * Loads a demo page if the title matches a particular pattern.
 * @param Title title The Title to check or create.
function wfLoadDemoPageOnDemand( $title, $article ){
  // 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!', 
	// All done (returning false to kill PoD's wfRunHooks stack)
	return false;


version 0.2 requires 1.18 or later

Works with MediaWiki 1.23

version 0.1:

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

Works with MediaWiki 1.11.0 ---Snuck 01:52, 6 October 2008 (UTC)

Works with MediaWiki 1.19.6


  • Download from https://github.com/jimhu-tamu/hulab_wiki-extensions/archive/master.zip
  • 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
    • ArticleOnDemand - a means to start an article in the main namespace by planting a seedling of a template or other starting point
    • 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
      • This requires an additional extension for using NCBI's web E-Utilities web services.
  • add
    require_once("$IP" ."/extensions/PagesOnDemand/PagesOnDemand.php");
    to LocalSettings.php , along with require statements for any additional extensions that use PagesOnDemand


Inputbox can be used to prepopulate a new page, but it takes you to an edit page, not the page itself. In particular, the Inputbox extension cannot be used to run arbitrary PHP code (the module) to generate the page text.