Extension:CategoryHook.php
<?
- CategoryHook Extension
- - Adds a hook allowing articles to be added to additional categories based on wikitext content
- - Version 0.1 (2007-04-18)
- - See http://www.mediawiki.org/wiki/Extension:CategoryHook for installation and usage details
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
- {{#Security:*|dev}}{{#Security:view|*}}Template:Php
$wgExtensionCredits['parserhook'][] = array( 'name' => 'CategoryHook', 'author' => 'User:Nad', 'url' => 'http://www.mediawiki.org/Extension:CategoryHook', );
$wgHooks['ArticleAfterFetchContent'][] = 'wfCategoryHookProcess'; $wgHooks['ParserAfterTidy'][] = 'wfCategoryHookAdd';
$wgCategoryHookCatList = array();
- Determine the additional categories from the article's raw wikitext
function wfCategoryHookProcess(&$article,&$text) { global $wgCategoryHookCatList; $defaultSortKey = $article->mTitle->getDBkey();
# Articles containing trees if (preg_match('/\\{\\{#tree:/i',$text)) $wgCategoryHookCatList['Articles_containing_trees'] = $defaultSortKey;
return true; }
- Add the categories
function wfCategoryHookAdd(&$parser,&$text,&$strip_state) { global $wgCategoryHookCatList,$wgProfiler; $updating = $wgProfiler->getCurrentSection === 'Article::editUpdates'; foreach ($wgCategoryHookCatList as $dbkey => $sortkey) $parser->mOutput->addCategory($dbkey,$sortkey); return true; } ?>