* To activate the extension, rename this file to dewikify.php and * include it from your LocalSettings.php * with: require_once("extensions/dewikify.php"); */ $wgExtensionFunctions[]="dewikifyExtension"; $wgHooks['ParserBeforeStrip'][] = 'checkRemoveWikiOnly'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'dewikify', 'version' => '2006/04/29', 'author' => 'Austin Che', 'url' => 'http://openwetware.org/wiki/User:Austin/Extensions/Dewikify', 'description' => 'Enable dewikifying of web pages', ); function dewikifyExtension() { global $wgEnableParserCache, $wgRequest; if ($wgRequest->getVal('dewikify', 'no') == 'yes') { // we are dewikifying // disabling the parser cache and re-parsing the page allows our // hook to be called that re-parses the page with the wikionly tags $wgEnableParserCache = false; } } function checkRemoveWikiOnly ( &$parser , &$text, &$strip_state ) { /* strips everything within wikionly or nonwikionly tags depending on our context and removes the other tags so that everything inside is processed normally only removes newlines if the tag is only thing on that line to do this, does the replacement in a couple steps in first step, does lazy match to remove everything between appropriate tag but leaves the opening wikionly tag the second match, removes any line that contains only a wikionly tag the last line removes any remaining tags */ global $wgRequest; if ($wgRequest->getVal('dewikify', 'no') == 'yes') { # dewikifying $text = preg_replace('/.*?<\/wikionly>/is', '', $text); $text = preg_replace('/\n\n/is', "\n", $text); $text = preg_replace('//is', '', $text); $text = preg_replace('/(.*?)<\/nonwikionly>/is', '$1', $text); } else { # on the wiki $text = preg_replace('/.*?<\/nonwikionly>/is', '', $text); $text = preg_replace('/\n\n/is', "\n", $text); $text = preg_replace('//is', '', $text); $text = preg_replace('/(.*?)<\/wikionly>/is', '$1', $text); } // has to return true so other extensions can process this hook return true; } ?>