CXuesong / WikiClientLibrary

/*🌻*/ Wiki Client Library is an asynchronous MediaWiki API client library targeting modern .NET platforms
https://github.com/CXuesong/WikiClientLibrary/wiki
Apache License 2.0
80 stars 16 forks source link

Client fails to connect to marvel.fandom.com #73

Closed mthomason12 closed 4 years ago

mthomason12 commented 4 years ago

marvel.fandom.com (and possibly other fandom sites) fail to connect via the client due to the following problems (note that I've put in workaround code to solve this, and have included it below, but it's probably a bit messy)

`

    internal NamespaceCollection(WikiSite site, JObject namespaces, JArray jaliases)
    {
        // jaliases : query.namespacealiases
        if (site == null) throw new ArgumentNullException(nameof(site));
        if (namespaces == null) throw new ArgumentNullException(nameof(namespaces));
        idNsDict = namespaces.ToObject<IDictionary<int, NamespaceInfo>>(Utility.WikiJsonSerializer);  
        nameNsDict = new Dictionary<string, NamespaceInfo>();
        //build dictionary entry-by-entry, checking for duplicate keys due to Fandom having two "portal" namespaces
        foreach (var ns in idNsDict.Values)
        {
            string newkey = ns.CanonicalName.ToLowerInvariant();
            if (!nameNsDict.ContainsKey(newkey))
            {
                nameNsDict.Add(newkey, ns);
            }
        }

`

`

public class InterwikiEntry
{
    private string _Prefix;
    /// <summary>
    /// The prefix of the interwiki link;
    /// this is used the same way as a namespace is used when editing.
    /// </summary>
    /// <remarks>Prefixes must be all lower-case.</remarks>
    [JsonProperty]
    public string Prefix
    {
        get { return _Prefix; }
        private set
        {
            //if (value != null) Debug.Assert(value == value.ToLowerInvariant()); //commented out to prevent assertion due to Fandom having some uppercase prefixes
            _Prefix = value;
        }
    }

`

CXuesong commented 4 years ago

Which version of WCL are you using? I think this issue has been resolved by now, If you are referencing CXuesong.MW.WikiClientLibrary.Wikia NuGet package only, please also install latest CXuesong.MW.WikiClientLibrary package, if necessary.

https://github.com/CXuesong/WikiClientLibrary/blob/52899e7d715460a00441244d3902b416e599afa9/WikiClientLibrary/Sites/SiteInfo.cs#L402-L414

CXuesong commented 4 years ago

As for duplicate Portal namespaces, here is the response of https://marvel.fandom.com/api.php?action=query&format=json&meta=siteinfo&siprop=namespaces%7Cnamespacealiases . Note that Portal ns takes both 124 and 126 ns_id.

@mthomason12 you should probably report this issue to your staff, since Portal namespace looks like a site-specific one.

