定制 sophivorus/easy-wiki 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sophivorus/easy-wiki

Composer 安装命令:

composer require sophivorus/easy-wiki

包简介

Friendly PHP client for the MediaWiki Action API

README 文档

README

EasyWiki is a friendly PHP client for the MediaWiki Action API.

Quickstart

composer require sophivorus/easy-wiki
require 'vendor/autoload.php';

// Connect to a MediaWiki Action API endpoint
$api = new EasyWiki( 'https://en.wikipedia.org/w/api.php' );

// Read data immediately
$wikitext = $api->getWikitext( 'Science' );

Authentication

If you only want to read data from a public wiki (such as Wikipedia), then you don't need to authenticate, you can move on to the next section.

However, if you want to write data or read data from a private wiki, you'll need to authenticate with a bot account. Bot accounts are created from Special:BotPasswords and are the simplest way to get through the MediaWiki security mechanisms.

// Be very careful not to publish your bot password by accident!!!
$api->login( 'Your bot username', 'Your bot password' );

Reading

// Get the wikitext of the page named 'Foo'
$api->getWikitext( 'Foo' );

// Get the HTML of the page named 'Foo'
$api->getHTML( 'Foo' );

// Get the categories of the page named 'Foo'
$api->getCategories( 'Foo' );

If none of the available methods serves your needs, you can always query the API directly. EasyWiki provides handy methods for doing so and for extracting the desired data from the results. Check out the MediaWiki Action API documentation for the available parameters.

// Get the results as an associative array
$data = $api->query( [ 'titles' => 'Foo', 'prop' => 'info' ] );

// Magically extract the desired piece of data from the gazillion wrappers
$language = $api->find( 'pagelanguage', $query );

// If the result contains more than one relevant piece of data, you'll get an array of values instead
$data = $api->query( [ 'titles' => 'Foo|Bar|Baz', 'prop' => 'info' ] );
$languages = $api->find( 'pagelanguage', $data );
foreach ( $languages as $language ) {
    echo $language;
}

Writing

// Create a page named 'Foo' with content 'Hello world!'
$api->create( 'Foo', 'Hello world!' );

// Replace the content of the page named 'Foo' with 'Bye!'
$api->edit( 'Foo', [ 'text' => 'Bye!' ] );

// Rename the page named 'Foo' to 'Bar'
$api->move( 'Foo', 'Bar' );

// Delete the page named 'Bar'
$api->delete( 'Bar' );

All methods have an optional last argument where you can specify extra parameters. For example:

// Add a summary
$api->create( 'Foo', 'Hello world!', [ 'summary' => 'My first edit!' ] );

// Mark the edit as minor
$api->edit( 'Foo', 'Bye!', [ 'minor' => true ] );

// Don't leave a redirect behind and move all subpages too
$api->move( 'Foo', 'Bar', [ 'noredirect' => true, 'movesubpages' => true ] );

Architecture

Check out the source code for the ultimate documentation.

  • Base methods are the basic building blocks to interact with the MediaWiki Action API:
    • get() makes a GET request to the API
    • post() makes a POST request to the API
    • find() extracts data from the results
  • Action methods use the base methods to interact with the API modules:
    • login()
    • logout()
    • query()
    • parse()
    • edit()
    • move()
    • delete()
  • Shorthand methods simplify common requests:
    • create()
    • append()
    • prepend()
    • getHTML()
    • getWikitext()
    • getCategories()
    • getPageInfo()
    • getSiteInfo()
    • getNamespaces()
    • getToken()

If none of the existing methods serves your needs, you can always call the base methods directly.

sophivorus/easy-wiki 适用场景与选型建议

sophivorus/easy-wiki 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.07k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wiki」 「mediawiki」 「wikipedia」 「wikipedia-api」 「mediawiki-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sophivorus/easy-wiki 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sophivorus/easy-wiki 我们能提供哪些服务?
定制开发 / 二次开发

基于 sophivorus/easy-wiki 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2022-07-24