Now the extension works with the wrregioncache table.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 18 Nov 2013 22:36:48 +0000 (22:36 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 18 Nov 2013 22:36:48 +0000 (22:36 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrreport/trunk@1827 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php

index 95f008c123ca83848b021f84f959cfeb790c7664..525a2b8ad5b5c3f54e89a5a89858f9a2622f7ffc 100644 (file)
@@ -618,8 +618,9 @@ class WrReport {
        }
 
 
-       /// Returns the region details if the current page is one: Region name (as in the database) and region border (as WKB).
+       /// 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).
        private static function getPageRegion($title) {
+               $region_id = null;
                $region_name = null;
                $region_border_wkb = null;
                $categories = $title->getParentCategories(); // e.g. array('Kategorie:Region' => 'Osttirol')
@@ -629,21 +630,22 @@ class WrReport {
                        // 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('name', 'aswkb(border)'), array('page_id' => $title->getArticleID()));
+                       $res = $dbr->select('wrregion', array('id', '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];
+                               $region_id = $row[0];
+                               $region_name = $row[1];
+                               $region_border_wkb = $row[2];
                        }
                        $dbr->freeResult($res);
                }
-               return array($region_name, $region_border_wkb);
+               return array($region_id, $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);
+               list($region_id, $region_name, $region_border_wkb) = WrReport::getPageRegion($title);
                if (is_null($region_name)) return;
                global $wgWrReportFeedRoot;
                global $wgOut; // class OutputPage
@@ -814,20 +816,20 @@ class WrReport {
                $parser->getOutput()->addModules('ext.wrreport');
 
                // get border for region
-               list($region_name, $region_border_wkb) = WrReport::getPageRegion($parser->getTitle());
+               list($region_id, $region_name, $region_border_wkb) = WrReport::getPageRegion($parser->getTitle());
                if (is_null($region_name)) return; // no region page
 
                // get titles that are in the region
                $page_titles = array();
                $dbr = wfGetDB(DB_SLAVE);
-               $res = $dbr->select('wrsledruncache', 'page_id', array('CONTAINS(GEOMFROMWKB(' . $dbr->addQuotes($region_border_wkb) . '), POINT(position_longitude, position_latitude))', 'under_construction' => false), __METHOD__, 'page_title');
+               // 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);
 
-               // note that MySQL returns too many data compared to real "CONTAINS".
-
                $html = WrReport::createBahnentabelle($page_titles);
                return array($html, 'noparse' => true, 'isHTML' => true);
        }