Extension:CustomTitle
From MediaWiki.org
| This extension stores its source code on a wiki page. Please be aware that this code may be unreviewed or maliciously altered. They may contain security holes, outdated interfaces that are no longer compatible etc. Note: No localisation updates are provided for this extension by translatewiki.net. |
|
CustomTitle Release status: beta |
|||
|---|---|---|---|
| Implementation | Parser function | ||
| Description | Modify the default page title and header | ||
| Author(s) | Wiktor Walc (Wwalctalk) | ||
| Last version | 2008-01-30 (2008-01-30) | ||
| MediaWiki | tested on 1.11.0 | ||
| Database changes | no | ||
| License | GPL | ||
| Download | see below | ||
| Example | see below | ||
|
|||
| Check usage and version matrix | |||
The CustomTitle extension allows you to modify the page header and title.
Contents |
Installation [edit]
- Create a directory
CustomTitlein theextensionsdirectory - Create a file in the
CustomTitledirectory named CustomTitle.php - In your LocalSettings.php add:
require_once $IP . "/extensions/CustomTitle/CustomTitle.php" ;
- Edit the file and place the following in it:
<?php # Not a valid entry point, skip unless MEDIAWIKI is defined if (!defined('MEDIAWIKI')) { echo <<<HEREDOC To install this extension, put the following line in LocalSettings.php: require_once( "\$IP/extensions/CustomTitle/CustomTitle.php" ); HEREDOC; exit( 1 ); } $wgExtensionCredits['other'][] = array( "name" => "CustomTitle", "author" => "Wiktor Walc", "version" => '1.0', "url" => "https://www.mediawiki.org/wiki/Extension:CustomTitle", "description" => "Allows to modify the page header and title" ); $oCustomTitleExtension = new CustomTitle_MediaWiki(); $oCustomTitleExtension->registerHooks(); $wgExtensionFunctions[] = array($oCustomTitleExtension, "setupExtensionFunction"); $wgHooks['LanguageGetMagic'][] = array($oCustomTitleExtension, "addMagicWord"); class CustomTitle_MediaWiki { protected $customTitle; protected $customPageTitle; function setupExtensionFunction() { global $wgParser; $wgParser->setFunctionHook( 'customtitle', array($this, "substitute")); } function substitute(&$parser, $param1 = '', $param2 = '') { $ret = ""; if ($param1 !== '') $ret .= "xxx-CustomTitleStart-xxx". $param1 ."xxx-CustomTitleEnd-xxx"; if ($param2 !== '') $ret .= "xxx-CustomPageTitleStart-xxx". $param2 ."xxx-CustomPageTitleEnd-xxx"; return $ret; } function addMagicWord(&$magicWords, $langCode) { $magicWords['customtitle'] = array( 0, 'customtitle' ); return true; } function onSkinTemplateOutputPageBeforeExec(&$m_skinTemplate, &$m_tpl) { if (isset($this->customTitle)) $m_tpl->set('title', $this->customTitle); if (isset($this->customPageTitle)) $m_tpl->set('pagetitle', $this->customPageTitle); return true; } function onOutputPageBeforeHTML(&$out, &$text) { if (($found = strpos($text, 'xxx-CustomTitleStart-xxx')) !== false) { if (preg_match("/xxx-CustomTitleStart-xxx(.*?)xxx-CustomTitleEnd-xxx/", $text, $matches)) { $this->customTitle = $matches[1]; $text = str_replace($matches[0], "", $text); } } if (($found = strpos($text, 'xxx-CustomPageTitleStart-xxx')) !== false) { if (preg_match("/xxx-CustomPageTitleStart-xxx(.*?)xxx-CustomPageTitleEnd-xxx/", $text, $matches)) { $this->customPageTitle = $matches[1]; $text = str_replace($matches[0], "", $text); } } return true; } public function registerHooks() { global $wgHooks; $wgHooks['SkinTemplateOutputPageBeforeExec'][] = array($this, 'onSkinTemplateOutputPageBeforeExec'); $wgHooks['OutputPageBeforeHTML'][] = array($this, 'onOutputPageBeforeHTML'); } }
Usage [edit]
- To change the page header and title
{{#customtitle:My header|My Title}}
- To change header only:
{{#customtitle:My header}}
Important Notes [edit]
This extension modifies template variables and nothing more. You have to remember that although different title is being displayed, you still have to link to that page using the real page name.
Example [edit]
Let's say we have a page named "Example". Even if you change the title to "My own title" with {{#customtitle:My own title}}, to create a link to that page, you still have to use [[Example]].