Kategorien
Bearbeiten von „FreewarWiki:Bot/Skripts/maplist.php“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
{{Scriptquelltextverwendung}} | {{Scriptquelltextverwendung}} | ||
Das Skript ist semantisch identisch zu [[FreewarWiki:Bot/Skripts/maplist.pl]] mit dem Unterschied, dass es die Informationen aus [[:Kategorie:Felder]] holt. | |||
<pre> | <pre> | ||
<?php | <?php | ||
header('Content-Type: text/plain; charset=utf-8;'); | header('Content-Type: text/plain; charset=utf-8;'); | ||
error_reporting(E_ALL ^ E_NOTICE); | error_reporting(E_ALL ^ E_NOTICE); | ||
define('TEMPLATE_GET_KEY', 1); | define('TEMPLATE_GET_KEY', 1); | ||
define('TEMPLATE_GET_VALUE', 2); | define('TEMPLATE_GET_VALUE', 2); | ||
function is_obsolete($wiki_text) | function is_obsolete($wiki_text) { | ||
{ | |||
// Veraltetes Feld=none liefert true! | // Veraltetes Feld=none liefert true! | ||
return (bool)preg_match('/Veraltetes Feld=[^}]+/', $wiki_text); | return (bool)preg_match('/Veraltetes Feld=[^}]+/', $wiki_text); | ||
} | } | ||
function get_areas($url, $prefix) { | |||
// | preg_match_all("/>$prefix:([^<]+)</", file_get_contents($url), $areas); | ||
function get_templates($template, $wiki_text) | return $areas[1]; | ||
{ | } | ||
function get_templates($template, $wiki_text) { | |||
$pattern = '/\{\{(Vorlage:)?' . preg_quote($template, '/') . '/'; | $pattern = '/\{\{(Vorlage:)?' . preg_quote($template, '/') . '/'; | ||
$templates = preg_split($pattern, $wiki_text); | $templates = preg_split($pattern, $wiki_text); | ||
return array_slice($templates, 1); | return array_slice($templates, 1); | ||
} | } | ||
function parse_field_article($area, $host) { | |||
function parse_field_article($area) | |||
{ | |||
$fields = array(); | $fields = array(); | ||
// Artikel fetchen | // Artikel fetchen | ||
$field_url = | $field_url = "$host/index.php/Felder:" . str_replace(' ', '%20', $area). | ||
"?action=raw"; | |||
$html = file_get_contents($field_url); | $html = file_get_contents($field_url); | ||
Zeile 66: | Zeile 55: | ||
} | } | ||
function parse_field_template($wiki_text) { | |||
function parse_field_template($wiki_text) | |||
{ | |||
// Standard-Werte | // Standard-Werte | ||
$field = array( | $field = array( | ||
'accessible' => 1, | 'accessible' => 1, | ||
'pos_x' => -10, | 'pos_x' => -10, | ||
'pos_y' => -9, | 'pos_y' => -9, | ||
'npc' => array(), | 'npc' => array(), | ||
'url' => '', | 'url' => '', | ||
'passages' => array() | 'passages' => array() | ||
); | ); | ||
Zeile 110: | Zeile 72: | ||
$field['pos_x'] = (int)$template['X']; | $field['pos_x'] = (int)$template['X']; | ||
$field['pos_y'] = (int)$template['Y']; | $field['pos_y'] = (int)$template['Y']; | ||
$field['url'] = $template['Bild']; | $field['url'] = $template['Bild']; | ||
// Passagen lesen | // Passagen lesen | ||
Zeile 120: | Zeile 82: | ||
// keine Koordinaten gesetzt | // keine Koordinaten gesetzt | ||
if ( | if (!isset($passage['X']) || !isset($passage['Y'])) { | ||
trigger_error('Keine Koordinatenangabe in Passage von '. | |||
$template['Name'] . ' nach ' . $passage['Nach'], E_USER_WARNING); | |||
} else { | } else { | ||
$field['passages'][] = $passage['X'] . ',' . $passage['Y']; | $field['passages'][] = $passage['X'] . ',' . $passage['Y']; | ||
Zeile 131: | Zeile 91: | ||
// npcs lesen | // npcs lesen | ||
preg_match_all('/\[\[([^]]+)]]/', $template['NPC'], $npc_matches | preg_match_all('/\[\[([^]]+)\]\]/', $template['NPC'], $npc_matches); | ||
$field['npc'] = $npc_matches[1]; | $field['npc'] = $npc_matches[1]; | ||
Zeile 137: | Zeile 97: | ||
} | } | ||
function parse_template($text) | function parse_template($text) { | ||
{ | |||
$template = array(); | $template = array(); | ||
Zeile 157: | Zeile 116: | ||
for ($i = 1, $length = strlen($text); $i < $length; ++$i) { | for ($i = 1, $length = strlen($text); $i < $length; ++$i) { | ||
if ($text[$i] === '{' && $text[$i + 1] === '{') { // weitere Vorlage | if ($text[$i] === '{' && $text[$i+1] === '{') { // weitere Vorlage | ||
++$depth; | ++$depth; | ||
++$i; | ++$i; | ||
$template[$key] .= '{'; | $template[$key] .= '{'; | ||
} else if ($text[$i] === '}' && $text[$i + 1] === '}') { // geschlossene Vorlage | } else if ($text[$i] === '}' && $text[$i+1] === '}') { // geschlossene Vorlage | ||
if ($depth === 0) { | if ($depth === 0) { | ||
Zeile 170: | Zeile 129: | ||
$template[$key] .= '}'; | $template[$key] .= '}'; | ||
} | } | ||
} else if ($text[$i] === '[' && $text[$i + 1] === '[') { // geöffneter Link | } else if ($text[$i] === '[' && $text[$i+1] === '[') { // geöffneter Link | ||
++$depth; | ++$depth; | ||
++$i; | ++$i; | ||
$template[$key] .= '['; | $template[$key] .= '['; | ||
} else if ($text[$i] === ']' && $text[$i + 1] === ']') { // geschlossener Link | } else if ($text[$i] === ']' && $text[$i+1] === ']') { // geschlossener Link | ||
if ($depth === 0) { | if ($depth === 0) { | ||
Zeile 199: | Zeile 158: | ||
} | } | ||
return array_map('trim', $template); | return array_map('trim',$template); | ||
} | } | ||
// | $host = 'http://fwwiki.de'; | ||
$prefix = 'Felder'; // Wiki-Namespace | |||
$parser_function = 'parse_field_article'; // Parser Funktion des Skripts | |||
$category_url = "$host/index.php/Kategorie:Felder"; // Gebietskategorie | |||
// init | |||
$fields = array(); | |||
// | // Gebiete fetchen | ||
$areas = get_areas($category_url, $prefix); | |||
// durchlaufen | |||
foreach ($areas | foreach ($areas as $area) { | ||
$fields = array_merge($fields, | $fields = array_merge($fields, $parser_function($area, $host)); | ||
} | } | ||
// | // und ausgeben | ||
$delimiter = ';'; | |||
// head | |||
#echo implode($delimiter, array_keys($fields[0])) . "\n"; | |||
// body | |||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||
// output wie maplist.pl | // output wie maplist.pl | ||
$field['npc'] = implode('/', $field['npc']); | |||
$field['passages'] = implode('/', $field['passages']); | |||
echo implode($delimiter, $field) . "\n"; | |||
} | } | ||
</pre> | </pre> |