Jump to content

Extension:NamespacePreload

From mediawiki.org
MediaWiki extensions manual
NamespacePreload
Release status: stable
Implementation Page action
Description Preloads templates on new pages based on their namespace
Author(s) Ostrzycieltalk
Latest version 1.2.0
Compatibility policy Snapshots releases along with MediaWiki. Master is not backward compatible.
MediaWiki 1.30+ (I think)
PHP 7.3+
Database changes No
License GNU General Public License 2.0 or later
Download
  • $wgNamespacePreloadDoExpansion
  • $wgNamespacePreloadDoPreSaveTransform

The NamespacePreload extension lets you define text that should be preloaded on new pages in a certain namespace. This can be useful if you want to enforce some categorization style, or make all pages in a namespace use a certain template.

Pre-save transforms can be optionally applied before showing the edit page to the user. See: Configuration.

Installation

[edit]
  • Download and place the file(s) in a directory called NamespacePreload in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'NamespacePreload' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

[edit]
$wgNamespacePreloadDoExpansion
Whether to expand templates of the preloaded text. Default is true.
$wgNamespacePreloadDoPreSaveTransform
Whether to apply pre-save transforms to the preloaded text before showing the edit page to the user. Default is false.

Usage

[edit]

To define text that should be preloaded for a namespace first you have to determine the namespace ID. Please refer to the MediaWiki docs on how to do this. Once you obtain your namespace ID simply create a page by the following name: MediaWiki:Preload-namespace-<namespace ID>. For example, if you want to define a preload for the main namespace (ID 0), you should save it to this page: MediaWiki:Preload-namespace-0.

Template expansion

[edit]

When $wgNamespacePreloadDoExpansion is set to true (the default value), all templates in the preload message will be expanded before displaying the edit form. You can disable that for all namespaces using this configuration setting.

You can also disable expansion selectively using a trick: let's say your preload message is {{SomeTemplate}}. Create a new template, (let's call it Template:Lbraces) with the following content: {{. Then, in your preload text replace all occurences of {{ with {{Lbraces}}, so instead of {{SomeTemplate}} you would have {{Lbraces}}SomeTemplate}}.