{
    "query": {
        "namespaces": {
            "-2": {
                "id": -2,
                "case": "first-letter",
                "*": "Media",
                "canonical": "Media"
            },
            "-1": {
                "id": -1,
                "case": "first-letter",
                "*": "Special",
                "canonical": "Special"
            },
            "0": {
                "id": 0,
                "case": "first-letter",
                "*": "",
                "subpages": "",
                "content": ""
            },
            "1": {
                "id": 1,
                "case": "first-letter",
                "*": "Talk",
                "subpages": "",
                "canonical": "Talk"
            },
            "2": {
                "id": 2,
                "case": "first-letter",
                "*": "User",
                "subpages": "",
                "canonical": "User"
            },
            "3": {
                "id": 3,
                "case": "first-letter",
                "*": "User talk",
                "subpages": "",
                "canonical": "User talk"
            },
            "4": {
                "id": 4,
                "case": "first-letter",
                "*": "Marvel Database",
                "subpages": "",
                "canonical": "Project"
            },
            "5": {
                "id": 5,
                "case": "first-letter",
                "*": "Marvel Database talk",
                "subpages": "",
                "canonical": "Project talk"
            },
            "6": {
                "id": 6,
                "case": "first-letter",
                "*": "File",
                "subpages": "",
                "canonical": "File"
            },
            "7": {
                "id": 7,
                "case": "first-letter",
                "*": "File talk",
                "subpages": "",
                "canonical": "File talk"
            },
            "8": {
                "id": 8,
                "case": "first-letter",
                "*": "MediaWiki",
                "subpages": "",
                "canonical": "MediaWiki"
            },
            "9": {
                "id": 9,
                "case": "first-letter",
                "*": "MediaWiki talk",
                "subpages": "",
                "canonical": "MediaWiki talk"
            },
            "10": {
                "id": 10,
                "case": "first-letter",
                "*": "Template",
                "subpages": "",
                "canonical": "Template"
            },
            "11": {
                "id": 11,
                "case": "first-letter",
                "*": "Template talk",
                "subpages": "",
                "canonical": "Template talk"
            },
            "12": {
                "id": 12,
                "case": "first-letter",
                "*": "Help",
                "subpages": "",
                "canonical": "Help"
            },
            "13": {
                "id": 13,
                "case": "first-letter",
                "*": "Help talk",
                "subpages": "",
                "canonical": "Help talk"
            },
            "14": {
                "id": 14,
                "case": "first-letter",
                "*": "Category",
                "subpages": "",
                "canonical": "Category"
            },
            "15": {
                "id": 15,
                "case": "first-letter",
                "*": "Category talk",
                "subpages": "",
                "canonical": "Category talk"
            },
            "100": {
                "id": 100,
                "case": "first-letter",
                "*": "Merge",
                "canonical": "Merge"
            },
            "101": {
                "id": 101,
                "case": "first-letter",
                "*": "Merge talk",
                "canonical": "Merge talk"
            },
            "110": {
                "id": 110,
                "case": "first-letter",
                "*": "Forum",
                "subpages": "",
                "canonical": "Forum"
            },
            "111": {
                "id": 111,
                "case": "first-letter",
                "*": "Forum talk",
                "subpages": "",
                "canonical": "Forum talk"
            },
            "112": {
                "id": 112,
                "case": "first-letter",
                "*": "News",
                "canonical": "News"
            },
            "113": {
                "id": 113,
                "case": "first-letter",
                "*": "News talk",
                "canonical": "News talk"
            },
            "114": {
                "id": 114,
                "case": "first-letter",
                "*": "Blogs",
                "canonical": "Blogs"
            },
            "115": {
                "id": 115,
                "case": "first-letter",
                "*": "Blogs talk",
                "canonical": "Blogs talk"
            },
            "116": {
                "id": 116,
                "case": "first-letter",
                "*": "Comics",
                "canonical": "Comics",
                "content": ""
            },
            "117": {
                "id": 117,
                "case": "first-letter",
                "*": "Comics talk",
                "canonical": "Comics talk"
            },
            "118": {
                "id": 118,
                "case": "first-letter",
                "*": "Glossary",
                "canonical": "Glossary",
                "content": ""
            },
            "119": {
                "id": 119,
                "case": "first-letter",
                "*": "Glossary talk",
                "canonical": "Glossary talk"
            },
            "120": {
                "id": 120,
                "case": "first-letter",
                "*": "Minor",
                "canonical": "Minor"
            },
            "121": {
                "id": 121,
                "case": "first-letter",
                "*": "Minor talk",
                "canonical": "Minor talk"
            },
            "122": {
                "id": 122,
                "case": "first-letter",
                "*": "Instant Expert",
                "canonical": "Instant Expert"
            },
            "123": {
                "id": 123,
                "case": "first-letter",
                "*": "Instant Expert talk",
                "canonical": "Instant Expert talk"
            },
            "124": {
                "id": 124,
                "case": "first-letter",
                "*": "Portal",
                "subpages": "",
                "canonical": "Portal",
                "content": ""
            },
            "125": {
                "id": 125,
                "case": "first-letter",
                "*": "Portal talk",
                "subpages": "",
                "canonical": "Portal talk",
                "content": ""
            },
            "126": {
                "id": 126,
                "case": "first-letter",
                "*": "Portal",
                "subpages": "",
                "canonical": "Portal",
                "content": ""
            },
            "127": {
                "id": 127,
                "case": "first-letter",
                "*": "Portal talk",
                "canonical": "Portal talk"
            },
            "500": {
                "id": 500,
                "case": "first-letter",
                "*": "User blog",
                "subpages": "",
                "canonical": "User blog"
            },
            "501": {
                "id": 501,
                "case": "first-letter",
                "*": "User blog comment",
                "subpages": "",
                "canonical": "User blog comment"
            },
            "502": {
                "id": 502,
                "case": "first-letter",
                "*": "Blog",
                "subpages": "",
                "canonical": "Blog"
            },
            "503": {
                "id": 503,
                "case": "first-letter",
                "*": "Blog talk",
                "subpages": "",
                "canonical": "Blog talk"
            },
            "828": {
                "id": 828,
                "case": "first-letter",
                "*": "Module",
                "subpages": "",
                "canonical": "Module"
            },
            "829": {
                "id": 829,
                "case": "first-letter",
                "*": "Module talk",
                "subpages": "",
                "canonical": "Module talk"
            },
            "1200": {
                "id": 1200,
                "case": "first-letter",
                "*": "Message Wall",
                "subpages": "",
                "canonical": "Message Wall"
            },
            "1201": {
                "id": 1201,
                "case": "first-letter",
                "*": "Thread",
                "subpages": "",
                "canonical": "Thread"
            },
            "1202": {
                "id": 1202,
                "case": "first-letter",
                "*": "Message Wall Greeting",
                "canonical": "Message Wall Greeting"
            },
            "2000": {
                "id": 2000,
                "case": "first-letter",
                "*": "Board",
                "canonical": "Board"
            },
            "2001": {
                "id": 2001,
                "case": "first-letter",
                "*": "Board Thread",
                "subpages": "",
                "canonical": "Board Thread"
            },
            "2002": {
                "id": 2002,
                "case": "first-letter",
                "*": "Topic",
                "canonical": "Topic"
            }
        },
        "namespacealiases": [
            {
                "id": 6,
                "*": "Image"
            },
            {
                "id": 7,
                "*": "Image talk"
            }
        ]
    }
}
mthomason12 commented 4 years ago

