]> ToastFreeware Gitweb - philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff - wrmap.body.php
Removed the ul element from the sledrun info box.
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / wrmap.body.php
index 059eab5bc605bf6d9bd2679235ad629a9234edda..2ce595d0300b94328e27c2e5ca28af7c17d8179f 100644 (file)
@@ -72,6 +72,44 @@ class WrBaseMap {
        }
 
 
+       /// Takes a page title from the wiki and returns an image (if available)
+       /// or Null. For image wiki pages, the image is the corresponding image,
+       /// for inns it's the image of the "Gasthausbox".
+       public static function wikipage_to_image($title, $width) {
+               $file = false; // File class or false
+               // for NS_FILE titles, use the corresponding file as image
+               if ($title->getNamespace() == NS_FILE) {
+                       $file = wfFindFile($title); // $file is a mediawiki File class or false
+               } else {
+                       $categories = $title->getParentCategories(); // e.g. array('Kategorie:Rodelbahn' => 'Juifenalm')
+                       global $wgContLang;
+                       $key_sledrun = $wgContLang->getNSText(NS_CATEGORY) . ':Rodelbahn';
+                       if (array_key_exists($key_sledrun, $categories)) {
+                               // for sledrun titles use the image from the rodelbahnbox
+                               $dbr = wfGetDB(DB_SLAVE);
+                               $res = $dbr->select('wrsledruncache', 'image', array('page_id' => $title->getArticleID()), __METHOD__);
+                               $image = $dbr->fetchRow($res);
+                               if ($image && !is_null($image['image'])) $file = wfFindFile($image['image']);
+                               $dbr->freeResult($res);
+                       }
+                       $key_inn = $wgContLang->getNSText(NS_CATEGORY) . ':Gasthaus';
+                       if (array_key_exists($key_inn, $categories)) {
+                               // for inn titles use the image from the gasthausbox
+                               $dbr = wfGetDB(DB_SLAVE);
+                               $res = $dbr->select('wrinncache', 'image', array('page_id' => $title->getArticleID()), __METHOD__);
+                               $image = $dbr->fetchRow($res);
+                               if ($image && !is_null($image['image'])) $file = wfFindFile($image['image']);
+                               $dbr->freeResult($res);
+                       }
+               }
+               if ($file === false) return Null;
+               if (!$file->canRender()) return Null;
+               $thumb_url = $file->createThumb($width, $width); // limit width and hight to $width
+               if (strlen($thumb_url) == 0) return Null;
+               return $thumb_url;
+       }
+
+
        // convert sledruns to geojson (http://www.geojson.org/geojson-spec.html)
        // Returns an array of features
        public static function sledruns_to_json_features() {
@@ -88,6 +126,8 @@ class WrBaseMap {
                        $properties = array('type' => 'sledrun', 'name' => $title->getText(), 'wiki' => $title->getLocalUrl());
                        if (!is_null($sledrun['date_report'])) $properties['date_report'] = $sledrun['date_report'];
                        if (!is_null($sledrun['condition'])) $properties['condition'] = intval($sledrun['condition']);
+                       $image_url = WrBaseMap::wikipage_to_image($title, 150);
+                       if (!is_null($image_url)) $properties['thumb_url'] = $image_url;
                        $json_feature = array(
                                'type' => 'feature',
                                'geometry' => array(
@@ -137,6 +177,8 @@ class WrBaseMap {
                                        if ($property == 'wiki') {
                                                $title = Title::newFromText($propval);
                                                $propval = $title->getLocalUrl();
+                                               $file_url = WrBaseMap::wikipage_to_image($title, 200);
+                                               if (!is_null($file_url)) $properties['thumb_url'] = $file_url;
                                        }
                                        $properties[$property] = $propval;
                                }