Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanasimi/wikibot
Some MediaWiki bot examples including wikipedia, wikidata using MediaWiki module of CeJS library. 採用 CeJS MediaWiki 自動化作業用程式庫來製作 MediaWiki (維基百科/維基數據) 機器人的範例。
https://github.com/kanasimi/wikibot
cejs mediawiki mediawiki-bot wiki wikidata wikipedia wikipedia-bot wikitext
Last synced: 2 months ago
JSON representation
Some MediaWiki bot examples including wikipedia, wikidata using MediaWiki module of CeJS library. 採用 CeJS MediaWiki 自動化作業用程式庫來製作 MediaWiki (維基百科/維基數據) 機器人的範例。
- Host: GitHub
- URL: https://github.com/kanasimi/wikibot
- Owner: kanasimi
- Created: 2016-02-27T09:47:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-26T22:58:49.000Z (3 months ago)
- Last Synced: 2024-09-27T05:23:35.298Z (3 months ago)
- Topics: cejs, mediawiki, mediawiki-bot, wiki, wikidata, wikipedia, wikipedia-bot, wikitext
- Language: JavaScript
- Homepage:
- Size: 4 MB
- Stars: 26
- Watchers: 6
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![GitHub commit activity the past week, 4 weeks, year](https://img.shields.io/github/commit-activity/y/kanasimi/wikibot.svg)
# CeJS MediaWiki bots demo
Some MediaWiki bot examples including wikipedia, wikidata using [MediaWiki module](https://github.com/kanasimi/CeJS/blob/master/application/net/wiki) of [CeJS library](https://github.com/kanasimi/CeJS) and [wikiapi](https://github.com/kanasimi/wikiapi).
採用 CeJS [MediaWiki 自動化作業用程式庫](https://github.com/kanasimi/CeJS/blob/master/application/net/wiki)來製作 MediaWiki (維基百科/維基數據) 機器人的範例。You might also be interested in [wikiapi](https://github.com/kanasimi/wikiapi).
## Node.js usage
### Installation
1. Please install [node.js](https://nodejs.org/) and [7-Zip](https://www.7-zip.org/) 18.01+.
2. Creating a working directory and extracting files via executing commands under Windows:
```bat
npm i gh-updater
node_modules\.bin\gh-updater kanasimi/wikibot
cd wikibot-master
npm i wikiapi
copy "wiki configuration.sample.js" "wiki configuration.js"
```Or under Linux:
```bash
npm i gh-updater
node_modules/.bin/gh-updater kanasimi/wikibot
cd wikibot-master
npm i wikiapi
cp "wiki configuration.sample.js" "wiki configuration.js"
```
3. Setup [wiki configuration.js](https://github.com/kanasimi/wikibot/blob/master/wiki%20configuration.sample.js): Edit `wiki configuration.js` and fill username / password.### Execution
Let's try it:
```bash
$ node
```
```javascript
// Load CeJS library.
require('cejs');// Load modules.
CeL.run([ 'application.net.wiki', 'application.net.wiki.data', 'application.net.wiki.admin' ]);// 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'
});```
* [An example for wiki_session.query()](https://github.com/kanasimi/wikibot/blob/9727497238c81cfe8189bcafdb6bb17684720a9d/20171025.fix_LintErrors.js)
* [An example for CeL.wiki.query()](https://github.com/kanasimi/wikibot/blob/3913874380093eebae250442c083e74883239620/20171025.fix_LintErrors.js)Wikidata example:
```javascript
// 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](https://github.com/kanasimi/wikibot/blob/master/routine/20151002.WPCHECK.js) (fix_16 only):* Output on console:
![On console](https://upload.wikimedia.org/wikipedia/commons/7/7c/20151002.WPCHECK.console.c.png)* Log page on Wikipedia (ページ上への作業ログ出力):
![Log page](https://upload.wikimedia.org/wikipedia/commons/d/da/20151002.WPCHECK.log.c.png)* The contributions:
![Contributions](https://upload.wikimedia.org/wikipedia/commons/f/f1/20151002.WPCHECK.contributions.c.png)## Features of CeJS MediaWiki module
* Batch processing.
* Access and edit wikimedia sister projects + wikidata.
* Support [Flow](https://www.mediawiki.org/wiki/Flow) page: Using the same way adding section to normal page and Flow page.
* Detection of edit conflicts and{{[bots](https://meta.wikimedia.org/wiki/Template:Bots)}}
.
* Query [list](https://www.mediawiki.org/wiki/API:Lists) of backlinks, embeddedin, imageusage, linkshere, fileusage, et al.
* [Parse wikitext](https://kanasimi.github.io/CeJS/_test%20suite/wikitext_parser.html) and modify [wikitext](https://www.mediawiki.org/wiki/Wikitext) inplace.
* Listen to recent changes with diff function supported.* Parse XML file of [Wikimedia database backup dumps](http://dumps.wikimedia.org/backup-index.html).
* Import Wikimedia database backup dumps data to user-created database on [Tool Labs](http://tools.wmflabs.org/). (See [process_dump.js](https://github.com/kanasimi/wikibot/blob/master/task/process_dump.js))
* Traversal all 1.5M pages of zhwiki in 12 minutes on Tool Labs. (See [traversal_pages.clear.js](https://github.com/kanasimi/wikibot/blob/master/archive/traversal_pages.clear.js). It will automatically download xml dump file first.) 12分鐘遍歷所有 zhwiki 頁面。(於 Tool Labs,將自動先下載 xml dump file。)