Пример #1
0
 public function readQueryParms($par)
 {
     global $wgRequest, $wgUser;
     $this->formAction = $wgRequest->getVal('formAction');
     $this->namespace = $wgRequest->getVal('ns');
     $this->editToken = $wgRequest->getVal('wpEditToken');
     $this->isMerging = $wgRequest->getCheck('merging');
     $this->gedcomTab = $wgRequest->getVal('gedcomtab');
     $this->gedcomKey = $wgRequest->getVal('gedcomkey');
     $this->gedcomDataString = $wgRequest->getCheck('gedcom') ? GedcomUtil::getGedcomDataString() : $wgRequest->getVal('gedcomdata');
     if ($this->gedcomDataString) {
         $this->gedcomData = GedcomUtil::getGedcomDataMap($this->gedcomDataString);
         $this->gedcomId = GedcomUtil::getGedcomId($this->gedcomDataString);
     }
     $this->isTrusted = CompareForm::isTrustedMerger($wgUser, $this->gedcomDataString);
     $this->addWatches = $wgUser->getOption('watchdefault');
     //wfDebug("merge user={$wgUser->getName()} formAction={$this->formAction} ns=$this->namespace gedcomId={$this->gedcomId} wpEditToken={$this->editToken} merging={$this->isMerging}\n");
     if (!$this->editToken) {
         // first phase
         $maxPages = $wgRequest->getVal('maxpages');
         if ($this->namespace == 'Family') {
             $maxChildren = $wgRequest->getVal('maxchildren');
             for ($i = 0; $i < $maxChildren + self::$CHILD_START_ROW; $i++) {
                 $this->data[$i] = array();
                 // create a bunch of empty rows
             }
         } else {
             $maxChildren = 0;
             $this->data[0] = array();
         }
         //wfDebug("merge phase1 maxpages=$maxPages maxchildren=$maxChildren\n");
         for ($i = 0; $i < $maxPages; $i++) {
             $pageTitle = trim($wgRequest->getVal('m_' . $i));
             //wfDebug("m_$i=$pageTitle\n");
             if ($pageTitle) {
                 $this->appendTitle(0, $pageTitle);
                 if ($this->namespace == 'Family') {
                     $pageTitle = trim($wgRequest->getVal('mh_' . $i));
                     //wfDebug("mh_$i=$pageTitle\n");
                     if ($pageTitle) {
                         $this->appendTitle(self::$HUSBAND_ROW, $pageTitle);
                     }
                     $pageTitle = trim($wgRequest->getVal('mw_' . $i));
                     //wfDebug("mw_$i=$pageTitle\n");
                     if ($pageTitle) {
                         $this->appendTitle(self::$WIFE_ROW, $pageTitle);
                     }
                 }
             }
         }
         if ($this->namespace == 'Family') {
             for ($c = 0; $c < $maxChildren; $c++) {
                 for ($i = 0; $i < $maxPages; $i++) {
                     if ($wgRequest->getVal('m_' . $i)) {
                         $mergeRow = $wgRequest->getVal("mcr_{$i}_{$c}");
                         //wfDebug("mcr_{$i}_$c=$mergeRow\n");
                         if ($mergeRow) {
                             $childTitle = trim($wgRequest->getVal("mc_{$i}_{$c}"));
                             //wfDebug("mc_{$i}_$c=$childTitle\n");
                             $this->appendTitle($mergeRow - 1 + self::$CHILD_START_ROW, $childTitle);
                         }
                     }
                 }
             }
             $this->removeSingletonFamilyMemberRows();
         }
     } else {
         // second phase: merges = #merges; merges_m = #pages in merge m; merges_m_p = page title; rows_m = #rows in merge m;
         // add_m_p_r = 1 if checked; key_m_p_r = key of row r
         $mergesCount = $wgRequest->getVal('merges');
         //wfDebug("merge phase2 merges=$mergesCount\n");
         for ($m = 0; $m < $mergesCount; $m++) {
             $pagesCount = $wgRequest->getVal("merges_{$m}");
             $rowsCount = $wgRequest->getVal("rows_{$m}");
             $this->target[$m] = $wgRequest->getVal("target_{$m}");
             //wfDebug("merges_$m=$pagesCount rows_$m=$rowsCount target_$m={$this->target[$m]}\n");
             $this->data[$m] = array();
             $this->add[$m] = array();
             $this->key[$m] = array();
             $pos = 0;
             $namespace = $this->namespace == 'Family' && $m == 0 ? 'Family' : 'Person';
             for ($p = 0; $p < $pagesCount; $p++) {
                 $pageTitle = trim($wgRequest->getVal("merges_{$m}_{$p}"));
                 //wfDebug("merges_{$m}_{$p}=$pageTitle\n");
                 if ($pageTitle) {
                     $this->data[$m][$pos] = array();
                     $this->add[$m][$pos] = array();
                     $this->key[$m][$pos] = array();
                     $this->data[$m][$pos]['title'] = $pageTitle;
                     //						$this->data[$m][$pos]['missingdata'] = false;
                     for ($r = 0; $r < $rowsCount; $r++) {
                         $this->add[$m][$pos][$r] = $wgRequest->getVal("add_{$m}_{$p}_{$r}");
                         $this->key[$m][$pos][$r] = $wgRequest->getVal("key_{$m}_{$p}_{$r}");
                         //wfDebug("add_{$m}_{$p}_{$r}={$this->add[$m][$pos][$r]} key_{$m}_{$p}_{$r}={$this->key[$m][$pos][$r]}\n");
                         //							if ($this->key[$m][$pos][$r] && !$this->add[$m][$pos][$r]) {
                         //								$this->data[$m][$pos]['missingdata'] = true;
                         //							}
                     }
                     $pos++;
                 } else {
                     error_log("merge readQueryParms page title missing user={$wgUser->getName()}");
                 }
             }
         }
         $this->userComment = $wgRequest->getVal("userComment");
     }
 }
Пример #2
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);
 }
Пример #3
0
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>";
}