Exemplo n.º 1
0
 public static function onArticleSaveComplete(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId)
 {
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . "\n");
     // store queued model or clear data for the article (if no model was passed)
     $storage = PlaceStorage::newFromArticle($article);
     if (self::$modelToSave instanceof PlaceModel) {
         // use model from parser hook
         // self::$modelToSave is set in PlacesParserHookHandler::renderPlaceTag
         $storage->setModel(self::$modelToSave);
     } else {
         // no geo data fround - use an empty model
         $storage->setModel(new PlaceModel());
     }
     $storage->store();
     // purge autoplaceholdr position
     F::app()->sendRequest('Places', 'purgeGeoLocationButton');
     wfProfileOut(__METHOD__);
     return true;
 }
Exemplo n.º 2
0
 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');
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * 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();
     }
 }
Exemplo n.º 6
0
 /**
  * Create a new place based on geo data provided and store it in the database
  */
 public function saveNewPlaceToArticle()
 {
     $oPlaceModel = F::build('PlaceModel');
     $oPlaceModel->setPageId($this->getVal('articleId', 0));
     if ($oPlaceModel->getPageId() == 0) {
         $this->setVal('error', wfMsg('places-error-no-article'));
         $this->setVal('success', false);
     } else {
         $oStorage = PlaceStorage::newFromId($oPlaceModel->getPageId());
         if ($oStorage->getModel()->isEmpty() == false) {
             $this->setVal('error', wfMsg('places-error-place-already-exists'));
             $this->setVal('success', false);
         } else {
             $oPlaceModel->setAlign($this->getVal('align', false));
             $oPlaceModel->setWidth($this->getVal('width', false));
             $oPlaceModel->setHeight($this->getVal('height', false));
             $oPlaceModel->setLat($this->getVal('lat', false));
             $oPlaceModel->setLon($this->getVal('lon', false));
             $oPlaceModel->setZoom($this->getVal('zoom', false));
             $sText = $this->sendRequest('PlacesController', 'getPlaceWikiTextFromModel', array('model' => $oPlaceModel))->toString();
             $oTitle = Title::newFromID($oPlaceModel->getPageId());
             if ($oTitle instanceof Title && $oTitle->exists()) {
                 $oArticle = F::build('Article', array($oTitle));
                 $sNewContent = $sText . $oArticle->getContent();
                 $status = $oArticle->doEdit($sNewContent, wfMsg('places-updated-geolocation'), EDIT_UPDATE);
                 $this->setVal('success', true);
             } else {
                 $this->setVal('error', wfMsg('places-error-no-article'));
                 $this->setVal('success', false);
             }
         }
     }
 }