User:Diegodlh/Web2Cit/script
The Web2Cit user script integrates Web2Cit into Wikipedia's visual editor. Web2Cit is a tool to collaboratively define procedures to automatically extract citation metadata from web sources.
How to install it?
[edit]Open your common.js file (or meta:Special:MyPage/global.js, to install across Wikimedia projects), add this at the end and save your changes:
// Web2Cit
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Diegodlh/Web2Cit/script.js&action=raw&ctype=text/javascript' ); // Backlink: [[:en:User:Diegodlh/Web2Cit/script.js]]
You may need to bypass your browser's cache for the changes to take effect.
Alternatively, follow the instructions in Wikipedia:User_scripts#How_do_you_install_user_scripts?.
How to use it?
[edit]The user script will add a "Web2Cit" checkbox to the dialog that opens when you click on the Visual Editor's "Cite" button.
If the checkbox is enabled, automatic citation generation will be handled by the Web2Cit translation server, which will return two citation results:
- The citation returned by Citoid, at the top; and
- The citation returned by Web2Cit, at the bottom.
In this case, a "Powered by Zotero & Web2Cit" legend will appear on the bottom-right corner. Click on "Web2Cit" to see more details and edit the results.
Note that only queries that look like URLs (i.e., starting with http://
, https://
or following the pattern www.something.somethingelse...
) will be handled this way. Other queries will be handled directly by Citoid as usual.
How do I report an issue?
[edit]Please open a task in Phabricator, or post a message on this page's Talk page.
Alternative Web2Cit server instance
[edit]
By default, Web2Cit user script uses the production instance of Web2Cit server at https://web2cit.toolforge.org/. If you want to use an alternative instance (e.g., the test instance at https://w2c-beta.toolforge.org/), add the following setting to your common.js
file:
window.web2citServer = "https://w2c-beta.toolforge.org/"
How does the user script work?
[edit]Briefly, the user script applies three monkey patches:
$.ajax
patch
[edit]It monitors all $.ajax requests and modifies those matching the following criteria (all other requests are left untouched):
- The target path begins with
/api/rest_v1/data/citation/mediawiki/
; i.e., a Citoid request - The
search
parameter of the Citoid request is a URL (starts withhttp://
,https://
or follows the patternwww.something.somethingelse...
.
These requests are routed to the Web2Cit translation server instead: https://web2cit.toolforge.org/translate?citoid=true&format=mediawiki&url=...
.
By using the citoid
parameter, the Web2Cit translation server returns both a raw Citoid citation and a Web2Cit citation. This avoids having to make two separate Citoid requests: one for the Citoid citation, and another one for any Citoid selection steps in the Web2Cit translation procedures.
CitoidInspector's patchBuildTemplateResults
patch
[edit]This patch adds "Web2Cit" to the credits legend, including a link to the translation result details.
CitoidInspector's initialize
patch
[edit]This adds the "Web2Cit" checkbox to the "Cite" dialog, to enable and disable Web2Cit translation (i.e., to patch or unpatch $.ajax
and CitoidInspector's patchBuildTemplateResults)
.
This setting is persisted by being saved to the browser's local storage web2cit.disabled
item.