diff --git a/DFRawFunctions.body.php b/DFRawFunctions.body.php index 331de79..6e3704e 100644 --- a/DFRawFunctions.body.php +++ b/DFRawFunctions.body.php @@ -1,7 +1,34 @@ setFunctionHook('df_raw', [ self::class, 'raw']); + $parser->setFunctionHook('df_tag', [ self::class, 'tag']); + $parser->setFunctionHook('df_tagentry', [ self::class, 'tagentry']); + $parser->setFunctionHook('df_tagvalue', [ self::class, 'tagvalue']); + $parser->setFunctionHook('df_foreachtag', [ self::class, 'foreachtag']); + $parser->setFunctionHook('df_foreachtoken', [ self::class, 'foreachtoken']); + $parser->setFunctionHook('df_makelist', [ self::class, 'makelist']); + $parser->setFunctionHook('df_statedesc', [ self::class, 'statedesc']); + $parser->setFunctionHook('df_cvariation', [ self::class, 'cvariation']); + $parser->setFunctionHook('mreplace', [ self::class, 'mreplace']); + $parser->setFunctionHook('delay', [ self::class, 'delay']); + $parser->setFunctionHook('eval', [ self::class, 'evaluate']); + return true; + } // Takes some raws and returns a 2-dimensional token array // If 2nd parameter is specified, then only tags of the specified type will be returned // Optional 3rd parameter allows specifying an array which will be filled with indentation for each line @@ -59,15 +86,23 @@ private static function loadFile ($data) if (!is_dir($wgDFRawPath)) return $data; - $filename = explode(':', $data, 2); - if (count($filename) != 2) - return $data; - $filename = str_replace(array('/', '\\'), '', $filename); + global $wgDFRawVersion; + $version_name = explode(':', $data, 2); + if ( count($version_name) == 2 and $version_name[0] != "") { + $version_name = str_replace(array('/', '\\'), '', $version_name); + $raw_version = $version_name[0]; + $file_name = $version_name[1]; + + if ($raw_version == 'DF2012') $raw_version = 'v0.34'; // HACK to handle both DF2012 and v0.34 - once the /raw pages for 0.34 have been fixed, this can go away + } else { + if ( $wgDFRawVersion == "" ) + return $data; - // HACK to handle both DF2012 and v0.34 - once the /raw pages for 0.34 have been fixed, this can go away - if ($filename[0] == 'DF2012') $filename[0] = 'v0.34'; + $raw_version = $wgDFRawVersion; + $file_name = str_replace(array('/', '\\', ":"), '', $data); + } - $wantfile = $wgDFRawPath .'/'. $filename[0] .'/'. $filename[1]; + $wantfile = $wgDFRawPath .'/'. $raw_version .'/'. $file_name; if (!is_file($wantfile)) return $data; @@ -160,7 +195,7 @@ public static function tagentry (&$parser, $data = '', $type = '', $num = 0, $of return $notfound; foreach ($tags as $tag) { - if ($offset >= count($tag)) + if ((int)$offset >= count($tag)) continue; $match = true; for ($i = 0; $i < $numcaps; $i++) @@ -281,12 +316,12 @@ public static function makelist (&$parser, $data = '', $object = '', $string = ' $val = self::statedesc($parser, substr($data, $start, $end - $start), $getoffset, $checkoffset); $rep_out[$i] = $val; continue; - } + } foreach ($tags as $tag) { if (($tag[0] != $gettype) || ($getoffset >= count($tag))) continue; - if (($checkoffset < 0) || (($checkoffset < count($tag)) && ($tag[$checkoffset] == $checkval))) + if (($checkoffset < 0) || (($checkoffset < count($tag)) && ($tag[$checkoffset] == $checkval))) { $rep_out[$i] = $tag[$getoffset]; break; diff --git a/DFRawFunctions.i18n.magic.php b/DFRawFunctions.i18n.magic.php index 0c29ce3..14953a6 100644 --- a/DFRawFunctions.i18n.magic.php +++ b/DFRawFunctions.i18n.magic.php @@ -4,20 +4,35 @@ * Dwarf Fortress Raw parser functions */ -$magicWords = array(); +$magicWords = []; -# English -$magicWords['en'] = array( - 'df_raw' => array(0, 'df_raw'), - 'df_tag' => array(0, 'df_tag'), - 'df_tagentry' => array(0, 'df_tagentry'), - 'df_tagvalue' => array(0, 'df_tagvalue'), - 'df_foreachtag' => array(0, 'df_foreachtag'), - 'df_foreachtoken' => array(0, 'df_foreachtoken'), - 'df_makelist' => array(0, 'df_makelist'), - 'df_statedesc' => array(0, 'df_statedesc'), - 'df_cvariation' => array(0, 'df_cvariation'), - 'mreplace' => array(0, 'mreplace'), - 'delay' => array(0, 'delay'), - 'eval' => array(0, 'eval'), -); +/** English */ +$magicWords['en'] = [ + 'df_raw' => [ 0, 'df_raw' ], + 'df_tag' => [ 0, 'df_tag' ], + 'df_tagentry' => [ 0, 'df_tagentry' ], + 'df_tagvalue' => [ 0, 'df_tagvalue' ], + 'df_foreachtag' => [ 0, 'df_foreachtag' ], + 'df_foreachtoken' => [ 0, 'df_foreachtoken' ], + 'df_makelist' => [ 0, 'df_makelist' ], + 'df_statedesc' => [ 0, 'df_statedesc' ], + 'df_cvariation' => [ 0, 'df_cvariation' ], + 'mreplace' => [ 0, 'mreplace' ], + 'delay' => [ 0, 'delay' ], + 'eval' => [ 0, 'eval' ], +]; + +$magicWords['ru'] = [ + 'df_raw' => [ 0, 'df_raw' ], + 'df_tag' => [ 0, 'df_tag' ], + 'df_tagentry' => [ 0, 'df_tagentry' ], + 'df_tagvalue' => [ 0, 'df_tagvalue' ], + 'df_foreachtag' => [ 0, 'df_foreachtag' ], + 'df_foreachtoken' => [ 0, 'df_foreachtoken' ], + 'df_makelist' => [ 0, 'df_makelist' ], + 'df_statedesc' => [ 0, 'df_statedesc' ], + 'df_cvariation' => [ 0, 'df_cvariation' ], + 'mreplace' => [ 0, 'mreplace' ], + 'delay' => [ 0, 'delay' ], + 'eval' => [ 0, 'eval' ], +]; \ No newline at end of file diff --git a/DFRawFunctions.php b/DFRawFunctions.php deleted file mode 100644 index 59e165c..0000000 --- a/DFRawFunctions.php +++ /dev/null @@ -1,58 +0,0 @@ - __FILE__, - 'name' => 'DFRawFunctions', - 'author' => 'Quietust', - 'url' => 'http://dwarffortresswiki.org/index.php/User:Quietust', - 'description' => 'Dwarf Fortress Raw parser functions', - 'version' => '1.7.3', -); - -$wgAutoloadClasses['DFRawFunctions'] = dirname(__FILE__) . '/DFRawFunctions.body.php'; - -$wgHooks['ParserFirstCallInit'][] = 'efDFRawFunctions_Initialize'; - -$wgExtensionMessagesFiles['DFRawFunctions'] = dirname(__FILE__) . '/DFRawFunctions.i18n.magic.php'; - -function efDFRawFunctions_Initialize (&$parser) -{ - $parser->setFunctionHook('df_raw', 'DFRawFunctions::raw'); - $parser->setFunctionHook('df_tag', 'DFRawFunctions::tag'); - $parser->setFunctionHook('df_tagentry', 'DFRawFunctions::tagentry'); - $parser->setFunctionHook('df_tagvalue', 'DFRawFunctions::tagvalue'); - $parser->setFunctionHook('df_foreachtag', 'DFRawFunctions::foreachtag'); - $parser->setFunctionHook('df_foreachtoken', 'DFRawFunctions::foreachtoken'); - $parser->setFunctionHook('df_makelist', 'DFRawFunctions::makelist'); - $parser->setFunctionHook('df_statedesc', 'DFRawFunctions::statedesc'); - $parser->setFunctionHook('df_cvariation', 'DFRawFunctions::cvariation'); - $parser->setFunctionHook('mreplace', 'DFRawFunctions::mreplace'); - $parser->setFunctionHook('delay', 'DFRawFunctions::delay'); - $parser->setFunctionHook('eval', 'DFRawFunctions::evaluate'); - return true; -} diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..59a8564 --- /dev/null +++ b/extension.json @@ -0,0 +1,36 @@ +{ + "name": "DFRawFunctions", + "version": "1.7.3", + "author": "Quietust", + "url": "http://dwarffortresswiki.org/index.php/User:Quietust", + "description": "Dwarf Fortress Raw parser functions", + "type": "parserhook", + "requires": { + "MediaWiki": ">= 1.33" + }, + "Hooks": { + "ParserFirstCallInit": "DFRawFunctions::efDFRawFunctions_Initialize" + }, + "AutoloadClasses": { + "DFRawFunctions": "DFRawFunctions.body.php" + }, + "ExtensionMessagesFiles": { + "DFRawFunctionsMagic": "DFRawFunctions.i18n.magic.php" + }, + "config": { + "DFRawEnableDisk": { + "value": false, + "description": "Enables reading files from disk" + }, + "DFRawPath": { + "value": "raws", + "path": true, + "description": "Relative path to raws directory" + }, + "DFRawVersion": { + "value": "", + "description": "Version of raw files that will be used when version prefix before filename non defined or empty, for example ':entity_default.txt'" + } + }, + "manifest_version": 2 +} \ No newline at end of file