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 297 Deliverable 04

Adding a feature "What Links Here" to Yioop

Description

This deliverable involved adding a new feature to Yioop: "What Links Here." This feature lists all wiki pages that are linked to any particular page. The results displayed will be hyperlinks that will take the user to that wiki page. The wiki parser of Yioop fetches each individual MediaWiki internal links present in MediaWiki documents to be able to discover connections between different pages. This is done using a regular expression. For example, if page A is related to page B with a link that is displayed as Page B Link, then MediaWiki of document A would have [[PageB|Page B Link]]. Thus, the presence of these types of internal links can be extracted using a regular expression. Once we have all the links between the pages, it can be saved to the back end, and later used for information retrieval of linkages between different pages.

To perform this action, the following steps needs to be followed:

1. Add "What Links Here" to the drop down of the actions that can be performed on wiki pages.

2. Fetch the pages linked to any particular wiki page from the data base.

3. Render the link page by displaying the results as hyperlinks pointing to the wiki content of their pages.

Steps to be followed

Step 01

To fetch all links from any particular page, the first step is to add this feature, selecting which triggers the action of getting all linked pages to any particular page. This is done by assigning a keyword "links", which can then be used in the switch case used to trigger an action to the database.

Step 02

The controller calls method which fetches all pages that are linked to any wiki page. This is done by obtaining the page id where linkages are to found. This page id is passed to the database to get all linked pages. The page name of all linked pages is obtained and passed back to the controller.

Step 03

The final step renders the fetched results to the webpage. The results are displayed as a hyperlink, directing to the wiki page content of each result.

Deliverables

Mantis Bug ID:0000181

src/controllers/components/SocialComponent.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 'links':
                    $data["MODE"] = "links";
                    $data["PAGE_NAME"] = "linked";
                    if (!isset($page_id) || !$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["PAGES"]) =
                        $group_model->getPagesLinkedToList($page_id, $limit,
                        $num);
                    break;

At the model, the following code has been added to interact with the database:

   /**
     * Gets all the pages that are linked to a particular wiki page
     * by providing that page id from the table Group_Page_Link.
     *
     * @param int $page_id identifier for the current page
     * @param string $limit first row we want from the result set
     * @param string $num number of rows we want starting from the
     *     first row in the result set
     * @return array of elements which represent all pages linked
     *     to the given wiki page
     */
    public function getPagesLinkedToList($page_id, $limit, $num)
    {
        $db = $this->db;
        $sql = "SELECT COUNT(*) AS NUM FROM GROUP_PAGE_LINK
            WHERE TO_ID = ?";
        $result = $db->execute($sql, [$page_id]);
        if ($result) {
            $row = $db->fetchArray($result);
            $total = $row['NUM'];
        }
        $i = 0;
        $pages = [];
        $sql = "SELECT G.TITLE AS PAGES_THAT_LINK
            FROM GROUP_PAGE_LINK L, GROUP_PAGE G
            where L.TO_ID = ? AND (L.FROM_ID = G.ID)"
            .$db->limitOffset($limit, $num);
        $result = $db->execute($sql, [$page_id]);
        if ($result) {
            while ($pages[$i] = $db->fetchArray($result)) {
                $i++;
            }
            unset($pages[$i]);
            $i--;
        }
        return [$total,$pages];
    }

References

Yioop Documentation: Link