Exemplo n.º 1
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__);
 }
Exemplo n.º 2
0
 /**
  * Create a new place based on geo data provided and store it in the database
  */
 public function saveNewPlaceToArticle()
 {
     $oPlaceModel = new 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 = new Article($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);
             }
         }
     }
 }