function wfMatchFamily($args)
{
    global $wgUser, $wgAjaxCachePolicy;
    $wgAjaxCachePolicy->setPolicy(0);
    $status = GE_SUCCESS;
    $result = '';
    $gedcomId = GedcomUtil::getGedcomId($args);
    if (!$wgUser->isLoggedIn()) {
        $status = GE_NOT_LOGGED_IN;
    } else {
        if ($wgUser->isBlocked() || wfReadOnly()) {
            $status = GE_NOT_AUTHORIZED;
        } else {
            if (!$args || !$gedcomId || !preg_match('/^<gedcom [^>]*id="([^"]+)"/', $args, $idMatches) || !preg_match('/^<gedcom [^>]*match="([^"]+)"/', $args, $titleMatches)) {
                $status = GE_INVALID_ARG;
            } else {
                // calc family match scores
                $id = $idMatches[1];
                $matchTitle = Title::newFromText($titleMatches[1], NS_FAMILY);
                $matchTitleString = $matchTitle->getText();
                $gedcomData = GedcomUtil::getGedcomDataMap($args);
                $gedcomTitleString = $gedcomData[$id]['title'];
                if (strpos($gedcomTitleString, 'Person:') === 0 || strpos($gedcomTitleString, 'Family:') === 0) {
                    $gedcomTitleString = substr($gedcomTitleString, 7);
                }
                $compare = new CompareForm('Family', array($gedcomTitleString, $matchTitleString), $gedcomData, $args);
                list($compareData, $compareChildren, $maxChildren) = $compare->readCompareData();
                $dataLabels = $compare->getDataLabels();
                list($compareClass, $husbandScores, $wifeScores, $totalScores) = $compare->scoreCompareData($dataLabels, $compareData);
                // matched if not multiple husbands/wives, total score > threshold, husband + wife scores > threshold, and all gedcom children matched
                $gedcomHusbandCount = count($compareData[$gedcomTitleString]['husbandTitle']);
                $gedcomWifeCount = count($compareData[$gedcomTitleString]['wifeTitle']);
                $matchHusbandCount = count($compareData[$matchTitleString]['husbandTitle']);
                $matchWifeCount = count($compareData[$matchTitleString]['wifeTitle']);
                $matched = $gedcomHusbandCount <= 1 && $gedcomWifeCount <= 1 && $matchHusbandCount <= 1 && $matchWifeCount <= 1 && $totalScores[1] >= 4 && ($gedcomHusbandCount == 0 || $matchHusbandCount == 0 || $husbandScores[1] > 0) && ($gedcomWifeCount == 0 || $matchWifeCount == 0 || $wifeScores[1] > 0);
                //wfDebug("MATCHCOMPARE gedcomTitle=$gedcomTitleString matchTitle=$matchTitleString ghc=$gedcomHusbandCount gwc=$gedcomWifeCount mhc=$matchHusbandCount mwc=$matchWifeCount".
                //			" totalScore={$totalScores[1]} husbandScore={$husbandScores[1]} wifeScore={$wifeScores[1]} matched=$matched\n");
                if ($matched) {
                    $unmatchedGedcomChild = false;
                    $unmatchedWikiChild = false;
                    for ($i = 0; $i < $maxChildren; $i++) {
                        if (count(@$compareChildren[$gedcomTitleString][$i]['childTitle']) == 1 && count(@$compareChildren[$matchTitleString][$i]['childTitle']) != 1) {
                            $unmatchedGedcomChild = true;
                        } else {
                            if (count(@$compareChildren[$gedcomTitleString][$i]['childTitle']) != 1 && count(@$compareChildren[$matchTitleString][$i]['childTitle']) == 1) {
                                $unmatchedWikiChild = true;
                            }
                        }
                    }
                    if ($unmatchedGedcomChild && $unmatchedWikiChild) {
                        // could be a mismatched child
                        $matched = false;
                        //wfDebug("MATCHCOMPARE failed on children\n");
                    }
                }
                if ($matched) {
                    // save matches and return related matches
                    $keys = array();
                    $keys[] = $id;
                    $matches = array();
                    $matches[] = $matchTitle->getPrefixedText();
                    $merged = array();
                    $merged[] = 'false';
                    if ($gedcomHusbandCount == 1 && $matchHusbandCount == 1) {
                        $key = GedcomUtil::getKeyFromTitle($compareData[$gedcomTitleString]['husbandTitle'][0]);
                        if ($key) {
                            // not already merged
                            $keys[] = $key;
                            $matches[] = 'Person:' . $compareData[$matchTitleString]['husbandTitle'][0];
                            $merged[] = 'false';
                        }
                    }
                    if ($gedcomWifeCount == 1 && $matchWifeCount == 1) {
                        $key = GedcomUtil::getKeyFromTitle($compareData[$gedcomTitleString]['wifeTitle'][0]);
                        if ($key) {
                            $keys[] = $key;
                            $matches[] = 'Person:' . $compareData[$matchTitleString]['wifeTitle'][0];
                            $merged[] = 'false';
                        }
                    }
                    for ($i = 0; $i < $maxChildren; $i++) {
                        if (count(@$compareChildren[$gedcomTitleString][$i]['childTitle']) == 1 && count(@$compareChildren[$matchTitleString][$i]['childTitle']) == 1) {
                            $key = GedcomUtil::getKeyFromTitle($compareChildren[$gedcomTitleString][$i]['childTitle'][0]);
                            if ($key) {
                                $keys[] = $key;
                                $matches[] = 'Person:' . $compareChildren[$matchTitleString][$i]['childTitle'][0];
                                $merged[] = 'false';
                            }
                        }
                    }
                    $status = fgUpdateMatches($gedcomId, $keys, $matches, $merged);
                    if ($status == GE_SUCCESS) {
                        $result = fgGetRelatedMatches($keys, $matches);
                    }
                } else {
                    // save as potential match and return
                    $keys = array($id);
                    $matches = array($matchTitleString);
                    $status = fgUpdatePotentialMatches($gedcomId, $keys, $matches);
                    if ($status == GE_SUCCESS) {
                        $result = '<match id="' . StructuredData::escapeXml($id) . '" matches="' . StructuredData::escapeXml($matchTitleString) . '"/>';
                    }
                }
            }
        }
    }
    return "<matchfamily status=\"{$status}\">{$result}</matchfamily>";
}
Beispiel #2
0
 public static function generateGedcomMergeLogKey($titleString)
 {
     return 'g' . GedcomUtil::getKeyFromTitle($titleString);
 }
