Esempio n. 1
0
function wfGetTreeData($rsargs = null)
{
    global $wgAjaxCachePolicy, $wgRequest;
    $callback = $wgRequest->getVal('callback');
    $orn = $wgRequest->getVal('orn');
    $titleText = $wgRequest->getVal('id');
    $setRoot = $wgRequest->getBool('setRoot');
    $numDescLevels = $wgRequest->getVal('descLevels');
    if ($numDescLevels > 10) {
        $numDescLevels = 10;
    }
    $numAncLevels = $wgRequest->getVal('ancLevels');
    if ($numAncLevels > 20) {
        $numAncLevels = 20;
    }
    // set cache policy
    $wgAjaxCachePolicy->setPolicy(0);
    // set content type
    $wgAjaxCachePolicy->setContentType($callback ? 'application/javascript' : 'application/json');
    $data = null;
    $treeData = new TreeData();
    if ($titleText) {
        $title = Title::newFromText($titleText);
        if ($title) {
            if ($setRoot) {
                // we can get a person initially and when someone sets a new root
                if ($orn == 'left') {
                    $numDescLevels = 0;
                    if (!$numAncLevels) {
                        $numAncLevels = $title->getNamespace() == NS_PERSON ? 7 : 6;
                    }
                } else {
                    if (!$numDescLevels) {
                        $numDescLevels = $title->getNamespace() == NS_PERSON ? 1 : 2;
                    }
                    $numAncLevels = 0;
                }
            } else {
                if ($orn == 'left') {
                    $numDescLevels = 0;
                    if (!$numAncLevels) {
                        $numAncLevels = 2;
                    }
                } else {
                    if ($orn == 'right') {
                        if (!$numDescLevels) {
                            $numDescLevels = 2;
                        }
                        $numAncLevels = 0;
                    } else {
                        // make sure we have the final redirect
                        $title = StructuredData::getRedirectToTitle($title);
                        $orn = 'center';
                        if ($title->getNamespace() == NS_PERSON) {
                            if (!$numDescLevels) {
                                $numDescLevels = 1;
                            }
                            if (!$numAncLevels) {
                                $numAncLevels = 7;
                            }
                        } else {
                            if (!$numDescLevels) {
                                $numDescLevels = 2;
                            }
                            if (!$numAncLevels) {
                                $numAncLevels = 6;
                            }
                        }
                    }
                }
            }
            if ($title->getNamespace() == NS_PERSON) {
                $data = $treeData->getPersonData($title->getText(), $orn, $numDescLevels, $numAncLevels);
            } else {
                if ($title->getNamespace() == NS_FAMILY) {
                    $data = $treeData->getFamilyData($title->getText(), $orn, $numDescLevels, $numAncLevels);
                }
            }
        }
    }
    if (!$data) {
        $data = array('error' => 'invalid title');
    }
    $json = StructuredData::json_encode($data);
    if ($callback) {
        $json = $callback . '(' . $json . ');';
    }
    return $json;
}