Skip to content
The Wikipedia bot examples using MediaWiki module of CeJS library. 採用 CeJS 函式庫來製作維基百科機器人的範例。
JavaScript Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
archive
wikitech
20150503.提報關注度不足過期提醒.js
20150916.Multiple_issues.v2.js
20150929.校訂繁簡轉換,修正錯別字.js
20151002.WPCHECK.js
20160414.import_label_from_wiki_link.js
20160517.解消済み仮リンクをリンクに置き換える.js
20160628.insert_navigation.插入導航模板.js
20160704.fix_link.js
20160714.archive_news.js
20160719.clean_sandbox.js
20160828.clear_category.清空分類.js
20160906.archive_moegirl.js
20160915.TaiBNET.js
20160923.modify_link.リンク元修正.js
20160924.import_book_data.js
20161011.modify_category_via_petscan.js
20161112.modify_category.js
20170428.modify_link.リンク元修正v2.js
20170515.signature_check.js
20170708.import_VOA.js
20170828.search_and_replace.js
20170828.soccerbase_citation_converter.js
20170902.cleanup_Panoramio_files_needing_categories.js
20170915.topic_list.js
20170922.scan_link_targets_in_page.js
20171025.fix_LintErrors.js
20180125.most_sitelinked_articles_to_write.js
20180511.headline.js
20181016.import_earthquake_shakemap.js
20181216.move_contents_of_ref_tag_with_name.js
20190101.featured_content_maintainer.js
20190215.clean_overcategorization.js
20190413.modify_template_parameter.js
20190629.import_hurricane_track_maps.js
20190912.fix_Infobox_company.js
20190913.move_link.js
README.md
archive_logs.js
check_parser.js
cross_wiki_notice.js
package.json
process_dump.js
special page configuration.js
traversal_pages.js
undo_edit.js
wiki configuration.sample.js
wiki loader.js
校訂繁簡轉換,修正錯別字 轉換表.txt

README.md

GitHub commit activity the past week, 4 weeks, year

CeJS MediaWiki bots demo

Some MediaWiki bot examples including wikipedia, wikidata using MediaWiki module of CeJS library. 採用 CeJS MediaWiki 自動化作業用程式庫來製作 MediaWiki (維基百科/維基數據) 機器人的範例。

You might also be interested in wikiapi.

Node.js usage

Installation

  1. Please see Node.js usage section at CeJS for detail.
  2. Setup _CeL.path.txt if necessary.
  3. Setup wiki configuration.js.

Execution

Let's try it:

$ node
// Load CeJS library.
require('cejs');

// Load modules.
CeL.run('application.net.wiki');

// Set default language. 改變預設之語言。
CeL.wiki.set_language('en');

// Set up the wiki instance.
var wiki = CeL.wiki.login(user_name, password, 'en');

wiki
// Select page(s) and get the contents of the page(s).
.page('Wikipedia:Sandbox')

// Replace the contents of a page.
.edit('wikitext to replace', {
	nocreate : 1
})

// Add a new section to a normal page or a Flow page.
.edit(': text to add.', {
	section : 'new',
	sectiontitle : 'Sandbox test section',
	summary : 'Sandbox test edit (section)',
	nocreate : 1
})

// Modify the page contents.
.edit(function(page_data) {
	/** {String}page title */
	var title = CeL.wiki.title_of(page_data),
	/** {String}page content, maybe undefined. */
	content = CeL.wiki.content_of(page_data);
	// append a new section
	return content + '\n== New section ==\n: text to add.';
}, {
	summary : 'summary'
});

wiki.categorymembers(category_title, function(page_data_list, error) {
	;
}, {
	limit : 'max'
});

Wikidata example:

// Cache the id of "性質" first. 先快取必要的屬性id值。
CeL.wiki.data.search.use_cache('性質', function(id_list) {
	// Get the id of property '性質' first.
	// and here we get the id of '性質': "P31"
	CeL.log(id_list);
	// 執行剩下的程序. run rest codes.
}, {
	must_callback : true,
	type : 'property'
});

// ----------------------------
// rest codes:

// Set up the wiki instance.
var wiki = CeL.wiki.login(user_name, password, 'zh');

wiki.data('維基數據沙盒2', function(data_JSON) {
	data_JSON.value('性質', {
		// resolve wikibase-item
		resolve_item : true
	}, function(entity) {
		// get "Wikidata Sandbox"
		CeL.log(entity.value('label', 'en'));
	});
});

// Old style. The same effect as codes above.
wiki.data('維基數據沙盒2', function(data_JSON) {
	wiki.data(data_JSON.value('性質'), function(entity) {
		// via wikidata_entity_value()
		// get "维基数据测试沙盒"
		CeL.log(entity.value('label'));
	});
});

// edit properties
wiki.edit_data(function(entity) {
	// add new / set single value with references
	return {
		生物俗名 : '維基數據沙盒2',
		language : 'zh-tw',
		references : {
			臺灣物種名錄物種編號 : 123456,
			// [[d:Special:AbuseFilter/54]]
			// 導入自 : 'zhwikipedia',
			載於 : '臺灣物種名錄物種',
			來源網址 : 'https://www.wikidata.org/',
			檢索日期 : new Date
		}
	};

	// set multiple values
	return {
		labels : {
			ja : 'ウィキデータ・サンドボックス2',
			'zh-tw' : [ '維基數據沙盒2', '維基數據沙盒#2', '維基數據沙盒-2' ]
		},
		descriptions : {
			'zh-tw' : '作為沙盒以供測試功能'
		},
		claims : [ {
			生物俗名 : [ 'SB2#1', 'SB2#2', 'SB2#3' ],
			multi : true,
			language : 'zh-tw',
			references : {
				臺灣物種名錄物種編號 : 123456
			}
		}, {
			読み仮名 : 'かな',
			language : 'ja',
			references : {
				'imported from Wikimedia project' : 'jawikipedia'
			}
		} ]
	};

	// remove specified value 生物俗名=SB2
	return {
		生物俗名 : 'SB2',
		language : 'zh-tw',
		remove : true
	};

	// to remove ALL "生物俗名"
	return {
		生物俗名 : CeL.wiki.edit_data.remove_all,
		language : 'zh-tw'
	};

}, {
	bot : 1,
	summary : 'bot test: edit properties'
});

Screenshot

Screenshot of WPCHECK.js (fix_16 only):

  • Output on console: On console

  • Log page on Wikipedia (ページ上への作業ログ出力): Log page

  • The contributions: Contributions

Features of CeJS MediaWiki module

  • Batch processing.

  • Access and edit wikimedia sister projects + wikidata.

  • Support Flow page: Using the same way adding section to normal page and Flow page.

  • Detection of edit conflicts and {{bots}}.

  • Query list of backlinks, embeddedin, imageusage, linkshere, fileusage, et al.

  • Parse wikitext and modify wikitext inplace.

  • Listen to recent changes with diff function supported.

  • Parse XML file of Wikimedia database backup dumps.

  • Import Wikimedia database backup dumps data to user-created database on Tool Labs. (See process_dump.js)

  • Traversal all 1.5M pages of zhwiki in 12 minutes on Tool Labs. (See traversal_pages.clear.js. It will automatically download xml dump file first.) 12分鐘遍歷所有 zhwiki 頁面。(於 Tool Labs,將自動先下載 xml dump file。)

You can’t perform that action at this time.