Esempio n. 1
0
/**
 * constructor
 */
function wfSpecialPlaceMap()
{
    global $wgOut, $wgRequest, $wgUser;
    $wgOut->setArticleRelated(false);
    $wgOut->setRobotpolicy('noindex,nofollow');
    $titleText = $wgRequest->getVal('pagetitle');
    $error = '';
    if ($titleText) {
        $title = Title::newFromText($titleText, NS_PLACE);
        if (is_null($title) || $title->getNamespace() != NS_PLACE || !$title->exists()) {
            $error = 'Please enter the title of a place page';
        } else {
            $revision = StructuredData::getRevision($title, true);
            if (!$revision) {
                $error = "Place map revision not found!\n";
            } else {
                $sk = $wgUser->getSkin();
                $text =& $revision->getText();
                $xml = StructuredData::getXml('place', $text);
                $wgOut->setPageTitle('Map of ' . $revision->getTitle()->getText());
                // place map
                $wgOut->addHTML('<H2>Map for ' . $sk->makeKnownLinkObj($revision->getTitle(), $revision->getTitle()->getText()) . '</H2>');
                $wgOut->addHTML('<div id="placemap" style="width: 760px; height: 520px"></div><br>');
                $mapData = SpecialPlaceMap::getContainedPlaceMapData($xml);
                if (!$mapData) {
                    $mapData = SpecialPlaceMap::getSelfMapData($revision->getTitle(), $xml);
                }
                $wgOut->addHTML(SpecialPlaceMap::getMapScripts(1, $mapData));
                $wgOut->addHTML('<div id="latlnginst" style="display: block">Click on the map to see the latitude and longitude at the cursor position.</div>');
                $wgOut->addHTML('<div id="latlngbox" style="display: none">Clicked on Latitude: <span id="latbox"></span> Longitude: <span id="lngbox"></span></div><br>');
                $unmappedPlaces = SpecialPlaceMap::getUnmappedPlaces($sk, $xml);
                if ($unmappedPlaces) {
                    $wgOut->addHTML("<h3>Places not on map</h3>" . $unmappedPlaces);
                }
                return;
            }
        }
    }
    $wgOut->setPageTitle('Place Map');
    if ($error) {
        $wgOut->addHTML("<p><font color=red>{$error}</font></p>");
    }
    $queryBoxStyle = 'width:100%;text-align:center;';
    $form = <<<END
<form name="search" action="/wiki/Special:PlaceMap" method="get">
<div id="searchFormDiv" style="{$queryBoxStyle}">
Place title: <input type="text" name="pagetitle" size=24 maxlength="100" value="{$titleText}" onfocus="select()" />
<input type="submit" value="Go" />
</div>
</form>
END;
    $wgOut->addHTML($form);
}
Esempio n. 2
0
    /**
     * Create wiki text from xml property
     */
    protected function toWikiText($parser)
    {
        if (isset($this->xml)) {
            $name = $this->getLV('Name', "<span class=\"wr-infobox-title\">{$this->prefName}</span>");
            $values = array();
            foreach ($this->xml->alternate_name as $altName) {
                $source = '';
                if ((string) $altName['source']) {
                    $source = 'source: ' . (string) $altName['source'];
                }
                $values[] = array($altName['name'], $source);
            }
            $altNames = $this->getLV('Alt names', $values);
            $type = $this->getLV('Type', (string) $this->xml->type);
            $coordinates = '';
            $lat = (string) $this->xml->latitude;
            $lng = (string) $this->xml->longitude;
            if ($lat && $lng) {
                if ($lat >= 0) {
                    $ns = 'N';
                } else {
                    $lat = $lat * -1.0;
                    $ns = 'S';
                }
                if ($lng >= 0) {
                    $ew = 'E';
                } else {
                    $lng = $lng * -1.0;
                    $ew = 'W';
                }
                $coordinates = $this->getLV('Coordinates', "{$lat}&deg;{$ns} {$lng}&deg;{$ew}");
            }
            $fromYear = (string) $this->xml->from_year;
            $toYear = (string) $this->xml->to_year;
            $yearRange = '';
            if ($fromYear || $toYear) {
                $yearRange = " &nbsp;&nbsp;&nbsp; ({$fromYear} - {$toYear})";
            }
            if ($this->locatedIn) {
                $locatedIn = $this->getLV('Located in', "[[Place:{$this->locatedIn}|{$this->locatedIn}]]{$yearRange}");
            } else {
                $locatedIn = '';
            }
            $values = array();
            foreach ($this->xml->also_located_in as $ali) {
                $yearRange = '';
                if ((string) $ali['from_year'] || (string) $ali['to_year']) {
                    $yearRange = "({$ali['from_year']} - {$ali['to_year']})";
                }
                $place = (string) $ali['place'];
                $values[] = "[[Place:{$place}|{$place}]] &nbsp;&nbsp;&nbsp; {$yearRange}";
            }
            $alsoLocatedIn = $this->getLV('Also located in', $values);
            $values = array();
            foreach ($this->xml->see_also as $seeAlso) {
                $reason = '';
                if ((string) $seeAlso['reason']) {
                    $reason = (string) $seeAlso['reason'];
                }
                $place = (string) $seeAlso['place'];
                $values[] = array("[[Place:{$place}|{$place}]]", $reason);
            }
            $seeAlso = $this->getLV('See also', $values);
            $map = '';
            $this->mapData = SpecialPlaceMap::getContainedPlaceMapData($this->xml);
            if ($this->mapData) {
                $showContainedPlacesMap = true;
            } else {
                $showContainedPlacesMap = false;
                $this->mapData = SpecialPlaceMap::getSelfMapData($this->title, $this->xml);
                if ($this->mapData) {
                    $map = $this->addMap();
                }
            }
            $containedPlaces = '';
            if (isset($this->xml->contained_place)) {
                //                $result .= "|-\n| align=\"center\" | Contained Places\n";
                //                $result .= "|-\n!Contained Places\n";
                if ($showContainedPlacesMap) {
                    $map = $this->addMap();
                }
                $containedPlaces = $this->addContainedPlaces($this->xml->contained_place);
            }
        }
        $placeCat = Place::getPlaceCategory($this->titleString);
        $result = <<<END
<div class="wr-infobox wr-infobox-place clearfix">
<div class="wr-infobox-map">{$map}</div><table class="wr-infobox-content">
{$name}
{$altNames}
{$type}
{$coordinates}
{$locatedIn}
{$alsoLocatedIn}
{$seeAlso}
</table></div>
<wr_ad></wr_ad>
{$containedPlaces}
END;
        $result .= "[[Category:{$placeCat}" . ($placeCat == $this->titleString ? "|*" : "") . "]]";
        return $result;
    }