Exemple #1
0
    /**
     * Create wiki text from xml property
     */
    protected function toWikiText($parser)
    {
        global $wgESINHandler, $wgOut;
        $result = '';
        if (isset($this->xml)) {
            //			$result = '{| id="structuredData" border=1 class="floatright" cellpadding=4 cellspacing=0 width=30%'."\n";
            //			$result = "<div class=\"infobox-header\">Family Information</div>\n{|\n";
            //         $result = "{|\n";
            //			$hideTopBorder = false;
            //			$result .= $this->addValuesToTableDL(null, $this->xml->husband, 'formatFamilyMember', array('Husband', @$this->xml->husband[0]), $hideTopBorder);
            //			$hideTopBorder = $hideTopBorder || isset($this->xml->husband);
            //			$result .= $this->addValuesToTableDL(null, $this->xml->wife, 'formatFamilyMember', array('Wife', @$this->xml->wife[0]), $hideTopBorder);
            //			$hideTopBorder = $hideTopBorder || isset($this->xml->wife);
            //			$result .= $wgESINHandler->showEventsFacts($this->xml, $hideTopBorder);
            //			if (isset($this->xml->child)) {
            //				$result .= "|-\n! Children\n";
            //				$result .= $this->addValuesToTableDL(null, $this->xml->child, 'formatFamilyMember', array(null, null), true);
            //			}
            //			$result .= $this->showWatchers();
            //			$result .= "|}\n";
            // add infobox
            $image = $wgESINHandler->getPrimaryImage($this->xml);
            $numHusbands = $numWives = 0;
            foreach ($this->xml->husband as $spouse) {
                $numHusbands++;
            }
            foreach ($this->xml->wife as $spouse) {
                $numWives++;
            }
            if ($numHusbands < 1) {
                $numHusbands = 1;
            }
            if ($numWives < 1) {
                $numWives = 1;
            }
            $width = floor(100 / ($numHusbands + $numWives));
            $spouses = '';
            $firstChildClass = 'first-child';
            $husbandName = $wifeName = '';
            if (isset($this->xml->husband)) {
                foreach ($this->xml->husband as $spouse) {
                    $spouses .= $this->getSpouseInfo($spouse, $width, $firstChildClass);
                    $firstChildClass = '';
                    if (!$husbandName) {
                        $husbandName = StructuredData::constructName(@$spouse['given'], @$spouse['surname']);
                    }
                }
            } else {
                list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($this->titleString);
                $spouses .= $this->getSpouseInfo(null, $width, $firstChildClass, $hg, $hs, true);
                $firstChildClass = '';
                $husbandName = StructuredData::constructName($hg, $hs);
            }
            if ($image) {
                $spouses .= $this->getImageInfo($image, $firstChildClass);
                $firstChildClass = '';
            }
            if (isset($this->xml->wife)) {
                foreach ($this->xml->wife as $spouse) {
                    $spouses .= $this->getSpouseInfo($spouse, $width, $firstChildClass);
                    $firstChildClass = '';
                    if (!$wifeName) {
                        $wifeName = StructuredData::constructName(@$spouse['given'], @$spouse['surname']);
                    }
                }
            } else {
                list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($this->titleString);
                $spouses .= $this->getSpouseInfo(null, $width, $firstChildClass, $wg, $ws, false);
                $firstChildClass = '';
                $wifeName = StructuredData::constructName($wg, $ws);
            }
            // check rename needed
            if (!$this->isGedcomPage && mb_strpos($this->titleString, 'Unknown') !== false) {
                list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($this->titleString);
                $husbandTitle = StructuredData::constructName($hg, $hs);
                $wifeTitle = StructuredData::constructName($wg, $ws);
                if (Person::isRenameNeeded($husbandTitle, $husbandName) || Person::isRenameNeeded($wifeTitle, $wifeName)) {
                    $correctTitle = StructuredData::constructFamilyName($husbandName, $wifeName);
                    $t = Title::makeTitle(NS_SPECIAL, 'Movepage');
                    $url = $t->getLocalURL('target=' . $this->title->getPrefixedURL() . '&wpNewTitle=' . wfUrlencode("Family:{$correctTitle}") . '&wpReason=' . wfUrlencode('make page title agree with name'));
                    $parser->mOutput->mSubtitle = 'This page can be <a href="' . $url . '">renamed</a>';
                    $wgOut->setSubtitle($parser->mOutput->mSubtitle);
                }
            }
            $marriageDate = $marriagePlace = '';
            $marriageFound = false;
            if (isset($this->xml->event_fact)) {
                foreach ($this->xml->event_fact as $eventFact) {
                    if ($eventFact['type'] == 'Marriage') {
                        $marriageFound = true;
                        $marriageDate = (string) $eventFact['date'];
                        $marriagePlace = $this->getPlace($eventFact);
                    }
                }
            }
            $marriage = '';
            if ($marriageFound) {
                $marriage = "<div class=\"wr-infobox-event\">m. <span class=\"wr-infobox-date\">{$marriageDate}</span> <span class=\"wr-infobox-place\">{$marriagePlace}</span></div>";
            }
            $result = <<<END
<div class="wr-infobox wr-infobox-family">
   <table class="wr-infobox-spouses">
      <tr>
         {$spouses}
      </tr>
   </table>
   {$marriage}
</div>
<wr_ad></wr_ad>
<div id="wr_familytreelink"><span class="wr-familytreelink-text">Family tree</span><span class="wr-familytreelink-arrow">▼</span></div>
END;
            // add source citations, images, notes
            $result .= $wgESINHandler->addSourcesImagesNotes($this, $parser);
            // add categories
            $surnames = array();
            foreach ($this->xml->husband as $husband) {
                $surnames[] = (string) $husband['surname'];
            }
            foreach ($this->xml->wife as $wife) {
                $surnames[] = (string) $wife['surname'];
            }
            $places = ESINHandler::getPlaces($this->xml);
            $result .= StructuredData::addCategories($surnames, $places, false);
        }
        return $result;
    }
