Initial commit
This commit is contained in:
commit
c494723346
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
#--------------------------------------------------
|
||||
# Step 1: choose a magic word id
|
||||
#--------------------------------------------------
|
||||
|
||||
# storing the chosen id in a constant is not required
|
||||
# but still good programming practice - it makes
|
||||
# searching for all occurrences of the magic word id a
|
||||
# bit easier - note that the name of the constant
|
||||
# and the value it is assigned don't have to have anthing
|
||||
# to do with each other.
|
||||
|
||||
define('MAG_LOCALMOTD', 'localmotd');
|
||||
|
||||
#---------------------------------------------------
|
||||
# Step 2: define some words to use in wiki markup
|
||||
#---------------------------------------------------
|
||||
|
||||
$wgHooks['LanguageGetMagic'][] = 'wfLocalMotdWikiWords';
|
||||
function wfLocalMotdWikiWords(&$aWikiWords, $langID) {
|
||||
|
||||
#tell MediaWiki that all {{NiftyVar}}, {{NIFTYVAR}},
|
||||
#{{CoolVar}}, {{COOLVAR}} and all case variants found
|
||||
#in wiki text should be mapped to magic id 'mycustomvar1'
|
||||
# (0 means case-insensitive)
|
||||
$aWikiWords[MAG_LOCALMOTD] = array(0, 'LocalMotd');
|
||||
|
||||
#must do this or you will silence every LanguageGetMagic
|
||||
#hook after this!
|
||||
return true;
|
||||
}
|
||||
|
||||
#---------------------------------------------------
|
||||
# Step 3: assign a value to our variable
|
||||
#---------------------------------------------------
|
||||
|
||||
function toHtml($data) {
|
||||
return sprintf('<h3>%s</h3><p><em>Skrevet %s av %s</em></p><p>%s</p>',
|
||||
$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;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
# Tidspunkt for neste nerdepizza
|
||||
|
||||
define('PVV_NESTE_PIZZA_ID', 'pvv_neste_pizza');
|
||||
|
||||
$wgHooks['LanguageGetMagic'][] = 'pvvMagicWords';
|
||||
function pvvMagicWords(&$magicWords, $lang) {
|
||||
$magicWords[PVV_NESTE_PIZZA_ID] = array(0, 'NestePizza');
|
||||
return true;
|
||||
}
|
||||
|
||||
$wgHooks['ParserGetVariableValueSwitch'][] = 'pvvVariableValues';
|
||||
function pvvVariableValues(&$parser, &$cache, &$magicWordId, &$ret) {
|
||||
if ($magicWordId == PVV_NESTE_PIZZA_ID) {
|
||||
$ret = pvvNestePizza();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function pvvNestePizza() {
|
||||
$time = time();
|
||||
$week = date('W');
|
||||
$weekday = date('N');
|
||||
if ($week % 2 == 0 && $weekday <= 5) {
|
||||
$daysUntilPizza = 5 - $weekday;
|
||||
} elseif ($week % 2 == 0 && $weekday > 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;
|
||||
}
|
||||
|
|
@ -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.
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
|
||||
if (!defined('MEDIAWIKI')) {
|
||||
echo <<<EOT
|
||||
To install my extension, put the following line in LocalSettings.php:
|
||||
require_once( "\$IP/extensions/UserloginHTTPS/UserloginHTTPS.php" );
|
||||
EOT;
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
$wgExtensionCredits['specialpage'][] = array(
|
||||
'name' => '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);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue