From c4947233464b4bb6051950c1d8ad886d8ca057be Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 18 May 2023 22:39:11 +0200 Subject: [PATCH] Initial commit --- LocalMotd/LocalMotd.php | 125 ++++++++++++++++++++++++++++++ NerdePizza/NerdePizza.php | 49 ++++++++++++ README.md | 4 + UserloginHTTPS/UserloginHTTPS.php | 58 ++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 LocalMotd/LocalMotd.php create mode 100644 NerdePizza/NerdePizza.php create mode 100644 README.md create mode 100644 UserloginHTTPS/UserloginHTTPS.php diff --git a/LocalMotd/LocalMotd.php b/LocalMotd/LocalMotd.php new file mode 100644 index 0000000..c67ae01 --- /dev/null +++ b/LocalMotd/LocalMotd.php @@ -0,0 +1,125 @@ +%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; +} diff --git a/NerdePizza/NerdePizza.php b/NerdePizza/NerdePizza.php new file mode 100644 index 0000000..4d86b79 --- /dev/null +++ b/NerdePizza/NerdePizza.php @@ -0,0 +1,49 @@ + 5) { + $daysUntilPizza = 5 - $weekday + 14; + } else { + $daysUntilPizza = 5 - $weekday + 7; + } + $pizzaTime = $time + $daysUntilPizza*24*3600; + return 'Neste nerdepizza er fredag ' + . date('d.m.Y', $pizzaTime) + . ' (' . $daysUntilPizza . ' dager igjen).'; +} + +$wgExtensionCredits['variable'][] = array( + 'name' => 'NestePizza', + 'author' => 'Øystein Skartsæterhagen', + 'url' => 'http://wiki.pvv.ntnu.no/pvv/Nerdepizza', + 'description' => 'Gir datoen for neste nerdepizza' + ); + +$wgHooks['MagicWordwgVariableIDs'][] = 'pvvDeclareVarIds'; +function pvvDeclareVarIds(&$aCustomVariableIds) { + $aCustomVariableIds[] = PVV_NESTE_PIZZA_ID; + return true; +} + diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f78c3c --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Custom mediawiki extensions + +This is a repository to track PVVs custom mediawiki modules. +They are currently not in use, but might be reinstated at a later date, or just used as a reference. diff --git a/UserloginHTTPS/UserloginHTTPS.php b/UserloginHTTPS/UserloginHTTPS.php new file mode 100644 index 0000000..99335e0 --- /dev/null +++ b/UserloginHTTPS/UserloginHTTPS.php @@ -0,0 +1,58 @@ + 'UserloginHTTPS', + 'author' => 'Magnus Kristiansen', + 'url' => 'http://www.mediawiki.org/wiki/Extension:UserloginHTTPS', + 'description' => 'Redirect Special:Userlogin to HTTPS if accessed via HTTP', + 'descriptionmsg' => 'userloginhttps-desc', + 'version' => '1.0.0', +); + +$wgHooks['SpecialPage_initList'][] = 'ulh_overrideUserlogin'; + +function ulh_overrideUserlogin(&$list) { + global $ulh_originalData; + + $ulh_originalData = $list['Userlogin']; + $list['Userlogin'] = array('SpecialPage', 'Userlogin', '', true, 'ulh_SpecialUserlogin', __FILE__); + + return true; +} + +function ulh_SpecialUserlogin($par) { + global $wgRequest, $wgOut, $ulh_originalData; + + $url = $wgRequest->getFullRequestURL(); + if (substr($url, 0, 5) == 'http:') { + $new_url = 'https:' . substr($url, 5); + $wgOut->redirect($new_url); + return; + } + + $rec = $ulh_originalData; + if ( is_string( $rec ) ) { + $className = $rec; + $sp = new $className; + } elseif ( is_array( $rec ) ) { + $className = array_shift( $rec ); + $sp = wfCreateObject( $className, $rec ); + } else { + $wgOut->showErrorPage('Internal error', 'Error in Userlogin override.'); + return; + } + + require_once($sp->getFile()); + wfSpecialUserlogin($par); +} + +?>