Closed hugolpz closed 3 years ago
I don't know yet how to create this man, as a readme, or by improving the in-code phrasing within wikiapi.js and test.js. But for reference, see best practice for README.md API with d3-array :
# d3.max(iterable[, accessor]) · Source. Returns .... If ..., returns.... An optional option_name does .... See also related_stuff.
I'am starting work below. Still a testing around, style and things can change. Please tell me if I'am on the right road. Help welcome. Kanasimi, I believe you have the userrights to edit my post, feel free to do so 😁 . The content below is intended to complete the current readme.md.
Former d3-style API proposal below.
# .site_name(language[,options]): {description}
language
: string.options
: object.# .login(username, password, API_URL): login into the target API using the provided username and password.
username
: string - Account username. For bot, see [Special:BotPasswords] on your wiki.password
: string - Account's password. For bot, see [Special:BotPasswords] on your wiki.API_URL
: string (url) - Target wiki's API url.# .query(parameters[,options]): {description}
parameters
:options
: object.# .page(title[,options]): given a title, returns the page's data.
title
: string.options
: object.# .tracking_revisions(title,to_search[,options]): {description}
title
: string.to_search
: …options
: object.# .edit_page(title, function(d){…}[,options]): edits content of target page.
title
: string.conent
: string - Use function(d){…}
to return the new wikicode, where d
is the page data.options
: object.
bot
: boolean.nocreate
: boolean - Avoid creating new page.minor
: boolean - Edit is minor.summary
: string - Edit summary.# .edit(content[,options]) {…}: to use with and after edit_page
. {description}
content
: …options
: object.# .move_to(move_to_title[,options]): move page to new title address.
move_to_title
: string.options
: object.
reason
: string.noredirect
: booleanmovetalk
: boolean.# .move_page(move_from_title, move_to_title[,options]): moves target page to new title address.
move_from_title
: string.move_to_title
: string.options
: object.
reason
: string.noredirect
: booleanmovetalk
: boolean.# .purge(title[,options]): {description}
title
: string.options
: object.# .listen(listener[,options]listener, options) {}: to use with and after …. {description}
listener
: …options
: object.# .category_tree(root_category[,options]): {description}
root_category
: string.options
: object.# .search(key[,options]): {description}
key
: …options
: object.# .redirects_root(title[,options]): {description}
title
: string.options
: object.# .redirects_here(title[,options]): {description}
title
: string.options
: object.# .register_redirects(template_name[,options]): {description}
template_name
: string.options
: object.# .upload(file_data): given a target file, upload it to the target wiki.
file_data
: object - Upload configurations.
file_path
: string - Local path. Alternative to _mediaurl. media_url
: string - URL path. Alternative to _filepath. comment
: string - Upload comment.text
: string - Wikicode which to fill the file's page. Alternative for most fields below. description
: string - File description.date
: date string - YYYY-MM-DD, ex: new Date() || '2021-01-01'. source_url
: string - Source where the file comes from, typically an url. author
: string - Author's name or username in wikicode, ex: '[[User:Yoda|Yoda]]'.permission
: string - …, ex: '{{cc-by-sa-2.5}}'.other_versions
: string - Wikicode displaying alternative files. other_fields
: string - …license
: array of strings - License under which the file is uploaded, ex: ['{{cc-by-sa-2.5}}'].categories
: array of strings - Categories for this file, ex: ['[[Category:test images]]'].ignorewarnings
: boolean=0 - Overwrite existing files.# .get_featured_content(options): {description}
options
: object.# .for_each_page(page_list, for_each[,options]): {description}
page_list
: …for_each
: …options
: object.# .for_each(type, title, for_each[,options]): {description}
type
: …title
: string.for_each
: …options
: object. # .data(key, property[,options]): {description}
key
: …property
: string.options
: object.# .convert_Chinese(text[,options]): {description}
text
: string - … <------------------- wikicode ? raw text ?options
: object.# .run_SQL(SQL, for_each_row): {description}
SQL
: …for_each_row
: …# .setup_layout_elements(options): {description}
options
: object.Here we could list all options ?
_Here comes pagedata's explainer
Other tricks
…
.{description}
. Good practice is Given {input} does {something}
or Given {input} return {something} in {format}
. Format being string, object, array, number, etc.get_featured_content
and setup_layout_elements
.categoryembers
: # .categorymembers(title[,options]): returns an array of members.
title
: string. Category's name.Well....I didn't expected this but I did it most of it. I thing you can complete the blanks easily. 😁
Maybe we can also use https://github.com/jsdoc/jsdoc ?
TL;DR: expand readme above will be faster. Code clean up required. Then JSdoc3 can come over.
Long version : I'am discovering JSdoc3. On the long run it's a very good idea. But as of now I lack visibility.
Your wikiapi.js code currently has (i think) a mix of comment syntaxes. I have no idea how it will play out with installing JSdoc. Aside, JSdoc renderings that I checked are not concise.
Meanwhile, the markdown API draft above is 1~2h away from becoming a clean documentation for +90% of wikiapi.js code and methods. This will be concise and elegant.
Later on, this markdown can be converted back into JSdoc3, when ready. Namely : 1) wikiapi.js comments cleaned up, 2) you/we properly learnt JSdoc3 syntaxes, 3) we know which template to use, 4) we know which project to use (JSDoc GitHub Action, jsdoc-to-markdown, other ?)
Then, some regex will help convert :
<a name="move_to" href="#move_to">#</a> .<b>move_to</b>(<i>move_to_title</i>[,<i>options</i>]): move page to new title address.
* `move_to_title`: string - target page's title.
* `options`: object - options.
* `reason`: string - reason for the move.
* `noredirect`: boolean
* `movetalk`: boolean.
...into...
/**
* @alias .move_to
* @description Moves page to new title address.
* @param {String} move_to_title - target page's title.
* @param {Object} [options] - options.
* @param {String} [options.reason] - reason for the move.
* @param {Boolean=1} [options.noredirect] - do not leave a redirect.
* @param {Boolean=1} [options.movetalk] - move the talkpage as well.
* @returns {Object} - returns (does not exist on .move_to but I put it here for demo)
* @memberof Wikiapi.prototype
* @example
* result = await targetWiki.move_page('Page A', 'Page Alpha', { reason: 'Correcting name.', noredirect: true, movetalk: true });
*/
function move_to (move_to_title,options) {
// do stuff here
}
If you have the ability to make a quick, full JSdoc3 migration (points 1, 2, 3 and 4 above), go ahead.
But overall and given the main objective is to provide an API soon, I suggest to expand the markdown API drafted above. It will give you time to clean the wikiapi.js's comments and other improvements you see fit. Both actions prepare for a later JSdoc3 migration.
(Also since I have to catch upover my IRL todo list, I should better not be active this weekend and the coming week.)
Nice 😎
Saw today changes. Starts to be awesome !
Substantial changes of documents have ended now.
Good work done. Close. Thank @kanasimi !
API actionables