public static function onBeforePageDisplay(OutputPage $out, Skin $sk) { wfProfileIn(__METHOD__); $title = $out->getTitle(); if ($title instanceof Title && $title->isContentPage()) { $storage = PlaceStorage::newFromTitle($out->getTitle()); $model = $storage->getModel(); /* @var $model PlaceModel */ if ($model instanceof PlaceModel && !$model->isEmpty()) { $out->addMeta('geo.position', implode(',', $model->getLatLon())); } } if ($title instanceof Title && $title->getNamespace() == NS_CATEGORY) { $out->addScript('<script src="' . F::app()->wg->extensionsPath . '/wikia/Places/js/GeoEnableButton.js"></script>'); $out->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/wikia/Places/css/GeoEnableButton.scss')); } wfProfileOut(__METHOD__); return true; }
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__); }
public function index() { $this->wg->Out->setPageTitle(wfMsg('places')); $sParam = $this->getPar(); $oTitle = Title::newFromText($sParam); if (!empty($oTitle) && $oTitle->exists()) { if ($oTitle->getNamespace() == NS_CATEGORY) { $this->markers = $this->placesForCategory($oTitle); } else { $oMarker = PlaceStorage::newFromTitle($oTitle)->getModel(); $this->center = $oMarker->getForMap(); $this->markers = $this->allPlaces(); } } else { $this->markers = $this->allPlaces(); } $this->wg->Out->setSubtitle(wfMsgExt('places-on-map', array('parsemag'), count($this->markers))); // use Places controller to render interactive map $this->request->setVal('center', $this->center); $this->request->setVal('markers', $this->markers); $this->request->setVal('height', 500); $this->forward('Places', 'renderMarkers'); }
/** * Get geo data of all "nearby" articles (within given distance in kilometres) * * TODO: implement * * @param Title $title article title to find nearby places for * @param int $distance define nearby distance (in km) * @return array set of PlaceModel objects */ public function getNearbyByTitle(Title $title, $distance = 10) { wfProfileIn(__METHOD__); $storage = PlaceStorage::newFromTitle($title); $models = $this->getNearby($storage->getModel(), $distance); wfProfileOut(__METHOD__); return $models; }
/** * Renders the geolocation button for adding coordinates to a page */ public function getGeolocationButton() { if ($this->app->wg->title->isContentPage() && PlaceStorage::newFromTitle($this->app->wg->title)->getModel()->isEmpty() && PlaceCategory::newFromTitle($this->app->wg->title->getFullText())->isGeoTaggingEnabledForArticle($this->app->wg->title)) { $this->setVal('geolocationParams', $this->getGeolocationButtonParams()); $this->response->setVal('jsSnippet', PlacesParserHookHandler::getJSSnippet()); (new JSMessages())->enqueuePackage('PlacesGeoLocationModal', JSMessages::INLINE); } else { $this->skipRendering(); } }