コード例 #1
0
 /**
  * Render <place> 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 renderPlaceTag($content, array $attributes, Parser $parser, PPFrame $frame)
 {
     wfProfileIn(__METHOD__);
     // wrap data in a model object
     $placeModel = PlaceModel::newFromAttributes($attributes);
     // are we rendering for RTE?
     $inRTE = !empty(F::app()->wg->RTEParserEnabled);
     if ($inRTE) {
         $wikitext = RTEData::get('wikitext', self::$lastWikitextId);
         $data = array('wikitext' => $wikitext, 'placeholder' => 1);
         $rteData = RTEData::convertDataToAttributes($data);
     } else {
         $rteData = false;
     }
     // render parser hook
     $html = F::app()->sendRequest('Places', 'placeFromModel', array('model' => $placeModel, 'rteData' => $rteData))->toString();
     // add JS snippets code
     if (!$inRTE) {
         $html .= self::getJSSnippet();
     }
     // add model to be stored in database
     (new PlacesHooks())->setModelToSave($placeModel);
     $html = self::cleanHTML($html);
     wfProfileOut(__METHOD__);
     return $html;
 }
コード例 #2
0
 /**
  * Render static map from given set of attributes
  *
  * Used to render <place> parser hook
  */
 public function placeFromAttributes()
 {
     $attributes = $this->getVal('attributes', array());
     $oPlaceModel = PlaceModel::newFromAttributes($attributes);
     $this->request->setVal('model', $oPlaceModel);
     $this->forward('Places', 'placeFromModel');
 }
コード例 #3
0
ファイル: PlacesTest.php プロジェクト: Tjorriemorrie/app
 protected function setUp()
 {
     $this->setupFile = __DIR__ . '/../Places.setup.php';
     parent::setUp();
     $this->attribs = array('align' => 'right', 'width' => 300, 'caption' => 'Foo', 'lat' => '52.406878', 'lon' => '16.922124');
     $this->model = PlaceModel::newFromAttributes($this->attribs);
     // use main page as an article for this place
     $mainPage = Title::newMainPage();
     $this->model->setPageId($mainPage->getArticleId());
 }
コード例 #4
0
 /**
  * Perform database query to get geo data
  *
  * @param array $filters additional statements to filter geo data by
  * @return array set of PlaceModel objects
  */
 private function query(array $filters = array())
 {
     wfProfileIn(__METHOD__);
     $dbr = $this->getDB();
     // build query
     $tables = array(self::WPP_TABLE);
     $fields = array('page_id', 'propname', 'props');
     $where = array('propname' => array(WPP_PLACES_LATITUDE, WPP_PLACES_LONGITUDE));
     // apply filters
     if (isset($filters['categories'])) {
         $tables[] = 'categorylinks';
         $where[] = 'cl_from = page_id';
         $where['cl_to'] = $filters['categories'];
     } else {
         if (isset($filters['nearby'])) {
             $lat = $filters['nearby']['lat'];
             $lon = $filters['nearby']['lon'];
             wfDebug(__METHOD__ . "::nearby - {$lat},{$lon}\n");
         }
     }
     // apply rows limit
     $options = array();
     if (!empty($filters['limit'])) {
         $options['LIMIT'] = $filters['limit'] * 2;
     }
     // perform the query
     $res = $dbr->select($tables, $fields, $where, __METHOD__, $options);
     // get data from table rows
     $attrs = array();
     while ($row = $res->fetchObject()) {
         $value = (double) $row->props;
         $pageId = intval($row->page_id);
         $attrs[$pageId]['pageId'] = $pageId;
         switch ($row->propname) {
             case WPP_PLACES_LATITUDE:
                 $attrs[$pageId]['lat'] = $value;
                 break;
             case WPP_PLACES_LONGITUDE:
                 $attrs[$pageId]['lon'] = $value;
                 break;
         }
     }
     // we now have lat/lon data in $cords array
     // now let's create PlaceModel objects
     $models = array();
     foreach ($attrs as $attr) {
         $models[] = PlaceModel::newFromAttributes($attr);
     }
     wfProfileOut(__METHOD__);
     return $models;
 }