Extension:UserMagic
![]() |
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. |
UserMagic Release status: experimental |
|||
---|---|---|---|
Implementation | Extended syntax, MyWiki | ||
Description | Defines several username-producing magic words | ||
Author(s) | Ross McClure (Algorithmtalk) | ||
Latest version | 1.1 (2013-01-15) | ||
MediaWiki | 1.12+ | ||
Database changes | No | ||
License | GPL v2 + | ||
Download | see below | ||
Example | http://wikible.org/en/ | ||
|
|||
Translate the UserMagic extension if it is available at translatewiki.net |
|||
Check usage and version matrix; code metrics |
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[edit | edit source]
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.
Lastly, these magic words will not be replaced in Preview mode.
Code[edit | edit source]
<?php /** * UserMagic * Defines several username-producing magic words. * * @author Algorithm [http://meta.wikimedia.org/wiki/User:Algorithm] * @version 1.1 (2013-01-15) * @copyright © 2006 Algorithm */ $wgHooks['OutputPageBeforeHTML'][] = 'wfUserMagic'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'UserMagic', 'author' => 'Ross McClure', 'description' => 'Defines several username-producing magic words', 'url' => 'https://www.mediawiki.org/wiki/Extension:UserMagic', 'version' => '1.1' ); function wfUserMagic($parserOutput, $text) { global $wgUser; $text = str_replace( array("__USERNAME__","__USERPAGE__","__USERIP__"), array($wgUser->getName(), $wgUser->getSkin()->makeLinkObj( $wgUser->getUserPage(), $wgUser->getName()), wfGetIP()), $text); return true; }