Test:EstensioneCalendar
Da Uno Sguardo nel Buio.
Scopo
Questa estensione serve per poter presentare la data odierna (fuso orario del server) nel formato equivalente del calendario di Dere. Il calendario di Dere è organizzato come segue:
- 12 mesi (ognuno dei quali è associato ad uno dei Dodici Dei) di 30 giorni ciascuno più i 5 giorni dedicati al Dio senza nome, per complessivi 365 giorni
- non esistono gli anni bisestili
- il calendario inizia con il mese di Prajos, corrispondente al nostro Luglio, e precisamente il 5 di Luglio
- la settimana è identica alla nostra, anche se i nomi dei giorni sono differenti, per comodità vengono mappati uno a uno, anche se occorre tener presente delle possibili discontinuità dovute al fatto che l'anno terrestre può essere bisestile
Installazione
Inserire la seguente riga nel file LocalSettings.php
require_once( "extensions/DSADate/DSADate.php" );
Copiare il seguente codice nel file DSADate.php
<?php if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); } $wgExtensionFunctions[] = 'wfSetupDSADate'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'DSADate', 'url' => 'http://meta.wikimedia.org/wiki/DSADate', 'author' => 'Giuseppe Briotti', 'description' => 'converting date in DSA Calendars', ); $wgHooks['LanguageGetMagic'][] = 'wfDSADateLanguageGetMagic'; class ExtDSADate { function clearState() { return true; } function convertDSA( &$parser, $data = '', $dsacal = DSAHAL ) { $parser->disableCache(); // settings calendars information $d_dayname = array ( 'Praiostag', 'Rondratag', 'Feuertag', 'Wassertag', 'Windstag', 'Erdtag', 'Markttag'); $e_dayname = array ('Domenica', 'Lunedi', 'Martedi', 'Mercoledi', 'Giovedi', 'Venerdi', 'Sabato'); $d_monthname = array ('Firun', 'Tsa', 'Phex', 'Peraine', 'Ingerimm', 'Rahja', 'Tag des Namenlosen', 'Praios', 'Rondra', 'Efferd', 'Travia', 'Boron', 'Hesinde' ); $e_monthname = array ('Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ); $e_daypermonth = array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31); $d_daypermonth = array (30, 30, 30, 30, 30, 30, 5, 30, 30, 30, 30, 30, 30); try { if($data == '') { $e_year = date(Y); $e_month = date(m); $e_day = date(d); $e_dayofweek = date(w); } else { $e_year = date(Y, strtotime($data )); $e_month = date(m, strtotime($data )) ; $e_day = date(d, strtotime($data )); $e_dayofweek = date(w, strtotime($data )); } // compute the year in several DSA calendars switch ($dsacal){ case 1: $d_year = $e_year - 1970; $d_yearsym = "HAL"; break; case 2: $d_year = $e_year - 977; $d_yearsym = "BF"; break; case 3: $d_year = $e_year + 515; $d_yearsym = "Hor"; break; } // correcting the year since 5th of July is new year $e_date_4july=strtotime($e_year.'-07-04'); $e_date_totest=strtotime($e_year.'-'.$e_month.'-'.$e_day); if ($e_date_totest > $e_date_4july) { $d_year += 1 ; } // reduce the month by 1 to start base 0 instead of 1 $e_month -= 1; // computing the days since the year begin $e_daysincebeginning = $e_day; $i=0; for ($i; $i<$e_month; $i++) { $e_daysincebeginning += $e_daypermonth[$i]; } // retrieving the corresponding DSA month $i = 0; $d_daysincebeginning = $e_daysincebeginning; while ( $d_daysincebeginning > 0 ) { $d_daysincebeginning -= $d_daypermonth[$i]; $i++; } $d_month = $i-1; // computing the day of the month $d_day = $d_daysincebeginning + $d_daypermonth[$i-1]; //assuming that the day of the week is the same $d_dayofweek = $e_dayofweek; //return the day string return "{$d_dayname[$d_dayofweek]}, {$d_day} {$d_monthname[$d_month]} {$d_year} {$d_yearsym}"; } catch(Exception $e) { return $e->getMessage(); } } } function wfSetupDSADate() { global $wgParser, $wgMessageCache, $wgExtDSADate, $wgMessageCache, $wgHooks; $wgExtDSADate = new ExtDSADate; $wgParser->setFunctionHook( 'calDSA', array( &$wgExtDSADate, 'convertDSA' ) ); require_once( dirname( __FILE__ ) . '/DSADate.i18n.php' ); foreach( efDSADateMessages() as $lang => $messages ) $wgMessageCache->addMessages( $messages, $lang ); $wgHooks['ParserClearState'][] = array( &$wgExtDSADate, 'clearState' ); } function wfDSADateLanguageGetMagic( &$magicWords, $langCode ) { require_once( dirname( __FILE__ ) . '/DSADate.i18n.php' ); foreach( efDSADateWords( $langCode ) as $word => $trans ) $magicWords[$word] = $trans; return true; } ?>
Copiare il seguente codice nel file DSADate.i18n.php
<?php /** * Get translated magic words, if available * * @param string $lang Language code * @return array */ function efDSADateWords( $lang ) { $words = array(); /** * English */ $words['en'] = array( 'calDSA' => array( 0, 'calDSA' ), ); # English is used as a fallback, and the English synonyms are # used if a translation has not been provided for a given word return ( $lang == 'en' || !isset( $words[$lang] ) ) ? $words['en'] : array_merge( $words['en'], $words[$lang] ); } /** * Get extension messages * * @return array */ function efDSADateMessages() { $messages = array( /* English */ 'en' => array( 'ifunc_error' => 'Error', ), /* German */ 'de' => array( 'ifunc_error' => 'Fehler', ), /* French */ 'fr' => array( 'ifunc_error' => 'Erreur', ), /* Hebrew */ 'he' => array( 'ifunc_error' => 'שגוי', ), /* Dutch */ 'nl' => array( 'ifunc_error' => 'Fout', ), /* Italian */ 'it' => array( 'ifunc_error' => 'Errore', ), ); return $messages ; } ?>
Copiare i file DSADate.php e DSADate.i18n.php nella cartella extensions/DSADate