示例#1
0
 public function scoreCompareData($dataLabels, $compareData)
 {
     $compareClass = array();
     $husbandScores = array();
     $wifeScores = array();
     $totalScores = array();
     for ($i = 0; $i < count($this->compareTitles); $i++) {
         $husbandScores[$i] = $wifeScores[$i] = $totalScores[$i] = 0;
     }
     foreach ($dataLabels as $label) {
         $compareClass[$label] = array();
         for ($i = 0; $i < count($this->compareTitles); $i++) {
             $t = $this->compareTitles[$i];
             $stdValues =& CompareForm::standardizeValues($label, @$compareData[$t][$label]);
             if ($i == 0) {
                 $baseStdValues = $stdValues;
             }
             list($score, $compareClass[$label][$i]) = CompareForm::getCompareScoreClass($i == 0, $label, $baseStdValues, $stdValues);
             $totalScores[$i] += $score;
             if (strpos($label, 'husband') !== false) {
                 //wfDebug("COMPARE HUSBAND $label $score\n");
                 $husbandScores[$i] += $score;
             } else {
                 if (strpos($label, 'wife') !== false) {
                     //wfDebug("COMPARE WIFE $label $score\n");
                     $wifeScores[$i] += $score;
                 }
             }
         }
     }
     if ($this->namespace == 'Family') {
         $gedcomId = $this->gedcomDataString ? GedcomUtil::getGedcomId($this->gedcomDataString) : '';
         $titleString = $compareData[$this->compareTitles[0]]['familyTitle'][0];
         for ($i = 1; $i < count($this->compareTitles); $i++) {
             wfDebug("COMPARE title1={$titleString} title2=" . $compareData[$this->compareTitles[$i]]['familyTitle'][0] . " gedcomID={$gedcomId} totalScore={$totalScores[$i]}  husbandScore={$husbandScores[$i]}  wifeScore={$wifeScores[$i]}\n");
         }
     }
     return array($compareClass, $husbandScores, $wifeScores, $totalScores);
 }
