Extension:Urlencode
See also Help:Magic words
|
|
This extension is obsolete! It has been replaced by core functionality in the MediaWiki software. |
|
Urlencode Release status: unknown |
|
|---|---|
| Implementation | Tag |
| Description | performs the exact same function as the PHP function of the exact same name. See External Links for clarification. The string passed to the extension for urlencoding is first parsed by the wiki engine to evaluate any code. See Usage for clarification. |
| Author(s) | w:User:Dmb000006 ?? |
| MediaWiki | 1.6.10 |
| License | No license specified |
| Download | No link |
|
Check usage (experimental) |
|
The extension urlencode performs the exact same function as the PHP function of the exact same name. See External Links for clarification. The string passed to the extension for urlencoding is first parsed by the wiki engine to evaluate any code. See Usage for clarification.
This function was created to fill the gap left by the lack of proper parser functions in MediaWiki Version 1.6.10.
Note: For newer versions of Mediawiki, you don't need this extension. Just use the {{urlencode:...}} parser functions. See Help:Parser function on Meta.
[edit] Install
Create a file called 'urlify.php' in your extensions/ directory, and add the following code...
<?php /** * Setup and Hooks for the CategoryTree extension, an AJAX based gadget * to display the category structure of a wiki * * @addtogroup Extensions * @author ¿? * @licence GNU General Public Licence 2.0 or later */ /** * Register extension setup hook and credits */ $wgExtensionFunctions[] = "wfExtensionUrlify"; $wgExtensionCredits['parserhook'][] = array( 'name' => 'Urlencode', 'author' => 'none', 'url' => 'http://www.mediawiki.org/wiki/Extension:Urlencode', 'description' => 'PHP urlencode function, adds <nowiki><urlencode></nowiki> tag', ); function wfExtensionUrlify() { global $wgParser; # register the extension with the WikiText parser # the first parameter is the name of the new tag. # In this case it defines the tag <urlencode> ... </urlencode> # the second parameter is the callback function for # processing the text between the tags $wgParser->setHook( "urlencode", "urlify" ); } # The callback function for converting the input text to HTML output function urlify( $input, $argv, &$parser ) { $output = $parser->parse( $input, $parser->mTitle, $parser->mOptions, false, false ); return urlencode( $output->getText() ); } ?>
Then simply add the following line to the end of your LocalSettings.php file:
include("extensions/urlify.php");
and you are ready to go! Go to the sandbox and see if it works!
[edit] Usage
| You type... | The result is... |
|---|---|
| <urlencode>hello world</urlencode> | hello+world |
| <urlencode>{{PAGENAME}}</urlencode> | the+page+name |
| <urlencode>teacher's books</urlencode> | teacher%27s+books |
| <urlencode>any string you like</urlencode> | same result as PHP's urlencode |
