Wikipedia:WikiProject Orphanage/Orphaned Articles/How to update

Apart from "manual" updating of the Orphaned Articles list, the automatic routine described on this page can be used.


 * 1) Use at your own risk, no warranty implied or given
 * 2) Please debug/improve the query.

DROP TABLE IF EXISTS temp_deorphan;

CREATE TABLE `temp_deorphan` ( `l_from` int(8) unsigned NOT NULL default '0',  `l_to` int(8) unsigned NOT NULL default '0',  KEY `l_from` (`l_from`),  KEY `l_to` (`l_to`) ) TYPE=MyISAM;
 * 1)  Define as the links table, droping some keys

INSERT INTO temp_deorphan SELECT l_from, l_to FROM links LIMIT 10000000;
 * 1) This is slow .. links has over 6 mio entries

DELETE FROM temp_deorphan USING temp_deorphan, cur WHERE l_from = cur_id AND (cur_namespace <>0   #links from namespaces other than the article namespace.      OR cur_is_redirect=1);          #links from redirects
 * 1) Remove links that don't de-orphan pages
 * 2) This version does two in one
 * 3)    1.1 millon rows

DROP TABLE IF EXISTS temp_disambigid;
 * 1) find cur_id of disambig marker (Template:Disambig)

CREATE TABLE temp_disambigid SELECT cur_id AS d_id FROM cur WHERE (cur_title = 'Disambig') AND cur_namespace=10;  #     10 = Template namespace

DELETE FROM temp_deorphan USING temp_disambigid AS id, links AS l, temp_deorphan AS d WHERE l.l_to = id.d_id AND l.l_from=d.l_from;
 * 1) links from disambiguation pages are not included
 * 2) i.e. a page linked only from a disambiguation page is an orphan
 * 3) approx. 100000 rows

INSERT INTO temp_deorphan SELECT DISTINCT 999999, l_from FROM links, temp_disambigid WHERE d_id = l_to LIMIT 20000;
 * 1) This avoids that disambiguation pages show up as orphans

DROP TABLE IF EXISTS temp_orphans; CREATE TABLE temp_orphans SELECT cur_id FROM cur LEFT JOIN temp_deorphan ON cur_id=l_to WHERE l_to IS NULL AND cur_namespace=0 AND cur_is_redirect=0 LIMIT 20000;
 * 1) Adds a temporary table with the orphans
 * 2) 12000 rows

SELECT CONCAT('#', REPLACE (cur_title, '_', ' '), '') AS orphanslist INTO OUTFILE 'wp:\wp_orphanend_articles.txt' #set this to path you need FROM cur, temp_orphans WHERE temp_orphans.cur_id = cur.cur_id AND NOT (cur_title LIKE '%(CDP)%'       OR cur_title LIKE '%(town)%'         OR cur_title LIKE '%(city)%'         OR cur_title LIKE '%(village)%'         OR cur_title LIKE '%Township%') ORDER BY Lower(cur_title) LIMIT 20000;
 * 1) Output from list (filtering some 600 rambot orphans)

Note: these queries are slow.