示例#1
0
 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;
 }
示例#2
0
 protected function toEditFields(&$textbox1)
 {
     global $wgOut, $wgScriptPath, $wgESINHandler, $wgRequest;
     $result = '';
     $target = $wgRequest->getVal('target');
     // add javascript functions
     $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/jquery.tablednd_0_5.yui.1.js\"></script>");
     $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/personfamily.31.js\"></script>");
     $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgScriptPath}/autocomplete.10.js\"></script>");
     $tm = new TipManager();
     $invalidStyle = ' style="background-color:#fdd;"';
     $husbandStyle = '';
     $wifeStyle = '';
     $childStyle = '';
     $husbands = array();
     $wives = array();
     $children = array();
     if (!isset($this->xml)) {
         // && !StructuredData::isRedirect($textbox1)) {
         // construct <family> text from What Links Here
         $oldText = $this->getPageTextFromWLH(true, $wgRequest);
         $this->xml = StructuredData::getXml('family', $oldText);
     }
     if (isset($this->xml)) {
         $husbands = StructuredData::getTitlesAsArray($this->xml->husband);
         $wives = StructuredData::getTitlesAsArray($this->xml->wife);
         $children = StructuredData::getTitlesAsArray($this->xml->child);
     }
     $this->addRequestMembers('ht', $husbands);
     $this->addRequestMembers('wt', $wives);
     $this->addRequestMembers('ct', $children);
     if (!$this->isGedcomPage && !StructuredData::titleStringHasId($this->titleString)) {
         $result .= "<p><font color=red>The page title does not have an ID; please create a page with an ID using <a href='/wiki/Special:AddPage/Family'>Add page</a></font></p>";
     }
     if (StructuredData::titlesOverlap($husbands, $wives)) {
         $result .= "<p><font color=red>The same person cannot be both husband and wife</font></p>";
         $husbandStyle = $invalidStyle;
         $wifeStyle = $invalidStyle;
     }
     if (StructuredData::titlesOverlap($husbands, $children)) {
         $result .= "<p><font color=red>The same person cannot be both husband and child</font></p>";
         $husbandStyle = $invalidStyle;
     }
     if (StructuredData::titlesOverlap($wives, $children)) {
         $result .= "<p><font color=red>The same person cannot be both wife and child</font></p>";
         $wifeStyle = $invalidStyle;
     }
     if (!$this->isGedcomPage && (StructuredData::titlesMissingId($husbands) || !StructuredData::titlesExist(NS_PERSON, $husbands))) {
         $result .= "<p><font color=red>Husband page not found; please click remove and add a new one</font></p>";
     }
     if (!$this->isGedcomPage && (StructuredData::titlesMissingId($wives) || !StructuredData::titlesExist(NS_PERSON, $wives))) {
         $result .= "<p><font color=red>Wife page not found; please click remove and add a new one</font></p>";
     }
     if (!$this->isGedcomPage && (StructuredData::titlesMissingId($children) || !StructuredData::titlesExist(NS_PERSON, $children))) {
         $result .= "<p><font color=red>Child page not found; please click remove and add a new one</font></p>";
     }
     if (ESINHandler::hasAmbiguousDates($this->xml)) {
         $result .= "<p><font color=red>Please write dates in \"<i>D MMM YYYY</i>\" format so they are unambiguous (ie 5 Jan 1900)</font></p>";
     }
     // add spouse input
     list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($this->titleString);
     $g = @$wgRequest->getVal('hg');
     $s = @$wgRequest->getVal('hs');
     $husbandParam = $g || $s;
     if ($husbandParam) {
         $hg = $g;
         $hs = $s;
     }
     $g = @$wgRequest->getVal('wg');
     $s = @$wgRequest->getVal('ws');
     $wifeParam = $g || $s;
     if ($wifeParam) {
         $wg = $g;
         $ws = $s;
     }
     $result .= $this->addPersonInput($husbands, 'husband', 'Husband', $husbandStyle, $tm, $invalidStyle, $hg, $hs, $husbandParam);
     $result .= $this->addPersonInput($wives, 'wife', 'Wife', $wifeStyle, $tm, $invalidStyle, $wg, $ws, $wifeParam);
     // add event_fact input table
     $result .= $wgESINHandler->addEventsFactsInput($this->xml, self::$STD_EVENT_TYPES, self::$OTHER_EVENT_TYPES);
     // add children input
     $result .= $this->addPersonInput($children, 'child', 'Children', $childStyle, $tm, $invalidStyle);
     // add sources, images, notes input tables
     $result .= $wgESINHandler->addSourcesImagesNotesInput($this->xml);
     $result .= $tm->getTipTexts();
     $result .= '<h2>Family History</h2>';
     return $result;
 }
示例#3
0
 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;
 }
示例#4
0
 public static function standardizeFamilyData($data)
 {
     $stdValues = array();
     list($hg, $hs, $wg, $ws) = StructuredData::parseFamilyTitle($data['title']);
     $stdValues['HusbandGiven'] = CompareForm::standardizeValues('HusbandGiven', array($hg));
     $stdValues['HusbandSurname'] = CompareForm::standardizeValues('HusbandSurname', array($hs));
     $stdValues['WifeGiven'] = CompareForm::standardizeValues('WifeGiven', array($wg));
     $stdValues['WifeSurname'] = CompareForm::standardizeValues('WifeSurname', array($ws));
     $marriagedates = array();
     $marriageplaces = array();
     foreach (@$data['events'] as $event) {
         if ($event['stdtype'] == Family::$MARRIAGE_TAG) {
             $marriagedates[] = $event['date'];
             $marriageplaces[] = $event['place'];
         }
     }
     $stdValues['Marriagedate'] = CompareForm::standardizeValues('Marriagedate', $marriagedates);
     $stdValues['Marriageplace'] = CompareForm::standardizeValues('Marriageplace', $marriageplaces);
     return $stdValues;
 }
示例#5
0
 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;
             }
         }
     }
 }
示例#6
0
    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);
    }