Menu

#36 Page class needs a function to retrieve full intra-Wiki links by text.

closed
nobody
None
5
2016-02-13
2015-04-06
Korval
No

Page.GetLinks is a useful function for fetching all links to other articles in that Wiki. However, it has certain flaws. Namely, the flaw that it extracts links to pages.

What I mean is that, if you want to find all links in one page to a particular section of a page, you're basically out of luck (or rather, you have to write it yourself). By contrast, if the page were a redirect, you get the full page+section link of the redirect when you call Page.RedirectsTo.

This is because Page.GetLinks returns a PageList, not a List<string>. Since a Page only can refer to a page rather than a page+section link, this is not useful in many cases.

Page.GetAllLinks returns links by text, and it also provides page+section links. The problem is that it gets all links. If you're just looking for intra-wiki page+section links, you now have to parse through the results, culling out all the various kinds of links you're not interested in.

There should be a function that operates on the same list of links that Page.GetLinks does, but by returning the text page+section, rather than a PageList.

Discussion

  • CodeDriller

    CodeDriller - 2016-02-13
    • status: open --> closed
     
  • CodeDriller

    CodeDriller - 2016-02-13

    I'll think about it. But it seems fairly easy to select required links from what Page.GetAllLinks() function returns. Like that:

    ...
    Page p = new Page(mySite, "MyPage");
    p.Load();
    
    // Intra-page links to a particular section:
    var links1 = p.GetAllLinks().Where(l => l.StartsWith(p.title + "#Section 1")).ToArray();
    
    // Short intra-page links to a particular section:
    var links2 = p.GetAllLinks().Where(l => l.StartsWith("#Section 1")).ToArray();
    
    // Links to other pages with section anchors:
    var links3 = p.GetAllLinks().Where(l => l.Contains("#")).ToArray();
    
     

Log in to post a comment.