This query is marked as a draft This query has been published by Achim55.

SQL

AخA
 
USE commonswiki_p;
(SELECT CONCAT ('[[Category:', REPLACE (page_title,'_',' '), ']]') AS touchlist
FROM page
INNER JOIN categorylinks ON cl_from = page_id
WHERE page_namespace = 14
AND page_is_redirect = 0
AND page_title NOT IN  ('Author_disambiguation',
                        'Files_moved_from_de.wikipedia_to_Commons_requiring_review_-_No_timestamp_given',
                        'Non-empty_disambiguation_categories',
                        'Tagged_ambiguous')
AND page_title NOT LIKE 'Undelete_in%'
AND page_title NOT LIKE 'Disambiguation_%'
AND page_title NOT LIKE 'Media_needing_categories_as_of%'
AND
(
 (cl_to = 'Disambiguation'                                     #cats from here
  AND EXISTS (SELECT 1 FROM categorylinks                      #which are not empty
              WHERE cl_to = page_title)
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #and are not yet listed...
                  WHERE cl_from = page_id
                  AND cl_to = 'Non-empty_disambiguation_categories') #...here
 )
 OR
 (cl_to = 'Non-empty_disambiguation_categories'                #or cats from here
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
 )
 OR
 (cl_to = 'Non-empty_category_redirects'                       #or cats from here
  AND page_title NOT REGEXP '^[0-9]'                           #temp for caching prob in 2019-12
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
 )
/* OR #obsolete
 (cl_to = 'Images_from_the_Geograph_British_Isles_project_needing_categories_by_grid_square' #or cats from here
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #and are not yet listed...
                  WHERE cl_from = page_id
                  AND cl_to = 'Other_speedy_deletions')        #...here
  AND EXISTS (SELECT 1 FROM templatelinks                      #and are...
              INNER JOIN linktarget ON tl_target_id = lt_id
              WHERE tl_from = page_id
              AND lt_namespace = 2
              AND lt_title = 'Avicennasis/emptycat')           #...transcluded tagged speedy
 )*/
 OR
 (cl_to = 'Files_moved_from_de.wikipedia_to_Commons_requiring_review' #or cats from here
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #and are not yet listed...
                  WHERE cl_from = page_id
                  AND cl_to = 'Other_speedy_deletions')        #...here
  AND EXISTS (SELECT 1 FROM templatelinks                      #and are...
              INNER JOIN linktarget ON tl_target_id = lt_id
              WHERE tl_from = page_id
              AND lt_namespace = 10
              AND lt_title = 'BotMoveToCommonsHeader')         #...transcluded tagged speedy
 )
 OR
 (cl_to = 'OTRS_pending'                                       #or cats from here
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #and are not yet listed...
                  WHERE cl_from = page_id
                  AND cl_to = 'Other_speedy_deletions')        #...here
  AND EXISTS (SELECT 1 FROM templatelinks                      #and are...
              INNER JOIN linktarget ON tl_target_id = lt_id
              WHERE tl_from = page_id
              AND lt_namespace = 10
              AND lt_title = 'OTRS_pending_header')            #...transcluded tagged speedy
 )
/* OR #obsolete
 (cl_to IN 'Media_needing_categories_in_use_in_galleries'      #or cats from here
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #and are not yet listed...
                  WHERE cl_from = page_id
                  AND cl_to = 'Other_speedy_deletions')        #...here
  AND EXISTS (SELECT 1 FROM templatelinks                      #and are...
              INNER JOIN linktarget ON tl_target_id = lt_id
              WHERE tl_from = page_id
              AND lt_namespace = 10
              AND lt_title = 'UncategorizedHeader')            #...transcluded tagged speedy
 )*/
 OR
 (cl_to = 'Media_needing_categories_requiring_human_attention' #or cats from here
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #which are already empty
                  WHERE cl_to = page_title)
  AND NOT EXISTS (SELECT 1 FROM categorylinks                  #and are not yet listed...
                  WHERE cl_from = page_id
                  AND cl_to = 'Other_speedy_deletions')        #...here
 )
 OR cl_to = 'Cfd_requests_with_missing_discussion_page'        #or all cats from here precautionary
 OR cl_to = 'Broken category redirects'                        #or all cats from here precautionary
# OR cl_to = "ASI_monuments_with_known_ID's"                    #single run for moved cat
# OR cl_to = 'Category_pages_with_broken_file_links'            #single run after template change
# OR cl_to = 'Q18075656_(given_name)'                           #single run after error on wikidata
# OR cl_to = 'Q1171311_(given_name)'                            #single run after error on wikidata
# OR page_title LIKE '2019–20 coronavirus%'                     #single run after change of naming scheme
)
GROUP BY page_title
)
UNION #broken cat redirects that don't show up in Category:Broken category redirects
(SELECT CONCAT ('[[Category:', REPLACE (page_title,'_',' '), ']]') AS touchlist
FROM page
INNER JOIN templatelinks ON tl_from = page_id
INNER JOIN linktarget ON tl_target_id = lt_id AND lt_namespace = 10 AND lt_title = 'Category_redirect'
INNER JOIN pagelinks ON pl_from = page_id AND pl_from_namespace = 14 AND pl_namespace = 14
WHERE page_namespace = 14
AND (SELECT COUNT(*) FROM pagelinks pl2 WHERE pl2.pl_from = page_id AND pl2.pl_from_namespace = 14 AND pl2.pl_namespace = 14) = 1
AND NOT EXISTS (SELECT 1 FROM page p2 WHERE p2.page_namespace = 14 AND p2.page_title = pl_title)
)
LIMIT 1000;
By running queries you agree to the Cloud Services Terms of Use and you irrevocably agree to release your SQL under CC0 License.
All SQL code is licensed under CC0 License.

Checking query status...