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?
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?

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.
A "Powered by Web2Cit" legend will appear on the bottom-right corner of the Web2Cit citation. 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.
Usage tracking
If one or more Web2Cit-generated citations are inserted in an article, a #Web2Cit hashtag will be included in the edit summary draft before publishing. Edits tagged with this hashtag may be tracked using Hashtags tool here.
We also track a few actions, such as citation generation, insertion, and Web2Cit config edit attempts. These can be monitored on Grafana here.
Full details on these tracking implementations can be read at phab:T321568.
How do I report an issue?
Please open a task in Phabricator, or post a message on this page's Talk page.
Alternative Web2Cit server instance
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?
Briefly, the user script applies three monkey patches:
$.ajax patch
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
searchparameter 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 patchPerformLookup patch
This patch adds "Web2Cit" to the credits legend, including a link to the translation result details.
CitoidInspector's initialize patch
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.
Development
The code is hosted on Wikimedia GitLab at https://gitlab.wikimedia.org/diegodlh/w2c-gadget. It is manually copied to User:Diegodlh/Web2Cit/script.js, from where it is served as a user script.[Note 1]
To load your local version of the user script while working on it, you can serve it from a local web server as explained in Wikipedia:User scripts/Guide#Loading it from a localhost web server.
For debugging, you can use your browser's development tools. Because the script modifies the visual editor behavior, you may find it useful reloading the page with ?debug=true to get the non-compacted version of it.
Notes
- ^ We are considering the possibility of avoiding this extra step by serving the code from Wikimedia GitLab using the gitlab-content reverse proxy tool: User talk:Diegodlh/Web2Cit/script#Serve from Wikimedia Gitlab.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.