Skip to content

rebase extension.json work around new codebase #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions DFRawFunctions.body.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
<?php
/*
* DFRawFunctions extension by Quietust
* Dwarf Fortress Raw parser functions
*/

if (!defined('MEDIAWIKI'))
{
echo "This file is an extension of the MediaWiki software and cannot be used standalone\n";
die(1);
}

class DFRawFunctions
{

public static function efDFRawFunctions_Initialize (Parser $parser)
{
$parser->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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 31 additions & 16 deletions DFRawFunctions.i18n.magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
];
58 changes: 0 additions & 58 deletions DFRawFunctions.php

This file was deleted.

36 changes: 36 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't it also be absolute? I don't see any checks for the path root in DFRawFunctions.body.php

Copy link
Contributor Author

@MEXAHOTABOP MEXAHOTABOP Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With "path": true mediawiki insert extension directory to path without any other checks.
So only relative.

https://github.com/wikimedia/mediawiki/blob/9afab251cac5b02564a68c13f25418c522df9467/includes/registration/ExtensionProcessor.php#L831

},
"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
}