Extension:Bashfr
|
Bashfr Random Quotes Release status: beta |
|||
|---|---|---|---|
| Implementation | Tag | ||
| Description | Random quotes from bashfr.org | ||
| License | No license specified | ||
| Download | No link | ||
| Example | sorry | ||
|
|||
| Check usage and version matrix | |||
Contents |
What can this extension do? [edit]
Like Extension:RandomInclude or RandomText it provides a random quote from a pre-formatted file.
Usage [edit]
Merely include this tag within any page at the place you wish to display a random quotation from the bashfr_fortunes file:
<bashfr />
Installation [edit]
- Create a folder: mediawiki/extensions/bashfr
- Create a text file named bashfr.php and paste the php code listed below into it.
- Get a bashfr_fortunes file from http://www.bashfr.org/bashfr_fortunes
Note: This site is only in French and I could not find any Fortune files there. However, any Fortune text file (such as from this site) can be copied to the /mediawiki/extensions/bashfr directory and renamed bashfr_fortunes and it will work. A Fortunes text file has this format:
I reject your reality and substitute my own... % This is one of those "What the hell am I doing?" moments, over! % We got a robot in the water, he's stuffed with tuna and it's just another day here at Mythbusters.
- Edit LocalSettings.php and add:
require_once("$IP/extensions/bashfr/bashfr.php");
- Put <bashfr /> tag on the desired pages at the location you wish the quote to appear.
Parameters [edit]
None.
Changes to LocalSettings.php [edit]
require_once("$IP/extensions/bashfr/bashfr.php");
Code [edit]
<?php # Bashfr extension # <bashfr /> # with: include("extensions/bashfr.php"); $wgExtensionFunctions[] = "wfBashfrExtension"; function wfBashfrExtension() { global $wgParser; $wgParser->setHook( "bashfr", "renderBashfr" ); } function renderBashfr( $input, $argv, &$parser ) { //$fortunes = explode(chr(13).chr(10)."%".chr(13).chr(10), file_get_contents('bashfr_fortunes')); $fortunes = explode("\n%\n", file_get_contents('extensions/bashfr/bashfr_fortunes')); $fortune = htmlentities($fortunes[array_rand($fortunes)], ENT_QUOTES); $output = nl2br(ereg_replace('[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]', '<a href="\\0">\\0</a>', $fortune)); return $output; } ?>
Bypassing the MediaWiki cache [edit]
At this stage it gets a bit tricky, though, due to the automatic caching of pages in MediaWiki. If you save a page with the source code above, the page will be created and placed in the cache with one of the lines in it. This will only change once the source code is changed again. To get around this, I invalidate every page that is older than one day (= 86400 seconds). This can be achieved by placing the following in LocalSettings.php:
require("includes/GlobalFunctions.php"); $wgCacheEpoch = wfTimestamp( TS_MW, time() - 86400 ); # 60*60*24 = 1 day
Of course it is possible to set this value to a lower number but keep in mind that this will have an impact on server load as pages are regenerated more often rather than pulled from cache.
To help testing the extension without modifying the Cache Epoch, a refresh of a cached page can be forced by appending &action=purge to the URL.
