Vikipedija:Alternatyvios statistikos pusiau rankinė įranga/MySQL/process

Puslapis iš Vikipedijos, laisvosios enciklopedijos.
DELIMITER $$

DROP PROCEDURE IF EXISTS `wiki1`.`vikiprocess` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vikiprocess`(uz varchar(255), vlst1 varchar(255),  vlst1os varchar(255), vlst2 varchar(255),  vlst2os varchar(255))
BEGIN
DECLARE kiek INT;

SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
-- šablonai

DROP TABLE IF EXISTS templates;
create table templates (
        templ_id int(10) unsigned NOT NULL default '0',
        templ_title varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
        templ_namespace integer  NOT NULL default 0,
        PRIMARY KEY  (templ_id),
        unique key `templ_title` (templ_title, templ_namespace) ) as
select distinct p.page_id as templ_id, tl.tl_title as templ_title, tl.tl_namespace as templ_namespace
from page p
join templatelinks tl on (p.page_title = tl.tl_title and p.page_namespace = tl.tl_namespace)
;

DROP TABLE IF EXISTS templatepagelinks;
create table templatepagelinks (
        pl_from int(10) unsigned NOT NULL default '0',
        pl_title varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
        pl_namespace integer  NOT NULL default 0,
        PRIMARY KEY  (pl_from, pl_title, pl_namespace),
        index `pl_title` (pl_title, pl_namespace) ) as
select distinct pl.pl_from, pl.pl_title, pl.pl_namespace
from templates p
join pagelinks pl on (p.templ_id = pl.pl_from)
;

-- Kategoriju medis

DROP TABLE IF EXISTS categorytree;
create table categorytree (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Kita',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_tree` (cat_tree) ) as
select c.cat_id `cat_id`, p.page_id `cat_pid`, p.page_title `cat_title`, 'Nekategorizuota' `cat_parent`, 'Kita' cat_tree
from category c
join page p on (p.page_title = c.cat_title and p.page_namespace=14)
where not exists (
  select 1 from categorylinks cl
  where cl.cl_from = p.page_id
);

insert into categorytree (cat_id, cat_pid, cat_title, cat_parent, cat_tree)
select distinct c.cat_id `cat_id`, p.page_id `cat_pid`, p.page_title `cat_title`, cp.page_title `cat_parent`, 'Kita' cat_tree
from category c
join page p on (p.page_title = c.cat_title and p.page_namespace=14)
join categorylinks cl on (cl.cl_from = p.page_id)
join page cp on (cl.cl_to = cp.page_title and cp.page_namespace=14);

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Vikipedija')
set cat_soft_parent = 1;

-- Vikipedijos kategorijos

DROP TABLE IF EXISTS vikipedija;
create table vikipedija (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Vikipedija',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       if(c.cat_title = 'Kandidatai_skubiai_trinti', 1, 0) cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Vikipedija' cat_tree
from categorytree c
where c.cat_title in ('Vikipedija', 'Kandidatai_skubiai_trinti');

-- kartoti kol nebeiterpia
label1: LOOP
  insert ignore into vikipedija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
  select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita'), c.cat_soft_parent, 2) cat_soft_parent,
       if(c.cat_title = 'Nepilni', 1, v.cat_soft_1) cat_soft_1,
       if(c.cat_title = 'Nesutvarkyti_straipsniai', 1, v.cat_soft_2) cat_soft_2,
       if(c.cat_title = 'Nebaigti-terminai', 1, v.cat_soft_3) cat_soft_3,
       if(c.cat_title = 'Nepilni_(Lietuvos_gyvenvietės)', 1, v.cat_soft_4) cat_soft_4,
       if(c.cat_title = 'Beviltiški', 1, v.cat_soft_5) cat_soft_5,
       if(c.cat_title = 'Kandidatai_jungti', 1, v.cat_soft_6) cat_soft_6,
       if(c.cat_title = 'Kandidatai_skaidyti', 1, v.cat_soft_7) cat_soft_7,
       if(c.cat_title = 'Tušti_straipsniai', 1, v.cat_soft_8) cat_soft_8,
       if(c.cat_title = 'Kandidatai_skubiai_trinti', 1, v.cat_soft_9) cat_soft_9,
       if(c.cat_title = 'Kandidatai_trinti', 1, v.cat_soft_10) cat_soft_10,
       if(c.cat_title = 'Nuorodiniai_straipsniai', 1, v.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Vikipedija', c.cat_tree) cat_tree
  from categorytree c
  join vikipedija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
  where not exists (
    select 1 from vikipedija nv
    where nv.cat_id = c.cat_id
    and   nv.cat_parent = c.cat_parent
  );

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE label1; END IF;
END LOOP label1;

update categorytree c
join vikipedija v on (v.cat_id = c.cat_id and v.cat_tree = 'Vikipedija')
set c.cat_tree = 'Vikipedija';

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Vikipedija|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM vikipedija g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'Vikipedijos kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

-- straipsnių požymiai

DROP TABLE IF EXISTS vikipedija_page;
create table vikipedija_page (
        p_id int(10) unsigned NOT NULL default '0',
        p_title varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
        p_soft_1 TINYINT(1)  NOT NULL default 0,
        p_soft_2 TINYINT(1)  NOT NULL default 0,
        p_soft_3 TINYINT(1)  NOT NULL default 0,
        p_soft_4 TINYINT(1)  NOT NULL default 0,
        p_soft_5 TINYINT(1)  NOT NULL default 0,
        p_soft_6 TINYINT(1)  NOT NULL default 0,
        p_soft_7 TINYINT(1)  NOT NULL default 0,
        p_soft_8 TINYINT(1)  NOT NULL default 0,
        p_soft_9 TINYINT(1)  NOT NULL default 0,
        p_soft_10 TINYINT(1)  NOT NULL default 0,
        p_soft_11 TINYINT(1)  NOT NULL default 0,
        p_is_redirect TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
        PRIMARY KEY  (p_id),
        unique key `p_title` (p_title) );

insert into vikipedija_page (p_id, p_title)
select p.page_id as p_id, p.page_title as p_title
from page p
where p.page_namespace=0;

update vikipedija_page p
set p_soft_1 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_1 = 1
);

update vikipedija_page p
set p_soft_2 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_2 = 1
);

