Skip to content

Commit 3a42e51

Browse files
committed
rebase extension.json work around new codebase
fix problem with non evalable wgDFRawPath
1 parent 89f3a81 commit 3a42e51

4 files changed

Lines changed: 113 additions & 86 deletions

File tree

DFRawFunctions.body.php

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
<?php
2+
/*
3+
* DFRawFunctions extension by Quietust
4+
* Dwarf Fortress Raw parser functions
5+
*/
6+
7+
if (!defined('MEDIAWIKI'))
8+
{
9+
echo "This file is an extension of the MediaWiki software and cannot be used standalone\n";
10+
die(1);
11+
}
212

313
class DFRawFunctions
414
{
15+
16+
public static function efDFRawFunctions_Initialize (Parser $parser)
17+
{
18+
$parser->setFunctionHook('df_raw', [ self::class, 'raw']);
19+
$parser->setFunctionHook('df_tag', [ self::class, 'tag']);
20+
$parser->setFunctionHook('df_tagentry', [ self::class, 'tagentry']);
21+
$parser->setFunctionHook('df_tagvalue', [ self::class, 'tagvalue']);
22+
$parser->setFunctionHook('df_foreachtag', [ self::class, 'foreachtag']);
23+
$parser->setFunctionHook('df_foreachtoken', [ self::class, 'foreachtoken']);
24+
$parser->setFunctionHook('df_makelist', [ self::class, 'makelist']);
25+
$parser->setFunctionHook('df_statedesc', [ self::class, 'statedesc']);
26+
$parser->setFunctionHook('df_cvariation', [ self::class, 'cvariation']);
27+
$parser->setFunctionHook('mreplace', [ self::class, 'mreplace']);
28+
$parser->setFunctionHook('delay', [ self::class, 'delay']);
29+
$parser->setFunctionHook('eval', [ self::class, 'evaluate']);
30+
return true;
31+
}
532
// Takes some raws and returns a 2-dimensional token array
633
// If 2nd parameter is specified, then only tags of the specified type will be returned
734
// 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)
5683
return $data;
5784

5885
global $wgDFRawPath;
86+
if ($wgDFRawPath == "")
87+
$wgDFRawPath = __DIR__ . '/raws';
5988
if (!is_dir($wgDFRawPath))
60-
return $data;
61-
62-
$filename = explode(':', $data, 2);
63-
if (count($filename) != 2)
64-
return $data;
65-
$filename = str_replace(array('/', '\\'), '', $filename);
66-
67-
// HACK to handle both DF2012 and v0.34 - once the /raw pages for 0.34 have been fixed, this can go away
68-
if ($filename[0] == 'DF2012') $filename[0] = 'v0.34';
89+
return __DIR__ . $data;
90+
91+
global $wgDFRawVersion;
92+
$version_name = explode(':', $data, 2);
93+
if ( count($version_name) == 2 and $version_name[0] != "") {
94+
$version_name = str_replace(array('/', '\\'), '', $version_name);
95+
$raw_version = $version_name[0];
96+
$file_name = $version_name[1];
97+
98+
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
99+
} else {
100+
if ( $wgDFRawVersion == "" )
101+
return $data;
102+
103+
$raw_version = $wgDFRawVersion;
104+
$file_name = str_replace(array('/', '\\', ":"), '', $data);
105+
}
69106

70-
$wantfile = $wgDFRawPath .'/'. $filename[0] .'/'. $filename[1];
107+
$wantfile = $wgDFRawPath .'/'. $raw_version .'/'. $file_name;
71108

72109
if (!is_file($wantfile))
73110
return $data;
@@ -281,12 +318,12 @@ public static function makelist (&$parser, $data = '', $object = '', $string = '
281318
$val = self::statedesc($parser, substr($data, $start, $end - $start), $getoffset, $checkoffset);
282319
$rep_out[$i] = $val;
283320
continue;
284-
}
321+
}
285322
foreach ($tags as $tag)
286323
{
287324
if (($tag[0] != $gettype) || ($getoffset >= count($tag)))
288325
continue;
289-
if (($checkoffset < 0) || (($checkoffset < count($tag)) && ($tag[$checkoffset] == $checkval)))
326+
if (($checkoffset < 0) || (($checkoffset < count($tag)) && ($tag[$checkoffset] == $checkval)))
290327
{
291328
$rep_out[$i] = $tag[$getoffset];
292329
break;

DFRawFunctions.i18n.magic.php

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@
44
* Dwarf Fortress Raw parser functions
55
*/
66

7-
$magicWords = array();
7+
$magicWords = [];
88

9-
# English
10-
$magicWords['en'] = array(
11-
'df_raw' => array(0, 'df_raw'),
12-
'df_tag' => array(0, 'df_tag'),
13-
'df_tagentry' => array(0, 'df_tagentry'),
14-
'df_tagvalue' => array(0, 'df_tagvalue'),
15-
'df_foreachtag' => array(0, 'df_foreachtag'),
16-
'df_foreachtoken' => array(0, 'df_foreachtoken'),
17-
'df_makelist' => array(0, 'df_makelist'),
18-
'df_statedesc' => array(0, 'df_statedesc'),
19-
'df_cvariation' => array(0, 'df_cvariation'),
20-
'mreplace' => array(0, 'mreplace'),
21-
'delay' => array(0, 'delay'),
22-
'eval' => array(0, 'eval'),
23-
);
9+
/** English */
10+
$magicWords['en'] = [
11+
'df_raw' => [ 0, 'df_raw' ],
12+
'df_tag' => [ 0, 'df_tag' ],
13+
'df_tagentry' => [ 0, 'df_tagentry' ],
14+
'df_tagvalue' => [ 0, 'df_tagvalue' ],
15+
'df_foreachtag' => [ 0, 'df_foreachtag' ],
16+
'df_foreachtoken' => [ 0, 'df_foreachtoken' ],
17+
'df_makelist' => [ 0, 'df_makelist' ],
18+
'df_statedesc' => [ 0, 'df_statedesc' ],
19+
'df_cvariation' => [ 0, 'df_cvariation' ],
20+
'mreplace' => [ 0, 'mreplace' ],
21+
'delay' => [ 0, 'delay' ],
22+
'eval' => [ 0, 'eval' ],
23+
];
24+
25+
$magicWords['ru'] = [
26+
'df_raw' => [ 0, 'df_raw' ],
27+
'df_tag' => [ 0, 'df_tag' ],
28+
'df_tagentry' => [ 0, 'df_tagentry' ],
29+
'df_tagvalue' => [ 0, 'df_tagvalue' ],
30+
'df_foreachtag' => [ 0, 'df_foreachtag' ],
31+
'df_foreachtoken' => [ 0, 'df_foreachtoken' ],
32+
'df_makelist' => [ 0, 'df_makelist' ],
33+
'df_statedesc' => [ 0, 'df_statedesc' ],
34+
'df_cvariation' => [ 0, 'df_cvariation' ],
35+
'mreplace' => [ 0, 'mreplace' ],
36+
'delay' => [ 0, 'delay' ],
37+
'eval' => [ 0, 'eval' ],
38+
];

DFRawFunctions.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

extension.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "DFRawFunctions",
3+
"version": "1.7",
4+
"author": "Quietust",
5+
"url": "http://dwarffortresswiki.org/index.php/User:Quietust",
6+
"description": "Dwarf Fortress Raw parser functions",
7+
"type": "parserhook",
8+
"requires": {
9+
"MediaWiki": ">= 1.33"
10+
},
11+
"Hooks": {
12+
"ParserFirstCallInit": "DFRawFunctions::efDFRawFunctions_Initialize"
13+
},
14+
"AutoloadClasses": {
15+
"DFRawFunctions": "DFRawFunctions.body.php"
16+
},
17+
"ExtensionMessagesFiles": {
18+
"DFRawFunctionsMagic": "DFRawFunctions.i18n.magic.php"
19+
},
20+
"config": {
21+
"DFRawEnableDisk": {
22+
"value": false
23+
},
24+
"DFRawPath": {
25+
"value": ""
26+
},
27+
"DFRawVersion": {
28+
"value": ""
29+
}
30+
},
31+
32+
"manifest_version": 2
33+
}

0 commit comments

Comments
 (0)