Wikipedia:专题/提升为命名空间/影响页面/列举.js

function find_by_title(){
	var black_list=['Wikipedia:专题','Wikipedia:專題','Wikipedia:专题委员会'];
	var api = new mw.Api(), sentApi = (offset,limit,callback)=>api.get({
		action: 'query',
		list: 'search',
		srlimit: limit?limit:50,
		sroffset: offset?offset:0,
		srnamespace: 4,
		srprop: '',
		srsearch: 'intitle:/[專专][題题]/',
		format: 'json'
	}).done(data=>((typeof(callback)===typeof(()=>{}))?callback(data):null));
	sentApi(0,40,function(init_data){
		var page_count=parseInt(init_data.query.searchinfo.totalhits);
		var all_page={};
		var read_index=init_data.query.search.length;
		var checking_data=0;
		for(var i=0; i<init_data.query.search.length; ++i)all_page[init_data.query.search[i].title]=init_data.query.search[i];
		var find_all_result=function(callback){
			if(Object.keys(all_page).length<=page_count){
				if(checking_data==read_index)read_index++;
				else checking_data=read_index;
				if(read_index>=page_count)return ((typeof(callback)===typeof(()=>{}))?callback():null);
				read_index-=10;
				console.log(`request ${read_index}/${page_count}(${0.1*Math.floor(1000*(read_index/page_count))}%) ...`);
				sentApi(read_index,40,function(continue_data){
					page_count=parseInt(continue_data.query.searchinfo.totalhits);
					read_index+=continue_data.query.search.length-10;
					for(var i=0; i<continue_data.query.search.length; ++i)all_page[continue_data.query.search[i].title]=continue_data.query.search[i];
					window.setTimeout((()=>find_all_result(callback)), 5000);
				});
			}else{
				return ((typeof(callback)===typeof(()=>{}))?callback():null);
			}
		};
		find_all_result(function(){
			var page_list=[];
			Object.keys(all_page).map(function(objectKey, index) {
				if(all_page[objectKey].ns==4 && /Wikipedia:[^\/]*[專专][題题]/.test(objectKey) && !black_list.includes(objectKey))page_list.push(objectKey);
			});
			console.log(page_list);
		});
	});
}
function find_by_category(){
	var api = new mw.Api();
	var all_pages={},page_list=[],cats=['不活跃维基专题‎','半活跃维基专题‎','废弃维基专题‎','活跃维基专题','筹备中的维基专题'];
	console.log(`searching from 维基专题状态...`);
	api.get( {
		action: 'query',
		format: 'json',
		list: 'backlinks',
		bllimit: 500,
		bltitle: 'Template:维基专题状态'
	} ).done( function ( data ) {
		var backlinks = data.query.backlinks,cat_lists=[];
		for (var c in cats )cat_lists.push(cats[c]);
		for (var b in backlinks ) {
			var pjName=`${backlinks[ b ].title}/`.split('/')[0];
			all_pages[pjName]=all_pages[pjName]||backlinks[ b ];
		}
		var get_all_cat=function(get_all_cats,complete){
			if(cat_lists.length<=0){
				complete();
			}else{
				var find_title=cat_lists.pop();
				console.log(`searching from ${find_title}...`);
				api.get( {
					action: 'query',
					list: 'categorymembers',
					cmtitle: 'Category:'+find_title,
					cmlimit: 500,
					format: 'json'
				} ).done( function ( data ) {
					var pages = data.query.categorymembers,page;
					for ( page in pages ) {
						var pjName=`${pages[page].title}/`.split('/')[0];
						all_pages[pjName]=all_pages[pjName]||pages[page];
					}
					get_all_cats(get_all_cats,complete);

				} );
			}
		};
		get_all_cat(get_all_cat,function(){
			Object.keys(all_pages).map(function(objectKey, index) {
				if(all_pages[objectKey].ns==4)page_list.push(objectKey);
			});
			var check_pages=[];
			for (var p in page_list )check_pages.push(page_list[p]);
			
			var get_all_subpage=function(get_all_subpages,complete){
				if(check_pages.length<=0){
					complete();
				}else{
					var find_title=check_pages.pop();
					console.log(`searching from ${find_title}...`);
					api.get( {
						action: 'query',
						format: 'json',
						list: 'allpages',
						apnamespace: 4,
						aplimit: 500,
						apprefix: find_title.substring(10)
					} ).done( function ( data ) {
						var pages = data.query.allpages;
						console.log(`add ${pages.length} pages...`);
						for (var page in pages ) {
							var pjName=pages[page].title;
							all_pages[pjName]=all_pages[pjName]||pages[page];
						}
						get_all_subpages(get_all_subpages,complete);

					} );
				}
			};
			get_all_subpage(get_all_subpage,function(){
				page_list=[];
				Object.keys(all_pages).map(function(objectKey, index) {
					if(all_pages[objectKey].ns==4)page_list.push(objectKey);
				});
				console.log(page_list);
			});
		});
	} );
}
var _addText="{{Historical}}{{see also|Wikipedia:专题/提升为命名空间/影响页面|Wikipedia:专题/提升为命名空间/影响页面.json}}";