update vikipedija_page p
set p_soft_3 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_3 = 1
);

update vikipedija_page p
set p_soft_4 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_4 = 1
);

update vikipedija_page p
set p_soft_5 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_5 = 1
);

update vikipedija_page p
set p_soft_6 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_6 = 1
);

update vikipedija_page p
set p_soft_7 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_7 = 1
);

update vikipedija_page p
set p_soft_8 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_8 = 1
);

update vikipedija_page p
set p_soft_9 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_9 = 1
);

update vikipedija_page p
set p_soft_10 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_10 = 1
);

update vikipedija_page p
set p_soft_11 = 1
where exists (
  select 1
  from categorylinks cl
  join vikipedija v on (v.cat_title = cl.cl_to)
  where cl.cl_from = p.p_id
  and v.cat_soft_11 = 1
);

update vikipedija_page p
set p_is_redirect = 1
where exists (
  select 1
  from page pp
  where pp.page_id = p.p_id
  and pp.page_is_redirect = 1
);

-- [[Vikipedija:Trokštamiausi nesukurti straipsniai (silpni ryšiai)]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių (skaičiuojant ir nuorodas šablonuose). (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'''''Taip pat žiūrėkite:''''' from dual
union select _utf8'* [[Vikipedija:Trokštamiausi nesukurti straipsniai|Nepradėti kurti straipsniai]], nepradėti kurti straipsniai, į kuriuos tiesiogiai rodo daugiausiai straipsnių.' from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']] ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select p.pl_title AS pl_title,count(1) AS kiekis
  from pagelinks p
  where not exists (
    select 1
    from vikipedija_page pg
    where p.pl_title = pg.p_title
  )
  and p.pl_namespace = 0
  group by p.pl_title
) a
where (a.kiekis > 10)
order by a.kiekis desc, a.pl_title
limit 1000
) b
INTO OUTFILE 'Trokstami silpni rysiai straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

