%s

Skrevet %s av %s

%s

', $data["title"], $data["date"], $data["user"], preg_replace('/@pvv\./', ' AT pvv.', $data["body"])); } function tolower($str) { return str_replace( array("\xc3\x86", "\xc3\x98", "\xc3\x85"), // ÆØÅ array("\xc3\xa6", "\xc3\xb8", "\xc3\xa5"), // æøå strtolower($str)); } $wgHooks['ParserGetVariableValueSwitch'][] = 'wfLocalMotdAssignAValue'; function wfLocalMotdAssignAValue(&$parser, &$cache, &$magicWordId, &$ret) { if (MAG_LOCALMOTD == $magicWordId) { // We found a value //$ret='This is a really silly value'; //$ret = file_get_contents( '/local/etc/motd' ); #$lines = file('/local/etc/motd'); $lines = file('/usr/local/etc/motd'); $data = array(); $ret = ""; foreach ($lines as $line) { if (preg_match('/^(\d{4})(\d\d)(\d\d) (.*)/', $line, $matches)) { if (count($data) > 0) { $ret .= toHtml($data); $data = array(); } $data["date"] = $matches[1]."-".$matches[2]."-".$matches[3]; $data["title"] = substr($matches[4], 0, 1).tolower(substr($matches[4], 1)); $data["body"] = ""; } elseif (preg_match('/^([a-z]+)\s+(.*)/', $line, $matches)) { $data["user"] = $matches[1]; $data["body"] .= rtrim($matches[2]); } elseif (preg_match('/^\s*$/', $line)) { $data["body"] .= "\n\n"; } else { $data["body"] .= rtrim($line); } } $ret .= toHtml($data); } // We must return true for two separate reasons: // 1. To permit further callbacks to run for this hook. // They might override our value but that's life. // Returning false would prevent these future callbacks from running. // 2. At the same time, "true" indicates we found a value. // Returning false would the set variable value to null. // // In other words, true means "we found a value AND other // callbacks will run," and false means "we didn't find a value // AND abort future callbacks." It's a shame these two meanings // are mixed in the same return value. So as a rule, return // true whether we found a value or not. return true; } #--------------------------------------------------- # Step 4: register the custom variables so that it # shows up in Special:Version under the # listing of custom variables #--------------------------------------------------- $wgExtensionCredits[MAG_LOCALMOTD][] = array( 'name' => 'Local MOTD', 'author' => 'Magnus Kristiansen', 'url' => 'http://www.mediawiki.org/wiki/Extension:LocalMotd', 'description' => 'Includes the motd from the filesystem' ); #--------------------------------------------------- # Step 5: register wiki markup words associated with # MAG_NIFTYVAR as a variable and not some # other type of magic word #--------------------------------------------------- $wgHooks['MagicWordwgVariableIDs'][] = 'wfLocalMotdDeclareVarIds'; function wfLocalMotdDeclareVarIds(&$aCustomVariableIds) { #aCustomVariableIds is where MediaWiki wants to store its #list of custom variable ids. We oblige by adding ours: $aCustomVariableIds[] = MAG_LOCALMOTD; #must do this or you will silence every MagicWordwgVariableIds #registered after this! return true; }