User:Diegodlh/Web2Cit/script

From WikiProjectMed
Jump to navigation Jump to search

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?

Integration of Web2Cit tool into Wikipedia's visual editor

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:

  1. The citation returned by Citoid, at the top; and
  2. 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?

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 search parameter of the Citoid request is a URL (starts with http://, https:// or follows the pattern www.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

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.