Thank you for the quick response!

I'm not connected to the marvel.fandom.com wiki in any way (I'm just trying to pull some data), but will let them know about the namespace problem.

I was using the nuget packages CXuesong.MW.WikiClientLib 0.7.0 and 0.7.2, and CXuesong.MW.WikiClientLib.Wikia 0.7.0. After running into the problems I copied the master branch from git (as of 26-Jul-2020) to debug it and put in the workarounds.

CXuesong commented 4 years ago

Fixed in a2f8a0f6c88c294cb39e3e4a47ff674312fcee5d.

CXuesong commented 4 years ago

Released in v0.7.3.

CXuesong commented 4 years ago

Please re-open the issue if you see further problems related to this.

mthomason12 commented 4 years ago

This is working perfectly now, thank you! Am glad this was resolved in the library, as I don't seem to be able to get hold of anyone in charge of that wiki to fix it at their end (the wikia helpdesk just ran me in circles trying to find someone responsible for removing the duplicate portal)

CXuesong commented 4 years ago

the wikia helpdesk just ran me in circles trying to find someone responsible for removing the duplicate portal

@mthomason12 thanks for your effort! I've checked namespace map just now and the Portal namespace is still taking both 124 and 126 namespace ids.

Not sure if it's disturbing but @KockaAdmiralac do you happen to know what we should do if we find there are conflicting namespace IDs under same namespace canonical name on a specific FANDOM site? I believe there chould be some configuration error in LocalSettings.php… Thanks in advance.

CXuesong commented 4 years ago

Just checked with Kocka and I've submitted another support ticket via https://fandom.zendesk.com/hc/requests/new. Should receive some response next week.

CXuesong commented 4 years ago

Not sure whether everyone can see it but here is the ticket: https://fandom.zendesk.com/hc/en-us/requests/963003

CXuesong commented 4 years ago

Ticket resolved, ns_id 124 is gone now.