查看“︁使用方法/Example”︁的源代码
来自康健生活
←
使用方法/Example
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 标题文本 == == 权限验证 == 基于皮肤做一些小的改动,比如说<code>未登录时</code>隐藏一些功能按键。 修改 skin.json 时除了必要的加载命名空间之外, ValidSkinNames.example.class 也需要指向入口文件。 {{hc|head=父级目录/mediawiki/skins/Example/skin.json|output=<syntaxhighlight lang="json" highlight="6,10"> { "name": "Example", "version": "1.0.0", "ValidSkinNames": { "example": { "class": "MediaWiki\\Skins\\Example\\SkinExample", } }, "AutoloadNamespaces": { "MediaWiki\\Skins\\Example\\": "includes/" }, } </syntaxhighlight>}} 添加入口文件并继承 Skin 的 <code>SkinMustache</code> 基类。 {{hc|head=父级目录/mediawiki/skins/Example/includes/SkinExample.php|output=<syntaxhighlight lang="php"> <?php namespace MediaWiki\Skins\Example; use MediaWiki\Skin\SkinMustache; use RuntimeException; class SkinExample extends SkinMustache { public function getTemplateData() { // 埋点测试,用于验证文件是否被加载 // die( 'SkinMySkin.php 已经被成功读取执行!' ); $parentData = parent::getTemplateData(); // 注入自定义布尔值到模板数据中 $parentData['is-logged-in'] = $this->getUser()->isRegistered(); return $parentData; } } </syntaxhighlight>}} 在 mustache 模板中增加限定条件(依据是否已经登陆)。 {{hc|head=父级目录/mediawiki/skins/Example/templates/skin.mustache|output=<syntaxhighlight lang="html" highlight="4,10-11,13"> <div id="mw-wrapper"> /* ...... */ <div id="mw-navigation"> {{#is-logged-in}} <div id="site-navigation"> {{#data-portlets-sidebar.data-portlets-first}}{{>Portlet}}{{/data-portlets-sidebar.data-portlets-first}} {{#data-portlets-sidebar.array-portlets-rest}}{{>Portlet}}{{/data-portlets-sidebar.array-portlets-rest}} {{#data-portlets.data-languages}}{{>Portlet}}{{/data-portlets.data-languages}} </div> {{/is-logged-in}} {{^is-logged-in}} <div class="login-prompt">一</div> {{/is-logged-in}} </div> {{#data-footer}}{{>Footer}}{{/data-footer}} </div> </syntaxhighlight>}} == Example == [https://www.mediawiki.org/wiki/Skin:example Skin:example] 是一个示例皮肤。
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
返回
使用方法/Example
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。