コード例 #1
0
/**
 * Remove family tree page
 *
 * @param unknown_type $args user, name, ns, title
 * @return FTE_SUCCESS, FTE_INVALID_ARG, FTE_NOT_LOGGED_IN, FTE_NOT_AUTHORIZED, FTE_NOT_FOUND, FTE_DUP_KEY, FTE_DB_ERROR
 */
function wfRemoveFamilyTreePage($args)
{
    global $wgAjaxCachePolicy;
    // set cache policy
    $wgAjaxCachePolicy->setPolicy(0);
    $ns = '';
    $titleString = '';
    $delete = false;
    $deleteStatus = '';
    // validate args
    $args = AjaxUtil::getArgs($args);
    $status = ftValidateUpdateFamilyTreePageArgs($args);
    if ($status == FTE_SUCCESS) {
        // get tree id
        $treeId = 0;
        $status = ftGetTreeId($args['user'], $args['name'], $treeId);
        $delete = @$args['delete_page'] == 1;
    }
    if ($status == FTE_SUCCESS) {
        // get page
        $ns = $args['ns'];
        $titleString = $args['title'];
        $title = Title::newFromText($titleString, $ns);
        if (!$title || $title->isTalkPage()) {
            $status = FTE_INVALID_ARG;
        }
    }
    if ($status == FTE_SUCCESS) {
        $dbw =& wfGetDB(DB_MASTER);
        $dbw->ignoreErrors(true);
        $dbw->begin();
        if (!FamilyTreeUtil::removePage($dbw, $treeId, $title)) {
            $status = FTE_DB_ERROR;
        }
        if ($delete && $status == FTE_SUCCESS) {
            $status = ftDelPage($title);
            if ($status == FTE_NOT_AUTHORIZED) {
                $deleteStatus = FTE_NOT_AUTHORIZED;
                $status = FTE_SUCCESS;
            } else {
                if ($status == FTE_SUCCESS) {
                    $deleteStatus = FTE_SUCCESS;
                }
            }
            $deleteStatus = " delete_status=\"{$deleteStatus}\"";
        }
        if ($status == FTE_SUCCESS) {
            $dbw->commit();
        } else {
            $dbw->rollback();
        }
    }
    // return status
    $titleString = StructuredData::escapeXml($titleString);
    return "<remove status=\"{$status}\" ns=\"{$ns}\" title=\"{$titleString}\"{$deleteStatus}></remove>";
}
コード例 #2
0
ファイル: GedcomUtil.php プロジェクト: k-hasan-19/wiki
 public static function updateGedcomMatch($dbw, $treeId, $gedcomId, $key, $matchTitle, $merged, $gedcomUser)
 {
     $newTitle = $matchTitle == '#nomatch#' ? null : Title::newFromText($matchTitle);
     $oldTitle = null;
     // read old match_namespace and title
     $row = $dbw->selectRow('familytree_gedcom_data', array('fgd_match_namespace', 'fgd_match_title'), array('fgd_gedcom_id' => $gedcomId, 'fgd_gedcom_key' => $key));
     if ($row && $row->fgd_match_namespace > 0) {
         $oldTitle = Title::makeTitle($row->fgd_match_namespace, $row->fgd_match_title);
         if ($oldTitle && ($oldTitle->getNamespace() == NS_PERSON || $oldTitle->getNamespace() == NS_FAMILY || $oldTitle->getNamespace() == NS_MYSOURCE) && (!$newTitle || $oldTitle->getPrefixedText() != $newTitle->getPrefixedText())) {
             // remove match title from tree
             if (!FamilyTreeUtil::removePage($dbw, $treeId, $oldTitle)) {
                 return false;
             }
             // unwatch match title if no other trees contain it
             if (!$dbw->selectField('familytree_page', 'fp_tree_id', array('fp_namespace' => $row->fgd_match_namespace, 'fp_title' => $row->fgd_match_title, 'fp_user_id' => $gedcomUser->getID()))) {
                 $article = new Article($oldTitle, 0);
                 StructuredData::removeWatch($gedcomUser, $article);
             }
         }
     }
     if ($newTitle) {
         $matchTitle = $newTitle->getDBkey();
         $matchNamespace = $newTitle->getNamespace();
         $potentialMatchesAttr = '';
         $potentialMatchesValue = '';
         $potentialMatchesUpdate = '';
         if (($newTitle->getNamespace() == NS_PERSON || $newTitle->getNamespace() == NS_FAMILY || $newTitle->getNamespace() == NS_MYSOURCE) && (!$oldTitle || $oldTitle->getPrefixedText() != $newTitle->getPrefixedText())) {
             // add match title to tree
             if (!FamilyTreeUtil::addPage($dbw, $gedcomUser, $treeId, $newTitle, 0, 0)) {
                 return false;
             }
             // watch match title
             $article = new Article($newTitle, 0);
             StructuredData::addWatch($gedcomUser, $article);
         }
     } else {
         $matchTitle = '';
         $matchNamespace = -1;
         $merged = 0;
         $potentialMatchesAttr = ', fgd_potential_matches';
         // reset potential matches to what's in the gedcom
         $potentialMatchesValue = ", ''";
         $potentialMatchesUpdate = ", fgd_potential_matches=''";
     }
     $matchTitle = $dbw->addQuotes($matchTitle);
     $sql = "INSERT INTO familytree_gedcom_data (fgd_gedcom_id, fgd_gedcom_key, fgd_match_namespace, fgd_match_title, fgd_merged{$potentialMatchesAttr})" . " VALUES({$gedcomId}," . $dbw->addQuotes($key) . ",{$matchNamespace},{$matchTitle},{$merged}{$potentialMatchesValue})" . " ON DUPLICATE KEY UPDATE fgd_match_namespace={$matchNamespace}, fgd_match_title={$matchTitle}, fgd_merged={$merged}{$potentialMatchesUpdate}";
     $dbw->query($sql);
     return $dbw->lastErrno() == 0;
 }
