You are browsing a read-only backup copy of Wikitech. The primary site can be found at wikitech.wikimedia.org

Nova Resource:Tools.tsreports/Converting queries

From Wikitech-static
Jump to navigation Jump to search

Converting TSReports queries to Quarry, in 7 steps:

  1. Open the TSReports page you want to convert. This example will use https://tools.wmflabs.org/tsreports/?wiki=nlwiki&report=mostlinked (Most linked-to pages - https://nl.wikipedia.org)
  2. In the git repository, open the report template with the same name, which you can find in the URL: report=mostlinked. Copy the content between %query and %end. In this case:
    SELECT pl_namespace, pl_title, COUNT(*) AS nlinks
    	FROM pagelinks
    	GROUP BY pl_namespace, pl_title
    	ORDER BY nlinks DESC LIMIT 1000
    
  3. Open Quarry and log in with your Wikimedia username.
  4. Click on 'New Query'
  5. In the SQL field, type use <wiki>_p; , where wiki comes from the URL: wiki=nlwiki. On the next line, copy in the query. In this case:
    use nlwiki_p;
    SELECT pl_namespace, pl_title, COUNT(*) AS nlinks
    	FROM pagelinks
    	GROUP BY pl_namespace, pl_title
    	ORDER BY nlinks DESC LIMIT 1000
    
  6. Click 'Submit query'
  7. After some time, the result of the query will appear.


Bonus: creating wikilinks from namespace and title. Rewrite the above to read

CONCAT('[[{{ns:', pl_namespace, '}}:', pl_title, ']]') as pagelink

The wikitable export will now generate clickable wikilinks.