-- [[Vikipedija:Trokštamiausi nesukurti straipsniai]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'''''Taip pat žiūrėkite:''''' from dual
union select _utf8'* [[Vikipedija:Trokštamiausi nesukurti straipsniai (silpni ryšiai)|Nepradėti kurti straipsniai]], į kuriuos tiesiogiai rodo daugiausiai straipsnių (skaičiuojant ir nuorodas iš šablonų).' from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']] ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select p.pl_title AS pl_title,count(1) AS kiekis
  from pagelinks p
  where p.pl_namespace = 0
  and not exists (
    select 1
    from vikipedija_page pg
    where p.pl_title = pg.p_title
  )
  and not exists (
    select 1
    from vikipedija_page cl
    where p.pl_from = cl.p_id
    and   cl.p_soft_8 = 1
  )
  and not exists(
    select 1 from templatelinks tl
    where p.pl_from = tl.tl_from
    and exists(
      select 1 from templates t
      where tl.tl_namespace = t.templ_namespace
      and tl.tl_title = t.templ_title
      and exists(
        select 1 from templatepagelinks tpl2
        where t.templ_id = tpl2.pl_from
        and tpl2.pl_namespace = 0
        and tpl2.pl_title = p.pl_title
      )
    )
  )
  and not exists (
    select 1 from templatepagelinks tpl
    where p.pl_from = tpl.pl_from
    and tpl.pl_namespace = p.pl_namespace
    and tpl.pl_title = p.pl_title
  )
  group by p.pl_title
) a
where (a.kiekis > 10)
order by a.kiekis desc, a.pl_title
limit 1000
) b
INTO OUTFILE 'Trokstami straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Įvykiai')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS ivykiai;
create table ivykiai (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Įvykiai',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Įvykiai' cat_tree
from categorytree c
where c.cat_title in ('Įvykiai');

-- kartoti kol nebeiterpia
labelivykiai: LOOP
insert ignore into ivykiai (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Įvykiai', c.cat_tree) cat_tree
from categorytree c
join ivykiai v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from ivykiai nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelivykiai; END IF;
END LOOP labelivykiai;

update categorytree c
join ivykiai v on (v.cat_id = c.cat_id and v.cat_tree = 'Įvykiai')
set c.cat_tree = 'Įvykiai';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Įvykiai')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Įvykiai|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM ivykiai g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'ivykiai kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš įvykių straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join ivykiai g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'ivykiai trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Biografijos')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS biografijos;
create table biografijos (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Biografijos',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Biografijos' cat_tree
from categorytree c
where c.cat_title in ('Biografijos');

-- kartoti kol nebeiterpia
labelBiografijos: LOOP
insert ignore into biografijos (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Įvykiai'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Biografijos', c.cat_tree) cat_tree
from categorytree c
join biografijos v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from biografijos nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelBiografijos; END IF;
END LOOP labelBiografijos;

update categorytree c
join biografijos v on (v.cat_id = c.cat_id and v.cat_tree = 'Biografijos')
set c.cat_tree = 'Biografijos';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Biografijos')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Biografijos|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM biografijos g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'biografijos kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš biografinių straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join biografijos g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'biografijos trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Lietuva')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS lietuva;
create table lietuva (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Lietuva',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Lietuva' cat_tree
from categorytree c
where c.cat_title in ('Lietuva');

-- kartoti kol nebeiterpia
labelLietuva: LOOP
insert ignore into lietuva (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Įvykiai'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Lietuva', c.cat_tree) cat_tree
from categorytree c
join lietuva v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from lietuva nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelLietuva; END IF;
END LOOP labelLietuva;

update categorytree c
join lietuva v on (v.cat_id = c.cat_id and v.cat_tree = 'Lietuva')
set c.cat_tree = 'Lietuva';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Lietuva')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Lietuva|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM lietuva g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'lietuva kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš straipsnių, susijusių su Lietuva. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join lietuva g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'lietuva trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Mitologija')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS mitologija;
create table mitologija (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Mitologija',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Mitologija' cat_tree
from categorytree c
where c.cat_title in ('Mitologija');

-- kartoti kol nebeiterpia
labelMitologija: LOOP
insert ignore into mitologija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Lietuva'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Mitologija', c.cat_tree) cat_tree
from categorytree c
join mitologija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from mitologija nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelMitologija; END IF;
END LOOP labelMitologija;

update categorytree c
join mitologija v on (v.cat_id = c.cat_id and v.cat_tree = 'Mitologija')
set c.cat_tree = 'Mitologija';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Mitologija')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Mitologija|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM mitologija g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'mitologija kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš mitologijos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join mitologija g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'mitologija trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Sportas')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS sportas;
create table sportas (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Sportas',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Sportas' cat_tree
from categorytree c
where c.cat_title in ('Sportas');

-- kartoti kol nebeiterpia
labelSportas: LOOP
insert ignore into sportas (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva', 'Įvykiai'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Sportas',
       if(c.cat_tree in ('Lietuva'), 'Lietuvos sportas', c.cat_tree)) cat_tree
from categorytree c
join sportas v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from sportas nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelSportas; END IF;
END LOOP labelSportas;

update categorytree c
join sportas v on (v.cat_id = c.cat_id and v.cat_tree = 'Sportas')
set c.cat_tree = 'Sportas';

update categorytree c
join sportas v on (v.cat_id = c.cat_id and v.cat_tree = 'Lietuvos sportas')
set c.cat_tree = 'Lietuvos sportas';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Sportas')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Sportas|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM sportas g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'sportas kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš sporto straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join sportas g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'sportas trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Botanika')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS botanika;
create table botanika (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Botanika',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Botanika' cat_tree
from categorytree c
where c.cat_title in ('Botanika');

-- kartoti kol nebeiterpia
labelBotanika: LOOP
insert ignore into botanika (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Botanika', c.cat_tree) cat_tree
from categorytree c
join botanika v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from botanika nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelBotanika; END IF;
END LOOP labelBotanika;

update categorytree c
join botanika v on (v.cat_id = c.cat_id and v.cat_tree = 'Botanika')
set c.cat_tree = 'Botanika';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Botanika')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Botanika|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM botanika g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'botanika kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš botanikos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join botanika g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'botanika trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Biologija')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS biologija;
create table biologija (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Biologija',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Biologija' cat_tree
from categorytree c
where c.cat_title in ('Biologija');

-- kartoti kol nebeiterpia
labelBiologija: LOOP
insert ignore into biologija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva', 'Botanika'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Biologija', c.cat_tree) cat_tree
from categorytree c
join biologija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from biologija nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelBiologija; END IF;
END LOOP labelBiologija;

update categorytree c
join biologija v on (v.cat_id = c.cat_id and v.cat_tree = 'Biologija')
set c.cat_tree = 'Biologija';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Biologija')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Biologija|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM biologija g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'biologija kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš biologijos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join biologija g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'biologija trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Teisės_mokslai')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS teisesmokslai;
create table teisesmokslai (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Teisės_mokslai',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Teisės_mokslai' cat_tree
from categorytree c
where c.cat_title in ('Teisės_mokslai');

-- kartoti kol nebeiterpia
labelTeises: LOOP
insert ignore into teisesmokslai (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Teisės_mokslai', c.cat_tree) cat_tree
from categorytree c
join teisesmokslai v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from teisesmokslai nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelTeises; END IF;
END LOOP labelTeises;

update categorytree c
join teisesmokslai v on (v.cat_id = c.cat_id and v.cat_tree = 'Teisės_mokslai')
set c.cat_tree = 'Teisės_mokslai';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Teisės_mokslai')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Teisės mokslai|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM teisesmokslai g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'teisesmokslai kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš teisės mokslų straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join teisesmokslai g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'teisesmokslai trokstami.csv'
LINES TERMINATED BY '\r\n'
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas teisės straipsnių, į kuriuos yra daugiausia nuorodų. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all),
       _utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
left join vikipedija_tpage_refs vtpr on (vp.p_title = vtpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) > 1
and vpr.page_links_all > vpr.page_links_tusti+if(vtpr.page_links_all is null,0,vtpr.page_links_all)
and exists (
      select 1
      from categorylinks cl
      join teisesmokslai g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
order by vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Svarbiausi teisesmokslai straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

-- [[Vikipedija:Trokštamiausi nebaigti]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nebaigtų teisės straipsnių, į kuriuos yra daugiausia nuorodų. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all),
       _utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
left join vikipedija_tpage_refs vtpr on (vp.p_title = vtpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) > 1
and vpr.page_links_all > vpr.page_links_tusti+if(vtpr.page_links_all is null,0,vtpr.page_links_all)
and (
  vp.p_soft_1 = 1 or
  vp.p_soft_2 = 1 or
  vp.p_soft_3 = 1 or
  vp.p_soft_4 = 1 or
  vp.p_soft_5 = 1 or
  vp.p_soft_6 = 1 or
  vp.p_soft_7 = 1 or
  vp.p_soft_8 = 1 or
  vp.p_soft_9 = 1 or
  vp.p_soft_10 = 1
)
and exists (
      select 1
      from categorylinks cl
      join teisesmokslai g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
order by vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Trokstamiausi nebaigti teisesmokslai straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Politologija')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS politologija;
create table politologija (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Politologija',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Politologija' cat_tree
from categorytree c
where c.cat_title in ('Politologija');

-- kartoti kol nebeiterpia
labelPolitologija: LOOP
insert ignore into politologija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Politologija', c.cat_tree) cat_tree
from categorytree c
join politologija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from politologija nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelPolitologija; END IF;
END LOOP labelPolitologija;

update categorytree c
join politologija v on (v.cat_id = c.cat_id and v.cat_tree = 'Politologija')
set c.cat_tree = 'Politologija';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Politologija')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Politologija|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM politologija g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'politologija kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš politologijos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join politologija g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'politologija trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Paveldas')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS paveldas;
create table paveldas (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Paveldas',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Paveldas' cat_tree
from categorytree c
where c.cat_title in ('Paveldas');

-- kartoti kol nebeiterpia
labelPaveldas: LOOP
insert ignore into paveldas (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Paveldas', c.cat_tree) cat_tree
from categorytree c
join paveldas v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from paveldas nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelPaveldas; END IF;
END LOOP labelPaveldas;

update categorytree c
join paveldas v on (v.cat_id = c.cat_id and v.cat_tree = 'Paveldas')
set c.cat_tree = 'Paveldas';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Paveldas')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Paveldas|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM paveldas g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'paveldas kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš paveldo straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join paveldas g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'paveldas trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Pedagogika')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS pedagogika;
create table pedagogika (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Pedagogika',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Pedagogika' cat_tree
from categorytree c
where c.cat_title in ('Pedagogika');

-- kartoti kol nebeiterpia
labelPedagogika: LOOP
insert ignore into pedagogika (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Pedagogika',
       if(c.cat_tree in ('Lietuva'), 'Lietuvos švietimas', c.cat_tree)) cat_tree
from categorytree c
join pedagogika v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from pedagogika nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelPedagogika; END IF;
END LOOP labelPedagogika;

update categorytree c
join pedagogika v on (v.cat_id = c.cat_id and v.cat_tree = 'Pedagogika')
set c.cat_tree = 'Pedagogika';

update categorytree c
join pedagogika v on (v.cat_id = c.cat_id and v.cat_tree = 'Lietuvos švietimas')
set c.cat_tree = 'Lietuvos švietimas';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Pedagogika')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Pedagogika|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM pedagogika g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'pedagogika kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš pedagogikos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join pedagogika g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'pedagogika trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Religijotyra')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS religijotyra;
create table religijotyra (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Religijotyra',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Religijotyra' cat_tree
from categorytree c
where c.cat_title in ('Religijotyra');

-- kartoti kol nebeiterpia
labelReligijotyra: LOOP
insert ignore into religijotyra (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva', 'Pedagogika'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Religijotyra',
       if(c.cat_tree in ('Lietuva'), 'Lietuvos religija', c.cat_tree)) cat_tree
from categorytree c
join religijotyra v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from religijotyra nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelReligijotyra; END IF;
END LOOP labelReligijotyra;

update categorytree c
join religijotyra v on (v.cat_id = c.cat_id and v.cat_tree = 'Religijotyra')
set c.cat_tree = 'Religijotyra';

update categorytree c
join religijotyra v on (v.cat_id = c.cat_id and v.cat_tree = 'Lietuvos religija')
set c.cat_tree = 'Lietuvos religija';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Religijotyra')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Religijotyra|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM religijotyra g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'religijotyra kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš religijotyros straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join religijotyra g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'religijotyra trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Kultūra')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS kultura;
create table kultura (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Kultūra',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Kultūra' cat_tree
from categorytree c
where c.cat_title in ('Kultūra');

-- kartoti kol nebeiterpia
labelKultura: LOOP
insert ignore into kultura (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva', 'Paveldas', 'Įvykiai'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Kultūra', c.cat_tree) cat_tree
from categorytree c
join kultura v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from kultura nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelKultura; END IF;
END LOOP labelKultura;

update categorytree c
join kultura v on (v.cat_id = c.cat_id and v.cat_tree = 'Kultūra')
set c.cat_tree = 'Kultūra';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Kultūra')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Kultūra|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM kultura g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'kultura kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš kultūros straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join kultura g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'kultura trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Istorija')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS istorija;
create table istorija (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Istorija',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Istorija' cat_tree
from categorytree c
where c.cat_title in ('Istorija');

-- kartoti kol nebeiterpia
labelIstorija: LOOP
insert ignore into istorija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva', 'Paveldas', 'Įvykiai'),
          c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Istorija', c.cat_tree) cat_tree
from categorytree c
join istorija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from istorija nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelIstorija; END IF;
END LOOP labelIstorija;

update categorytree c
join istorija v on (v.cat_id = c.cat_id and v.cat_tree = 'Istorija' and v.cat_soft_parent = 0)
set c.cat_tree = 'Istorija';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Istorija')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Istorija|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM istorija g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'istorija kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš istorijos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join istorija g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'istorija trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Geografija')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS geografija;
create table geografija (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Geografija',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Geografija' cat_tree
from categorytree c
where c.cat_title in ('Geografija');

-- kartoti kol nebeiterpia
labelGeografija: LOOP
insert ignore into geografija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Lietuva', 'Paveldas'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Geografija', c.cat_tree) cat_tree
from categorytree c
join geografija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from geografija nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelGeografija; END IF;
END LOOP labelGeografija;

update geografija v
set v.cat_soft_parent = 0
where v.cat_title = 'Geografai';

-- kartoti kol nebeiterpia
labelGeografija2: LOOP
insert ignore into geografija (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita', 'Vikipedija', 'Biografijos', 'Lietuva', 'Paveldas'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Geografija', c.cat_tree) cat_tree
from categorytree c
join geografija v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from geografija nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelGeografija2; END IF;
END LOOP labelGeografija2;

update categorytree c
join geografija v on (v.cat_id = c.cat_id and v.cat_tree = 'Geografija')
set c.cat_tree = 'Geografija';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Geografija')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Geografija|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM geografija g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'geografija kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš geografijos straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join geografija g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'geografija trokstami.csv'
LINES TERMINATED BY '\r\n'
;

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Kita')
set cat_soft_parent = 1;

DROP TABLE IF EXISTS kita;
create table kita (
        cat_id int(10) unsigned NOT NULL default '0',
        cat_pid int(10) unsigned NOT NULL default '0',
        cat_title varchar(255)  NOT NULL default '',
        cat_parent varchar(255)  NOT NULL default '',
        cat_soft_parent TINYINT(1)  NOT NULL default 0,
        cat_soft_1 TINYINT(1)  NOT NULL default 0,
        cat_soft_2 TINYINT(1)  NOT NULL default 0,
        cat_soft_3 TINYINT(1)  NOT NULL default 0,
        cat_soft_4 TINYINT(1)  NOT NULL default 0,
        cat_soft_5 TINYINT(1)  NOT NULL default 0,
        cat_soft_6 TINYINT(1)  NOT NULL default 0,
        cat_soft_7 TINYINT(1)  NOT NULL default 0,
        cat_soft_8 TINYINT(1)  NOT NULL default 0,
        cat_soft_9 TINYINT(1)  NOT NULL default 0,
        cat_soft_10 TINYINT(1)  NOT NULL default 0,
        cat_soft_11 TINYINT(1)  NOT NULL default 0,
        cat_tree varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Kita',
        PRIMARY KEY  (cat_id, cat_parent),
        UNIQUE KEY `cat_pid` (cat_pid, cat_parent),
        UNIQUE KEY `cat_title` (cat_title, cat_parent),
        INDEX `cat_parent` (cat_parent),
        INDEX `cat_soft` (cat_soft_1,cat_soft_2,cat_soft_3,cat_soft_4,cat_soft_5,
                          cat_soft_6,cat_soft_7,cat_soft_8,cat_soft_9,cat_soft_10,cat_soft_11),
        INDEX `cat_tree` (cat_tree) ) as
select cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
       0 cat_soft_1,0 cat_soft_2,0 cat_soft_3,0 cat_soft_4,0 cat_soft_5,0 cat_soft_6,0 cat_soft_7,0 cat_soft_8,
       0 cat_soft_9, 0 cat_soft_10, 0 cat_soft_11, 'Kita' cat_tree
from categorytree c
where c.cat_title in ('Kategorijos');

-- kartoti kol nebeiterpia
labelKita: LOOP
insert ignore into kita (cat_id, cat_pid, cat_title, cat_parent, cat_soft_parent,
                               cat_soft_1, cat_soft_2, cat_soft_3, cat_soft_4, cat_soft_5,
                               cat_soft_6, cat_soft_7, cat_soft_8, cat_soft_9, cat_soft_10,
                               cat_soft_11, cat_tree)
select c.cat_id, c.cat_pid, c.cat_title, c.cat_parent,
       if(c.cat_tree in ('Kita'), c.cat_soft_parent, 2) cat_soft_parent,
       if(vv.cat_soft_1 is null, v.cat_soft_1, vv.cat_soft_1) cat_soft_1,
       if(vv.cat_soft_2 is null, v.cat_soft_2, vv.cat_soft_2) cat_soft_2,
       if(vv.cat_soft_3 is null, v.cat_soft_3, vv.cat_soft_3) cat_soft_3,
       if(vv.cat_soft_4 is null, v.cat_soft_4, vv.cat_soft_4) cat_soft_4,
       if(vv.cat_soft_5 is null, v.cat_soft_5, vv.cat_soft_5) cat_soft_5,
       if(vv.cat_soft_6 is null, v.cat_soft_6, vv.cat_soft_6) cat_soft_6,
       if(vv.cat_soft_7 is null, v.cat_soft_7, vv.cat_soft_7) cat_soft_7,
       if(vv.cat_soft_8 is null, v.cat_soft_8, vv.cat_soft_8) cat_soft_8,
       if(vv.cat_soft_9 is null, v.cat_soft_9, vv.cat_soft_9) cat_soft_9,
       if(vv.cat_soft_10 is null, v.cat_soft_10, vv.cat_soft_10) cat_soft_10,
       if(vv.cat_soft_11 is null, v.cat_soft_11, vv.cat_soft_11) cat_soft_11,
       if(c.cat_tree in ('Kita'), 'Kita', c.cat_tree) cat_tree
from categorytree c
join kita v on (v.cat_title = c.cat_parent and v.cat_soft_parent = 0)
left join vikipedija vv on (c.cat_id = vv.cat_id)
where not exists (
  select 1 from kita nv
  where nv.cat_id = c.cat_id
  and   nv.cat_parent = c.cat_parent
);

  SELECT row_count() INTO kiek;

  IF kiek = 0 THEN LEAVE labelKita; END IF;
END LOOP labelKita;

update categorytree c
join kita v on (v.cat_id = c.cat_id and v.cat_tree = 'Kita')
set c.cat_tree = 'Kita';

update categorytree c
join wiki.softcategory sc on (c.cat_parent = sc.cat_parent and c.cat_title = sc.cat_title and sc.cat_for = 'Kita')
set cat_soft_parent = 0;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas kategorijos „[[:Kategorija:Kategorijos|]]“ pokategorijų sąrašas. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select _utf8'{| class="sortable" {{graži lentelė}}' from dual
union select _utf8'! Kategorija !! {{Ref label|Note|1|1}} !! {{Ref label|Note|2|2}} !! {{Ref label|Note|3|3}} !! {{Ref label|Note|4|4}} !! {{Ref label|Note|5|5}} !! {{Ref label|Note|6|6}} !! {{Ref label|Note|7|7}} !! {{Ref label|Note|8|8}} !! {{Ref label|Note|9|9}} !! {{Ref label|Note|10|10}} !! {{Ref label|Note|11|11}} !! {{Ref label|Note|n|n}} arba {{Ref label|Note|r|r}} !! Tėvinė kategorija !! psl.{{Ref label|Note|p|p}} !! kat.{{Ref label|Note|k|k}} !! vaizd.{{Ref label|Note|v|v}}' from dual
union select * from (
SELECT concat('|-\n| [[:Kategorija:',replace(g.cat_title,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_title,_utf8'_',_utf8' '),_utf8']]',
  if (g.cat_soft_1 = 1, ' || {{Ref label|Note|1|1}}', ' ||'),
  if (g.cat_soft_2 = 1, ' || {{Ref label|Note|2|2}}', ' ||'),
  if (g.cat_soft_3 = 1, ' || {{Ref label|Note|3|3}}', ' ||'),
  if (g.cat_soft_4 = 1, ' || {{Ref label|Note|4|4}}', ' ||'),
  if (g.cat_soft_5 = 1, ' || {{Ref label|Note|5|5}}', ' ||'),
  if (g.cat_soft_6 = 1, ' || {{Ref label|Note|6|6}}', ' ||'),
  if (g.cat_soft_7 = 1, ' || {{Ref label|Note|7|7}}', ' ||'),
  if (g.cat_soft_8 = 1, ' || {{Ref label|Note|8|8}}', ' ||'),
  if (g.cat_soft_9 = 1, ' || {{Ref label|Note|9|9}}', ' ||'),
  if (g.cat_soft_10 = 1, ' || {{Ref label|Note|10|10}}', ' ||'),
  if (g.cat_soft_11 = 1, ' || {{Ref label|Note|11|11}}', ' ||'),
  ' ||',
  if (g.cat_soft_parent = 1, ' {{Ref label|Note|n|n}}', ''),
  if (g.cat_soft_parent = 2,
     concat(' {{Ref label|Note|r|r}} [[Naudotojas:Vpovilaitis/Statistika/', g.cat_tree, '/Kategorijos|žr.]]'), ''),
  _utf8' || [[:Kategorija:',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8'|',replace(g.cat_parent,_utf8'_',_utf8' '),_utf8']]',
  _utf8' ||align=right| ', c.cat_pages-c.cat_subcats-c.cat_files,
  _utf8' ||align=right| ', c.cat_subcats,
  _utf8' ||align=right| ', c.cat_files
) AS `title`
FROM kita g
join category c on g.cat_id = c.cat_id
order by g.cat_title) a
union select _utf8'|}' from dual
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|n|n}} - Kategorijos pokategorijos neįtrauktos į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|r|r}} - Kategorija ir jos straipsniai neįtraukta į šį sąrašą.' from dual
union select _utf8'* {{Note label|Note|p|p}} - Puslapių skaičius į kurį nėra įskaičiuota pokategorijose esantys puslapiai.' from dual
union select _utf8'* {{Note label|Note|k|k}} - Kategorijų skaičius į kurį nėra įskaičiuota pokategorijose esančios kategorijos.' from dual
union select _utf8'* {{Note label|Note|v|v}} - Vaizdų skaičius į kurį nėra įskaičiuota pokategorijose esantys vaizdai.'
INTO OUTFILE 'kita kategorijos.csv'
LINES TERMINATED BY '\r\n'
from dual
;

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nepradėtų kurti (trokštamiausių) straipsnių, į kuriuos yra daugiausiai nuorodų iš kitokių straipsnių. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (select concat(_utf8'# [[',replace(a.pl_title,_utf8'_',_utf8' '),_utf8']]',
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.pl_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select b.pl_title AS pl_title, if(b.pl_title is null, 0, count(distinct b.pl_from, b.pl_title)) AS kiekis
  from (
    select distinct p.pl_title as pl_title, vp.p_id as pl_from
    from vikipedija_page vp
    join pagelinks p on (vp.p_id = p.pl_from and p.pl_namespace = 0 and vp.p_soft_8 = 0)
    where exists (
      select 1
      from categorylinks cl
      join kita g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
    and not exists (
      select 1
      from vikipedija_page pg
      where p.pl_namespace = 0
      and p.pl_title = pg.p_title
      limit 1
    )
    and not exists(
      select 1 from templatelinks tl
      where vp.p_id = tl.tl_from
      and exists(
        select 1 from templates t
        where tl.tl_namespace = t.templ_namespace
        and tl.tl_title = t.templ_title
        and exists(
          select 1 from templatepagelinks tpl2
          where t.templ_id = tpl2.pl_from
          and tpl2.pl_namespace = 0
          and tpl2.pl_title = p.pl_title
          and p.pl_namespace = 0
          limit 1
        )
        limit 1
      )
      limit 1
    )
    and not exists (
      select 1 from templatepagelinks tpl
      where p.pl_from = tpl.pl_from
      and tpl.pl_namespace = 0
      and tpl.pl_title = p.pl_title
      and p.pl_namespace = 0
      limit 1
    )
  ) b
  group by b.pl_title
) a
where a.kiekis > 1
order by a.kiekis desc, a.pl_title
limit 1000
) c
INTO OUTFILE 'kita trokstami.csv'
LINES TERMINATED BY '\r\n'
;

-- [[Vikipedija:Nekategorizuoti straipsniai]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas straipsnių, nepriskirtų jokiai kategorijai. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(a.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(a.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(a.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(a.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(a.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(a.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(a.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(a.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(a.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(a.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(a.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(a.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       ' ([[:Specialus:Whatlinkshere/',
       replace(a.p_title,_utf8'_',_utf8' '),_utf8'|',a.kiekis,_utf8' nuorodos]])') AS title
from (
  select pp.p_title, pp.p_soft_1, pp.p_soft_2, pp.p_soft_3, pp.p_soft_4, pp.p_soft_5,
         pp.p_soft_6, pp.p_soft_7, pp.p_soft_8, pp.p_soft_9, pp.p_soft_10, pp.p_soft_11,
         if(p.pl_title is null, 0, count(1)) AS kiekis
  from vikipedija_page pp
  left join pagelinks p on (p.pl_namespace = 0 and pp.p_title = p.pl_title)
  where not exists (
    select 1
    from categorylinks cl
    join categorytree ct on ct.cat_title = cl.cl_to
    where pp.p_id = cl.cl_from
    and ct.cat_title not in (
        select c.cat_title from vikipedija c
        where ct.cat_title = c.cat_title
        and (c.cat_soft_1 = 1
        or c.cat_soft_2 = 1
        or c.cat_soft_3 = 1
        or c.cat_soft_4 = 1
        or c.cat_soft_5 = 1
        or c.cat_soft_6 = 1
        or c.cat_soft_7 = 1
        or c.cat_soft_8 = 1
        or c.cat_soft_9 = 1
        or c.cat_soft_10 = 1)
    )
  )
  and pp.p_is_redirect = 0
  group by pp.p_title
  ) a
-- where (a.kiekis > 5)
order by a.kiekis desc, a.p_title
) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]'
INTO OUTFILE 'Nekategorizuoti straipsniai.csv'
LINES TERMINATED BY '\r\n'
from dual
;

DROP TABLE IF EXISTS vikipedija_page_refs;
create table vikipedija_page_refs (
        page_title varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
        page_links_all int(10) unsigned NOT NULL default '0',
        page_links_tusti int(10) unsigned NOT NULL default '0',
        PRIMARY KEY  (page_title) ) as
select pg.p_title AS page_title,
       count(distinct vp.p_id) AS page_links_all,
       sum(if(vp.p_soft_8 is null,0,vp.p_soft_8)) as page_links_tusti
from vikipedija_page pg
left join pagelinks p on (p.pl_title = pg.p_title and p.pl_namespace=0)
left join vikipedija_page vp on (vp.p_id = p.pl_from and p.pl_namespace=0)
group by pg.p_title
;

-- [[Vikipedija:Svarbiausi straipsniai (silpni ryšiai)]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas straipsnių, į kuriuos yra daugiausia nuorodų (skaičiuojant ir nuorodas šablonuose). (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti,_utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti > 10
and vpr.page_links_all > vpr.page_links_tusti
order by vpr.page_links_all-vpr.page_links_tusti desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Svarbiausi silpni rysiai straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

-- [[Vikipedija:Trokštamiausi nebaigti (silpni ryšiai)]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nebaigtų straipsnių, į kuriuos yra daugiausia nuorodų (skaičiuojant ir nuorodas iš šablonų). (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti,_utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti > 10
and vpr.page_links_all > vpr.page_links_tusti
and (
  vp.p_soft_1 = 1 or
  vp.p_soft_2 = 1 or
  vp.p_soft_3 = 1 or
  vp.p_soft_4 = 1 or
  vp.p_soft_5 = 1 or
  vp.p_soft_6 = 1 or
  vp.p_soft_7 = 1 or
  vp.p_soft_8 = 1 or
  vp.p_soft_9 = 1 or
  vp.p_soft_10 = 1
)
order by vpr.page_links_all-vpr.page_links_tusti desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Trokstamiausi nebaigti silpni rysiai straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

DROP TABLE IF EXISTS vikipedija_tpage_refs;
create table vikipedija_tpage_refs (
        page_title varchar(255) BINARY CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
        page_links_all int(10) unsigned NOT NULL default '0',
        PRIMARY KEY  (page_title) ) as
select pg.p_title AS page_title,
       count(distinct p.pl_from) AS page_links_all
from vikipedija_page pg
left join pagelinks p on (p.pl_title = pg.p_title and p.pl_namespace=0)
left join templatelinks tl on (tl.tl_from = p.pl_from and p.pl_namespace=0)
where exists(
      select 1 from templates t
      where tl.tl_namespace = t.templ_namespace
      and tl.tl_title = t.templ_title
      and exists(
        select 1 from templatepagelinks tpl2
        where t.templ_id = tpl2.pl_from
        and tpl2.pl_namespace = 0
        and tpl2.pl_title = p.pl_title
      )
    )
group by pg.p_title
;

-- [[Vikipedija:Svarbiausi straipsniai]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas straipsnių, į kuriuos yra daugiausia nuorodų. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all),
       _utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
left join vikipedija_tpage_refs vtpr on (vp.p_title = vtpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) > 10
and vpr.page_links_all > vpr.page_links_tusti+if(vtpr.page_links_all is null,0,vtpr.page_links_all)
order by vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Svarbiausi straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

-- [[Vikipedija:Trokštamiausi nebaigti]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nebaigtų straipsnių, į kuriuos yra daugiausia nuorodų. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all),
       _utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
left join vikipedija_tpage_refs vtpr on (vp.p_title = vtpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) > 10
and vpr.page_links_all > vpr.page_links_tusti+if(vtpr.page_links_all is null,0,vtpr.page_links_all)
and (
  vp.p_soft_1 = 1 or
  vp.p_soft_2 = 1 or
  vp.p_soft_3 = 1 or
  vp.p_soft_4 = 1 or
  vp.p_soft_5 = 1 or
  vp.p_soft_6 = 1 or
  vp.p_soft_7 = 1 or
  vp.p_soft_8 = 1 or
  vp.p_soft_9 = 1 or
  vp.p_soft_10 = 1
)
order by vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Trokstamiausi nebaigti straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

-- Lietuva vikisrities straipsniai

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas Lietuvos straipsnių, į kuriuos yra daugiausia nuorodų. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all),
       _utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
left join vikipedija_tpage_refs vtpr on (vp.p_title = vtpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) > 1
and vpr.page_links_all > vpr.page_links_tusti+if(vtpr.page_links_all is null,0,vtpr.page_links_all)
and exists (
      select 1
      from categorylinks cl
      join lietuva g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
order by vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Svarbiausi Lietuva straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

-- [[Vikipedija:Trokštamiausi nebaigti]]

select _utf8':''''Šis straipsnis - vienas iš alternatyvios statistikos straipsnių. Žr. [[Vikipedija:Alternatyvi statistika|]]''''' AS `title` from dual
union select _utf8'' from dual
union select concat(_utf8'Žemiau pateiktas sąrašas nebaigtų Lietuvos straipsnių, į kuriuos yra daugiausia nuorodų. (''''Duomenys ', uz, ''''').') from dual
union select _utf8'' from dual
union select _utf8'[[Kategorija:Vikipedijos statistika]]' from dual
union select _utf8'----' from dual
union select * from (
select concat(_utf8'# [[',replace(vp.p_title,_utf8'_',_utf8' '),_utf8']]',
       if(vp.p_soft_1 = 1,'{{Ref label|Note|1|1}}',''),
       if(vp.p_soft_2 = 1,'{{Ref label|Note|2|2}}',''),
       if(vp.p_soft_3 = 1,'{{Ref label|Note|3|3}}',''),
       if(vp.p_soft_4 = 1,'{{Ref label|Note|4|4}}',''),
       if(vp.p_soft_5 = 1,'{{Ref label|Note|5|5}}',''),
       if(vp.p_soft_6 = 1,'{{Ref label|Note|6|6}}',''),
       if(vp.p_soft_7 = 1,'{{Ref label|Note|7|7}}',''),
       if(vp.p_soft_8 = 1,'{{Ref label|Note|8|8}}',''),
       if(vp.p_soft_9 = 1,'{{Ref label|Note|9|9}}',''),
       if(vp.p_soft_10 = 1,'{{Ref label|Note|10|10}}',''),
       if(vp.p_soft_11 = 1,'{{Ref label|Note|11|11}}',''),
       _utf8' ([[:Specialus:Whatlinkshere/',
       replace(vp.p_title,_utf8'_',_utf8' '),_utf8'|',vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all),
       _utf8' nuorodos]])') AS title
from vikipedija_page vp
join vikipedija_page_refs vpr on (vp.p_title = vpr.page_title)
left join vikipedija_tpage_refs vtpr on (vp.p_title = vtpr.page_title)
where vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) > 1
and vpr.page_links_all > vpr.page_links_tusti+if(vtpr.page_links_all is null,0,vtpr.page_links_all)
and (
  vp.p_soft_1 = 1 or
  vp.p_soft_2 = 1 or
  vp.p_soft_3 = 1 or
  vp.p_soft_4 = 1 or
  vp.p_soft_5 = 1 or
  vp.p_soft_6 = 1 or
  vp.p_soft_7 = 1 or
  vp.p_soft_8 = 1 or
  vp.p_soft_9 = 1 or
  vp.p_soft_10 = 1
)
and exists (
      select 1
      from categorylinks cl
      join lietuva g on (cl.cl_to = g.cat_title and g.cat_soft_parent < 2)
      where vp.p_id = cl.cl_from
      limit 1
    )
order by vpr.page_links_all-vpr.page_links_tusti-if(vtpr.page_links_all is null,0,vtpr.page_links_all) desc, vp.p_title
limit 1000) b
union select _utf8'== Išnašos ==' from dual
union select _utf8'* {{Note label|Note|1|1}} - [[:Kategorija:Nepilni|]]' from dual
union select _utf8'* {{Note label|Note|2|2}} - [[:Kategorija:Nesutvarkyti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|3|3}} - [[:Kategorija:Nebaigti-terminai|]]' from dual
union select _utf8'* {{Note label|Note|4|4}} - [[:Kategorija:Nepilni (Lietuvos gyvenvietės)|Nepilni (Lietuvos gyvenvietės)]]' from dual
union select _utf8'* {{Note label|Note|5|5}} - [[:Kategorija:Beviltiški|]]' from dual
union select _utf8'* {{Note label|Note|6|6}} - [[:Kategorija:Kandidatai jungti|]]' from dual
union select _utf8'* {{Note label|Note|7|7}} - [[:Kategorija:Kandidatai skaidyti|]]' from dual
union select _utf8'* {{Note label|Note|8|8}} - [[:Kategorija:Tušti straipsniai|]]' from dual
union select _utf8'* {{Note label|Note|9|9}} - [[:Kategorija:Kandidatai skubiai trinti|]]' from dual
union select _utf8'* {{Note label|Note|10|10}} - [[:Kategorija:Kandidatai trinti|]]' from dual
union select _utf8'* {{Note label|Note|11|11}} - [[:Kategorija:Nuorodiniai straipsniai|]]' from dual
INTO OUTFILE 'Trokstamiausi nebaigti Lietuva straipsniai.csv'
LINES TERMINATED BY '\r\n'
;

call vadovai(uz);
call kosmologija(uz);
call Menuo(uz, vlst1, vlst1os, vlst2, vlst2os);
call Latvija(uz);
call Argentina(uz);
call JAV(uz);
call Prancuzija(uz);
call Ukraina(uz);
call Kinija(uz);
call Japonija(uz);
call Indija(uz);
call kanada(uz);

SET character_set_client = @saved_cs_client;

END $$

DELIMITER ;