![]() Release status: unmaintained |
|
---|---|
Implementation | Extended syntax | , MyWiki
Description | Defines several username-producing magic words |
Author(s) | Ross McClure (Algorithmtalk) |
Latest version | 2.1.0 (2017-08-11) |
MediaWiki | 1.19+ |
PHP | 5.3+ |
Database changes | No |
License | GNU General Public License 2.0 or later |
Download | see below |
Hooks used
|
|
The UserMagic extension allows editors to place the name of the current user inside the content of an article, without affecting the page cache. This is done by replacing magic words inside the fully-parsed HTML after the page has been rendered and cached.
Currently defined magic words:
__USERNAME__
-> Name of the current user__USERPAGE__
-> Link to the page of the current user__USERIP__
-> IP address of the current user
Caveats
Since the magic words are not replaced until after the HTML is rendered, they cannot be used as the target of links or as template arguments. However, they can still be used as the alternate text of links, e.g. [[Special:Mypage|__USERNAME__]]
.
Additionally, since <nowiki> tags will have already been parsed out, these magic words cannot be invalidated by <nowiki>. In order to explicitly print one of these words, _
must be used in place of an underscore.
Installation
- Copy the code into a file called "UserMagic.php" and place the file(s) in a directory called
UserMagic
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php
require_once "$IP/extensions/UserMagic/UserMagic.php";
file: Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Code
- UserMagic.php
<?php
/**
* UserMagic
* Defines several username-producing magic words.
*
* @link https://www.mediawiki.org/wiki/Extension:UserMagic Documentation
* @version 2.1.0 (2017-08-11)
*
* @ingroup Extensions
* @package MediaWiki
*
* @author Ross McClure (Algorithm)
* @author Sébastien Beyou (Seb35)
* @author Karsten Hoffmeyer (Kghbln)
* @copyright (C) 2006 Ross McClure (Algorithm)
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License 2.0 or later
*/
// Ensure that the script cannot be executed outside of MediaWiki.
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This is an extension to MediaWiki and cannot be run standalone.' );
}
// Display extension properties on MediaWiki.
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'UserMagic',
'author' => array(
'Ross McClure',
'...'
),
'description' => 'Defines several username-producing magic words',
'url' => 'https://www.mediawiki.org/wiki/Extension:UserMagic',
'version' => '2.1.0',
'license-name' => 'GPL-2.0-or-later'
);
// Register extension hooks.
$wgHooks['OutputPageBeforeHTML'][] = 'wfUserMagic';
// Do the extension's action.
function wfUserMagic( $parserOutput, &$text ) {
global $wgUser, $wgRequest;
$text = str_replace(
array(
'__USERNAME__',
'__USERPAGE__',
'__USERIP__'
),
array(
$wgUser->getName(),
Linker::link( $wgUser->getUserPage(), $wgUser->getName() ),
$wgRequest->getIP()
),
$text
);
return true;
}
See also
- Extension:UserFunctions
- Extension:MyVariables
- UserMagic by MediaWiki4Intranet
This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.