From d4e2662c44dd10325dbaae5e76a130441d37410e Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Mon, 2 Jan 2023 05:47:38 +0300 Subject: [PATCH 1/8] rebase extension.json work around new codebase fix problem with non evalable wgDFRawPath --- DFRawFunctions.body.php | 61 ++++++++++++++++++++++++++++------- DFRawFunctions.i18n.magic.php | 47 ++++++++++++++++++--------- DFRawFunctions.php | 58 --------------------------------- extension.json | 33 +++++++++++++++++++ 4 files changed, 113 insertions(+), 86 deletions(-) delete mode 100644 DFRawFunctions.php create mode 100644 extension.json diff --git a/DFRawFunctions.body.php b/DFRawFunctions.body.php index 469c3d9..f3c0e16 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 @@ -56,18 +83,28 @@ private static function loadFile ($data) return $data; global $wgDFRawPath; + if ($wgDFRawPath == "") + $wgDFRawPath = __DIR__ . '/raws'; if (!is_dir($wgDFRawPath)) - return $data; - - $filename = explode(':', $data, 2); - if (count($filename) != 2) - return $data; - $filename = str_replace(array('/', '\\'), '', $filename); - - // 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'; + return __DIR__ . $data; + + 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; + + $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; @@ -281,12 +318,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..12df6d9 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 ba780d4..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.4', -); - -$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..416c8fd --- /dev/null +++ b/extension.json @@ -0,0 +1,33 @@ +{ + "name": "DFRawFunctions", + "version": "1.7", + "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 + }, + "DFRawPath": { + "value": "" + }, + "DFRawVersion": { + "value": "" + } + }, + + "manifest_version": 2 +} \ No newline at end of file From 0d299e04cc69f8e01a81ce110eafc338cd9bb9be Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Mon, 2 Jan 2023 06:32:19 +0300 Subject: [PATCH 2/8] replace space indention with tabs remove missed __DIR__ --- DFRawFunctions.body.php | 10 +++++----- DFRawFunctions.i18n.magic.php | 36 +++++++++++++++++------------------ extension.json | 1 - 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/DFRawFunctions.body.php b/DFRawFunctions.body.php index f3c0e16..a560d3f 100644 --- a/DFRawFunctions.body.php +++ b/DFRawFunctions.body.php @@ -13,7 +13,7 @@ class DFRawFunctions { - public static function efDFRawFunctions_Initialize (Parser $parser) + public static function efDFRawFunctions_Initialize (Parser $parser) { $parser->setFunctionHook('df_raw', [ self::class, 'raw']); $parser->setFunctionHook('df_tag', [ self::class, 'tag']); @@ -84,12 +84,12 @@ private static function loadFile ($data) global $wgDFRawPath; if ($wgDFRawPath == "") - $wgDFRawPath = __DIR__ . '/raws'; + $wgDFRawPath = __DIR__ . '/raws'; if (!is_dir($wgDFRawPath)) - return __DIR__ . $data; + return $data; - global $wgDFRawVersion; - $version_name = explode(':', $data, 2); + 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]; diff --git a/DFRawFunctions.i18n.magic.php b/DFRawFunctions.i18n.magic.php index 12df6d9..14953a6 100644 --- a/DFRawFunctions.i18n.magic.php +++ b/DFRawFunctions.i18n.magic.php @@ -11,28 +11,28 @@ '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' ], + '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' ], + '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/extension.json b/extension.json index 416c8fd..e7d51eb 100644 --- a/extension.json +++ b/extension.json @@ -28,6 +28,5 @@ "value": "" } }, - "manifest_version": 2 } \ No newline at end of file From 0c40111ea14b8fbedd1fa40351d2d8268044f8b9 Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Tue, 3 Jan 2023 05:11:37 +0300 Subject: [PATCH 3/8] extension.json: add description to config values --- extension.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extension.json b/extension.json index e7d51eb..bd651a1 100644 --- a/extension.json +++ b/extension.json @@ -19,13 +19,16 @@ }, "config": { "DFRawEnableDisk": { - "value": false + "value": false, + "description": "Enables reading files from disk" }, "DFRawPath": { - "value": "" + "value": "", + "description": "Absolute path to raws directory, when empty use 'raws' directory in extension catalog" }, "DFRawVersion": { - "value": "" + "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 From b3cab0092e66ac19ba4d1c3a7c702dd8f4415406 Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Tue, 3 Jan 2023 05:20:24 +0300 Subject: [PATCH 4/8] extension.json,DFRawFunctions.body.php: use relative path for DFRawPath --- DFRawFunctions.body.php | 2 -- extension.json | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DFRawFunctions.body.php b/DFRawFunctions.body.php index a560d3f..6e3704e 100644 --- a/DFRawFunctions.body.php +++ b/DFRawFunctions.body.php @@ -83,8 +83,6 @@ private static function loadFile ($data) return $data; global $wgDFRawPath; - if ($wgDFRawPath == "") - $wgDFRawPath = __DIR__ . '/raws'; if (!is_dir($wgDFRawPath)) return $data; diff --git a/extension.json b/extension.json index bd651a1..87f6379 100644 --- a/extension.json +++ b/extension.json @@ -23,8 +23,9 @@ "description": "Enables reading files from disk" }, "DFRawPath": { - "value": "", - "description": "Absolute path to raws directory, when empty use 'raws' directory in extension catalog" + "value": "raws", + "path": true, + "description": "Relative path to raws directory" }, "DFRawVersion": { "value": "", From 575c2cf817ad53a4fcf22b9bb997eaae9847ebed Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Wed, 8 Feb 2023 20:10:01 +0300 Subject: [PATCH 5/8] extension.json: version 1.7.1 --- extension.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.json b/extension.json index 87f6379..3145a72 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "DFRawFunctions", - "version": "1.7", + "version": "1.7.1", "author": "Quietust", "url": "http://dwarffortresswiki.org/index.php/User:Quietust", "description": "Dwarf Fortress Raw parser functions", From 5866967a12f8c046db5cb04d2ca42532dd423529 Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Fri, 11 Aug 2023 15:14:53 +0300 Subject: [PATCH 6/8] extension.json: version 1.7.2 --- extension.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.json b/extension.json index 3145a72..b112305 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "DFRawFunctions", - "version": "1.7.1", + "version": "1.7.2", "author": "Quietust", "url": "http://dwarffortresswiki.org/index.php/User:Quietust", "description": "Dwarf Fortress Raw parser functions", From 2f67ef5c7d4f78b7c9584a91d1bdb70660d56620 Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Tue, 14 Jan 2025 15:19:08 +0300 Subject: [PATCH 7/8] extension.json: version 1.7.3 --- extension.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.json b/extension.json index b112305..59a8564 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "DFRawFunctions", - "version": "1.7.2", + "version": "1.7.3", "author": "Quietust", "url": "http://dwarffortresswiki.org/index.php/User:Quietust", "description": "Dwarf Fortress Raw parser functions", From 5ce280e85b1c54cfd2622a9ecfd154578d0f77d4 Mon Sep 17 00:00:00 2001 From: mexahotabop Date: Tue, 23 Dec 2025 19:58:57 +0300 Subject: [PATCH 8/8] extension.json: version 1.7.4 --- extension.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.json b/extension.json index 59a8564..b025365 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "DFRawFunctions", - "version": "1.7.3", + "version": "1.7.4", "author": "Quietust", "url": "http://dwarffortresswiki.org/index.php/User:Quietust", "description": "Dwarf Fortress Raw parser functions",