Chris Pollett > Students > Kamboj

    Print View

    [Bio]

    [Blog]

    [CS297 Proposal]

    [CS297 Del #01 (study of wiki systems) - PDF]

    [CS297 Del #02 (adding multiple users)]

    [CS297 Del #03 (fetch links)]

    [CS297 Del #04 (what links here)]

    [CS297 Report - PDF]

    [CS298 Proposal]

    [CS298 Del #01 (getting relationship types)]

    [CS298 Del #02 (displaying to and from links)]

    [CS298 Del #03 (advanced search)]

    [CS298 Report - PDF]

    [CS298 Presentation - PDF]

























CS 298 Deliverable 01

Adding a feature "What Relates Here" to Yioop

Description

The links between different wiki pages are already saved in the database in CS297 Del 04. To delve further into how these pages link to each other, i.e., information about their relationship types, "What Relates To" feature is implemented. It works in conjunction with the wiki parser to extract the relationship type by creating a link extractor regular expression which takes into consideration the relationship type. For example, if page A is related to page B with a link that is displayed as Page B Link, and a relationship Parent, then MediaWiki of document A would have [[Parent|PageB|Page B Link]]. The fetched values, i.e., relationship type and the linked page are then stored in the database facilitating the search feature based on relationship type.

Steps to be followed

Step 01

The first step is to obtain the page id of the current page.

Step 02

Get a list of relationship types with which it is connected by joining the GROUP_PAGE_LIST table with PAGE_RELATIONSHIP table.

Deliverables

Mantis Bug ID:0000182

src/controllers/components/SocialComponent.php

src/library/WikiParser.php

src/locale/en_US/configure.ini

src/models/GroupModel.php

src/views/WikiView.php

src/views/elements/WikiElement.php

Code Snippet

Code added to the controller:
case 'relationships':
                    $data["MODE"] = "relationships";
                    $data["PAGE_NAME"] = "related";
                    if (empty($page_id)) {
                        continue;
                    }
                    $page_info = $group_model->getPageInfoByPageId(
                        $page_id);
                    if (!isset($page_name)) {
                        $page_name = empty($page_info['PAGE_NAME'])
                            ? "links" : $page_info['PAGE_NAME'];
                    }
                    $limit = isset($limit) ? $limit : 0;
                    $num = (isset($_SESSION["MAX_PAGES_TO_SHOW"])) ?
                        $_SESSION["MAX_PAGES_TO_SHOW"] :
                        C\DEFAULT_ADMIN_PAGING_NUM;
                    $data["PAGE_ID"] = $page_id;
                    $data["PAGE_NAME"] = $page_name;
                    $data["DISCUSS_THREAD"] = empty($page_info["DISCUSS_THREAD"]
                        ) ? -1 : $page_info['DISCUSS_THREAD'];
                    $data["GROUP_ID"]=$page_info["GROUP_ID"];
                    $data["LIMIT"] = $limit;
                    $data["RESULTS_PER_PAGE"] = $num;
                    list($data["TOTAL_ROWS"], $data["RELATIONSHIPS"]) =
                        $group_model->getRelationshipsToFromPage($page_id, $limit,
                        $num);
                    break;

Regex for finding relationships which link wiki pages:

['/\[\[([^\[\]]+?)\|([^\[\]]+?)\|([^\[\]]+?)\]\]/s', "$1:$3\t"]

Functions to interact with database and get required values:

public function getRelationshipID($relationship_type)
    {
        $db = $this->db;
        $sql = "SELECT ID AS RELATIONSHIP_ID FROM PAGE_RELATIONSHIP WHERE NAME=? "
            . $db->limitOffset(1);
        $result = $db->execute($sql, [$relationship_type]);
        if (!$result) {
            return false;
        }
        $row = $db->fetchArray($result);
        return $row['RELATIONSHIP_ID'];
    }
public function getRelationshipsToFromPage($page_id, $limit, $num)
    {
        $total = $this->PageHasRelationships($page_id);
        $db = $this->db;
        $i = 0;
        $relationships = [];
        $sql = "SELECT DISTINCT R.NAME AS RELATIONSHIP_TYPE
            FROM PAGE_RELATIONSHIP R, GROUP_PAGE_LINK G
            where (G.FROM_ID = ? OR G.TO_ID = ?) AND
            (R.ID = G.LINK_TYPE_ID)".$db->limitOffset($limit, $num);
        $result = $db->execute($sql, [$page_id, $page_id]);
        if ($result) {
            while ($relationships[$i] = $db->fetchArray($result)) {
                $i++;
            }
            unset($relationships[$i]);
            $i--;
        }
        return [$total,$relationships];
    }
    public function pageHasRelationships($page_id){
        if($page_id == NULL){
            return -1;
        }
        $db = $this->db;
        $sql = "SELECT COUNT(DISTINCT LINK_TYPE_ID) AS NUM FROM GROUP_PAGE_LINK
            WHERE TO_ID = ? OR FROM_ID = ?";
        $result = $db->execute($sql, [$page_id, $page_id]);
        if ($result) {
            $row = $db->fetchArray($result);
            $total = $row['NUM'];
        }
        return $total;
    }

References

Yioop Documentation: Link