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

  • Troy Millett
    Troy Millett

    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

    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;