// page_ids of sledrun titles that that are going to be returned
$page_ids = array();
foreach ($xml as $entry) { // entry is <rodelbahn>, <region> or <rodelbahnen>
+ $entry_page_ids = array(); // page_ids selected (or un-selected) for this entry.
$tagname = $entry->getName();
$attributes = array();
- foreach ($entry->attributes() as $key => $value) $attributes[] = $key;
-
- // is the element known?
- if (!in_array($tagname, array('rodelbahn', 'region', 'rodelbahnen')))
- throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
+ foreach ($entry->attributes() as $key => $value) $attributes[(string) $key] = (string) $value;
// parse operation attribute
$operation = '+'; // '+' (append) or '-' (subtract)
}
// parse in_arbeit attribute
- $unter_construction = false;
+ $under_construction = false; // false (only sledruns that are not under construction), true (only sledruns under construction) or null (doen't matter)
+ if ($tagname === 'rodelbahn') $under_construction = null; // different default value for tag <rodelbahn>.
if (array_key_exists('in_arbeit', $attributes)) {
- if (!in_array($attributes['in_arbeit'], array('ja', 'nein', '*')))
- throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-value', $tagname, 'operation', $operation)->text());
- if (in_array($attributes['in_arbeit'] === 'nein')) $under_construction = false;
- elseif (in_array($attributes['*'] === '*')) $under_construction = null;
+ if ($attributes['in_arbeit'] === 'nein') $under_construction = false;
+ elseif ($attributes['in_arbeit'] === 'ja') $under_construction = true;
+ elseif ($attributes['in_arbeit'] === '*') $under_construction = null;
+ else throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-value', $tagname, 'in_arbeit', $under_construction)->text());
unset($attributes['in_arbeit']);
}
// <rodelbahn>
if ($tagname == 'rodelbahn') {
$page_title = Title::newFromText(trim($entry));
- if ($page_title && $page_title->exists()) $page_ids[] = $page_title->getArticleID();
+ if ($page_title && $page_title->exists()) $entry_page_ids[] = $page_title->getArticleID();
}
- // <region>
- elseif ($tagname == 'region') {
- // get titles that are in the region
- // the following line would work if MySQL 5.5 would implement a real geospatial version of CONTAINS.
- // $res = $dbr->select('wrsledruncache', 'page_id', array('CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))', 'NOT under_construction'), __METHOD__, 'page_title');
- $res = $dbr->select(array('wrsledruncache', 'wrregioncache'), array('page_id' => 'wrregioncache.page_id'), array('wrregioncache.region_id' => $region_id, 'wrregioncache.page_id=wrsledruncache.page_id', 'NOT under_construction'), __METHOD__, 'page_title');
+ // <region> and <rodelbahn>
+ elseif ($tagname === 'region' || $tagname === 'rodelbahnen') {
+ $tables = array('wrsledruncache');
+ $where = array();
+
+ // region
+ if ($tagname === 'region') {
+ // the following line would work if MySQL 5.5 would implement a real geospatial version of CONTAINS.
+ // $where[] = 'CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))'
+ $tables[] = 'wrregion';
+ $tables[] = 'wrregioncache';
+ $where[] = 'wrregioncache.region_id=wrregion.id';
+ $where[] = 'wrregioncache.page_id=wrsledruncache.page_id';
+ $where['wrregion.name'] = $entry;
+ }
+
+ // under contruction
+ if ($under_construction === true) $where[] = 'wrsledruncache.under_construction';
+ if ($under_construction === false) $where[] = 'not wrsledruncache.under_construction';
+
+ // query
+ $res = $dbr->select($tables, array('page_id' => 'wrsledruncache.page_id'), $where, __METHOD__, 'page_id');
foreach ($res as $row) {
- $page_titles[] = Title::newFromId($row->page_id);
+ $entry_page_ids[] = $row->page_id;
}
$dbr->freeResult($res);
}
- // <rodelbahnen>
- elseif ($tagname == 'rodelbahnen') {
- }
-
else throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
+ // merge the entry page_ids with the page_ids
+ if ($operation == '+') $page_ids = array_merge($page_ids, $entry_page_ids);
+ elseif ($operation == '-') $page_ids = array_diff($page_ids, $entry_page_ids);
}
// page_titles that are going to be returned
- $page_titles = array();
- foreach ($page_ids as $page_id) {
- $page_titles[] = Title::newFromId($page_id);
- }
+ $page_titles = Title::newFromIDs($page_ids);
+
$html = WrReport::createBahnentabelle($page_titles);
} catch (WrReportException $e) {
'wrreport-bahnenregiontabelle-pagenoregion' => 'Text. Error message saying that the specified wiki page is no region page.',
'wrreport-bahnenregiontabelle-noregionid' => 'Text. Error message saying that the specified region ID was not found in the database (table wrregion)',
'wrreport-bahnenregiontabelle-noregionname' => 'Text. Error message saying that the specified region name was not found in the database (table wrregion)',
- 'wrreport-bahnenregiontabelle-invalidargument' => 'Text. Error message saying that the argument (given by $1) of <bahnenregiontabelle> is invalid',
+ 'wrreport-bahnenregiontabelle-invalid-argument' => 'Text. Error message saying that the argument (given by $1) of <bahnenregiontabelle> is invalid',
'wrreport-bahnenregiontabelle-error' => 'Text. Text describing that an error in paring/using the <bahnenregiontabelle> tag occurred. $1 gives details.',
+ 'wrreport-rodelbahntabelle-error' => 'Text. Text describing that an error in paring/using the <rodelbahntabelle> tag occurred. $1 gives details.',
'wrreport-rodelbahntabelle-textbetweenelements' => 'Text. Error message describing that invalid text is found between elements. $1 gives the complete XML.',
'wrreport-rodelbahntabelle-invalid-element' => 'Text. Error message describing that the element given as $1 is not known.',
'wrreport-rodelbahntabelle-invalid-attribute-name' => 'Text. Error message describing that the attribute given as $2 of the elment given as $1 is not known.',
'wrreport-bahnenregiontabelle-noregionname' => 'The specified region name was not found in the region table of the database.',
'wrreport-bahnenregiontabelle-invalidargument' => 'The argument $1 is not allowed.',
'wrreport-bahnenregiontabelle-error' => 'The following error occurred at the <bahnenregiontabelle> tag: $1',
+ 'wrreport-rodelbahntabelle-error' => 'The following error occurred while parsing <rodelbahntabelle>: $1',
'wrreport-rodelbahntabelle-textbetweenelements' => 'Unknown text was found between the subelements: $1',
'wrreport-rodelbahntabelle-invalid-element' => 'The element $1 is not known.',
'wrreport-rodelbahntabelle-invalid-attribute-name' => 'The attribute $2 of element $1 is not known.',