public static function readPersonData($pfx, $titleString, &$data, &$gedcomData, $includeRelativeData = false, $saveParentTitle = false, $saveSpouseTitle = false, $includeNonCompareData = false, $revid = 0, $timestamp = '') { $data[$pfx . 'Title'][] = $titleString; if (GedcomUtil::isGedcomTitle($titleString)) { $title = null; $data[$pfx . 'Exists'] = true; $xml = GedcomUtil::getGedcomXml($gedcomData, $titleString); $data[$pfx . 'GedcomMatchTitle'] = (string) $xml['match']; $contents = GedcomUtil::getGedcomContents($gedcomData, $titleString); } else { $title = Title::newFromText($titleString, NS_PERSON); $data[$pfx . 'Exists'] = $title->exists(); $p = new Person($titleString); $p->loadPage($revid); if ($revid) { $data[$pfx . 'Revid'][] = $revid; } // !!! this function can get called multiple times with the same pfx from SpecialReviewMerge $xml = $p->getPageXml(); $contents = $p->getPageContents(); } if (isset($xml)) { $found = true; // add match string $v = (string) @$xml->name['given']; if ($v) { $data[$pfx . 'Given'][] = $v; } $v = (string) @$xml->name['surname']; if ($v) { $data[$pfx . 'Surname'][] = $v; } $v = (string) @$xml->name['title_prefix']; if ($v) { $data[$pfx . 'Prefix'][] = $v; } $v = (string) @$xml->name['title_suffix']; if ($v) { $data[$pfx . 'Suffix'][] = $v; } if (!$pfx || $pfx == 'child') { $gender = (string) $xml->gender; $data[$pfx . 'Gender'][] = $gender; } foreach ($xml->alt_name as $an) { $v = (string) @$an['given']; if ($v) { $data[$pfx . 'Given'][] = $v; } $v = (string) @$an['surname']; if ($v) { $data[$pfx . 'Surname'][] = $v; } $v = (string) @$an['title_prefix']; if ($v) { $data[$pfx . 'Prefix'][] = $v; } $v = (string) @$an['title_suffix']; if ($v) { $data[$pfx . 'Suffix'][] = $v; } } foreach ($xml->event_fact as $ef) { $type = (string) $ef['type']; if ($type == Person::$BIRTH_TAG || $type == PERSON::$ALT_BIRTH_TAG) { CompareForm::getDatePlace($ef, $pfx . 'Birthdate', $pfx . 'Birthplace', $data); } else { if ($type == Person::$CHR_TAG || $type == PERSON::$ALT_CHR_TAG) { CompareForm::getDatePlace($ef, $pfx . 'Christeningdate', $pfx . 'Christeningplace', $data); } else { if ($type == Person::$DEATH_TAG || $type == PERSON::$ALT_DEATH_TAG) { CompareForm::getDatePlace($ef, $pfx . 'Deathdate', $pfx . 'Deathplace', $data); } else { if ($type == Person::$BUR_TAG || $type == PERSON::$ALT_BUR_TAG) { CompareForm::getDatePlace($ef, $pfx . 'Burialdate', $pfx . 'Burialplace', $data); } else { if ($includeNonCompareData) { CompareForm::getOtherEvent($ef, $pfx, $data); } } } } } } if ($includeNonCompareData) { CompareForm::getSINContents($xml, $contents, $pfx, $data); } if ($includeRelativeData) { CompareForm::initPersonData('father', $data); CompareForm::initPersonData('mother', $data); } foreach ($xml->child_of_family as $f) { $familyTitle = (string) $f['title']; if ($familyTitle && $includeRelativeData) { $f = new Family($familyTitle); $familyRevid = $timestamp ? StructuredData::getRevidForTimestamp($f->getTitle(), $timestamp) : 0; $f->loadPage($familyRevid); $famXml = $f->getPageXml(); $fatherFound = $motherFound = false; if (isset($famXml)) { $fatherFound = CompareForm::readRelativeData('father', $famXml->husband, $data, $gedcomData, false, false, $includeNonCompareData, $timestamp); $motherFound = CompareForm::readRelativeData('mother', $famXml->wife, $data, $gedcomData, false, false, $includeNonCompareData, $timestamp); } if (!$fatherFound || !$motherFound) { list($fg, $fs, $mg, $ms) = StructuredData::parseFamilyTitle($familyTitle); if (!$fatherFound) { if ($fg) { $data['fatherGiven'][] = $fg; } if ($fs) { $data['fatherSurname'][] = $fs; } } if (!$motherFound) { if ($mg) { $data['motherGiven'][] = $mg; } if ($ms) { $data['motherSurname'][] = $ms; } } } } else { if ($saveParentTitle) { $data[$pfx . 'ParentFamilyTitle'][] = $familyTitle; } } } if ($includeRelativeData) { CompareForm::initPersonData('spouse', $data); } foreach ($xml->spouse_of_family as $f) { $familyTitle = (string) $f['title']; if ($familyTitle && $includeRelativeData) { if (GedcomUtil::isGedcomTitle($familyTitle)) { $famXml = GedcomUtil::getGedcomXml($gedcomData, $familyTitle); } else { $f = new Family($familyTitle); $familyRevid = $timestamp ? StructuredData::getRevidForTimestamp($f->getTitle(), $timestamp) : 0; $f->loadPage($familyRevid); $famXml = $f->getPageXml(); } $spouseFound = false; if (isset($famXml)) { if ($gender == 'M') { $spouseFound = CompareForm::readRelativeData('spouse', $famXml->wife, $data, $gedcomData, false, false, $includeNonCompareData, $timestamp); } else { $spouseFound = CompareForm::readRelativeData('spouse', $famXml->husband, $data, $gedcomData, false, false, $includeNonCompareData, $timestamp); } } if (!$spouseFound) { list($fg, $fs, $mg, $ms) = StructuredData::parseFamilyTitle($familyTitle); if ($gender == 'M') { if ($mg) { $data['spouseGiven'][] = $mg; } if ($ms) { $data['spouseSurname'][] = $ms; } } else { if ($fg) { $data['spouseGiven'][] = $fg; } if ($fs) { $data['spouseSuranme'][] = $fs; } } } } else { if ($saveSpouseTitle) { $data[$pfx . 'SpouseFamilyTitle'][] = $familyTitle; } } } } else { if ($title && StructuredData::isRedirect($contents)) { $data[$pfx . 'Redirect'] = true; } list($g, $s) = StructuredData::parsePersonTitle($titleString); if ($g) { $data[$pfx . 'Given'][] = $g; } if ($s) { $data[$pfx . 'Surname'][] = $s; } } $data[$pfx . 'Nomerge'] = CompareForm::getNomergeTitleStrings($title); if ($title) { $data[$pfx . 'Updatable'] = CompareForm::isUpdatable($title, $contents); } }
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; }