Difference between revisions of "MediaWiki code snippets"
m (→Update templates) |
(just stick to small snippets) |
||
Line 2: | Line 2: | ||
=== Raw wikitext content === | === Raw wikitext content === | ||
+ | <php> | ||
+ | if ($rev = Revision::newFromTitle($title)) { | ||
+ | $lastmod = wfTimestamp(TS_RFC2822,$rev->getTimestamp()); | ||
+ | header("Last-modified: $lastmod"); | ||
+ | $text = $rev->getText(); | ||
+ | return $text; | ||
+ | } | ||
+ | </php> | ||
=== Return an HTTP error page === | === Return an HTTP error page === | ||
− | == Creating | + | == Creating and updating articles == |
=== Edit or create === | === Edit or create === | ||
− | === Expand templates === | + | == Using the parser == |
+ | === Parse wikitext === | ||
+ | <php> | ||
+ | $html = $wgParser->parse($wikitext,$title,new ParserOptions(),true,true)->getText(); | ||
+ | </php> | ||
+ | === Expand templates only === | ||
+ | <php> | ||
+ | $wikitext = $wgParser->preprocess($wikitext,$title,new ParserOptions()); | ||
+ | </php> | ||
− | === | + | == MediaWiki Environment == |
− | This | + | === Article title === |
+ | This should be called at an appropriate time such as from the ''OutputPageBeforeHTML'' hook. | ||
<php> | <php> | ||
− | + | $wgOut->setPageTitle('foo'); | |
+ | </php> | ||
− | + | == Article queries == | |
− | + | === List article titles from a category === | |
− | + | <php> | |
− | + | $db = &wfGetDB(DB_SLAVE); | |
− | + | $cl = $db->tableName('categorylinks'); | |
− | + | $result = $db->query("SELECT cl_from FROM $cl WHERE cl_to = '$category' ORDER BY cl_sortkey"); | |
− | + | while ($row = mysql_fetch_row($result)) $titleText = Title::newFromID($row[0])->getText(); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</php> | </php> | ||
[[Category:MediaWiki]] | [[Category:MediaWiki]] |
Revision as of 04:43, 14 June 2007
Contents
Returning content to the client
Raw wikitext content
<php> if ($rev = Revision::newFromTitle($title)) { $lastmod = wfTimestamp(TS_RFC2822,$rev->getTimestamp()); header("Last-modified: $lastmod"); $text = $rev->getText(); return $text; } </php>
Return an HTTP error page
Creating and updating articles
Edit or create
Using the parser
Parse wikitext
<php> $html = $wgParser->parse($wikitext,$title,new ParserOptions(),true,true)->getText(); </php>
Expand templates only
<php> $wikitext = $wgParser->preprocess($wikitext,$title,new ParserOptions()); </php>
MediaWiki Environment
Article title
This should be called at an appropriate time such as from the OutputPageBeforeHTML hook. <php> $wgOut->setPageTitle('foo'); </php>
Article queries
List article titles from a category
<php> $db = &wfGetDB(DB_SLAVE); $cl = $db->tableName('categorylinks'); $result = $db->query("SELECT cl_from FROM $cl WHERE cl_to = '$category' ORDER BY cl_sortkey"); while ($row = mysql_fetch_row($result)) $titleText = Title::newFromID($row[0])->getText(); </php>