Exemple #2
0
    /**
     * Create wiki text from xml property
     */
    protected function toWikiText($parser)
    {
        //        wfDebug("toWikiText=" . $this->xml->asXML() . "\n");
        global $wgESINHandler, $wgOut;
        $result = '';
        if (isset($this->xml)) {
            // check rename needed
            if (!$this->isGedcomPage && mb_strpos($this->titleString, 'Unknown') !== false) {
                $correctTitle = StructuredData::constructName(@$this->xml->name['given'], @$this->xml->name['surname']);
                if (Person::isRenameNeeded($this->titleString, $correctTitle)) {
                    $t = Title::makeTitle(NS_SPECIAL, 'Movepage');
                    $url = $t->getLocalURL('target=' . $this->title->getPrefixedURL() . '&wpNewTitle=' . wfUrlencode("Person:{$correctTitle}") . '&wpReason=' . wfUrlencode('make page title agree with name'));
                    $parser->mOutput->mSubtitle = 'This page can be <a href="' . $url . '">renamed</a>';
                    $wgOut->setSubtitle($parser->mOutput->mSubtitle);
                }
            }
            // add infoboxes
            $gender = (string) $this->xml->gender;
            switch ($gender) {
                case 'M':
                    $genderClass = '-male';
                    break;
                case 'F':
                    $genderClass = '-female';
                    break;
                default:
                    $genderClass = '';
            }
            $image = $wgESINHandler->getPrimaryImage($this->xml);
            $imageText = "<div class=\"wr-infobox-noimage{$genderClass}\"></div>";
            $imageURL = '';
            if (isset($image)) {
                $thumbWidth = SearchForm::THUMB_WIDTH;
                $filename = (string) $image['filename'];
                $t = Title::makeTitle(NS_IMAGE, $filename);
                if ($t && $t->exists()) {
                    $img = new Image($t);
                    $caption = (string) $image['caption'];
                    if (!$caption) {
                        $caption = $filename;
                    }
                    $maxWidth = 700;
                    $maxHeight = 300;
                    $width = $img->getWidth();
                    $height = $img->getHeight();
                    if ($maxWidth > $width * $maxHeight / $height) {
                        $maxWidth = wfFitBoxWidth($width, $height, $maxHeight);
                    }
                    $imageURL = $img->createThumb($maxWidth, $maxHeight);
                    $caption = str_replace('|', ' ', $caption);
                    $titleAttr = StructuredData::escapeXml("{$imageURL}|{$maxWidth}|{$caption}");
                    $imageText = "<span class=\"wr-imagehover\" title=\"{$titleAttr}\">[[Image:{$filename}|{$thumbWidth}x{$thumbWidth}px]]</span>";
                }
            }
            $fullname = StructuredData::getFullname($this->xml->name);
            if (!$fullname) {
                $fullname = '&nbsp;';
            }
            $birthDate = $birthPlace = $deathDate = $deathPlace = '';
            $chrDate = $chrPlace = $burDate = $burPlace = '';
            $birthFound = $deathFound = $chrFound = $burFound = false;
            $birthSource = $deathSource = false;
            if (isset($this->xml->event_fact)) {
                foreach ($this->xml->event_fact as $eventFact) {
                    if ($eventFact['type'] == 'Birth') {
                        $birthFound = true;
                        $birthDate = (string) $eventFact['date'];
                        $birthPlace = (string) $eventFact['place'];
                        $birthSource = (string) $eventFact['sources'];
                    } else {
                        if ($eventFact['type'] == 'Christening' || $eventFact['type'] == 'Baptism') {
                            $chrFound = true;
                            $chrDate = (string) $eventFact['date'];
                            $chrPlace = (string) $eventFact['place'];
                        } else {
                            if ($eventFact['type'] == 'Death') {
                                $deathFound = true;
                                $deathDate = (string) $eventFact['date'];
                                $deathPlace = (string) $eventFact['place'];
                                $deathSource = (string) $eventFact['sources'];
                            } else {
                                if ($eventFact['type'] == 'Burial') {
                                    $burFound = true;
                                    $burDate = (string) $eventFact['date'];
                                    $burPlace = (string) $eventFact['place'];
                                }
                            }
                        }
                    }
                }
            }
            $this->initHistoricalDataPerson($fullname, $gender, $imageURL);
            $birthLabel = '&nbsp;';
            if ($birthFound) {
                $birthLabel = 'b.';
                $this->addHistoricalDataEvent('birth', $birthDate, $birthPlace);
            } else {
                if ($chrFound) {
                    $birthLabel = 'chr.';
                    $this->addHistoricalDataEvent('christening', $chrDate, $chrPlace);
                    $birthDate = $chrDate;
                    $birthPlace = $chrPlace;
                }
            }
            $deathLabel = '&nbsp;';
            if ($deathFound) {
                $deathLabel = 'd.';
                $this->addHistoricalDataEvent('death', $deathDate, $deathPlace);
            } else {
                if ($burFound) {
                    $deathLabel = 'bur.';
                    $this->addHistoricalDataEvent('burial', $burDate, $burPlace);
                    $deathDate = $burDate;
                    $deathPlace = $burPlace;
                }
            }
            $fmtBirthPlace = Person::formatPlace($birthPlace);
            $fmtDeathPlace = Person::formatPlace($deathPlace);
            $familybadges = '';
            $marriageEvents = array();
            $parentFamilies = array();
            foreach ($this->xml->child_of_family as $f) {
                $parentFamilies[] = (string) $f['title'];
            }
            $found = false;
            foreach ($this->xml->child_of_family as $f) {
                list($key, $text) = $this->getFamilyBadge($f, true, $gender, $parentFamilies, $marriageEvents);
                $found = true;
                $familybadges .= $text;
            }
            if (!$found) {
                $familybadges .= $this->getAddFamilyLink(0);
            }
            $sort = array();
            $ix = 0;
            $prevKey = 0;
            $found = false;
            foreach ($this->xml->spouse_of_family as $f) {
                list($key, $text) = $this->getFamilyBadge($f, false, $gender, null, $marriageEvents);
                $found = true;
                if ($key) {
                    $prevKey = $key;
                } else {
                    $key = $prevKey;
                }
                $sort[$key * 50 + $ix] = $text;
                $ix++;
            }
            $result = <<<END
<div class="wr-infobox wr-infobox-person clearfix">
   <div class="wr-infobox-image">
      {$imageText}
   </div>
   <div class="wr-infobox-content">
      <div class="wr-infobox-fullname">{$fullname}</div>
      <div class="wr-infobox-event">{$birthLabel}<span class="wr-infobox-date">{$birthDate}</span> <span class="wr-infobox-place">{$fmtBirthPlace}</span></div>
      <div class="wr-infobox-event">{$deathLabel}<span class="wr-infobox-date">{$deathDate}</span> <span class="wr-infobox-place">{$fmtDeathPlace}</span></div>

   </div>
</div>
<wr_ad></wr_ad>
<div style="margin-top:2px" class="clearfix"><div id="wr_familytreelink" style="float:left">
<span class="wr-familytreelink-text">Family tree</span><span class="wr-familytreelink-arrow">▼</span>
</div><div style="float:right; margin-right:10px;">
</div></div>
END;
            ksort($sort, SORT_NUMERIC);
            foreach ($sort as $key => $text) {
                $familybadges .= $text;
            }
            $familybadges .= $this->getAddFamilyLink(!$found ? 1 : 2, (string) @$this->xml->name['given'], (string) @$this->xml->name['surname']);
            if ($familybadges) {
                $result .= "<div class=\"wr-infobox-familybadges\">{$familybadges}</div>";
            }
            //         $result .= '<div class="visualClearLeft"></div>';
            // add source citations, images, notes
            $result .= $wgESINHandler->addSourcesImagesNotes($this, $parser, $marriageEvents);
            // add categories
            $surnames = array();
            $surnames[] = (string) $this->xml->name['surname'];
            foreach ($this->xml->alt_name as $altName) {
                $surnames[] = (string) $altName['surname'];
            }
            $places = ESINHandler::getPlaces($this->xml);
            $result .= StructuredData::addCategories($surnames, $places, false);
        }
        return $result;
    }
