Пример #1
0
 /**
  * Return HTML for displaying search results
  * @return string HTML
  */
 public function getCompareResults()
 {
     global $wgUser;
     $this->setMergeTargets();
     list($compareData, $compareChildren, $maxChildren) = $this->readCompareData();
     $dataLabels = $this->getDataLabels();
     list($compareClass, $husbandScores, $wifeScores, $totalScores) = $this->scoreCompareData($dataLabels, $compareData);
     $output = '';
     $semiProtected = false;
     $isLoggedIn = $wgUser->isLoggedIn();
     if (!$isLoggedIn) {
         $output .= '<p><font color=red>You need to sign in to match and merge pages</font></p>';
     }
     $gedcomExtra = $this->gedcomDataString ? '?gedcomtab=' . htmlspecialchars($this->gedcomTab) . '&gedcomkey=' . htmlspecialchars($this->gedcomKey) : '';
     $output .= "<form id=\"compare\" name=\"compare\" action=\"/wiki/Special:Merge{$gedcomExtra}\" method=\"post\">" . "<input type=\"hidden\" id=\"ns\" name=\"ns\" value=\"{$this->namespace}\">" . "<input type=\"hidden\" id=\"maxpages\" name=\"maxpages\" value=\"" . count($this->compareTitles) . "\">" . ($this->namespace == 'Family' ? "<input id=\"maxchildren\" type=\"hidden\" name=\"maxchildren\" value=\"{$maxChildren}\">" : '') . '<table border="0" cellspacing="0" cellpadding="4">';
     foreach ($dataLabels as $label) {
         $labelClass = CompareForm::getLabelClass($label);
         if ($labelClass == self::$COMPARE_ULC_CLASS) {
             $output .= CompareForm::insertEmptyRow(count($this->compareTitles) + 1);
         }
         $found = !in_array($label, self::$OPTIONAL_LABELS);
         if (!$found) {
             foreach ($this->compareTitles as $t) {
                 if (is_array(@$compareData[$t][$label]) && count($compareData[$t][$label]) > 0) {
                     $found = true;
                     break;
                 }
             }
         }
         if ($found) {
             $output .= "<tr><td class=\"{$labelClass}\">" . CompareForm::formatLabel($label) . "</td>";
             // show target left if gedcom; right otherwise
             $i = $this->gedcomDataString ? 0 : count($this->compareTitles) - 1;
             while ($this->gedcomDataString && $i < count($this->compareTitles) || !$this->gedcomDataString && $i >= 0) {
                 $t = $this->compareTitles[$i];
                 $class = $compareClass[$label][$i];
                 $output .= "<td class=\"{$class}\">";
                 $first = true;
                 if (is_array(@$compareData[$t][$label])) {
                     foreach ($compareData[$t][$label] as $value) {
                         if (!$first) {
                             $output .= '<br>';
                         }
                         $output .= CompareForm::formatValue($label, $value);
                         $first = false;
                     }
                 }
                 if ($first) {
                     $output .= '&nbsp;';
                 }
                 if ($class == self::$COMPARE_PAGE_CLASS) {
                     $titlesCnt = count(@$compareData[$t][$label]);
                     $baseTitlesCnt = count(@$compareData[$this->compareTitles[0]][$label]);
                     if ($titlesCnt > 0) {
                         $value = htmlspecialchars($compareData[$t][$label][0]);
                         if ($label == 'husbandTitle') {
                             $relative = 'husband';
                             $relativeAbbrev = 'h';
                             $score = $husbandScores[$i];
                         } else {
                             if ($label == 'wifeTitle') {
                                 $relative = 'wife';
                                 $relativeAbbrev = 'w';
                                 $score = $wifeScores[$i];
                             } else {
                                 $relative = '';
                                 $relativeAbbrev = '';
                                 $score = 0;
                             }
                         }
                         if (!$compareData[$t]['Exists']) {
                             // base person/family not found
                             if (!$relative) {
                                 $output .= '<br>Not found';
                             }
                         } else {
                             if ($compareData[$t]['Redirect']) {
                                 // base person/family has been merged
                                 if (!$relative) {
                                     $output .= '<br>Already merged';
                                 }
                             } else {
                                 if ($compareData[$t][$relative . 'Redirect']) {
                                     // husband/wife has been merged
                                     $output .= '<br>Already merged';
                                 } else {
                                     if ($i == 0 && $this->gedcomDataString) {
                                         if (@$compareData[$t][$relative . 'GedcomMatchTitle']) {
                                             $skin =& $wgUser->getSkin();
                                             $gedcomMatchTitle = $compareData[$t][$relative . 'GedcomMatchTitle'];
                                             $temp = Title::newFromText($gedcomMatchTitle, StructuredData::endsWith($label, 'familyTitle', true) ? NS_FAMILY : NS_PERSON);
                                             $title = $skin->makeLinkObj($temp, htmlspecialchars($gedcomMatchTitle));
                                             $output .= "<br>Matched with {$title}";
                                         }
                                         $output .= "<input type=\"hidden\" id=\"m{$relativeAbbrev}_{$i}\" name=\"m{$relativeAbbrev}_{$i}\" value=\"{$value}\">";
                                     } else {
                                         if ($titlesCnt == 1 && $baseTitlesCnt <= 1) {
                                             //								if ($i == 0 || $baseTitlesCnt == 0 || $compareData[$this->compareTitles[0]][$label][0] != $compareData[$t][$label][0]) { // don't allow merge if same title
                                             if ($i == 0) {
                                                 $extra = " checked";
                                             } else {
                                                 if ($relative) {
                                                     // always check spouses
                                                     $extra = 'disabled checked';
                                                     //if ($score > self::$SPOUSE_MATCH_THRESHOLD) $extra .= ' checked';
                                                 } else {
                                                     $extra = '';
                                                 }
                                             }
                                             if ($this->namespace == 'Family' && !$relative) {
                                                 $extra .= " onClick=\"compareClick({$i})\"";
                                             }
                                             $output .= "<br><input id=\"m{$relativeAbbrev}_{$i}\" type=\"checkbox\" name=\"m{$relativeAbbrev}_{$i}\" value=\"{$value}\" {$extra}>&nbsp;Match";
                                             //								}
                                         } else {
                                             $output .= "<br>Multiple spouses - merge after merging family";
                                         }
                                     }
                                 }
                             }
                         }
                         $nomergeTitles = $this->getNomergeTitleMatches($compareData, $t, -1, $relative, '<br>');
                         if ($nomergeTitles) {
                             $output .= '<br><b>Do not merge with</b><br>' . $nomergeTitles;
                         }
                         if ((!$this->gedcomDataString || $i > 0) && !$compareData[$t][$relative . 'Updatable']) {
                             $output .= "<br><font color=\"red\">Semi-protected</font> (see below)";
                             $semiProtected = true;
                         }
                     }
                 }
                 $output .= '</td>';
                 $i += $this->gedcomDataString ? 1 : -1;
             }
             $output .= '</tr>';
         }
     }
     if ($this->namespace == 'Family') {
         for ($c = 0; $c < $maxChildren; $c++) {
             foreach (CompareForm::$CHILD_COMPARE_LABELS as $label) {
                 $labelClass = CompareForm::getLabelClass($label);
                 if ($labelClass == self::$COMPARE_ULC_CLASS) {
                     $output .= CompareForm::insertEmptyRow(count($this->compareTitles) + 1);
                 }
                 $found = !in_array($label, self::$OPTIONAL_LABELS);
                 if (!$found) {
                     foreach ($this->compareTitles as $t) {
                         if (is_array(@$compareChildren[$t][$c][$label]) && count($compareChildren[$t][$c][$label]) > 0) {
                             $found = true;
                             break;
                         }
                     }
                 }
                 if ($found) {
                     $output .= "<tr><td class=\"{$labelClass}\">" . CompareForm::formatLabel($label, $c + 1) . "</td>";
                     $baseStdValues =& CompareForm::standardizeValues($label, @$compareChildren[$this->compareTitles[0]][$c][$label]);
                     $i = $this->gedcomDataString ? 0 : count($this->compareTitles) - 1;
                     while ($this->gedcomDataString && $i < count($this->compareTitles) || !$this->gedcomDataString && $i >= 0) {
                         $t = $this->compareTitles[$i];
                         if ($i == 0) {
                             $stdValues = $baseStdValues;
                         } else {
                             $stdValues =& CompareForm::standardizeValues($label, @$compareChildren[$t][$c][$label]);
                         }
                         list($score, $class) = CompareForm::getCompareScoreClass($i == 0, $label, $baseStdValues, $stdValues);
                         $output .= "<td class=\"{$class}\">";
                         $children =& $compareChildren[$t];
                         $first = true;
                         if (count($children) > $c) {
                             if (is_array(@$children[$c][$label])) {
                                 foreach ($children[$c][$label] as $value) {
                                     if (!$first) {
                                         $output .= '<br>';
                                     }
                                     $output .= CompareForm::formatValue($label, $value);
                                     $first = false;
                                 }
                             }
                         }
                         if ($first) {
                             $output .= '&nbsp;';
                         }
                         if ($class == self::$COMPARE_PAGE_CLASS) {
                             if (count(@$compareChildren[$t][$c][$label]) == 1) {
                                 $value = htmlspecialchars($compareChildren[$t][$c][$label][0]);
                                 $output .= "<input type=\"hidden\" id=\"mc_{$i}_{$c}\" name=\"mc_{$i}_{$c}\" value=\"{$value}\">";
                                 if ($compareData[$t]['Redirect']) {
                                     // family has already been merged
                                 } else {
                                     if ($compareChildren[$t][$c]['childRedirect']) {
                                         // child has already been merged
                                         $output .= '<br>Already merged';
                                     } else {
                                         if ($i == 0 && $this->gedcomDataString) {
                                             if (@$compareChildren[$t][$c]['childGedcomMatchTitle']) {
                                                 $skin =& $wgUser->getSkin();
                                                 $gedcomMatchTitle = $compareChildren[$t][$c]['childGedcomMatchTitle'];
                                                 $temp = Title::newFromText($gedcomMatchTitle, StructuredData::endsWith($label, 'familyTitle', true) ? NS_FAMILY : NS_PERSON);
                                                 $title = $skin->makeLinkObj($temp, htmlspecialchars($gedcomMatchTitle));
                                                 $output .= "<br>Matched with {$title}";
                                             }
                                             $c1 = $c + 1;
                                             $output .= "<input type=\"hidden\" id=\"mcr_0_{$c}\" name=\"mcr_0_{$c}\" value=\"{$c1}\">";
                                         } else {
                                             //									else if (@$compareChildren[$this->compareTitles[0]][$c][$label][0] != $compareChildren[$t][$c][$label][0]) { // don't allow merge if same title
                                             //										$mergeChild = (count(@$compareChildren[$this->compareTitles[0]][$c][$label]) == 1 ? $c+1 : 0);
                                             $mergeChild = $c + 1;
                                             $extra = $i == 0 ? '' : 'disabled';
                                             $mergeChildSelectOptions = $this->getMergeChildSelectOptions($c, $maxChildren);
                                             $output .= '<br>' . StructuredData::addSelectToHtml(0, "mcr_{$i}_{$c}", $mergeChildSelectOptions, $mergeChild, $extra, false);
                                         }
                                     }
                                 }
                                 $nomergeTitles = $this->getNomergeTitleMatches($compareChildren, $t, $c, 'child', '<br>');
                                 if ($nomergeTitles) {
                                     $output .= '<br><b>Do not merge with</b><br>' . $nomergeTitles;
                                 }
                                 if ((!$this->gedcomDataString || $i > 0) && !$compareChildren[$t][$c]['childUpdatable']) {
                                     $output .= "<br><font color=\"red\">Semi-protected</font> (see below)";
                                     $semiProtected = true;
                                 }
                             }
                         }
                         $output .= '</td>';
                         $i += $this->gedcomDataString ? 1 : -1;
                     }
                     $output .= '</tr>';
                 }
             }
         }
     }
     if ($this->gedcomDataString) {
         $mergeLabel = 'Prepare to update';
         $mergeFunction = 'doGedcomPrepareToMerge()';
         $notMatchFunction = 'doGedcomNotMatch()';
         $notMatchTitle = 'GEDCOM family does not match any of the families shown';
     } else {
         $mergeLabel = 'Prepare to merge';
         $mergeFunction = 'doPrepareToMerge()';
         $notMatchFunction = 'doNotMatch()';
         $notMatchTitle = 'Notify others not to merge the selected ' . ($this->namespace == 'Family' ? 'families' : 'people');
     }
     $mergeTitle = 'Prepare to combine the selected ' . ($this->namespace == 'Family' ? 'families' : 'people');
     $output .= '<tr><td align=right colspan="' . (count($this->compareTitles) + 1) . '"><input type="hidden" name="formAction">' . ($this->gedcomDataString ? '<input type="button" title="Match people in your GEDCOM to people in the selected family" value="Match" onClick="doGedcomMatch()"/> &nbsp; ' : '') . ($this->gedcomDataString ? '' : "<input type=\"button\" title=\"{$mergeTitle}\" value=\"{$mergeLabel}\" onClick=\"{$mergeFunction}\"/> &nbsp; ") . "<input type=\"button\" title=\"{$notMatchTitle}\" value=\"Not a match\" onClick=\"{$notMatchFunction}\"/>";
     '</td></tr></table></form>';
     if ($semiProtected) {
         $output .= CompareForm::getSemiprotectedMessage(CompareForm::isTrustedMerger($wgUser, $this->gedcomDataString));
     }
     return $output;
 }
Пример #2
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;
    }