}
- /// Returns the region details if the current page is one: Region name (as in the database), region_id (as in the database) and region border (as WKB).
+ /// Returns the region details of the region specifed in $conditions.
+ /// region_id (as in the database), region name (as in the database), and region border (as WKB).
+ /// conditions is an array that's given to the where clause
+ private static function getRegionDetails($conditions) {
+ // Example: SELECT name FROM wrregion WHERE page_id = 882;
+ $dbr = wfGetDB(DB_SLAVE);
+ $res = $dbr->select('wrregion', array('id', 'name', 'aswkb(border)'), $conditions);
+ if ($dbr->numRows($res) == 1) {
+ $row = $dbr->fetchRow($res);
+ return array($row[0], $row[1], $row[2]); // region_id, region_name, region_border_wkb
+ }
+ $dbr->freeResult($res);
+ return array(null, null, null);
+ }
+
+
+ /// Returns the region details if the specified title is one.
+ /// region_id (as in the database), region name (as in the database), and region border (as WKB).
private static function getPageRegion($title) {
- $region_id = null;
- $region_name = null;
- $region_border_wkb = null;
$categories = $title->getParentCategories(); // e.g. array('Kategorie:Region' => 'Osttirol')
global $wgContLang;
$key_region = $wgContLang->getNSText(NS_CATEGORY) . ':Region';
if (array_key_exists($key_region, $categories)) {
- // Do we have an entry of the region?
- // Example: SELECT name FROM wrregion WHERE page_id = 882;
- $dbr = wfGetDB(DB_SLAVE);
- $res = $dbr->select('wrregion', array('id', 'name', 'aswkb(border)'), array('page_id' => $title->getArticleID()));
- if ($dbr->numRows($res) == 1) {
- $row = $dbr->fetchRow($res);
- $region_id = $row[0];
- $region_name = $row[1];
- $region_border_wkb = $row[2];
- }
- $dbr->freeResult($res);
+ return WrReport::getRegionDetails(array('page_id' => $title->getArticleID()));
}
- return array($region_id, $region_name, $region_border_wkb);
+ return array(null, null, null);
}
/// <bahnenregiontabelle />
///
/// Example 2:
- /// <bahnenregiontabelle region="Innsbruck" />
+ /// <bahnenregiontabelle wiki="Innsbruck" /> (refers to region represented by the MediaWiki Title name)
+ /// <bahnenregiontabelle region_id="3" /> (refers to id in the wrregion table)
+ /// <bahnenregiontabelle region_name="Innsbruck" /> (refers to name in the wrregion table)
public static function bahnenregiontabelleParserHook($input, $args, $parser) {
$parser->getOutput()->addModules('ext.wrreport');
- // git title representing the region the sledrun list should be generated for
- $title = $parser->getTitle(); // default title: current page
- if (isset($args['region'])) $title = Title::newFromText($args['region']);
+ try {
+ // we accept 0 or 1 parameters
+ if (count($args) > 1) throw new InvalidArgumentException(wfMessage('wrreport-bahnenregiontabelle-toomanyarguments')->text());
+
+ if (count($args) == 0) {
+ // current page represents a region
+ $title = $parser->getTitle(); // default title: current page
+ list($region_id, $region_name, $region_border_wkb) = WrReport::getPageRegion($title);
+ if (is_null($region_id)) throw new Exception(wfMessage('wrreport-bahnenregiontabelle-thispagenoregion')->text());
+ } elseif (isset($args['wiki'])) {
+ // other page represents a region
+ $title = Title::newFromText($args['wiki']);
+ list($region_id, $region_name, $region_border_wkb) = WrReport::getPageRegion($title);
+ if (is_null($region_id)) throw new Exception(wfMessage('wrreport-bahnenregiontabelle-pagenoregion')->text());
+ } elseif (isset($args['region_id'])) {
+ list($region_id, $region_name, $region_border_wkb) = WrReport::getRegionDetails(array('id' => $args['region_id']));
+ if (is_null($region_id)) throw new Exception(wfMessage('wrreport-bahnenregiontabelle-noregionid')->text());
+ } elseif (isset($args['region_name'])) {
+ list($region_id, $region_name, $region_border_wkb) = WrReport::getRegionDetails(array('name' => $args['region_name']));
+ if (is_null($region_id)) throw new Exception(wfMessage('wrreport-bahnenregiontabelle-noregionname')->text());
+ } else {
+ throw new InvalidArgumentException(wfMessage('wrreport-bahnenregiontabelle-invalidargument', array_keys($args)[0])->text());
+ }
- // get border for region
- list($region_id, $region_name, $region_border_wkb) = WrReport::getPageRegion($title);
- if (is_null($region_name)) return; // no region page
+ // get titles that are in the region
+ $page_titles = array();
+ $dbr = wfGetDB(DB_SLAVE);
+ // 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');
+ foreach ($res as $row) {
+ $page_titles[] = Title::newFromId($row->page_id);
+ }
+ $dbr->freeResult($res);
+ $html = WrReport::createBahnentabelle($page_titles);
- // get titles that are in the region
- $page_titles = array();
- $dbr = wfGetDB(DB_SLAVE);
- // 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');
- foreach ($res as $row) {
- $page_titles[] = Title::newFromId($row->page_id);
+ } catch (Exception $e) {
+ $doc = new WrDOMDocument();
+ $doc->appendElement('span', array('class' => 'error'))->appendText(wfMessage('wrreport-bahnenregiontabelle-error', $e->getMessage())->text());
+ $html = $doc->saveHTML($doc->firstChild);
}
- $dbr->freeResult($res);
- $html = WrReport::createBahnentabelle($page_titles);
return array($html, 'noparse' => true, 'isHTML' => true);
}
'wrreport-sledrun-walkuptime' => 'Text',
'wrreport-sledrun-height' => 'Text',
'wrreport-sledrun-length' => 'Text',
+ 'wrreport-bahnenregiontabelle-toomanyarguments' => 'Text. Error message saying that the <bahnenregiontabelle> tag accepts only one argument at once.',
+ 'wrreport-bahnenregiontabelle-thispagenoregion' => 'Text. Error message saying that the current page is no region page (as needed if <bahnenregiontabelle> is specified without arguments).',
+ '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-error' => 'Text. Text describing that an error in paring/using the <bahnenregiontabelle> tag occurred. $1 gives details.',
'wrreport-icon-sledrental' => 'Text',
'wrreport-icon-nightlight' => 'Text',
'wrreport-icon-lift' => 'Text',
'wrreport-sledrun-walkuptime' => 'Walk Time',
'wrreport-sledrun-height' => 'Altitude',
'wrreport-sledrun-length' => 'Length',
+ 'wrreport-bahnenregiontabelle-toomanyarguments' => 'Only one argument at once is allowed.',
+ 'wrreport-bahnenregiontabelle-thispagenoregion' => 'The current page is no region or the region was not found in the region table of the database.',
+ 'wrreport-bahnenregiontabelle-pagenoregion' => 'The specified page is no region or the region was not found in the region table of the database.',
+ 'wrreport-bahnenregiontabelle-noregionid' => 'The specified region ID was not found in the region table of the database.',
+ '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-icon-sledrental' => 'Sled Rental',
'wrreport-icon-nightlight' => 'Light at Night',
'wrreport-icon-lift' => 'Help me get up',
'wrreport-sledrun-walkuptime' => 'Gehzeit',
'wrreport-sledrun-height' => 'Höhe',
'wrreport-sledrun-length' => 'Länge',
+ 'wrreport-bahnenregiontabelle-toomanyarguments' => 'Es dürfen nicht mehrere Parameter gleichzeitig angegeben werden.',
+ 'wrreport-bahnenregiontabelle-thispagenoregion' => 'Die aktuelle Seite ist keine Region oder die Region wurde nicht in der Regionen-Tabelle der Datenbank gefunden.',
+ 'wrreport-bahnenregiontabelle-pagenoregion' => 'Die angegebene Wiki-Seite repräsentiert keine Region oder die Region wurde nicht in der Regionen-Tabelle der Datenbank gefunden.',
+ 'wrreport-bahnenregiontabelle-noregionid' => 'Die angegebene Regionen ID wurde nicht in der Regionen-Tabelle der Datenbank gefunden.',
+ 'wrreport-bahnenregiontabelle-noregionname' => 'Der angegebene Regionenname wurde nicht in der Regionen-Tabelle der Datenbank gefunden.',
+ 'wrreport-bahnenregiontabelle-invalidargument' => 'Das Argument $1 ist nicht erlaubt.',
+ 'wrreport-bahnenregiontabelle-error' => 'Der folgende Fehler ist bei der Interpretation von <bahnenregiontabelle> aufgetreten: $1',
'wrreport-icon-sledrental' => 'Rodelverleih',
'wrreport-icon-nightlight' => 'Beleuchtet',
'wrreport-icon-lift' => 'Aufstiegshilfe/Lift',