}
- /// Adds a region feed to the current page
- private static function addRegionFeedLink($parser) {
- $dbr = wfGetDB(DB_SLAVE);
- $title = $parser->getTitle();
+ /// Returns the region details if the current page is one: Region name (as in the database) and region border (as WKB).
+ private static function getPageRegion($title) {
+ $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 a feed entry of the region?
+ // Do we have an entry of the region?
// Example: SELECT name FROM wrregion WHERE page_id = 882;
- $res = $dbr->select('wrregion', 'name', array('page_id' => $title->getArticleID()));
- while ($row = $dbr->fetchObject($res)) {
- // If yes, create the feed.
- // Note: As (of MediaWiki 1.19), only one feed can be added and each feed added replaces the previous one, the following is possible without risk of having duplicated feed entries.
- global $wgWrReportFeedRoot;
- global $wgOut; // class OutputPage
- $wgOut->addFeedLink('atom', $wgWrReportFeedRoot . '/berichte/region/' . strtolower($row->name));
+ $dbr = wfGetDB(DB_SLAVE);
+ $res = $dbr->select('wrregion', array('name', 'aswkb(border)'), array('page_id' => $title->getArticleID()));
+ if ($dbr->numRows($res) == 1) {
+ $row = $dbr->fetchRow($res);
+ $region_name = $row[0];
+ $region_border_wkb = $row[1];
}
+ $dbr->freeResult($res);
}
- $dbr->freeResult($res);
+ return array($region_name, $region_border_wkb);
+ }
+
+
+ /// Adds a region feed to the current page
+ private static function addRegionFeedLink($title) {
+ list($region_name, $region_border_wkb) = WrReport::getPageRegion($title);
+ if (is_null($region_name)) return;
+ global $wgWrReportFeedRoot;
+ global $wgOut; // class OutputPage
+ $wgOut->addFeedLink('atom', $wgWrReportFeedRoot . '/berichte/region/' . strtolower($region_name));
}
$parser->getOutput()->addModules('ext.wrreport');
// Add feed
- WrReport::addRegionFeedLink($parser);
+ // Note: As (of MediaWiki 1.19), only one feed can be added and each feed added replaces the previous one, the following is possible without risk of having duplicated feed entries.
+ WrReport::addRegionFeedLink($parser->getTitle());
// Add each page title that has been found
$page_titles = array(); // array of Title objects