feat: add generic call-api pagebot action#54
Open
LukasGold wants to merge 2 commits into
Open
Conversation
Fold the call-api action into PageBot.js: - osl.ui.callApi(params): reads the page jsondata slot, projects it into a request body and POSTs it to a backend endpoint (typically via the ApiGateway extension), then drives an mw.notify summary and an optional reload. - Supporting helpers (getByPath, projectItem, renderTemplate, getPageJsonData, summarize, confirmThen, wrap, buildUrl, send) added to osl.util. - Render branch for action "call-api" in the .pagebot-button scan, passing params like edit-data.
The generic call-api PageBot action built its POST body only from the page's jsondata via jsonpath (`list_path` / `request_object_map`), so a button could only send data already present in the page's result list. That fits the batch "Create all" button but not a per-row button that must send a single, constant payload.
Add a `params.body` branch to `callApi()` that sends a literal payload as-is, skipping the jsondata read and projection entirely. It still honours `wrap_key`, `confirm`/%count% and `csrf`, and passes an empty object for jsondata (safe, since `buildUrl` only reads jsondata for `{{var}}` substitution in `source`, which a literal-body button omits).
This enables per-item buttons, e.g. a single-substance "Create" template whose ChemSpider ID is substituted into `body` by the wiki template layer before the script runs, so the JS sees a plain constant.
Backward compatible: `body` takes precedence over `list_path` / `request_object_map`, and existing buttons set no `body`, so they keep the unchanged jsondata path.
simontaurus
reviewed
Jul 9, 2026
| // into a request body and POST it to a backend endpoint (typically via the | ||
| // ApiGateway extension). Kept dependency-light so they also work in read mode. | ||
|
|
||
| // tiny jsonpath-ish getter. Supported forms: "$", "$.a.b.c", "$.a.b[*]" |
Collaborator
There was a problem hiding this comment.
this is duplicating a lot of https://github.com/OpenSemanticLab/mediawiki-extensions-MwJson/blob/main/modules/ext.MwJson.util/MwJson_extData.js - please reuse tooling from there, in particular jsonpath and handlebars libs are loaded in mwjson module, which is a dependency of the osl js modules
simontaurus
reviewed
Jul 9, 2026
|
|
||
| // Read the current page's jsondata slot via the action API. Avoids depending | ||
| // on mwjson.api being loaded in read mode. | ||
| static getPageJsonData(pageName) { |
Collaborator
There was a problem hiding this comment.
this should go to https://github.com/OpenSemanticLab/mediawiki-extensions-MwJson/blob/main/modules/ext.MwJson.api/MwJson_api.js and/or reuse code from there
simontaurus
reviewed
Jul 9, 2026
| // Build a response summary. Prefer an explicit response_message_path; else | ||
| // best-effort over common batch shapes ({ results: [{action|error}], | ||
| // *_ids: [...] } and { message }). | ||
| static summarize(data, params) { |
Collaborator
There was a problem hiding this comment.
this seems like a very specific result parsing. I would be better to use a handlebars template defined by the btn config to assembly a result msg
simontaurus
requested changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In some cases developers want to create buttons on wiki pages that take the data in the jsondata slot, process it and send it to an arbitrary API through the API gateway.