Exemple #3
0
 public static function constructFamilyTitle($husbandGivenname, $husbandSurname, $wifeGivenname, $wifeSurname)
 {
     // construct name and append id
     $husbandName = StructuredData::constructName($husbandGivenname, $husbandSurname);
     $wifeName = StructuredData::constructName($wifeGivenname, $wifeSurname);
     $titleText = StructuredData::constructFamilyName($husbandName, $wifeName);
     if ($titleText) {
         return StructuredData::appendUniqueId(Title::newFromText($titleText, NS_FAMILY));
     } else {
         return null;
     }
 }
 private function getPageTitle()
 {
     $ns = (int) $this->xml['ns'];
     if ($ns == NS_PERSON) {
         $pageTitle = StructuredData::constructName($this->cleanName(@$this->xml->name['given'], true), $this->cleanName(@$this->xml->name['surname'], false));
     } else {
         if ($ns == NS_FAMILY) {
             $husbandName = $wifeName = 'Unknown';
             foreach ($this->xml->husband as $spouse) {
                 $husbandName = StructuredData::constructName($this->cleanName(@$spouse['given'], true), $this->cleanName(@$spouse['surname'], false));
                 break;
             }
             foreach ($this->xml->wife as $spouse) {
                 $wifeName = StructuredData::constructName($this->cleanName(@$spouse['given'], true), $this->cleanName(@$spouse['surname'], false));
                 break;
             }
             $pageTitle = StructuredData::constructFamilyName($husbandName, $wifeName);
         } else {
             $pageTitle = $this->xml['title'];
         }
     }
     return $pageTitle;
 }