Introduced new function getPageRegion.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 16 Nov 2013 22:54:51 +0000 (22:54 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 16 Nov 2013 22:54:51 +0000 (22:54 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrreport/trunk@1819 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php

index e5f9dd1611f61eed7fb261085b42089a4ccc6796..4bc2cc9c154bc9aa04fa908b86f5a7b03c333211 100644 (file)
@@ -618,26 +618,36 @@ class WrReport {
        }
 
 
-       /// 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));
        }
 
 
@@ -776,7 +786,8 @@ class WrReport {
                $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