/** * Render <places> tag * * @param string $content tag content (will be ignored) * @param array $attributes tag attributes * @param Parser $parser MW parser instance * @param PPFrame $frame parent frame with the context * @return string HTML output of the tag */ public static function renderPlacesTag($content, array $attributes, Parser $parser, PPFrame $frame) { wfProfileIn(__METHOD__); // parse attributes $height = !empty($attributes['height']) && is_numeric($attributes['height']) ? $attributes['height'] : 400; $categories = !empty($attributes['category']) ? explode('|', $attributes['category']) : false; $animate = !empty($attributes['animate']) ? is_numeric($attributes['animate']) ? intval($attributes['animate']) : 5 : false; // get all places on this wiki $placesModel = new PlacesModel(); $markers = empty($categories) ? $placesModel->getAll() : $placesModel->getFromCategories($categories); // render parser hook $html = F::app()->sendRequest('Places', 'renderMarkers', array('markers' => $markers, 'height' => $height, 'options' => array('animate' => $animate)))->toString(); wfProfileOut(__METHOD__); return $html; }
public function execute() { wfProfileIn(__METHOD__); $placesModel = new PlacesModel(); $params = $this->extractRequestParams(); $places = array(); // get geodata from article by its ID if (isset($params['pageid'])) { $storage = PlaceStorage::newFromId($params['pageid']); $places = array($storage->getModel()); } elseif (isset($params['title'])) { $title = Title::newFromText($params['title']); if ($title instanceof Title) { $storage = PlaceStorage::newFromTitle($title); $places = array($storage->getModel()); } } elseif (isset($params['category'])) { $categories = explode('|', $params['category']); $places = $placesModel->getFromCategories($categories); } elseif (isset($params['related'])) { $title = Title::newFromText($params['related']); if ($title instanceof Title) { $places = $placesModel->getFromCategoriesByTitle($title); } } else { $places = $placesModel->getAll(); } // generate results $rows = array(); foreach ($places as $place) { $title = Title::newFromID($place->getPageId()); $rows[] = array('pageid' => $place->getPageId(), 'title' => $title instanceof Title ? $title->getPrefixedText() : '', 'lat' => $place->getLat(), 'lan' => $place->getLon()); } $results = $this->getResult(); $results->setIndexedTagName($rows, 'place'); $results->addValue('query', 'places', $rows); wfProfileOut(__METHOD__); }
protected function allPlaces() { $placesModel = new PlacesModel(); return $placesModel->getAll(500); // limit number of places for special pages }