Extension:AutoCreateTalkPage

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
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
require_once( "$IP/extensions/AutoCreateTalkPage.php" );
 * 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:

Customization
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 = ""; $summary = "Page automatically created by extension AutoCreateTalkPage";
 * 1) THESE COULD BE CUSTOMIZED AS NECESSARY BY THE USER

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
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
 * @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'        => '1.0.0.0',	'author'         => 'Tim Neumark',	'url'            => 'http://www.mediawiki.org/wiki/Extension:AutoCreateTalkPage',	'description'    => 'Creates talk page automatically when page created in main namespace', );

$wgExtensionFunctions[] = 'setupAutoCreateTalk';

/** * Extension setup */ function setupAutoCreateTalk { global $wgHooks; $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 if ( $article->mIsRedirect ) 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;

## THESE COULD BE CUSTOMIZED AS NECESSARY BY THE USER $text = ""; $summary = "Page automatically created by extension AutoCreateTalkPage";

#now create the page $talkPage = new Article( $talkTitle ); $talkPage->doEdit( $text, $summary, EDIT_NEW ); return true; }