MediaWiki extensions manual - list

Release status: stable

Implementation Page action
Description When a page is created in the Main namespace, a corresponding talk page is also created.
Author(s) Timneu22 (wikipedia), Timneu22
Last version (8 April 2010)
MediaWiki 1.15.2, but probably works with most versions before this.
License GPL
Download None. Source code is on this page.
Hooks used

The AutoCreateTalkPage extension does just what the name implies: it automatically creates a talk page. This uses the ArticleInsertComplete hook, and determines if the page being created is in the Main namespace; if it is, this extension automatically creates the corresponding talk page.

Versions Edit

The extension was written on a MediaWiki at version 1.15.2. The code uses some very basic functions that have probably existed forever, so it is quite likely that this works with just about any older version (at least since 1.6, when the ArticleInsertComplete hook was introduced). Feel free to try, but don't complain if it fails, which is unlikely.

Configuration Edit

  1. Copy the code block below into a file, AutoCreateTalkPage.php, and put that file in the extensions directory.
  2. Add the following line to LocalSettings.php:
require_once( "$IP/extensions/AutoCreateTalkPage.php" );

Customization Edit

When a new page is created, the defaults are to add the "talk page" template to the page, with an edit summary of Page automatically created by extension AutoCreateTalkPage. These can be changed; to customize the text, you can edit these lines in the file:

$text = "{{talk page}}";
$summary = "Page automatically created by extension AutoCreateTalkPage";

I could have (should have?) created variables for those, but this is such a simple extension it didn't seem right to make things more complicated than they are.

Future features Edit

This is a simple extension; I do not plan to work on it after this. If you require things like...

  • Other namespaces
  • Custom messages for other namespaces
  • Checks for permissions

... well these are all good ideas, but you should be able to modify the code to your needs. Again, this is a quite simple extension; hopefully you'll be able to modify it as necessary if it doesn't currently do things you need.

Code Edit

if ( ! defined( 'MEDIAWIKI' ) )
 * Extension to create talk page automatically after page in main namespace is created
 * @author Tim Neumark <>
 * @page creation extensions
 * @copyright © 2010 Tim Neumark
 * @license GNU General Public Licence 2.0 or later
$wgExtensionCredits['other'][] = array(
	'path' => __FILE__,
	'name'           => 'Auto Create Talk',
	'version'        => '',
	'author'         => 'Tim Neumark',
	'url'            => '',
	'description'    => 'Creates talk page automatically when page created in main namespace',
$wgHooks['ArticleInsertComplete'][] = 'AutoCreateTalkPage';
 * Hook on page creation
function AutoCreateTalkPage( &$article, &$user, $text, $summary, $minoredit, 
	$watchthis, $sectionanchor, &$flags, $revision ) {
	// if it's a redirect, nothing to create
        # apparently this doesn't work when the page is created?
	#if ( $article->mIsRedirect ) 
	#	return true;
        # so here's a hack way to do it. compare the text and
        # see if it starts with #redirect
	if ( strpos( strtolower( $text ), "#redirect" ) === 0 )
		return true;
	// we only do this for the main namespace
	if ( $article->mTitle->getNamespace() !== 0 )
		return true;
	$talkTitle = Title::makeTitle( NS_TALK, $article->mTitle );
	// nothing to do if it already exists. it is possible (but usually rare)
	// that a talk page exists without the primary article.
	if ( $talkTitle->exists() )
		return true;
	$text = "{{talk page}}";
	$summary = "Page automatically created by extension AutoCreateTalkPage";
	#now create the page	
	$talkPage = new Article( $talkTitle );
	$talkPage->doEdit( $text, $summary, EDIT_NEW );
	return true;

See also Edit