Extension:CategoryHook.php

From Organic Design wiki
Revision as of 07:59, 18 April 2007 by Nad (talk | contribs) (redo autocategorisation extension)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

<?

  1. CategoryHook Extension
  2. - Adds a hook allowing articles to be added to additional categories based on wikitext content
  3. - Version 0.1 (2007-04-18)
  4. - See http://www.mediawiki.org/wiki/Extension:CategoryHook for installation and usage details
  5. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
  6. - Author: http://www.organicdesign.co.nz/nad
  7. {{#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();

  1. 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; }

  1. 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; } ?>