function readPageXml($title) { $page = null; $xml = null; $titleString = $title->getText(); if ($title->getNamespace() == NS_PERSON) { $page = new Person($titleString); } else { $page = new Family($titleString); } if ($page) { $page->loadPage(); $xml = $page->getPageXml(); } return $xml; }
public static function readFamilyData($titleString, &$data, &$gedcomData, $includeRelativeData = false, $includeNonCompareData = false, $revid = 0, $timestamp = '') { $children = array(); $data['familyTitle'][] = $titleString; if (GedcomUtil::isGedcomTitle($titleString)) { $title = null; $data['Exists'] = true; $xml = GedcomUtil::getGedcomXml($gedcomData, $titleString); $data['GedcomMatchTitle'] = (string) $xml['match']; $contents = GedcomUtil::getGedcomContents($gedcomData, $titleString); } else { $title = Title::newFromText($titleString, NS_FAMILY); $data['Exists'] = $title->exists(); $p = new Family($titleString); $p->loadPage($revid); if ($revid) { $data['Revid'][] = $revid; } // for consistency with readPersonData $xml = $p->getPageXml(); $contents = $p->getPageContents(); } $husbandFound = $wifeFound = false; if ($includeRelativeData) { CompareForm::initPersonData('husband', $data); CompareForm::initPersonData('wife', $data); } if (isset($xml)) { foreach ($xml->event_fact as $ef) { $type = (string) $ef['type']; if ($type == Family::$MARRIAGE_TAG || $type == Family::$ALT_MARRIAGE_TAG) { CompareForm::getDatePlace($ef, 'Marriagedate', 'Marriageplace', $data); } else { if ($includeNonCompareData) { CompareForm::getOtherEvent($ef, '', $data); } } } if ($includeNonCompareData) { CompareForm::getSINContents($xml, $contents, '', $data); } if ($includeRelativeData) { $husbandFound = CompareForm::readRelativeData('husband', $xml->husband, $data, $gedcomData, true, false, $includeNonCompareData, $timestamp); $wifeFound = CompareForm::readRelativeData('wife', $xml->wife, $data, $gedcomData, true, false, $includeNonCompareData, $timestamp); $i = 0; foreach ($xml->child as $c) { $childTitle = (string) $c['title']; if ($childTitle) { $children[$i] = array(); CompareForm::initPersonData('child', $children[$i]); if (GedcomUtil::isGedcomTitle($childTitle)) { $childRevid = 0; } else { $t = Title::newFromText($childTitle, NS_PERSON); $childRevid = $timestamp ? StructuredData::getRevidForTimestamp($t, $timestamp) : 0; } CompareForm::readPersonData('child', $childTitle, $children[$i], $gedcomData, false, false, true, $includeNonCompareData, $childRevid); $i++; } } } else { $data['husbandTitle'] = array(); foreach ($xml->husband as $m) { $data['husbandTitle'][] = (string) $m['title']; } $data['wifeTitle'] = array(); foreach ($xml->wife as $m) { $data['wifeTitle'][] = (string) $m['title']; } $data['childTitle'] = array(); foreach ($xml->child as $m) { $data['childTitle'][] = (string) $m['title']; } } } else { if ($title && StructuredData::isRedirect($contents)) { $data['Redirect'] = true; } } if ($includeRelativeData && (!$husbandFound || !$wifeFound)) { list($fg, $fs, $mg, $ms) = StructuredData::parseFamilyTitle($titleString); if (!$husbandFound) { if ($fg) { $data['husbandGiven'][] = $fg; } if ($fs) { $data['husbandSurname'][] = $fs; } } if (!$wifeFound) { if ($mg) { $data['wifeGiven'][] = $mg; } if ($ms) { $data['wifeSurname'][] = $ms; } } } $data['Nomerge'] = CompareForm::getNomergeTitleStrings($title); if ($title) { $data['Updatable'] = CompareForm::isUpdatable($title, $contents); } return $children; }
public function getFamilyData($titleString, $orn, $numDescLevels, $numAncLevels) { global $wgServer, $wgStylePath; $family = new Family($titleString); $xml = $family->getPageXml(true); $obj = array(); if (isset($xml)) { $obj['name'] = 'Family'; $obj['id'] = $family->getTitle()->getPrefixedDBkey(); // populate data list($marriageYear, $marriageDate, $marriagePlace, $eventTypeIndex) = $this->getEventData($xml, array('Marriage')); $thumbURL = $this->getPrimaryImage($xml, false); $data = array(); $data['url'] = $family->getTitle()->getFullURL(); $found = false; list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($titleString); foreach ($xml->husband as $p) { $person = $this->getPersonSummary($p); if ($person['name']) { $data['husbandname'] = $person['name']; } if ($person['url']) { $data['husbandurl'] = $person['url']; } if ($person['yearrange']) { $data['husbandyearrange'] = $person['yearrange']; } $found = true; break; } if (!$found) { $data['husbandname'] = "{$hg} {$hs}"; } $found = false; foreach ($xml->wife as $p) { $person = $this->getPersonSummary($p); if ($person['name']) { $data['wifename'] = $person['name']; } if ($person['url']) { $data['wifeurl'] = $person['url']; } if ($person['yearrange']) { $data['wifeyearrange'] = $person['yearrange']; } $found = true; break; } if (!$found) { $data['wifename'] = "{$wg} {$ws}"; } $children = array(); // sort by birth date -- use sort for fetching children as well $sort = array(); $ix = 0; $prevKey = 0; foreach ($xml->child as $p) { $person = $this->getPersonSummary($p); $key = StructuredData::getDateKey($person['birthdate'], true); if ($key) { $prevKey = $key; } else { $key = $prevKey; } $sort[$key * 50 + $ix] = $person; $ix++; } ksort($sort, SORT_NUMERIC); $ix = 0; foreach ($sort as $key => $person) { if ($ix++ == 12) { $data['morechildren'] = 'true'; break; } $child = array(); if ($person['name']) { $child['name'] = $person['name']; } if ($person['url']) { $child['url'] = $person['url']; } if ($person['yearrange']) { $child['yearrange'] = $person['yearrange']; } $children[] = $child; } $data['children'] = $children; if ($marriageDate) { $data['marriagedate'] = $marriageDate; } if ($marriagePlace) { $data['marriageplace'] = $marriagePlace; } // if ($marriagePlaceUrl) $data['marriageplaceurl'] = $marriagePlaceUrl; $data['type'] = 'Family'; $data['$orn'] = $orn; if ($thumbURL) { $data['thumb'] = $this->makeImgTag($thumbURL, $titleString); } // $data['icon'] = $this->makeImgTag($wgServer.$wgStylePath.TreeData::FAMILY_ICON, 'Family', TreeData::FAMILY_ICON_WIDTH, TreeData::FAMILY_ICON_HEIGHT); $obj['data'] = $data; // populate children $children = array(); if ($numAncLevels > 0) { foreach ($xml->husband as $p) { $data = $this->getPersonData((string) $p['title'], 'left', 0, $numAncLevels - 1); if ($data) { $children[] = $data; } } foreach ($xml->wife as $p) { $data = $this->getPersonData((string) $p['title'], 'left', 0, $numAncLevels - 1); if ($data) { $children[] = $data; } } } if ($numDescLevels > 0) { foreach ($sort as $key => $person) { $data = $this->getPersonData($person['title'], 'right', $numDescLevels - 1, 0); if ($data) { $children[] = $data; } } } $obj['children'] = $children; } return $obj; }
private function setFamilyMatchVars($gedcomData) { if ($gedcomData) { $xml = GedcomUtil::getGedcomXml($gedcomData, $this->pagetitle); } else { $f = new Family($this->pagetitle); $xml = $f->getPageXml(); } if (isset($xml)) { // add match string foreach ($xml->husband as $h) { $this->husbandGivenname .= ($this->husbandGivenname ? ' ' : '') . (string) @$h['given']; $this->husbandSurname .= ($this->husbandSurname ? ' ' : '') . (string) @$h['surname']; } foreach ($xml->wife as $w) { $this->wifeGivenname .= ($this->wifeGivenname ? ' ' : '') . (string) @$w['given']; $this->wifeSurname .= ($this->wifeSurname ? ' ' : '') . (string) @$w['surname']; } foreach ($xml->event_fact as $ef) { $type = (string) $ef['type']; if ($type == Family::$MARRIAGE_TAG) { $this->marriagedate = (string) @$ef['date']; $this->marriageplace = (string) @$ef['place']; $pos = strpos($this->marriageplace, '|'); if ($pos !== false) { $this->marriageplace = substr($this->marriageplace, 0, $pos); } break; } } } if (!$this->husbandGivenname || !$this->husbandSurname || !$this->wifeGivenname || !$this->wifeSurname) { $t = Title::makeTitleSafe(NS_FAMILY, $this->pagetitle); if ($t) { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($t->getText()); if (!$this->husbandGivenname) { $this->husbandGivenname = $hg; } if (!$this->husbandSurname) { $this->husbandSurname = $hs; } if (!$this->wifeGivenname) { $this->wifeGivenname = $wg; } if (!$this->wifeSurname) { $this->wifeSurname = $ws; } } } }
protected function getFamilyBadge($family, $isParentsSiblings, $gender, $parentFamilies, &$marriageEvents) { global $wrHostName; $marriageKey = 0; $title = (string) $family['title']; $warning = ''; $subtitle = ''; if ($isParentsSiblings) { $label = "Parents and Siblings"; $husbandLabel = 'F'; $wifeLabel = 'M'; $childLabel = 'S'; $class = "wr-infobox-parentssiblings"; if (count($parentFamilies) > 1) { $pfs = array(); foreach ($parentFamilies as $pf) { $t = Title::newFromText($pf, NS_FAMILY); $pfs[] = wfUrlencode($t->getDBkey()); } $warning = "Duplicate parents - <span class=\"plainlinks\">[http://{$wrHostName}/wiki/Special:Compare?ns=Family&compare=" . join('|', $pfs) . " compare]</span>"; } } else { $label = "Spouse and Children"; $husbandLabel = 'H'; $wifeLabel = 'W'; $childLabel = 'C'; $class = "wr-infobox-spousechildren"; } $spouses = ''; $marriage = ''; $children = ''; $spouseLinks = array(); if ($this->isGedcomPage) { if (mb_strpos($title, ' - Excluded (') > 0) { $label .= ' - Excluded'; } $spouses = "<li>[[Family:{$title}|View family members]]<br><span style=\"font-size:75%\">family members not shown in gedcom review</span></li>"; } else { $familyObject = new Family($title); $familyXml = $familyObject->getPageXml(true); if (isset($familyXml)) { if (isset($familyXml->husband)) { foreach ($familyXml->husband as $spouse) { $spouses .= $this->getFamilyMember($spouse, $husbandLabel, !$isParentsSiblings && $gender == 'F', $spouseLinks); } } else { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($title); if ($hg || $hs) { $spouses .= $this->getFamilyMember(null, $husbandLabel, !$isParentsSiblings && $gender == 'F', $spouseLinks, "{$hg} {$hs}", 'M', $title); } } if (isset($familyXml->wife)) { foreach ($familyXml->wife as $spouse) { $spouses .= $this->getFamilyMember($spouse, $wifeLabel, !$isParentsSiblings && $gender == 'M', $spouseLinks); } } else { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($title); if ($wg || $ws) { $spouses .= $this->getFamilyMember(null, $wifeLabel, !$isParentsSiblings && $gender == 'M', $spouseLinks, "{$wg} {$ws}", 'F', $title); } } if (isset($familyXml->event_fact)) { foreach ($familyXml->event_fact as $eventFact) { if ((string) $eventFact['type'] == 'Marriage') { $marriageDate = (string) $eventFact['date']; $marriageKey = StructuredData::getDateKey($marriageDate, true); $marriage = "<div class=\"wr-infobox-event\">m. <span class=\"wr-infobox-date\">{$marriageDate}</span></div>"; } if (!$isParentsSiblings) { $marriageDesc = (string) $eventFact['desc']; if ($marriageDesc) { $marriageDesc .= '<br/>'; } // sometimes event type is "Reference Number" -- I don't know why $conjunction = @Family::$EVENT_CONJUNCTIONS[(string) $eventFact['type']]; $marriageDesc .= $conjunction . ' ' . join(' or ', $spouseLinks); $marriageEvents[] = array('type' => (string) $eventFact['type'], 'date' => (string) $eventFact['date'], 'place' => (string) $eventFact['place'], 'desc' => $marriageDesc, 'srcs' => (string) $eventFact['sources'], 'no_citation_needed' => true); } } } foreach ($familyXml->child as $child) { $children .= $this->getFamilyMember($child, $childLabel, false, $spouseLinks); } if ($children) { $children = "<ol>{$children}</ol>"; } } else { list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($title); if ($hg || $hs) { $spouses .= $this->getFamilyMember(null, $husbandLabel, false, $spouseLinks, "{$hg} {$hs}", 'M', $title); } if ($wg || $ws) { $spouses .= $this->getFamilyMember(null, $wifeLabel, false, $spouseLinks, "{$wg} {$ws}", 'F', $title); } } $t = Title::makeTitleSafe(NS_FAMILY, $title); $subtitle = "<div class=\"wr-infobox-editlink\"><span class=\"plainlinks\">([" . $t->getFullURL('action=edit') . " edit])</span></div>"; } if ($warning) { $subtitle = "<div class=\"wr-infobox-warning\">{$warning}</div>"; } $result = <<<END <div class="wr-infobox wr-infobox-familybadge {$class}"> <div class="wr-infobox-heading">[[Family:{$title}|{$label}]]</div>{$subtitle}<ul>{$spouses}</ul>{$marriage}{$children} </div> END; return array($marriageKey, $result); }