SourceForge has been redesigned. Learn more.

Can I tell if a page is protected (read-only)

  • Troy Millett

    Troy Millett - 2011-04-19

    I am working with a company where my login to the wiki is not a sysop.  I am reading through many records and updating them based on changes in other systems.  Sometimes my program tries to update a page that it doesn't have access to because the admin has protected the page (its read-only).  Is there any way I can find out if a page is protected before I try to write it out?  (Even though I have put exception handling around the save code, after 2 failed saves I get a connection error to the wiki).

  • CodeDriller

    CodeDriller - 2011-04-19

    There is no such built-in method. But if you really need it, you can easily create it by yourself. You can use GetPageHTM() function to get HTML source of a page and then search for edit link in HTML source before calling Save() function. Something like that:

    public bool IsProtected(string title) {
        string res = + site.indexPath + "index.php?title=" + HttpUtility.UrlEncode(title);
        string src = site.GetPageHTM(res);
        return src.Contains("...") ? false : true;
  • Juergen Thomas

    Juergen Thomas - 2015-01-10

    In version 3.11, I don't find a method like GetPageHTM() that returns HTML source. Using API:Properties and API:Meta I created a partial solution and post it in a new topic "Check page restrictions" in Open Discussion. Juergen

  • CodeDriller

    CodeDriller - 2015-01-18

    In version 3.x the method GetPageHTM() was renamed to GetWebPage().

  • Juergen Thomas

    Juergen Thomas - 2015-01-19

    Thank you, I'll check whether the content helps. Juergen


Log in to post a comment.