User:Dudemanfellabra/AddCommonsCatLinks

From Wikipedia, the free encyclopedia
Jump to: navigation, search

This script is used to add images from Wikimedia Commons and/or links to Commons categories to certain lists of monuments. A full list of monument registers supported by the script can be found below.

How to use it[edit]

Anyone can use this script by adding

importScript('User:Dudemanfellabra/AddCommonsCatLinks.js');

or on other language verions by adding

mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Dudemanfellabra/AddCommonsCatLinks.js&action=raw&ctype=text/javascript','text/javascript');

to the bottom of their personal JavaScript page. The script generates a button at the top of supported monument lists which reads "Check Commons for images and categories" (or the corresponding phrase in other supported languages). When clicked, the script extracts the unique IDs of the sites in the list and checks Commons for categories and images that have been identified with that same ID. If a match is found, the script prompts the user to choose to add the matched images and/or categories or elect not to add anything. Upon reaching the bottom of the list, the script automatically edits the list to include the chosen images/categories if the user chose to add any.

How it works[edit]

Every time the user visits a new page, the script queries the wikitext of that page and determines if a supported row template (see below) is transcluded therein. If one of these row templates is found, the button is placed at the top of the page; if not, the script exits itself. When the user clicks the button, the wikitext is parsed to extract all the rows and then cycles through them, querying Commons for matches to the unique ID specified in each row template one by one.

Row templates[edit]