示例#2
0
 public function doMerge()
 {
     global $wgOut, $wgUser;
     $skin =& $wgUser->getSkin();
     if ($this->isGedcom()) {
         $editFlags = EDIT_UPDATE;
         $mergeText = 'updated';
     } else {
         // create a mergelog record
         $mergeScore = $this->getMergeScore();
         $isTrustedUser = CompareForm::isTrustedMerger($wgUser, false);
         $isTrustedMerge = MergeForm::isTrustedMerge($mergeScore, $isTrustedUser);
         $mergeLogId = $this->logMerge($mergeScore, $isTrustedMerge);
         wfDebug("MERGESCORE mergeLogId={$mergeLogId} total score={$mergeScore}\n");
         if (!$isTrustedUser && $mergeScore < self::$LOW_MATCH_THRESHOLD) {
             error_log("WARNING suspect merge: id={$mergeLogId} user={$wgUser->getName()} score={$mergeScore}");
         }
         $editFlags = EDIT_UPDATE | EDIT_FORCE_BOT;
         $mergeText = 'merged';
     }
     // get merging people and families
     // add merging people and families to blacklist so propagation doesn't also try to update them
     $mergingPeople = array();
     $mergingFamilies = array();
     for ($m = 0; $m < count($this->data); $m++) {
         for ($p = 0; $p < count($this->data[$m]); $p++) {
             $titleString = $this->data[$m][$p]['title'];
             if ($this->namespace == 'Family' && $m == 0) {
                 if ($p > 0) {
                     $mergingFamilies[$titleString] = $this->data[$m][0]['title'];
                 }
                 $ns = NS_FAMILY;
             } else {
                 if ($p > 0) {
                     $mergingPeople[$titleString] = $this->data[$m][0]['title'];
                 }
                 $ns = NS_PERSON;
             }
             if (!GedcomUtil::isGedcomTitle($titleString)) {
                 $title = Title::newFromText($titleString, $ns);
                 PropagationManager::addBlacklistPage($title);
             }
         }
     }
     $output = "<H2>Pages {$mergeText} successfully</H2>";
     $output .= $this->getWarnings();
     $output .= '<ul>';
     $outputRows = array();
     $emptyRequest = new FauxRequest(array(), true);
     $mergeCmtSuffix = $this->isGedcom() ? '' : " - [[Special:ReviewMerge/{$mergeLogId}|review/undo]]";
     if ($this->namespace == 'Family' && !$this->isGedcom()) {
         $t = Title::newFromText($this->data[0][0]['title'], NS_FAMILY);
         $mergeCmtFamily = $this->namespace == 'Family' ? " in merge of [[{$t->getPrefixedText()}]]" : '';
     } else {
         $mergeCmtFamily = '';
     }
     // backwards, because you must merge family last, so that propagated person data in family xml is correct
     // and so that mergeCmtFamily can be cleared at the end and mergeSummary and mergeTargetTitle are correct after the for loop
     for ($m = count($this->data) - 1; $m >= 0; $m--) {
         $requestData = array();
         $contents = '';
         $talkContents = '';
         $outputRow = '';
         $mainOutput = '';
         $talkOutput = '';
         $nameCount = $eventCount = $sourceCount = $imageCount = $noteCount = $husbandCount = $wifeCount = $childrenCount = $parentFamilyCount = $spouseFamilyCount = 0;
         $primaryNameFound = $primaryImageFound = $birthFound = $christeningFound = $deathFound = $burialFound = $marriageFound = false;
         if ($this->namespace == 'Family' && $m == 0) {
             $mergeTargetNs = NS_FAMILY;
             $mergeTargetTalkNs = NS_FAMILY_TALK;
             $mergeCmtFamily = '';
         } else {
             $mergeTargetNs = NS_PERSON;
             $mergeTargetTalkNs = NS_PERSON_TALK;
         }
         $mergeTargetTitle = Title::newFromText($this->data[$m][0]['title'], $mergeTargetNs);
         if ($mergeTargetTitle->getNamespace() != $mergeTargetNs) {
             error_log("Merge glitch:{$mergeTargetNs}:{$this->data[$m][0]['title']}:{$mergeTargetTitle->getNamespace()}:");
         }
         $mergeTargetTalkTitle = Title::newFromText($this->data[$m][0]['title'], $mergeTargetTalkNs);
         $mergeSummary = '';
         $talkMergeSummary = '';
         $keepKeys = $this->generateKeepKeys($this->data[$m], $this->add[$m], $this->key[$m]);
         $notesMap = array();
         $noteAdoptions = array();
         $this->generateMapAdoptions('notes', 'N', $mergeTargetNs, $this->data[$m], $this->add[$m], $this->key[$m], $keepKeys, $notesMap, $noteAdoptions);
         $sourcesMap = array();
         $sourceAdoptions = array();
         $this->generateMapAdoptions('sources', 'S', $mergeTargetNs, $this->data[$m], $this->add[$m], $this->key[$m], $keepKeys, $sourcesMap, $sourceAdoptions);
         $imagesMap = array();
         $imageAdoptions = array();
         $this->generateMapAdoptions('images', 'I', $mergeTargetNs, $this->data[$m], $this->add[$m], $this->key[$m], $keepKeys, $imagesMap, $imageAdoptions);
         // get request data for merge target
         for ($p = 0; $p < count($this->data[$m]); $p++) {
             if ($this->isMergeable($this->data[$m][$p])) {
                 $this->addNotesToRequestData($requestData, $keepKeys[$p], $noteCount, $notesMap[$p], $this->data[$m][$p]['notes']);
                 $this->addImagesToRequestData($requestData, $keepKeys[$p], $imageCount, $imagesMap[$p], $primaryImageFound, $this->data[$m][$p]['images']);
                 $this->addSourcesToRequestData($requestData, $keepKeys[$p], $sourceCount, $sourcesMap[$p], $notesMap[$p], $imagesMap[$p], $this->data[$m][$p]['sources'], $noteAdoptions, $imageAdoptions);
                 $this->addEventsToRequestData($requestData, $keepKeys[$p], $eventCount, $mergeTargetNs == NS_PERSON ? Person::$STD_EVENT_TYPES : Family::$STD_EVENT_TYPES, $birthFound, $christeningFound, $deathFound, $burialFound, $marriageFound, $notesMap[$p], $imagesMap[$p], $sourcesMap[$p], $this->data[$m][$p]['events'], $noteAdoptions, $sourceAdoptions, $imageAdoptions);
                 if ($mergeTargetNs == NS_PERSON) {
                     $this->addNamesToRequestData($requestData, $keepKeys[$p], $nameCount, $primaryNameFound, $notesMap[$p], $sourcesMap[$p], $this->data[$m][$p]['names'], $noteAdoptions, $sourceAdoptions);
                     $this->addFamilyToRequestData($requestData, $mergingFamilies, 'child_of_family', $parentFamilyCount, $this->data[$m][$p]['child_of_families']);
                     $this->addFamilyToRequestData($requestData, $mergingFamilies, 'spouse_of_family', $spouseFamilyCount, $this->data[$m][$p]['spouse_of_families']);
                 } else {
                     $this->addFamilyMembersToRequestData($requestData, $mergingPeople, 'husband', $husbandCount, $this->data[$m][$p]['husbands']);
                     $this->addFamilyMembersToRequestData($requestData, $mergingPeople, 'wife', $wifeCount, $this->data[$m][$p]['wives']);
                     $this->addFamilyMembersToRequestData($requestData, $mergingPeople, 'child', $childrenCount, $this->data[$m][$p]['children']);
                 }
                 $pageContents = $this->mapContents($sourcesMap[$p], $imagesMap[$p], $notesMap[$p], $this->data[$m][$p]['contents']);
                 $this->addContents($contents, $keepKeys[$p], $pageContents);
                 if ($p > 0) {
                     if ($mergeSummary) {
                         $mergeSummary .= ', ';
                     }
                     if ($mainOutput) {
                         $mainOutput .= ', ';
                     }
                     if ($this->data[$m][$p]['gedcom']) {
                         $mergeSummary .= 'gedcom';
                         $mainOutput .= htmlspecialchars(($mergeTargetNs == NS_FAMILY ? 'Family:' : 'Person:') . $this->data[$m][$p]['title']);
                     } else {
                         $title = Title::newFromText($this->data[$m][$p]['title'], $mergeTargetNs);
                         $mergeSummary .= "[[" . $title->getPrefixedText() . "]]";
                         $mainOutput .= $skin->makeKnownLinkObj($title, htmlspecialchars($title->getPrefixedText()), 'redirect=no');
                     }
                 }
             }
         }
         // redirect other pages to merge target
         $redir = "#REDIRECT [[" . $mergeTargetTitle->getPrefixedText() . "]]";
         $talkRedir = "#REDIRECT [[" . $mergeTargetTalkTitle->getPrefixedText() . "]]";
         for ($p = 1; $p < count($this->data[$m]); $p++) {
             if (!$this->data[$m][$p]['gedcom']) {
                 $obj = $this->data[$m][$p]['object'];
                 $comment = $this->makeComment($this->userComment, "merge into [[" . $mergeTargetTitle->getPrefixedText() . "]]" . $mergeCmtFamily, $mergeCmtSuffix);
                 $obj->editPage($emptyRequest, $redir, $comment, $editFlags, false);
                 // redir talk page as well
                 if ($this->data[$m][$p]['talkrevid']) {
                     // if talk page exists
                     $talkTitle = Title::newFromText($this->data[$m][$p]['title'], $mergeTargetTalkNs);
                     $article = new Article($talkTitle, 0);
                     if ($article) {
                         $this->addTalkContents($talkContents, $talkTitle, $article->fetchContent());
                         if ($talkMergeSummary) {
                             $talkMergeSummary .= ', ';
                         }
                         if ($talkOutput) {
                             $talkOutput .= ', ';
                         }
                         $talkMergeSummary .= "[[" . $talkTitle->getPrefixedText() . "]]";
                         $talkOutput .= $skin->makeKnownLinkObj($talkTitle, htmlspecialchars($talkTitle->getPrefixedText()), 'redirect=no');
                         $comment = $this->makeComment($this->userComment, "merge into [[" . $mergeTargetTalkTitle->getPrefixedText() . "]]" . $mergeCmtFamily, $mergeCmtSuffix);
                         $article->doEdit($talkRedir, $comment, $editFlags);
                     }
                 }
             }
         }
         // update merge target talk
         if ($talkContents) {
             $article = new Article($mergeTargetTalkTitle, 0);
             if ($article) {
                 $mergeTargetTalkContents = $article->fetchContent();
                 if ($mergeTargetTalkContents) {
                     $mergeTargetTalkContents = rtrim($mergeTargetTalkContents) . "\n\n";
                 }
                 $comment = $this->makeComment($this->userComment, 'merged with ' . $talkMergeSummary . $mergeCmtFamily, $mergeCmtSuffix);
                 $article->doEdit($mergeTargetTalkContents . $talkContents, $comment, $editFlags);
                 if ($this->addWatches) {
                     StructuredData::addWatch($wgUser, $article, true);
                 }
             }
             $outputRow .= '<li>Merged ' . $talkOutput . ' into ' . $skin->makeKnownLinkObj($mergeTargetTalkTitle, htmlspecialchars($mergeTargetTalkTitle->getPrefixedText())) . "</li>";
         }
         $obj = $this->data[$m][0]['object'];
         if ($mergeTargetNs == NS_PERSON) {
             Person::addGenderToRequestData($requestData, $this->data[$m][0]['gender']);
         } else {
             // family
             $obj->isMerging(true);
             // to read propagated data from person pages, not from prev family revision
         }
         // update merge target
         $req = new FauxRequest($requestData, true);
         $comment = $this->makeComment($this->userComment, ($mergeSummary == 'gedcom' ? 'Add data from gedcom' : 'merged with ' . $mergeSummary) . $mergeCmtFamily, $mergeCmtSuffix);
         $obj->editPage($req, $contents, $comment, $editFlags, $this->addWatches);
         $outputRow .= '<li>Merged ' . $mainOutput . ' into ' . $skin->makeKnownLinkObj($mergeTargetTitle, htmlspecialchars($mergeTargetTitle->getPrefixedText())) . "</li>";
         $outputRows[] = $outputRow;
     }
     // add log and recent changes
     if (!$this->isGedcom()) {
         if (!$mergeSummary) {
             $mergeSummary = 'members of other families';
         }
         $mergeComment = 'Merge [[' . $mergeTargetTitle->getPrefixedText() . ']] and ' . $mergeSummary;
         $log = new LogPage('merge', false);
         $t = Title::makeTitle(NS_SPECIAL, "ReviewMerge/{$mergeLogId}");
         $log->addEntry('merge', $t, $mergeComment);
         RecentChange::notifyLog(wfTimestampNow(), $t, $wgUser, $mergeComment, '', 'merge', 'merge', $t->getPrefixedText(), $mergeComment, '', $isTrustedMerge, 0);
     }
     $nonmergedPages = $this->getNonmergedPages();
     $output .= join("\n", array_reverse($outputRows)) . '</ul>' . ($nonmergedPages ? '<p>In addition to the people listed above, the following have also been included in the target family' . ($this->isGedcom() ? '<br/>(GEDCOM people listed will be added when the GEDCOM is imported)' : '') . $nonmergedPages . "</p>\n" : '') . ($this->isGedcom() ? '' : '<p>' . $skin->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'ReviewMerge/' . $mergeLogId), htmlspecialchars("Review/undo merge")) . '<br>' . $skin->makeKnownLinkObj(Title::makeTitle(NS_SPECIAL, 'ShowDuplicates'), htmlspecialchars("Show more duplicates")) . '</p>');
     return $output;
 }
