$attributes = array();
foreach ($entry->attributes() as $key => $value) $attributes[(string) $key] = (string) $value;
+ // is the tagname valid?
+ if (!in_array($tagname, array('rodelbahn', 'rodelbahnen', 'region')))
+ throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-element', $tagname)->text());
+
// parse operation attribute
$operation = '+'; // '+' (append) or '-' (subtract)
if (array_key_exists('operation', $attributes)) {
if (count($attributes) > 0)
throw new WrReportException(wfMessage('wrreport-rodelbahntabelle-invalid-attribute-name', $tagname, array_keys($attributes)[0])->text());
+
+ // build SQL query
+ $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;
+ }
+
// <rodelbahn>
if ($tagname == 'rodelbahn') {
- $page_title = Title::newFromText(trim($entry));
- if ($page_title && $page_title->exists()) $entry_page_ids[] = $page_title->getArticleID();
+ $where['page_title'] = trim($entry);
}
- // <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';
+ // 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) {
- $entry_page_ids[] = $row->page_id;
- }
- $dbr->freeResult($res);
+ // query
+ $res = $dbr->select($tables, array('page_id' => 'wrsledruncache.page_id'), $where, __METHOD__, 'page_id');
+ foreach ($res as $row) {
+ $entry_page_ids[] = $row->page_id;
}
+ $dbr->freeResult($res);
- 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);