open-csp/w-s-slots 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

open-csp/w-s-slots

Composer 安装命令:

composer require open-csp/w-s-slots

包简介

This extension provides a mechanism to create new slots.

关键字:

README 文档

README

This extension provides a mechanism to create new slots.

Installation

  • Download an place the file(s) in a directory called WSSlots in your extensions/ folder.

  • Run Composer to install PHP dependencies, by issuing composer install --no-dev in the extension directory.

  • Add the following code to the bottom of your LocalSettings.php:

    wfLoadExtension( 'WSSlots' );
  • Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration

The extension provides the following configuration options:

$wgWSSlotsDefinedSlots

This is an array of the slots to define. Each item in the array corresponds to the name of the slot to define. It is also possible to optionally configure the slot's content model and slot role layout, like so:

$wgWSSlotsDefinedSlots = [
    "example" => [
        "content_model" => "wikitext",
        "slot_role_layout" => [
            "display" => "none",
            "region" => "center",
            "placement" => "append"
        ]
    ]
];

This configuration variable is also exposed as a JavaScript variable and can be accessed like so:

var site_slots = mw.config.get('wgWSSlotsDefinedSlots');

Please note that this only covers slots created by the WSSlots extension.

For more information on content models see MediaWiki.org and for more information on slot role layouts see here.

$wgWSSlotsDefaultContentModel

This is the default content model to use, if no content model is given explicitly.

$wgWSSlotsDefaultSlotRoleLayout

This is the default slot role layout to use, if no slot role layout is given explicitly.

$wgWSSlotsSemanticSlots

This configuration parameter defines which slots should be analysed for semantic annotations.

$wgWSSlotsDoPurge

This configuration option specifies whether to purge the page after a slot edit is performed.

$wgWSSlotsOverrideActions

When set to true, all actions are replaced by slot-aware actions when available. When set to an array, each item in the array specifies an action to replace with its slot aware counterpart. See #Actions below for a list of available slot-aware actions.

Parser functions

#slot

The extension provides the #slot parser function to get the content of a specific slot. For example, {{#slot: main}} returns the content of the main slot. You can optionally specify a page as the second parameter. For instance, {{#slot: main | Foobar }} gets the main slot from the page Foobar. An additional third parameter can be set to anything to have the returned content parsed.

#slotdata

The extension provides the #slotdata parser function to get structured content from a specific slot. The syntax of the parser function is as follows:

{{#slotdata: <slotname> | [<pagename> | [<key> | [<search> | [<compat>]]]]}}
  • <slotname>: The name of the slot to get the data from.
  • <pagename> (optional, default: {{FULLPAGENAME}} ): The name of the page to get the data from.
  • <key> (optional, default: ``): The key of the value to return. Use a JSONPath expression to traverse the path in your structure, regardless whether you are accessing JSON or wiki template content. Both dot and bracket styles of notation are acceptable. To retrieve the raw content of an element, add '_text' as the final node. For instance, if your wiki page uses a single template called "Log" and you want to get the content of a template parameter "Hours spent today", you can request it with the following expression: Log[0]["Hours spent today"]["_text"], or alternatively, `Log.0["Hours spent today"]._text`.
  • <search> (optional, default: ``): The search to perform before looking for the key, should be of the form key=value. If the given key-value pair is not unique, the first enclosing block that contains that pair will be used.
  • <compat> (optional, default: false): Whether to return the result in a manner that ArrayFunctions understands. Requires ArrayFunctions to be installed and enabled.

This function is aware of the content model of the page. This means that it parses a page differently, depending on what the content model is. The content models from which it can extract structured data are:

  • JsonContent: Parses the page as JSON;
  • WikitextContent: Parses the page using a wikitext parser to get template calls.

#slottemplates (deprecated)

The extension also provides the #slottemplates parser function that returns the templates in a specific slot as a multidimensional array. This parser function required WSArrays to be installed.

The parser function has two modes of operation. It can either process templates non-recursively (DEPRECATED), or it can process them recursively (RECOMMENDED). With the non-recursive parser function, multiple templates with the same name are not supported and nested template calls are not processed. With recursive parsing, this is supported. Recursive parsing also supports retrieving the original unparsed content of an argument.

The syntax of the parser function is as follows:

{{#slottemplates: <slotname> | <pagename> | <arrayname> | <recursive> }}

Lua functions

The following Lua functions are available:

mw.slots.slotContent(slotName, pageName)

Mirrors the functionality of the #slot parser function and makes it available in Lua. It takes the following parameters:

  • slotName (required, string): The name of the slot to get the content for;
  • pageName (optional, string, default={{PAGENAME}}): The name of the page to get the slot from.

mw.slots.slotTemplates(slotName, pageName) (deprecated)

Mirrors the functionality of the #slottemplates parser function and makes it available in Lua. It takes the following parameters:

  • slotName (required, string): The name of the slot to get the templates for;
  • pageName (optional, string, default={{PAGENAME}}): The name of the page to get the slot from.

This function is deprecated and will be replaced by mw.slots.slotData() soon.

mw.slots.slotContentModel(slotName, pageName)

Returns the content model of the specified slot. It takes the following parameters:

  • slotName (required, string): The name of the slot to get the content model for;
  • pageName (optional, string, default={{PAGENAME}}): The name of the page to get the slot from.

mw.slots.slotData(slotName, pageName)

Mirrors the functionality of the #slotdata parser function and makes it available in Lua. This function omits any advanced selection tools (JSONPath). It takes the following parameters:

  • slotName (required, string): The name of the slot to get the data for;
  • pageName (optional, string, default={{PAGENAME}}): The name of the page to get the slot from.

Actions

rawslot

Slot-aware version of action=raw (see RawAction). Returns the content of the specified slot as raw value (format depends on the slot content model). Example:

/wiki/MyMultislotPage?action=rawslot&slot=someslot

open-csp/w-s-slots 适用场景与选型建议

open-csp/w-s-slots 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.32k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 open-csp/w-s-slots 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 5
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-10-03