Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wikiapi

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wikiapi

Simple way to access MediaWiki API via JavaScript with simple wikitext parser.

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59
increased by13.46%
Maintainers
1
Weekly downloads
 
Created
Source

npm version npm downloads Build Status codecov

Known Vulnerabilities codebeat badge Codacy Badge DeepScan grade

JavaScript MediaWiki API

Simple way to access MediaWiki API via JavaScript with simple wikitext parser.

Features 特點

  • read / edit pages
  • get list of categorymembers, pages transclude specified template, and more...
  • Auto-limited editing rate.

Installation 安裝

Install node.js first.

npm install wikiapi

usage 運行方式

Here lists some examples of this module.

As node.js module

// load module
const Wikiapi = require('wikiapi');

// load page
(async () => {
	let wiki = new Wikiapi;
	let page_data = await wiki.page('Universe');
	console.log(page_data.wikitext);
})();

(async () => {
	let wiki = new Wikiapi;
	let page_data = await wiki.page('Universe', {
		// Get multi revisions
		revisions: 2
	});
	console.log(page_data.wikitext);
})();

// edit page
(async () => {
	let enwiki = new Wikiapi;
	await enwiki.login('bot name', 'password', 'en');
	let page_data = await enwiki.page('Wikipedia:Sandbox');
	await enwiki.edit(function(page_data) {
		return page_data.wikitext
			+ '\nTest edit using {{GitHub|kanasimi/wikiapi}}.';
	}, {bot: 1});
	console.log('Done.');
})();

// parse page (The parser is more powerful than the example. Try yourself!)
(async () => {
	let zhwiki = new Wikiapi('zh');
	await zhwiki.login('user', 'password');
	let page_data = await zhwiki.page('Universe');
	page_data.parse().each('template',
		token => console.log(token.name));
})();

// read wikidata
(async () => {
	let wiki = new Wikiapi;
	let page_data = await wiki.data('Q1');
	console.assert(CeL.wiki.data.value_of(page_data.labels.zh) === '宇宙');
})();

// read wikidata
(async () => {
	let wiki = new Wikiapi;
	let data = await wiki.data('Universe', 'P1419');
	console.assert(data.includes('shape of the universe'));
})();

// get list of [[w:en:Category:Chemical_elements]]
(async () => {
	let wiki = new Wikiapi;
	let list = await wiki.categorymembers('Chemical elements');
	console.log(list);
})();

// get pages transclude {{w:en:Periodic table}}
(async () => {
	let wiki = new Wikiapi;
	let list = await wiki.embeddedin('Template:Periodic table');
	console.log(list);
})();

More examples: Please see test.js.

OS support 作業系統支援

Platformsupport
Windows✔️
macOS✔️
UNIX, Linux✔️

See also

For old style JavaScript, or general environment usage, please see wikibot.

Contact 聯絡我們

Contact us at GitHub.

logo

Keywords

FAQs

Package last updated on 10 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc