コード例 #1
0
ファイル: StructuredData.php プロジェクト: k-hasan-19/wiki
 public static function json_encode($value)
 {
     $result = '';
     if (is_array($value)) {
         if (0 !== count(array_diff_key($value, array_keys(array_keys($value))))) {
             $result = "{\n";
             $first = true;
             foreach ($value as $key => $val) {
                 if (!$first) {
                     $result .= ",\n";
                 }
                 $result .= '"' . $key . '":' . StructuredData::json_encode($val);
                 $first = false;
             }
             $result .= "\n}";
         } else {
             $result = '[';
             for ($i = 0; $i < count($value); $i++) {
                 if ($i > 0) {
                     $result .= ",\n";
                 }
                 $result .= StructuredData::json_encode($value[$i]);
             }
             $result .= ']';
         }
     } else {
         $result = '"' . str_replace('"', "\\\"", trim($value)) . '"';
     }
     return $result;
 }
コード例 #2
0
ファイル: GetTreeData.php プロジェクト: k-hasan-19/wiki
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;
}
コード例 #3
0
ファイル: ListAjaxFunctions.php プロジェクト: k-hasan-19/wiki
function wfGetWatchlist()
{
    list($user, $ns, $callback) = readListParams();
    $result = array();
    $error = null;
    if ($user->getID()) {
        $dbr =& wfGetDB(DB_SLAVE);
        // map titles to trees
        $trees = array();
        $rows = $dbr->select(array('familytree', 'familytree_page'), array('ft_name', 'fp_title'), array('ft_user' => $user->getName(), 'fp_namespace' => $ns, 'ft_tree_id = fp_tree_id'), 'wfGetTree');
        $errno = $dbr->lastErrno();
        if ($errno == 0) {
            while ($row = $dbr->fetchObject($rows)) {
                $tree = @$trees[$row->fp_title];
                if ($tree) {
                    $tree .= ', ' . $row->ft_name;
                } else {
                    $tree = $row->ft_name;
                }
                $trees[$row->fp_title] = $tree;
            }
            $dbr->freeResult($rows);
            // read watchlist
            $rows = $dbr->select('watchlist', array('wl_title', 'wr_flags', 'wr_summary'), array('wl_user' => $user->getID(), 'wl_namespace' => $ns), 'wfGetWatchlist');
            $errno = $dbr->lastErrno();
            if ($errno == 0) {
                while ($row = $dbr->fetchObject($rows)) {
                    $o = array('title' => $row->wl_title, 'flags' => $row->wr_flags, 'trees' => @$trees[$row->wl_title]);
                    $fields = explode('|', $row->wr_summary);
                    if ($ns == NS_PERSON) {
                        if ($fields[0]) {
                            $o['surname'] = $fields[0];
                        }
                        if ($fields[1]) {
                            $o['given'] = $fields[1];
                        }
                        if ($fields[2]) {
                            $o['gender'] = $fields[2];
                        }
                        if ($fields[3]) {
                            $o['birthDate'] = $fields[3];
                        }
                        if ($fields[4]) {
                            $o['birthPlace'] = $fields[4];
                        }
                        if ($fields[5]) {
                            $o['deathDate'] = $fields[5];
                        }
                        if ($fields[6]) {
                            $o['deathPlace'] = $fields[6];
                        }
                    } else {
                        if ($ns == NS_FAMILY) {
                            if ($fields[0]) {
                                $o['husbandSurname'] = $fields[0];
                            }
                            if ($fields[1]) {
                                $o['husbandGiven'] = $fields[1];
                            }
                            if ($fields[2]) {
                                $o['wifeSurname'] = $fields[2];
                            }
                            if ($fields[3]) {
                                $o['wifeGiven'] = $fields[3];
                            }
                            if ($fields[4]) {
                                $o['marriageDate'] = $fields[4];
                            }
                            if ($fields[5]) {
                                $o['marriagePlace'] = $fields[5];
                            }
                        }
                    }
                    $result[] = $o;
                }
                $dbr->freeResult($rows);
            } else {
                $error = 'Can\'t read the database';
            }
        } else {
            $error = 'Can\'t read the database';
        }
    } else {
        $error = 'Unknown user';
    }
    if ($error) {
        $result = array('error' => $error);
    }
    $json = StructuredData::json_encode($result);
    if ($callback) {
        $json = $callback . '(' . $json . ');';
    }
    return $json;
}