protected function formatName($name, $parser, $defaultType, $firstChildClass = '') { $refs = $this->getRefsText($name, $parser, false); $type = (string) $name['type']; if (!$type) { $type = $defaultType; } $fullname = StructuredData::getFullname($name); return <<<END <tr> <td class="wr-infotable-type {$firstChildClass}"><span class="wr-infotable-type">{$type}</span>{$refs}</td> <td colspan="2" class="wr-infotable-fullname {$firstChildClass}"><span class="wr-infotable-fullname">{$fullname}</span></td> </tr> END; }
protected function formatFamilyMember($value, $parms) { $title = (string) $value['title']; if (isset($parms[0])) { $label = (isset($parms[1]) && $title != (string) $parms[1]['title'] ? 'Alternate ' : '') . $parms[0] . '<dd>'; } else { $label = ''; } $fullname = StructuredData::getFullname($value); if ($fullname) { $fullname = '|' . $fullname; } $bdate = (string) $value['birthdate']; $bplace = (string) $value['birthplace']; $cdate = (string) $value['chrdate']; $cplace = (string) $value['chrplace']; $ddate = (string) $value['deathdate']; $dplace = (string) $value['deathplace']; $udate = (string) $value['burialdate']; $uplace = (string) $value['burialplace']; $pf = (string) $value['child_of_family']; $birth = ''; if ($bdate || $bplace) { if ($bplace) { $bplace = ', [[Place:' . StructuredData::addBarToTitle($bplace) . ']]'; } $birth = "<dd>Birth: {$bdate}{$bplace}"; } else { if ($cdate || $cplace) { if ($cplace) { $cplace = ', [[Place:' . StructuredData::addBarToTitle($cplace) . ']]'; } $birth = "<dd>Chr: {$cdate}{$cplace}"; } } $death = ''; if ($ddate || $dplace) { if ($dplace) { $dplace = ', [[Place:' . StructuredData::addBarToTitle($dplace) . ']]'; } $death = "<dd>Death: {$ddate}{$dplace}"; } else { if ($udate || $uplace) { if ($uplace) { $uplace = ', [[Place:' . StructuredData::addBarToTitle($uplace) . ']]'; } $death = "<dd>Burial: {$udate}{$uplace}"; } } if ($pf) { $pf = '<dd>Parents: [[Family:' . StructuredData::addBarToTitle($pf) . ']]'; } return "<dt>{$label}[[Person:{$title}{$fullname}]]{$birth}{$death}{$pf}"; }
private function addEvent($pf, $type, $familyNumber, &$result) { if (isset($pf)) { $place = @$pf["{$type}place"]; $place = ShowPedigree::cleanPlace($place); $stdPlace = @$this->stdPlaces[$place]; if ($stdPlace) { $date = @$pf["{$type}date"]; $name = StructuredData::getFullname($pf); $title = Title::newFromText(@$pf['title'], NS_PERSON); $url = $title->getLocalURL(); $lat = $stdPlace['lat']; $lng = $stdPlace['lon']; $placeTitle = $stdPlace['title']; $color = ShowPedigree::$COLORS[$familyNumber]; $type = substr($type, 0, 1); // we only need first character $dateKey = StructuredData::getDateKey($date); $result .= '<p n="' . StructuredData::escapeXml($name) . '" u="' . StructuredData::escapeXml($url) . '" p="' . StructuredData::escapeXml($placeTitle) . '" d="' . StructuredData::escapeXml($date) . '" k="' . $dateKey . '" a="' . $lat . '" o="' . $lng . '" t="' . substr($type, 0, 1) . '" c="' . $color . "\"/>"; } } }
private function writeName($name) { $fullName = StructuredData::getFullname($name, true); $this->wl("1 NAME {$fullName}"); $namePiece = (string) $name['title_prefix']; if ($namePiece) { $this->wl("2 NPFX {$namePiece}"); } $namePiece = (string) $name['given']; if ($namePiece) { $this->wl("2 GIVN {$namePiece}"); } $namePiece = (string) $name['surname']; if ($namePiece) { $this->wl("2 SURN {$namePiece}"); } $namePiece = (string) $name['title_suffix']; if ($namePiece) { $this->wl("2 NSFX {$namePiece}"); } $type = (string) $name['type']; if ($type) { if ($type == 'Baptismal Name') { $type = 'baptismal'; } else { if ($type == 'Immigrant Name') { $type = 'immigrant'; } else { if ($type == 'Married Name') { $type = 'married'; } else { if ($type == 'Religious Name') { $type = 'religious'; } else { $type = 'aka'; // default } } } } $this->wl("2 TYPE {$type}"); } $this->writeCitationRefs(2, (string) $name['sources']); $this->writeNoteRefs(2, (string) $name['notes']); }
private function getPersonSummary($member) { $yearrange = ''; $url = ''; $title = (string) $member['title']; $t = Title::newFromText($title, NS_PERSON); if ($t) { $url = $t->getFullURL(); } $fullname = StructuredData::getFullname($member); $birthDate = (string) $member['birthdate'] ? (string) $member['birthdate'] : (string) $member['chrdate']; $beginYear = StructuredData::getYear($birthDate, true); $endYear = StructuredData::getYear((string) $member['deathdate'] ? (string) $member['deathdate'] : (string) $member['burialdate'], true); if ($beginYear || $endYear) { $yearrange = "{$beginYear} - {$endYear}"; } return array('name' => $fullname, 'url' => $url, 'yearrange' => $yearrange, 'birthdate' => $birthDate, 'title' => $title); }
/** * 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 = ' '; } $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 = ' '; if ($birthFound) { $birthLabel = 'b.'; $this->addHistoricalDataEvent('birth', $birthDate, $birthPlace); } else { if ($chrFound) { $birthLabel = 'chr.'; $this->addHistoricalDataEvent('christening', $chrDate, $chrPlace); $birthDate = $chrDate; $birthPlace = $chrPlace; } } $deathLabel = ' '; 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; }
public function getItems() { global $wrIconSize; $result = ''; $this->places = array(); $this->externals = array(); $this->otherEvents = array(); $this->latlngs = array(); foreach ($this->people as $titleText => $p) { $given = $surname = $fullname = ''; $birthDate = $birthPlace = $birthPlaceText = $birthYear = ''; $deathDate = $deathPlace = $deathPlaceText = $deathYear = ''; $imageURL = $iconURL = ''; $parents = $spouse = $allPlace = ''; $otherEvents = ''; $xml = $p['xml']; $position = $p['position']; $allPlaces = array(); if ($xml) { foreach ($xml->name as $name) { $given = (string) $name['given']; $surname = (string) $name['surname']; $fullname = StructuredData::getFullname($name); break; } list($birthEventType, $birthDate, $birthPlace, $birthPlaceText, $birthYear) = $this->getEventData($xml, array('Birth', 'Christening', 'Baptism')); list($deathEventType, $deathDate, $deathPlace, $deathPlaceText, $deathYear) = $this->getEventData($xml, array('Death', 'Burial')); $otherEvents = $this->getOtherEventData($xml, array($birthEventType, $deathEventType)); foreach ($xml->image as $image) { if ($image['primary'] == 'true') { $t = Title::makeTitle(NS_IMAGE, (string) $image['filename']); if ($t && $t->exists()) { $image = new Image($t); $imageURL = $image->createThumb(SearchForm::THUMB_WIDTH); $iconURL = $image->createThumb(PedigreeData::ICON_WIDTH, -1, true); break; } } } $parents = $this->getTitles($xml, 'child_of_family', 'Family'); $this->addExternals($parents); $spouse = $this->getTitles($xml, 'spouse_of_family', 'Family'); $this->addExternals($spouse); $allPlaces = $this->getAllEventPlaces($xml); $this->addPlaces($allPlaces); } if (substr($position, 0, 1) == 'P') { $pos = substr($position, 1); $line = self::$LINES[$pos]; $generation = self::$GENERATIONS[$pos]; } else { if ($position == 'Spouse') { $line = self::$LINES[1]; $generation = self::$GENERATIONS[1]; } else { // $position == 'Child' $line = self::$LINES[0]; $generation = self::$GENERATIONS[0]; } } $result .= ($result ? ",\n" : '') . '{ ' . PedigreeData::outJSON('type', 'Person') . PedigreeData::outJSON('label', 'Person:' . $titleText) . PedigreeData::outJSON('Surname', $surname) . PedigreeData::outJSON('Givenname', $given) . PedigreeData::outJSON('FullName', $fullname) . PedigreeData::outJSON('BirthYear', $birthYear) . PedigreeData::outJSON('BirthDate', $birthDate) . PedigreeData::outJSON('BirthPlace', $birthPlace) . PedigreeData::outJSON('BirthPlaceText', $birthPlaceText) . PedigreeData::outJSON('DeathYear', $deathYear) . PedigreeData::outJSON('DeathDate', $deathDate) . PedigreeData::outJSON('DeathPlace', $deathPlace) . PedigreeData::outJSON('DeathPlaceText', $deathPlaceText) . PedigreeData::outJSON('OtherEvents', $otherEvents) . PedigreeData::outJSON('ImageURL', $imageURL) . PedigreeData::outJSON('IconURL', $iconURL) . PedigreeData::outJSON('Parents', $parents) . PedigreeData::outJSON('Spouse', $spouse) . PedigreeData::outJSON('AllPlaces', $allPlaces) . PedigreeData::outJSON('Line', $line) . PedigreeData::outJSON('Generation', $generation) . PedigreeData::outJSON('Position', $position, false) . "}"; } foreach ($this->families as $titleText => $p) { $marriageDate = $marriagePlace = $marriagePlaceText = $marriageYear = ''; $husband = $wife = $children = ''; $otherEvents = ''; $xml = $p['xml']; $position = $p['position']; if ($xml) { list($marriageEventType, $marriageDate, $marriagePlace, $marriagePlaceText, $marriageYear) = $this->getEventData($xml, array('Marriage')); $otherEvents = $this->getOtherEventData($xml, array($marriageEventType)); $husband = $this->getTitles($xml, 'husband', 'Person'); $this->addExternals($husband); $wife = $this->getTitles($xml, 'wife', 'Person'); $this->addExternals($wife); $children = $this->getTitles($xml, 'child', 'Person'); $this->addExternals($children); } $result .= ($result ? ",\n" : '') . '{ ' . PedigreeData::outJSON('type', 'Family') . PedigreeData::outJSON('label', 'Family:' . $titleText) . PedigreeData::outJSON('MarriageYear', $marriageYear) . PedigreeData::outJSON('MarriageDate', $marriageDate) . PedigreeData::outJSON('MarriagePlace', $marriagePlace) . PedigreeData::outJSON('MarriagePlaceText', $marriagePlaceText) . PedigreeData::outJSON('OtherEvents', $otherEvents) . PedigreeData::outJSON('Husband', $husband) . PedigreeData::outJSON('Wife', $wife) . PedigreeData::outJSON('Child', $children) . PedigreeData::outJSON('Position', $position, false) . "}"; } // add externals foreach ($this->externals as $titleText => $dummy) { $result .= ($result ? ",\n" : '') . '{ ' . PedigreeData::outJSON('type', 'External') . PedigreeData::outJSON('label', $titleText, false) . "}"; } // add other events foreach ($this->otherEvents as $index => $event) { $result .= ($result ? ",\n" : '') . '{ ' . PedigreeData::outJSON('type', 'Event') . PedigreeData::outJSON('label', 'Event:' . ($index + 1)) . PedigreeData::outJSON('Date', $event['date']) . PedigreeData::outJSON('Place', $event['place']) . PedigreeData::outJSON('PlaceText', $event['placetext']) . PedigreeData::outJSON('EventType', $event['type'], false) . "}"; } // add places $stdPlaces = PlaceSearcher::getPlaceTitlesLatLong($this->places); foreach ($stdPlaces as $titleText => $stdPlace) { if ($stdPlace['lat'] || $stdPlace['lon']) { $result .= ($result ? ",\n" : '') . '{ ' . PedigreeData::outJSON('type', 'Place') . PedigreeData::outJSON('label', 'Place:' . $titleText) . PedigreeData::outJSON('addressLatLng', $stdPlace['lat'] . ',' . $stdPlace['lon'], false) . "}"; } } foreach ($this->latlngs as $latlng) { $result .= ($result ? ",\n" : '') . '{ ' . PedigreeData::outJSON('type', 'LatLng') . PedigreeData::outJSON('label', 'LatLng:' . $latlng) . PedigreeData::outJSON('addressLatLng', $latlng, false) . "}"; } return $result; }
protected function getFamilyMember($member) { $title = (string) $member['title']; $fullname = StructuredData::getFullname($member); if (!$fullname) { $fullname = trim(preg_replace('/\\(\\d+\\)\\s*$/', '', $title)); } $link = "[[Person:{$title}|{$fullname}]]"; $beginYear = StructuredData::getYear((string) $member['birthdate'] ? (string) $member['birthdate'] : (string) $member['chrdate'], true); $endYear = StructuredData::getYear((string) $member['deathdate'] ? (string) $member['deathdate'] : (string) $member['burialdate'], true); $yearrange = ''; if ($beginYear || $endYear) { $yearrange = "<span class=\"wr-infobox-yearrange\">{$beginYear} - {$endYear}</span>"; } return '<span class="wr-infobox-fullname">' . $link . '</span>' . $yearrange; }