Beispiel #3
0
    private function submitPage()
    {
        global $wgRequest, $wgOut;
        if (!$wgRequest->wasPosted() || !$wgRequest->getVal('wpEdittime')) {
            $this->showPage();
            return;
        }
        // from form
        $textbox1 = $wgRequest->getText('wpTextbox1');
        $ns = $wgRequest->getVal('gedcomns');
        $titleString = $wgRequest->getVal('gedcomtitle');
        $editPage = (object) array('textbox1' => $textbox1, 'section' => '');
        $obj = $this->getPageObj($ns, $titleString);
        $obj->importEditData($editPage, $wgRequest);
        if ($obj->getTitle()) {
            $titleString = $obj->getTitle()->getPrefixedText();
            // get updated title in case it was updated
        }
        $text = $editPage->textbox1;
        // grab xml and content from edited data
        $tagName = $obj->getTagName();
        $xml = StructuredData::getXml($tagName, $text);
        $content = trim(mb_substr($text, mb_strpos($text, '</' . $tagName . '>') + strlen("</{$tagName}>\n")));
        // add id's back and remove titles
        $saveTitles = array();
        foreach ($xml->child_of_family as $r) {
            $r['id'] = GedcomUtil::getKeyFromTitle((string) $r['title']);
            if ((string) $r['id']) {
                $saveTitles[(string) $r['id']] = (string) $r['title'];
                unset($r['title']);
            }
        }
        foreach ($xml->spouse_of_family as $r) {
            $r['id'] = GedcomUtil::getKeyFromTitle((string) $r['title']);
            if ((string) $r['id']) {
                $saveTitles[(string) $r['id']] = (string) $r['title'];
                unset($r['title']);
            }
        }
        foreach ($xml->husband as $r) {
            $r['id'] = GedcomUtil::getKeyFromTitle((string) $r['title']);
            if ((string) $r['id']) {
                $saveTitles[(string) $r['id']] = (string) $r['title'];
                unset($r['title']);
            }
        }
        foreach ($xml->wife as $r) {
            $r['id'] = GedcomUtil::getKeyFromTitle((string) $r['title']);
            if ((string) $r['id']) {
                $saveTitles[(string) $r['id']] = (string) $r['title'];
                unset($r['title']);
            }
        }
        foreach ($xml->child as $r) {
            $r['id'] = GedcomUtil::getKeyFromTitle((string) $r['title']);
            if ((string) $r['id']) {
                $saveTitles[(string) $r['id']] = (string) $r['title'];
                unset($r['title']);
            }
        }
        foreach ($xml->source_citation as $r) {
            $r['source_id'] = GedcomUtil::getKeyFromTitle((string) $r['title']);
            if ((string) $r['source_id']) {
                $saveTitles[(string) $r['source_id']] = (string) $r['title'];
                unset($r['title']);
            }
        }
        // save data to db
        $text = $xml->asXML();
        $text = substr($text, strpos($text, '<', 1)) . $content;
        // skip past the <?xml version="1.0"? > header and add content
        $dbw =& wfGetDB(DB_MASTER);
        $dbw->begin();
        $qtext = $dbw->addQuotes($text);
        $sql = 'INSERT INTO familytree_gedcom_data (fgd_gedcom_id, fgd_gedcom_key, fgd_text)' . ' VALUES(' . $dbw->addQuotes($this->gedcomid) . ',' . $dbw->addQuotes($this->gedcomkey) . ',' . $qtext . ')' . ' ON DUPLICATE KEY UPDATE fgd_text=' . $qtext;
        $dbw->query($sql);
        $dbw->commit();
        // convert to in-memory format and save to memory
        // add titles back
        foreach ($xml->child_of_family as $r) {
            if ((string) $r['id']) {
                $r['title'] = $saveTitles[(string) $r['id']];
            }
        }
        foreach ($xml->spouse_of_family as $r) {
            if ((string) $r['id']) {
                $r['title'] = $saveTitles[(string) $r['id']];
            }
        }
        foreach ($xml->husband as $r) {
            if ((string) $r['id']) {
                $r['title'] = $saveTitles[(string) $r['id']];
            }
        }
        foreach ($xml->wife as $r) {
            if ((string) $r['id']) {
                $r['title'] = $saveTitles[(string) $r['id']];
            }
        }
        foreach ($xml->child as $r) {
            if ((string) $r['id']) {
                $r['title'] = $saveTitles[(string) $r['id']];
            }
        }
        foreach ($xml->source_citation as $r) {
            if ((string) $r['source_id']) {
                $r['title'] = $saveTitles[(string) $r['source_id']];
            }
        }
        $xml->content = $content;
        $xml['id'] = $this->gedcomkey;
        $xml['ns'] = $ns;
        $xml['title'] = $titleString;
        $text = $xml->asXML();
        $text = substr($text, strpos($text, '<', 1));
        // skip past the <?xml version="1.0"? > header
        GedcomUtil::putGedcomDataString($text);
        // add script to notify swf of update
        $gedcomkey = htmlspecialchars($this->gedcomkey);
        $wgOut->addScript(<<<END
<script type="text/javascript">
//<![CDATA[
\$(document).ready(function(){
\ttry {
\t   if (parent && parent.review) {
\t      var swf=(navigator.appName.indexOf("Microsoft")!=-1) ? parent.review.window["gedcom"] : parent.review.document["gedcom"];
\t      if (swf && swf.pageUpdated) swf.pageUpdated("{$gedcomkey}");
\t   }
\t} catch (e) {}
});
//]]>
</script>
END
);
        // show page
        $this->showPage();
    }