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
82 stars 16 forks source link

Wikia API implementation, Part 1 #29

Closed CXuesong closed 7 years ago

CXuesong commented 7 years ago

Related issue #26

This is a brand-new set of API, some of which are well-documented, while some are not. I am not going to implement them one by one, but the goal is to provide some necessary generalization and infrastructure so that Fandom users can issue their API invocations neatly.

Thus the freshly-introduced WikiaSite class would be a simple set of methods that allows you to

I will implement some of the concrete methods (extension methods) on top of this. Considering the functionality of some Wikia API has already been covered by MediaWiki API, the subset might be relatively small.

Wikia API v1

Nirvana API

What's next

CXuesong commented 7 years ago

The schema provided by Wikia seems outdated. E.g. Documentation:

WikiDataContainer {
data (WikiData): wiki data
}
WikiData {
cacheBuster (integer): current wiki cachebuster value,
dbName (string),
defaultSkin (string),
id (integer),
language (WikiLanguageData),
namespaces (object),
sitename (string),
mainPageTitle (string),
wikiCategories (array[string]),
navData (NavigationResultSet),
vertical (string),
basePath (string),
isGASpecialWiki (boolean),
articlePath (string),
facebookAppId (string)
}
WikiLanguageData {
user (string),
userDir (string),
content (string),
contentDir (string)
}
NavigationResultSet {
navigation (NavigationItem): Wrapper for navigation objects
}
NavigationItem {
wikia (array[WikiaItem]): On the wiki navigation bar data,
wiki (array[WikiaItem]): User set navigation bars
}
WikiaItem {
text (string): On wiki navigation bar text,
href (string): The relative URL of the Page. Absolute URL: obtained from combining relative URL with basepath attribute from response.,
children (array[ChildrenItem]): Children collection containing article or special pages data
}
ChildrenItem {
text (string): Article or special page title,
href (string): The relative URL of the Page. Absolute URL: obtained from combining relative URL with basepath attribute from response.
}

The structure of actual response

object                          {1}
    data                        {35}
        appleTouchIcon              {2}
        cacheBuster : 1508417393
        cdnRootUrl : https://slot1-images.wikia.nocookie.net
        contentNamespaces           [2]
        dbName : dev
        defaultSkin : oasis
        disableAnonymousEditing : true
        disableAnonymousUploadForMercury : false
        disableMobileSectionEditor : false
        enableCommunityData : true
        enableDiscussions : false
        enableDiscussionsImageUpload : false
        enableFandomAppSmartBanner : true
        enableNewAuth : true
        favicon : https://vignette.wikia.nocookie.net/dev/images/6/64/Favicon.ico/revision/latest?cb=20161017232305
        homepage : http://www.wikia.com/fandom
        id : 7931
        isCoppaWiki : false
        isDarkTheme : false
        language                    {2}
            content : en
            contentDir : ltr
        mainPageTitle : Fandom_Open_Source_Library
        namespaces                  {36}
        siteMessage : FANDOM Open Source Library
        siteName : FANDOM Open Source Library
        theme                       {13}
        discussionColorOverride : 
        tracking                    {4}
        wikiCategories              [1]
        0 : tech
        localNav                [4]
            0                       {3}
                text : Scripts
                href : #
                children            [5]
            1                       {3}
            2                       {3}
            3                       {3}
        vertical : lifestyle
        basePath : http://dev.wikia.com
        articlePath : /wiki/
        image : https://vignette.wikia.nocookie.net/dev/images/f/f4/Wikia-Visualization-Main%2Cdev.png/revision/latest/window-crop/width/500/x-offset/124/y-offset/0/window-width/387/window-height/386?cb=20161102143556
        specialRobotPolicy : null
        htmlTitle                   {2}
            separator :  | 
            parts                   [2]
CXuesong commented 7 years ago

Nirvana API has some peculiarity on the JSON response