コード例 #3
0
ファイル: FamilyTreeUtil.php プロジェクト: k-hasan-19/wiki
 public static function updateTrees($dbw, $title, $revId, $allTrees, $treeOwnerIds, $checkedTreeIds, $updateChecked = true, $addWatch = true)
 {
     global $wgUser;
     $talkRevid = -1;
     $result = true;
     $added = false;
     $removed = false;
     foreach ($allTrees as $tree) {
         $treeId = $tree['id'];
         if (in_array($treeId, $checkedTreeIds) && !in_array($treeId, $treeOwnerIds)) {
             // add the page to the tree
             //wfDebug("updateTrees add " . $tree['name'] . "\n");
             if ($talkRevid == -1) {
                 $talkRevision = Revision::newFromTitle($title->getTalkPage());
                 if ($talkRevision) {
                     $talkRevid = $talkRevision->getId();
                 } else {
                     $talkRevid = 0;
                 }
             }
             $result = $result && FamilyTreeUtil::addPage($dbw, $wgUser, $treeId, $title, $revId, $talkRevid);
             $added = true;
         } else {
             if (!in_array($treeId, $checkedTreeIds) && in_array($treeId, $treeOwnerIds)) {
                 // remove the page from the tree
                 //wfDebug("updateTrees remove\n");
                 $result = $result && FamilyTreeUtil::removePage($dbw, $treeId, $title);
                 $removed = true;
             }
         }
         if ($updateChecked) {
             $checked = !$tree['checked'] && in_array($treeId, $checkedTreeIds);
             $unchecked = $tree['checked'] && !in_array($treeId, $checkedTreeIds);
             if ($checked || $unchecked) {
                 $dbw->update('familytree', array('ft_checked' => $checked ? 1 : 0), array('ft_tree_id' => $treeId));
                 FamilyTreeUtil::deleteFamilyTreesCache($wgUser->getName());
             }
         }
     }
     if ($added && !$wgUser->isWatched($title)) {
         //wfDebug("updateTrees - addWatch: ".$title->getPrefixedText()."\n");
         if ($addWatch) {
             StructuredData::addWatch($wgUser, new Article($title, 0));
         }
     } else {
         if ($added || $removed) {
             // purge the article and re-index it
             StructuredData::purgeTitle($title);
             StructuredData::requestIndex($title);
         }
     }
     return $result;
 }