Difference between revisions of "MediaWiki code snippets"
({{code}}) |
(Wikitext in Sidebar) |
||
Line 148: | Line 148: | ||
) | ) | ||
</pre>}} | </pre>}} | ||
+ | |||
+ | == Wikitext in Sidebar == | ||
+ | <php> | ||
+ | global $wgUser,$wgTitle,$wgParser; | ||
+ | $side = new Article(Title::newFromText('MediaWiki:Sidebar')); | ||
+ | if (is_object($wgParser)) { $psr = $wgParser; $opt = $wgParser->mOptions; } | ||
+ | else { $psr = new Parser; $opt = NULL; } | ||
+ | if (!is_object($opt)) $opt = ParserOptions::newFromUser($wgUser); | ||
+ | $html = $psr->parse($side->fetchContent(),$wgTitle,$opt,true,true)->getText(); | ||
+ | echo preg_replace("/<li>\\s*<\\/li>/",'',$html); | ||
+ | </php> | ||
+ | |||
[[Category:MediaWiki]][[Category:Examples]][[Category:Examples/PHP]] | [[Category:MediaWiki]][[Category:Examples]][[Category:Examples/PHP]] |
Revision as of 01:46, 31 July 2007
Contents
Returning content to the client
Raw wikitext content
This function returns the raw content specified in $text, it can be callled any time from extension-setup or after. If the $save parameter is supplied it will bring up a download dialog with teh default name set to $save, otherwise it will download and open unprompted. If $expand is set to true, then any templates, parser-functions or variables in the content will be expanded.
Return an HTTP error page
Domain-based default redirect
If no page title is specified, redirect to a default depending on the domain name in the requested URL. In this example requests to abc.org or any of it's subdomains with no title specified will redirect to the Welcome to ABC article, and any requests to the exact domain of www.xyz.org without a title end up at the XYZ Home article. Titleless requests to any other domain which resolves to this example wiki will be unaffected and left to the rest of the configuration to deal with. This code should be executed early in the LocalSettings before any extensions are included, but after $wgServer is defined.
Articles
Get article content
Edit or create
Using the parser
Parse wikitext
Expand templates only
MediaWiki Environment
Article title
This should be called at an appropriate time such as from the OutputPageBeforeHTML hook.
Article queries
List article titles from a category
Check if a title is in a category
Misc
examineBraces
This function returns an array of the brace structure found in the passed wikitext parameter.
') {
$brace =& $braces[$depths[$depth-1]]; $brace[LENGTH] = $match[0][1]-$brace[OFFSET]+2; $brace[DEPTH] = $depth--; } else { $depths[$depth++] = count($braces); $braces[] = array( NAME => $match[1][0], OFFSET => $match[0][1] ); } } return $braces; } </php>}}
The following input,
Gives the following array:
Wikitext in Sidebar
<php> global $wgUser,$wgTitle,$wgParser; $side = new Article(Title::newFromText('MediaWiki:Sidebar')); if (is_object($wgParser)) { $psr = $wgParser; $opt = $wgParser->mOptions; } else { $psr = new Parser; $opt = NULL; } if (!is_object($opt)) $opt = ParserOptions::newFromUser($wgUser); $html = $psr->parse($side->fetchContent(),$wgTitle,$opt,true,true)->getText();
echo preg_replace("/