示例#3
0
 private function loadFamilyMembers()
 {
     $xml = null;
     $this->prevFamilyMembers = array();
     if ($this->isGedcomPage) {
         $dataString = GedcomUtil::getGedcomDataString();
         if ($dataString) {
             $xml = simplexml_load_string($dataString);
         }
     } else {
         $revision = StructuredData::getRevision($this->title);
         if ($revision) {
             $content =& $revision->getText();
             $xml = StructuredData::getXml('family', $content);
         }
     }
     if (isset($xml)) {
         foreach ($xml->husband as $member) {
             $title = (string) $member['title'];
             $this->prevFamilyMembers[$title] = Family::getFamilyMemberAttributes($member);
         }
         foreach ($xml->wife as $member) {
             $title = (string) $member['title'];
             $this->prevFamilyMembers[$title] = Family::getFamilyMemberAttributes($member);
         }
         foreach ($xml->child as $member) {
             $title = (string) $member['title'];
             $this->prevFamilyMembers[$title] = Family::getFamilyMemberAttributes($member);
         }
     }
 }
示例#4
0
    private function formatResults($response, $recentDocs, $selfQuery)
    {
        global $wgUser;
        $output = '';
        $start = $response['response']['start'];
        $numFound = $response['response']['numFound'];
        $end = $start + $this->rows;
        if ($end > $numFound) {
            $end = $numFound;
        }
        if ($this->target && $this->namespace != 'Image') {
            // can't currently add images from here; just select them
            $jsFunction = $this->getAddJSFunction() . '; return preventDefaultAction(event);';
            $output .= "<table><tr><td><input type=\"submit\" value=\"Add Page\" onClick=\"{$jsFunction}\"/></td>" . "<td><b> Select one of the pages below, or click <a href=\"javascript:void(0);\" onClick=\"{$jsFunction}\">Add Page</a> to create a new page</b>" . ' &nbsp; <span id="pleasewait" style="display: none"><span style="font-size: 80%; padding: 0 .2em; color: #fff; background-color: #888">Please Wait</span></span>' . ($this->target != 'AddPage' && $this->target != 'gedcom' && ($this->namespace == 'Person' || $this->namespace == 'Family') ? '<br/>' . FamilyTreeUtil::generateTreeCheckboxes($wgUser, null, true) : '') . '</td></tr></table><hr/>';
        }
        if ($numFound == 0 && count($recentDocs) == 0) {
            $output .= '<p></p><p><font size=+1>Your search did not match any documents.</font></p>';
        } else {
            // display prev..next naviagtion
            if ($start > 0) {
                $prevStart = $start - $this->rows;
                if ($prevStart < 0) {
                    $prevStart = 0;
                }
            }
            $startPlusOne = $start + 1;
            $prevNextLinks = ($start > 0 ? "<a href=\"{$selfQuery}&start={$prevStart}\">&laquo;&nbsp;Prev</a> |" : '') . " Viewing <b>{$startPlusOne}-{$end}</b> of {$numFound}" . ($end < $numFound ? " | <a href=\"{$selfQuery}&start={$end}\">Next&nbsp;&raquo;</a>" : '');
            $output .= "<div class=\"prev_next_links_top\">{$prevNextLinks}</div>\n";
            // add compare button
            if ($this->match) {
                $skin =& $wgUser->getSkin();
                $wrCompareURL = "/wiki/Special:Compare";
                $t = Title::newFromText($this->namespace . ':' . $this->pagetitle);
                $ts = '';
                if ($t) {
                    $ts = htmlspecialchars($t->getText());
                    $titleText = GedcomUtil::isGedcomTitle($this->pagetitle) ? '<b>' . htmlspecialchars($t->getPrefixedText()) . '</b>' : $skin->makeKnownLinkObj($t);
                    $compareButton = '<input type="submit" value="Compare"/> checked pages with ' . $titleText;
                }
                $output .= '<form name="compare" action="' . $wrCompareURL . '" method="post">' . $compareButton . '<input type="hidden" name="ns" value="' . $this->namespace . '"/>' . '<input type="hidden" name="compare_0" value="' . $ts . '"/>';
            }
            // generate the result list
            $docs = $response['response']['docs'];
            $highlighting = $response['highlighting'];
            $output .= '<table class="searchresulttable">';
            $pos = 0;
            foreach ($recentDocs as $doc) {
                $output .= $this->formatResult($doc, array(), -1, $this->condensedView);
            }
            foreach ($docs as $doc) {
                $pageId = $doc['PageId'];
                $hl = $highlighting[$pageId];
                $output .= $this->formatResult($doc, $hl, $pos, $this->condensedView);
                $pos++;
            }
            $output .= '</table>';
            // add compare button
            if ($this->match) {
                $output .= $compareButton . '</form>';
            }
            // display prev..next navigation
            if ($this->namespace == 'Person' || $this->namespace == 'Family') {
                $similarNamesProject = wfMsgWikiHtml('SimilarNamesProjectLink');
            } else {
                $similarNamesProject = '';
            }
            $output .= <<<END
<table style="width:99%"><tr>
<td style="width:33%">&nbsp;</td>
<td style="width:33%; text-align:center">{$prevNextLinks}</td>
<td style=" width:33%; text-align:right">{$similarNamesProject}</td>
</tr></table>
END;
        }
        return $output;
    }
