Jump to content

Extension:NewArticleTemplates

From mediawiki.org
MediaWiki extensions manual
NewArticleTemplates
Release status: stable
Implementation User interface
Description Prefills newly created pages with some text.
Author(s) Mathias Ertl (MathiasErtltalk)
Latest version 1.4.1 (2026-02-03)
MediaWiki 1.43+
Database changes No
  • $wgNewArticleTemplatesDefault
  • $wgNewArticleTemplatesEnabledNamespaces
  • $wgNewArticleTemplatesNamespaceTemplates
  • $wgNewArticleTemplatesApplyToSubpages
Licence GNU General Public License 3.0 or later
Download
Changelog
Example see below

The NewArticleTemplates extension allows to automatically prefill text of new pages with the contents of other predefined wiki-pages. It is possible to distinguish between namespaces and specify a different text for new subpages.

Installation

[edit]

From your MediaWiki installation directory, clone the extension into the extensions directory:

cd extensions/
git clone https://github.com/jmnote/NewArticleTemplates.git

Then enable the extension in your Manual:LocalSettings.php file:

wfLoadExtension( 'NewArticleTemplates' );
$wgNewArticleTemplatesDefault = 'Template:New page';

The $wgNewArticleTemplatesDefault setting specifies the template page whose contents will be prefilled when a new page is created. Without this setting, no template content will be applied by default.

Configuration (version 1.4 and later)

[edit]

Starting with version 1.4, NewArticleTemplates uses extension.json-based configuration variables. The old variables are no longer supported.

Configuration variables

[edit]
Variable Description Default
$wgNewArticleTemplatesDefault Default template page title to preload. ""
$wgNewArticleTemplatesEnabledNamespaces List of namespace IDs where templates are applied. If empty or unset, applies to all namespaces. []
$wgNewArticleTemplatesNamespaceTemplates Map of namespace ID ⇒ template page title. []
$wgNewArticleTemplatesApplyToSubpages Whether templates are applied to subpages. true

Minimal configuration

[edit]

The simplest configuration applies a single template to all namespaces.

$wgNewArticleTemplatesDefault = 'Template:New page';

Full configuration example

[edit]

Namespace-specific templates override the default template.

$wgNewArticleTemplatesDefault = 'Template:New page';

$wgNewArticleTemplatesEnabledNamespaces = [
    NS_MAIN,
    NS_HELP,
    NS_PROJECT,
];

$wgNewArticleTemplatesNamespaceTemplates = [
    NS_MAIN => 'Template:New article',
    NS_HELP => 'Template:Help page',
];

$wgNewArticleTemplatesApplyToSubpages = true;

Notes

[edit]
  • Templates are plain wiki pages. The extension loads the template content and strips <noinclude></noinclude> sections and <includeonly></includeonly> tags.
  • If a namespace has a specific entry in $wgNewArticleTemplatesNamespaceTemplates, that template takes precedence over $wgNewArticleTemplatesDefault.
  • If $wgNewArticleTemplatesEnabledNamespaces is empty or unset, templates apply to all namespaces.
  • Subpages are included by default. Set $wgNewArticleTemplatesApplyToSubpages = false to opt out.
  • Template titles must match the actual page title, including case and spacing.

How templates are selected

[edit]

Templates are applied only when creating a page for the first time.

When a page is created, the extension selects a template in the following order:

  • If $wgNewArticleTemplatesNamespaceTemplates contains an entry for the page namespace, that template is used.
  • Otherwise, $wgNewArticleTemplatesDefault is used (if set).
  • If no template is configured, the edit form is left empty.

This selection logic ensures that namespace-specific templates always take precedence over the default template.

Subpage handling

[edit]

A page is considered a subpage only if the base page (the part of the title before the first "/") already exists. If subpage support is enabled (default: true) and the page is a subpage, the extension will look for a template page named <template>/Subpage. If such a page exists, it is used instead of the base template. Otherwise, the base template is applied.

Template content processing

[edit]

The extension loads the wikitext of the selected template page and preprocesses it before inserting it into the edit form.

The following elements are stripped from the template content:

  • <noinclude>...</noinclude> sections
  • <includeonly></includeonly> tags (the inner content is preserved)

This allows template pages to be reused safely both for transclusion and for preloading new page content.

Legacy configuration (version 1.3 and earlier)

[edit]

This section documents configuration options used in versions 1.3 and earlier. Behavior and template handling are identical to version 1.4.

Variable Description Default
$wgNewArticleTemplatesNamespaces List of namespaces where templates are applied. []
$wgNewArticleTemplatesPerNamespace Per-namespace template mapping. []
$wgNewArticleTemplatesDefault Default template page title to preload. ""
$wgNewArticleTemplatesOnSubpages Whether templates are applied to subpages. true

The extension provides several configuration options for fine-grained control. It is recommended that you use pages in the MediaWiki namespace for the templates, otherwise the templates are editable by everyone, which is probably not what you want. Here is a (hopefully) self-explanatory snippet of LocalSettings.php:

wfLoadExtension( 'NewArticleTemplates' );

# Templates are used in these namespaces:
$wgNewArticleTemplatesNamespaces = [
        NS_MAIN                 => 1,
        100                     => 1,
        102                     => 1,
        104                     => 1,
        106                     => 1
];

# new pages in the main namespace use MediaWiki:NewArticleTemplates:
$wgNewArticleTemplatesPerNamespace = array(
        NS_MAIN                 => "MediaWiki:NewArticleTemplates",
);

# new pages in any other namespace defined by $wgNewArticleTemplatesNamespaces use MediaWiki:NewArticleTemplatesDefault:
$wgNewArticleTemplatesDefault = "MediaWiki:NewArticleTemplatesDefault";

Changelog

[edit]
1.4.1 (2026-02-23)
  • Configuration variables were renamed and restructured
  • Migrated to extension.json-based configuration
  • Old configuration variables are no longer supported
  • Verified to work with MediaWiki 1.43
1.3 (2021-06-30)
  • Update for MediaWiki 1.35 and later
1.2 (2018-03-29)
  • Update for MediaWiki 1.29 and later
1.1 (rev. 187)
  • fixed a typo in the global imports
  • much refined handling of subpages
  • if the new page is a subpage and a subpage of the template named 'Subpage' exists, it is used instead
1.0
  • first version documented here

See Also

[edit]