For each of the supported registers listed below, there is a row template used to create the tables found in the list-articles on which this button is added. For example, lists of sites on the US National Register of Historic Places use the {{NRHP row}} template to create each row in the tables. In the coding of this template, a parameter for a unique alphanumeric ID that identifies the site on that row is included (for the US NRHP, it is |refnum=########). This ID is used to add the site to the monuments database on Commons, allowing this script to recognize it. A good place to look for these row templates is Category:Monument list templates, although not all of the members of this category are supported by the script, and some supported templates may not be in this category.

Besides the unique identifier, it is also necessary that the row template adds the CSS class='vcard' to the row so that the script can recognize it. If this class is not present, the script will throw an error and exit itself.

Commons templates[edit]

The row templates identify the sites on the English Wikipedia, but other templates are needed to identify the images and categories on Commons. These templates can be found in commons:Category:Monument templates, though, again, not all of these templates are supported and some that are supported may not be in this category. These templates can be added to categories and files on Commons to mark them as being related to sites on their respective monument register. This is done by adding them to a category with the sortkey equal to the unique ID for that site. This script then queries the members of that category to find matches here. For example, any file or category on which commons:Template:NRHP is transcluded (along with a unique ID) is added to commons:Category:National Register of Historic Places with known IDs, in which this script then looks for matches. If the ID of a file/category on Commons matches the ID of a row template on a page here, the script suggests that file/category for inclusion here. It's that simple!

Other suggested matches[edit]

In addition to strict matches, i.e. when the ID of a file/category matches the ID of a row template, the script also makes suggestions in situations where files may not actually be tagged with a Commons template. If, for instance, a row in a list has a commons category specified when the script encounters it but does not include an image, the script will suggest that the user add an image that is in the pre-existing category. This is also the case if a row template has neither an image nor a Commons category when the script encounters it and the script finds a matching category but no matching images. In this case, the script suggests the images in the newly matched category for addition to the template. Of course, these are just suggestions and may not be actual matches since they have not been tagged on Commons definitively stating that they are images of this site, but the suggestions are often times accurate. If the suggested images (or even the strict matches) are not of the site in question or are not in the user's opinion of sufficient quality, there is always the option to forego adding an image or category to a row.

Bot output[edit]

Though this script can be run on any supported list, User:ErfgoedBot is instrumental in keeping up the Commons monuments database mentioned above and has some very helpful output that can be used to pinpoint where images and categories that have been identified on Commons need to be added here. An example output is Wikipedia:WikiProject National Register of Historic Places/Missing commons category links, which lists articles on which this script can be used to add links to Commons categories related to sites on the US NRHP. When there is a bot output available for a given register, it is linked in the supported registers table below.

Supported registers[edit]

The following table shows an extensive list of the monument registers on the English Wikipedia supported by this template, along with the relevant templates and categories this script uses. See below for monument registers supported on other language Wikipedias.

Register name Country/Location Row template Unique ID parameter(s) Commons template Commons category Bot output
Cats Images
Antarctic Protected Areas Antarctica {{Antarctic Protected Area row}} |type=, |number= commons:Template:Antarctic Protected Area commons:Category:Antarctic Protected Areas with known IDs
Monuments of Aruba Aruba {{Table row Aruba monuments}} |objcode= commons:Template:Cultural Heritage Aruba commons:Category:Cultural heritage monuments in Aruba with known IDs
Beschermd erfgoed BelgiumFlemish Region {{Table row BE}} |id= commons:Template:Onroerend erfgoed commons:Category:Onroerend erfgoed with known IDs
Beschermd erfgoed BelgiumWallonia {{Table row Wallonia}} |niscode=, |objcode= commons:Template:Monument Wallonie commons:Category:Cultural heritage monuments in Wallonia with known IDs
Canadian Register of Historic Places Canada {{HPC row}} |idf=, |idp=, |idm= commons:Template:Historic Places in Canada commons:Category:Heritage properties in Canada with known IDs
Major Historical and Cultural Site Protected at the National Level China {{NHS China row}} |designation= commons:Template:Cultural Heritage China commons:Category:Cultural heritage monuments in China with known IDs
Ghana’s material cultural heritage Ghana {{Ghana Monument row}} |id= commons:Template:Cultural Heritage Ghana commons:Category:Cultural heritage monuments in Ghana with known IDs
Declared monuments of Hong Kong Hong Kong {{HK Declared Monument row}} |id= commons:Template:Declared monuments Hong Kong commons:Category:Declared monuments of Hong Kong with known IDs
Historic buildings in Hong Kong Hong Kong {{HK Historic Building row}} |id= commons:Template:Historic buildings Hong Kong commons:Category:Historic buildings of Hong Kong with known IDs
Indian Monuments of National Importance India {{ASI Monument row}} |number= commons:Template:Historic buildings Hong Kong commons:Category:ASI monuments with known ID's
Public art in Israel Israel {{Public art in Israel - row}} |id= commons:Template:Public Art Israel commons:Category:Public art in Israel with known IDs
Monuments of Japan Japan {{NHS Japan row}} |id= commons:Template:NHS Japan commons:Category:National historic sites of Japan with known IDs
Sites and monuments in Kenya Kenya {{Kenya Monument row}} |id= commons:Template:Kenya Monument commons:Category:Kenya Monuments with known IDs
Monuments in Nepal Nepal {{Nepal Monument row}} |number= commons:Template:Cultural Heritage Nepal commons:Category:Cultural heritage monuments in Nepal with known IDs
Cultural heritage sites in Pakistan Pakistan {{PKmonument row}} |number= commons:Template:Cultural Heritage Pakistan commons:Category:Cultural heritage monuments in Pakistan with known IDs
Cultural Properties of the Philippines Philippines {{Philippine cultural property row}} |cp-wmph-id= commons:Template:WMPH-ID commons:Category:Cultural heritage monuments in the Philippines with known IDs
National heritage sites of South Africa South Africa {{SAHRA heritage site row}} |SiteReference= commons:Template:South African Heritage Site commons:Category:South Africa Heritage Resources with known IDs
Swiss Inventory of Cultural Property of National and Regional Significance Switzerland {{SIoCPoNaRS row}} |KGS_nr= commons:Template:Cultural property of national significance in Switzerland commons:Category:Cultural properties of national significance in Switzerland with known IDs
Listed buildings in England United KingdomEngland {{EH listed building row}} |uid= commons:Template:Listed building England commons:Category:Listed buildings in England with known IDs
Listed buildings in Wales United KingdomWales {{Cadw listed building row}} |hb= commons:Template:Listed building Wales commons:Category:Listed buildings in Wales with known IDs
Listed buildings in Cardiff United KingdomWalesCardiff {{Cardiff listed building row}} |hb= commons:Template:Listed building Wales commons:Category:Listed buildings in Wales with known IDs
Listed buildings in Scotland United KingdomScotland {{HS listed building row}} |hb= commons:Template:Listed building Scotland commons:Category:Listed buildings in Scotland with known IDs
Listed buildings in Northern Ireland United KingdomNorthern Ireland {{NIEA listed building row}} |hb= commons:Template:Listed building Northern Ireland commons:Category:Listed buildings in Northern Ireland with known IDs
United States National Register of Historic Places listings United States {{NRHP row}} |refnum= commons:Template:NRHP commons:Category:National Register of Historic Places with known IDs
California Historical Landmarks United StatesCalifornia {{CHL row}} |refnum= commons:Template:US-CHL commons:Category:California Historical Landmarks with known IDs

Other language Wikipedias[edit]

This script also supports lists on other language Wikipedias and is constantly expanding that support. While it may be possible to edit a list on a non-English Wikipedia, the GUI may or may not be displayed in that language. If the GUI has not yet been translated, the script will default to English, as will the edit summary (though the parameters added to the wikitext will be in the native language). If you can help translate the GUI into another language, please leave me a message at my talk page with the section title "I can help translate the CommonsCat script into LANGUAGE!"

A full list of supported registers on non-English Wikipedias is included below, sorted by the ISO 639 language code for that language (e.g. German's code is "de"). Click [show] next to the relevant language to display the list.

Adding support for new registers/languages[edit]

In order to add support for new registers, the entire framework–row template, Commons template, and ID category–must be set up for the register. In addition to making this script more useful, converting existing lists of sites on heritage registers around the world into this format will improve the database on Commons as well and will be very useful for Wiki Loves Monuments, an annual international photo drive in which thousands of images of monuments are added to Commons. Support for any new registers which have been converted to this format can easily be added to the script by contacting User:Dudemanfellabra.

Support for registers on other language Wikipedias does not require anything more than registers on the English Wikipedia; however, if you want the GUI/edit summary to be displayed in the local language, it must first be translated from English. There are several strings that are displayed by the GUI, all of which must be translated before the language can be supported. The strings are shown below with their English versions and notes on when they are used when necessary as guidance for translation. If you are inclined to do so, translate the strings below and copy them to my talk page. I will add support for them as soon as possible.

Troubleshooting[edit]

The following are known issues with the script that have not yet been addressed or are not technically feasible due to limitations of Wikimedia software:

  • If a single Commons template is transcluded multiple times on the same category/image because, e.g., multiple parts of the site in question are designated independently, the script can only detect the last one transcluded on the page. This is due to the limitation that a page in a category cannot have more than one sortkey (explained above), so each successive template simply overwrites the existing sortkey, making it invisible to this script. Note: This only applies to sites where a single template is transcluded multiple times; if a site is designated on two different registers marked by two different templates which include the category/image in two different categories, the script should detect each designation individually.
  • Sometimes the script will suggest an image/category when there is already one there, falsely claiming that the existing image/category does not in fact exist. For images, this is usually because the image itself is not stored on Commons but on the local language's Wikipedia. Choosing to add a matched/suggested image in this case will replace the existing image with the one on Commons. For categories, this means that the commonscat previously specified in the template cannot be found on Commons (likely a typo in the row template?). Choosing a matched/suggested category will replace the existing one.
  • The code tries hard to preserve the original formatting of the wikicode for the row template. If the row template is found to have each parameter on its own newline, the script will add a new line for the image/commonscat parameter; if the wikicode does not include newlines but rather just one big block of code, the script will add the parameter inline without forcing a linebreak. That said, the script is not so good at preserving spacing and other aesthetic formatting. Many times editors like to include spaces between parameter names and the equals sign (=) or pipes (|) for other parameters so the wikicode is more readable. This script is not intelligent enough (yet) to known how many spaces are needed to preserve this formatting, but small improvements are always being made. For now, it may be in the user's best interest to manually review the wikicode after using the script to preserve any spacing and avoid angering other editors.

If any errors or undesired behaviors apart from those listed above are encountered while using this script, please direct questions to User:Dudemanfellabra, the script's creator.