Extension:UserMagic
<translate> This extension stores its source code on a wiki page.</translate> <translate> Please be aware that this code may be unreviewed or maliciously altered.</translate> <translate> They may contain security holes, outdated interfaces that are no longer compatible etc.</translate> <translate> Note:</translate> <translate> No [[<tvar name=localisation>Special:MyLanguage/Localisation#Translation resources</tvar>|localisation]] updates are provided for this extension by <tvar name=twn>translatewiki.net </tvar>.</translate> |
<translate> This extension is currently not actively maintained!</translate> <translate> Although it may still work, any bug reports or feature requests will more than likely be ignored.</translate> |
UserMagic Release status: unmaintained |
|
---|---|
Implementation | Extended syntax , MyWiki |
Description | Defines several username-producing magic words |
Author(s) | |
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 |
Quarterly downloads | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
Public wikis using | Lua error in Module:Extension at line 172: bad argument #1 to 'inNamespace' (unrecognized namespace name 'skin'). |
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
- <translate> <tvar name=1>Copy the code into a file called "UserMagic.php"</tvar> and place the file(s) in a directory called <tvar name=name>
UserMagic
</tvar> in your <tvar name=ext>extensions/
</tvar> folder.</translate> - <translate> Add the following code at the bottom of your <tvar name=1>LocalSettings.php </tvar> file:</translate>
require_once "$IP/extensions/UserMagic/UserMagic.php";
- File:OOjs UI icon check-constructive.svg <translate> Done</translate> – <translate> Navigate to <tvar name=special>Special:Version</tvar> on your wiki to verify that the extension is successfully installed.</translate>
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
- Extension:PageMagic
- Pages with script errors
- Pages with broken file links
- Extensions which host their code in-wiki
- Unmaintained extensions
- Extensions without an image
- Extended syntax extensions
- Personalization extensions
- Extensions without a compatibility policy
- Extensions with manual MediaWiki version
- GPL licensed extensions
- OutputPageBeforeHTML extensions
- All extensions
- Extensions not in ExtensionJson
- Extensions not using extension registration