示例#5
0
 public static function generateGedcomMergeLogKey($titleString)
 {
     return 'g' . GedcomUtil::getKeyFromTitle($titleString);
 }
示例#6
0
    /**
     * Return HTML for displaying search results
     * @return string HTML
     */
    public function getReviewResults()
    {
        $data = array();
        $roles = array();
        $this->getCompareData($data, $roles);
        $cols = count($data[0]);
        $tblCols = $cols + 1;
        $childNum = 0;
        $output = <<<END
<form name="unmerge" action="/wiki/Special:ReviewMerge/{$this->mergeId}" method="get">
<input type="hidden" name="action" value="unmerge"/>
<table border="0" cellspacing="0" cellpadding="4">
END;
        for ($i = 0; $i < count($data); $i++) {
            $output .= CompareForm::insertEmptyRow($tblCols);
            if ($roles[0] == 'Person') {
                $labels = self::$PERSON_COMPARE_LABELS;
            } else {
                if ($i == 0) {
                    $labels = self::$FAMILY_COMPARE_LABELS;
                } else {
                    $labels = self::$FAMILY_MEMBER_COMPARE_LABELS;
                }
            }
            foreach ($labels as $label) {
                $found = !in_array($label, self::$OPTIONAL_LABELS);
                if (!$found) {
                    for ($j = 0; $j < $cols; $j++) {
                        if (is_array(@$data[$i][$j][$label]) && count($data[$i][$j][$label]) > 0) {
                            $found = true;
                            break;
                        }
                    }
                }
                if ($found) {
                    $baseStdValues =& CompareForm::standardizeValues($label, @$data[$i][1][$label]);
                    if ($label == 'Title') {
                        $role = $roles[$i];
                        if ($role == 'child') {
                            $roleLabel = $role . $label;
                            $childNum++;
                        } else {
                            if ($role == 'Person' || $role == 'Family') {
                                $roleLabel = $label;
                            } else {
                                $roleLabel = $role . $label;
                            }
                        }
                    } else {
                        $roleLabel = $label;
                    }
                    if ($label == 'familyTitle') {
                        $revidLabel = 'Revid';
                    } else {
                        if (strpos($label, 'Title') !== false) {
                            $revidLabel = str_replace('Title', 'Revid', $label);
                        } else {
                            $revidLabel = '';
                        }
                    }
                    $labelClass = CompareForm::getLabelClass($roleLabel);
                    $output .= "<tr><td class=\"{$labelClass}\">" . CompareForm::formatLabel($roleLabel, $childNum) . "</td>";
                    for ($j = $cols - 1; $j >= 0; $j--) {
                        if ($j == 1) {
                            $stdValues = $baseStdValues;
                        } else {
                            $stdValues =& CompareForm::standardizeValues($label, @$data[$i][$j][$label]);
                        }
                        list($score, $class) = CompareForm::getCompareScoreClass($j == 0 || $j == 1, $label, $baseStdValues, $stdValues);
                        $output .= "<td class=\"{$class}\">";
                        $valueFound = false;
                        if (is_array(@$data[$i][$j][$label])) {
                            for ($v = 0; $v < count($data[$i][$j][$label]); $v++) {
                                $value = $data[$i][$j][$label][$v];
                                if (strpos($label, 'Title') !== false) {
                                    if (($label == 'familyTitle' || $label == 'Title') && @$data[$i][$j]['mergeresult']) {
                                        $formattedValue = 'Merge<br>result';
                                    } else {
                                        if (GedcomUtil::getGedcomMergeLogKey(@$data[$i][$j]['Revid'][$v])) {
                                            $formattedValue = '<b>GEDCOM page</b>';
                                        } else {
                                            $formattedValue = CompareForm::formatValue($label, $value, StructuredData::endsWith($label, 'FamilyTitle') ? '' : 'oldid=' . $data[$i][$j][$revidLabel][$v]);
                                        }
                                    }
                                } else {
                                    $formattedValue = CompareForm::formatValue($label, $value);
                                }
                                if ($v) {
                                    $output .= '<hr>';
                                }
                                $output .= $formattedValue;
                                $valueFound = true;
                            }
                        }
                        if (!$valueFound) {
                            $output .= '&nbsp;';
                        }
                        if ($class == CompareForm::$COMPARE_PAGE_CLASS) {
                            $titlesCnt = count(@$data[$i][$j][$label]);
                            if ($titlesCnt > 0) {
                                if (!$data[$i][$j]['Exists']) {
                                    // person/family not found
                                    $output .= '<br>Not found';
                                } else {
                                    if ($data[$i][$j]['Redirect']) {
                                        // person/family has been merged
                                        $output .= '<br>Already merged';
                                    } else {
                                        if ($data[$i][$j]['mergeTarget']) {
                                            $output .= '<br>' . ($data[$i][$j][$label][0] == $data[$i][$j]['mergeTarget'] ? 'Same as ' : 'Merged with ') . htmlspecialchars($data[$i][$j]['mergeTarget']);
                                        } else {
                                            if ($j == 1 && @$data[$i][0]['mergeresult']) {
                                                $output .= '<br>(merge target)';
                                            }
                                        }
                                    }
                                }
                            } else {
                                if (@$data[$i][$j]['deleted']) {
                                    $output .= 'Page has been deleted';
                                }
                            }
                        }
                        $output .= '</td>';
                    }
                    $output .= '</tr>';
                }
            }
        }
        if ($this->unmergeTimestamp) {
            $unmergeButton = 'Merge has been undone';
        } else {
            $unmergeButton = 'Unmerge reason: <input type="text" name="comment" size=36/><br><input type="submit" value="Unmerge"/>';
        }
        $output .= <<<END
<tr><td align=right colspan="{$tblCols}">{$unmergeButton}</td></tr>
</table>
</form>
END;
        return $output;
    }
示例#7
0
function fgUpdateMatches($gedcomId, &$keys, &$matches, &$merged)
{
    global $wgUser;
    $status = GE_SUCCESS;
    $dbw =& wfGetDB(DB_MASTER);
    $dbw->ignoreErrors(true);
    $dbw->begin();
    $row = $dbw->selectRow(array('familytree', 'familytree_gedcom'), array('fg_tree_id', 'ft_user'), array('fg_id' => $gedcomId, 'fg_tree_id = ft_tree_id'));
    if ($row != null) {
        $gedcomUser = User::newFromName($row->ft_user, false);
        for ($i = 0; $i < count($keys); $i++) {
            if (!GedcomUtil::updateGedcomMatch($dbw, $row->fg_tree_id, $gedcomId, $keys[$i], $matches[$i], $merged[$i] == 'true' ? 1 : -1, $gedcomUser)) {
                $status = GE_DB_ERROR;
                break;
            }
        }
    } else {
        $status = GE_INVALID_ARG;
    }
    if ($status != GE_SUCCESS) {
        $dbw->rollback();
    } else {
        $dbw->commit();
    }
    return $status;
}
示例#8
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();
    }