b62
{"ajaxicon":"https:\/\/slot1-images.wikia.nocookie.net\/__cb1508839704\/common\/skins\/common\/images\/ajax.gif","pagesCount":5,"avatar":"<img src=\"https:\/\/vignette.wikia.nocookie.net\/7c048e5a-b747-47ad-bef9-170599ee4fba\/scale-to-width-down\/50 [more text]
2498
ceTalk":1,"mUser":null,"mArticle":null,"mLastRevision":null,"mFirstRevision":null},"487106":{"mLastRevId":null,"mFirstRevId":null,"mNamespace":1,"mNamespaceTalk":1,"mUser":null,"mArticle":null,"mLastRevision":null,"mFirstRevision":null}}},"480731":{ [more text]
8fa
f=\"http:\/\/ru.warriors-cats.wikia.com\/wiki\/%D0%93%D1%80%D0%BE%D0%B7%D0%BE%D0%B2%D0%BE%D0%B5_%D0%BF%D0%BB%D0%B5%D0%BC%D1%8F?page=2#article-comments\" id=\"article-comments-pagination-link-2\" class=\"article-comments-pagination-link dark_text_1\" [more text]
0

It seems that the first line is the length of second line, including \r\n, in hexadecimal; then the content follows. Then another length, and another line. To obtain the actual response, I need to concatenate the lines together. Oops, it's just Chunked encoding… I need to do nothing about that.

CXuesong commented 7 years ago

It seems that there is no way I can retrieve the wikitext of article comments in JSON neatly. I've tried

/wikia.php?controller=ArticleComments&method=Content&articleId=579&format=html&page=1&useskin=oasis

It gives me the parsed HTML of the content area, including all the comment content.

Changed format=html to format=json, I got the JSON, but it contains no content information. Only the structure of comment area can be retrieved. Actually, it contains nothing but comment IDs, which, still, is not a page ID that I can used to retrieve the page. Actually, it is. (Thanks to Kocka) Not sure if I've tried hard enough đŸ˜¨

Then I tried

/index.php?action=ajax&rs=ArticleCommentsAjax&method=axGetComments&article=579&page=2&useskin=oasis

and I have

{
    "error": 0,
    "text": "<ul id=\"article-comments-ul\" class=\"comments\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t<li id=\"comm-389507\" class=\"comment SpeechBubble odd\" data [more text]
    "pagination": "<a href=\"\/wiki\/%D0%93%D1%80%D0%BE%D0%B7%D0%BE%D0%B2%D0%BE%D0%B5_%D0%BF%D0%BB%D0%B5%D0%BC%D1%8F?page=1#article-comments\" id=\"article-comments-pagi [more text]
}

Obviously, it's still HTML.

Then I tried to open the "edit comment" box, thinking this time I might get the wikitext that would be filled into the textarea. I sent the request

/index.php?action=ajax&article=264828&convertToFormat=&id=567434&method=axEdit&rs=ArticleCommentsAjax&useskin=oasis

and I got

{
    "error": 0,
    "id": "567434",
    "show": true,
    "text": "<div class=\"article-comments clearfix\">\n\t<div class=\"article-comm-input reset clearfix\">\n\t\t\t\t\t<div class=\"MiniEditorWrapper\" data-min-height=\"100\" data-max-height=\"400\">\n\t\t\t\t<form action=\"http:\/\/[****************]\" method=\"post\" id=\"article-comm-form-567434\" class=\"article-comm-form\">\n\t\t\t<input type=\"hidden\" name=\"wpArticleId\" value=\"567434\" \/>\n\t\t\t<div class=\"article-comm-input-text\">\n\t\t\t\t\t\t\t\t\t<div class=\"editarea\" data-space-type=\"editarea\">\n\t\t\t\t\t\t\t\t<textarea name=\"wpArticleComment\" id=\"article-comm-textfield-567434\">test test test test<\/textarea> [more text]
    "edgeCases": [],
    "emptyMsg": "You can't post an empty comment. <a  class=\"text\" href=\"http:\/\/mediawiki119.wikia.com\/wiki\/Talk:Random40156\/@comment-CXuesong-20171024144201?redirect=no&amp;action=delete\">Delete it instead?<\/a>"
}

Obviously, my wikitext is wrapped in the <textarea> element… This is just undesirable…