“MediaWiki:Common.js”与“Template:About”:页面之间的差异

H萌娘,万物皆可H的百科全书!
(页面间差异)
跳到导航 跳到搜索
imported>=海豚=
无编辑摘要
 
imported>Leogong2019
(搬运自主站)
 
第1行: 第1行:
/* eslint-disable no-var */
<includeonly><div class="notice dablink" style="font-size: small; margin: 1em; padding: 0.2em;"><table style="width: 100%;"><tr style="vertical-align: top; text-align: left;"><th style="width: 32px; position: relative; top: {{#if: {{{offset|}}}|{{{offset|}}}|-2}}px;"><img src="{{filepath:Disambig_gray.svg|26}}" /></th><th style="font-weight: inherit;"><!--
/* eslint-disable no-magic-numbers */
-->{{#if: {{{post|{{{后|}}}}}}||{{#if: {{{pre|{{{前|}}}}}}|{{{pre|{{{前|}}}}}}<br />}}}}<!--
/* global OO, mediaWiki, jQuery */
-->{{#if: {{{1|{{{本条目描述|}}}}}}|<!--
// <nowiki>
  -->本{{#if:{{{section|}}}|章节|{{#switch:{{NAMESPACENUMBER}}|0=条目|14=分类|页}}}} 介绍的是{{{1|{{{ 本条目描述|}}}}}} }}<!--
/* 这里的任何JavaScript将在全站加载
-->关于{{#if:{{{2|{{{另一含义|}}}}}}|{{{2|{{{另一含义|}}}}}}|{{#if:{{{消歧义页|}}}|{{{消歧义页|}}}|{{{3}}}}}的其他意思}} ,请见{{#if:{{{3|{{{另一条目名|{{{消歧义页|}}}}}}}}}|“'''[[{{{3|{{{ 另一条目名|{{{消歧义页|}}}}}}}}}]]'''”{{#ifeq:{{{4|}}}|and|和{{#if:{{{5|}}}|“'''[[{{{5}}}]]'''”|{{Error|错误:没有指定其他用法1的链接2}}}}}}|{{Error|错误:没有指定其他用法1的链接}}}}。<!--
*  loader模块 写法参见 https://www.mediawiki.org/wiki/ResourceLoader/Modules#mw.loader.load
-->{{#if:{{{2|}}}|{{#if:{{{4|}}}|<!--
*/
  -->{{#ifeq:{{{4|}}}|and||<!-- "and" 是特殊词,请不要将本模版用于“关于and……”
"use strict";
   --> 关于{{#ifeq:{{{4}}}|1|{{{5}}}的其他意思|{{{4}}}}},请见{{#if:{{{5|}}}|“'''[[{{{5}}}]]''' ”{{#ifeq:{{{6|}}}|and|和{{#if:{{{7|}}}|“'''[[{{{7}}}]]'''”|{{Error|错误:没有指定其他用法2的链接2}}}}}}|{{Error|错误:没有指定其他用法2的链接}}}}。}}<!--
(function($, mw) { //使用匿名函数防止污染顶级变量
  -->{{#if:{{{6|}}}|<!--
   /* MediaViewer#populateStatsFromXhr 错误屏蔽 */
   -->{{#ifeq:{{{6|}}}|and||<!--
   (function() {
    -->关于{{#ifeq:{{{6}}}|1|{{{7}}} 的其他意思|{{{6}}}}},请见{{#if:{{{7|}}}|“'''[[{{{7}}}]]'''”{{#ifeq:{{{8|}}}|and|和{{#if:{{{9|}}}|“'''[[{{{9}}}]]'''”|{{Error|错误:没有指定其他用法3 链接2}}}}}}|{{Error|错误:没有指定其他用法3的链接}}}}。}}<!--
     var getResponseHeader = XMLHttpRequest.prototype.getResponseHeader;
   -->{{#if:{{{8|}}}|<!--
     XMLHttpRequest.prototype.getResponseHeader = function(name) {
    -->{{#ifeq:{{{8|}}}|and||<!--
       return ("\n" + this.getAllResponseHeaders().toLowerCase()).includes("\n" + name.toLowerCase() + ": ") ? getResponseHeader.call(this, name) : (console.debug('Refused to get unsafe header "' + name + '"\n', this, "\n", new Error().stack), null);
     -->关于{{#ifeq:{{{8}}}|1|{{{9}}} 其他意思|{{{8}}}}},请见{{#if:{{{9|}}}|“'''[[{{{9}}}]]'''”|{{Error|错误:没有指定其他用法4的链接}}}}。}}<!--
     };
   -->}}<!--
   })();
  -->}}<!--
   //Extension:MultimediaViewer的半透明化修改。
-->}}}}<!--
   function multimediaViewer() {
-->{{#if: {{{post|{{{后|}}}}}}|<br />{{{post|{{{后|}}}}}}}}<!--
     var _scrollTo = window.scrollTo;
--></th></tr></table></div></includeonly><noinclude>
     var flag = location.hash !== "";
{{Documentation}}
     window.scrollTo = function scrollTo(x_option, y) {
</noinclude>
       if (flag) {
         console.info("Prevent multimediaViewer called");
       } else {
         if (y === undefined) { _scrollTo(x_option); } else { _scrollTo(x_option, y); }
       }
     };
     setInterval(function() {
       $("a.image img[data-file-width], a.image img[data-file-height], .mw-mmv-filepage-buttons a.mw-mmv-view-expanded").not(".multimediaViewerScrollSet").each(function() {
         this.addEventListener("click", function(e) {
           if ($(e.target).closest(".TabLabelText")[0] || $(e.target).closest("a").closest(".mw-customtoggle")[0]) {
             e.preventDefault();
             e.stopPropagation();
             e.stopImmediatePropagation();
             $($(e.target).closest(".TabLabelText")[0] || $(e.target).closest("a").closest(".mw-customtoggle")[0]).click();
             return false;
           }
           flag = true;
         }, captureSupported ? {
           capture: true,
         } : true);
         $(this).addClass("multimediaViewerScrollSet");
       });
       if ($(".mw-mmv-close")[0]) {
         if (mw.config.get("wgMultimediaViewerInjected") !== "on") {
           mw.config.set("wgMultimediaViewerInjected", "on");
           $(".mw-mmv-image").off("click")[0].addEventListener("click", function(e) {
             if ($(e.target).is("img")) {
               window.open($(e.target).attr("src").replace(/(img\.moegirl\.org\/common\/)thumb\/([a-z\d]+\/[a-z\d]+\/)([^/]+)\/\d+px-\3/i, "$1$2$3"), "_blank").focus();
               e.preventDefault();
               e.stopPropagation();
               e.stopImmediatePropagation();
               return false;
             } else if ($(e.target).closest(".error-box")[0]) { return; }
             $(".mw-mmv-close").click();
           }, captureSupported ? {
             capture: true,
           } : true);
         }
       } else if (mw.config.get("wgMultimediaViewerInjected") === "on") {
         flag = false;
         mw.config.set("wgMultimediaViewerInjected", "off");
       }
     }, 137);
   }
   //子页面页顶链接
   function subpage_links() {
     var links = mw.config.get("wgPageName").split("/"),
       link = "",
       subpages = $(".subpages")[0] ? $(".subpages").remove().empty().text("<") : $('<span class="subpages"/>').text("<"),
       length = links.length - 1,
       index;
     if (mw.config.get("wgPageName").indexOf("Special:移动页面") !== -1) { links.splice(0, 1); }
     for (index = 0; index < length; index++) {
       link += "/" + links[index];
       subpages.append($("<a/>", {
         text: " " + links[index],
         href: link,
       }));
       if (length - index > 1) { subpages.append(" |"); }
     }
     if (subpages.find("a")[0]) { $("#contentSub").prepend(subpages); }
   }
   //跨站重定向页顶链接
   function crossDomain_link() {
     var url = new mw.Uri(new mw.Uri().query.rdfrom);
     var link = url.query.title;
     var domain = url.host;
     var crossDomain = $("<div/>");
     var anchor = $("<a/>");
     crossDomain.text("<");
     anchor.attr("href", url + "").text(link + "【来自 " + domain + "】");
     crossDomain.append(anchor);
     $("#contentSub").prepend(crossDomain);
   }
   //重复文件列表函数
   function duplicatedFileList() {
     if (window.location.href.indexOf("title") === -1) { window.location.replace("http://www.hmoegirl.com/index.php?title=Special:ListDuplicatedFiles&limit=500&offset=0"); }
     $("#mw-content-text .mw-spcontent ol").attr("id",
       "picOl");
     $("#picOl").before('<p id="picOlTitle">图片列表:</p>').after('<p id="MP3OlTitle">MP3列表:</p><ol start="1" id="MP3Ol"></ol>');
     $("#picOlTitle, #MP3OlTitle").hide();
     $("#picOl").find("[href$='.mp3'], [href$='.ogg']").parent().appendTo("#MP3Ol");
     if ($("#picOl").find("li").length) { $("#picOlTitle").show(); }
     if ($("#MP3Ol").find("li").length) { $("#MP3OlTitle").show(); }
     $(".mw-spcontent > p:nth-child(1), .mw-spcontent > p:nth-child(2), .mw-spcontent > p:nth-child(7)").hide();
   }
   //编辑请求
   function editRequest() {
     var nsIds = mw.config.get("wgNamespaceIds"),
       nsId = mw.config.get("wgNamespaceNumber"),
       ns = [];
     for (var i in nsIds) {
       if (nsIds[i] === nsId) { ns.push(i); }
     }
     if (!ns[0]) { return; }
     var page = mw.config.get("wgPageName"),
       talkns;
     for (var j = 0, l = ns.length; j < l; j++) {
       if (/^[A-Za-z0-9]+[ _]talk$/i.test(ns[j])) { return; }
       if (/^[a-zA-Z0-9]+$/.test(ns[j])) { talkns = ns[j] + "_talk:"; }
       page = page.replace(new RegExp("^" + ns[j] + ":", "i"), "");
     }
     var talkpage = talkns + page;
     var container = $("<div/>", {
       "class": "editRequest",
     });
     container.append("您虽然无权编辑本页面,但您可以点击右侧按钮在本页 讨论页提出编辑请求,让可以编辑的人代为编辑:");
     $("<span/>").addClass("newComment").text("提出编辑请求").on("click", function() {
       window.open("https://www.hmoegirl.com/index.php?action=edit&preload=Template:编辑请求/comment&preloadtitle=编辑请求 - " + mw.config.get("wgUserName") + "&section=new&title=" + talkpage, "_blank");
     }).appendTo(container);
     $("#mw-content-text").children(".wikiEditor-ui:first, textarea[readonly]:first").before("<hr>").before(container);
   }
   //防滥用即将删除模板
   function antiAbuseListener(textarea, event) {
     var filters = [
       "{{ 即将删除",
       "{{ 即將刪除",
       "{{挂删",
       "{{ 模板: 即将删除",
       "{{ 模板:即將刪除",
       "{{template:即将删除",
       "{{template:即將刪除",
       "[[分类:即将删除 页面",
       "[[ 分類:即將刪除的頁面",
       "[[category:即将删除的页面",
       "[[category:即將刪除的頁面",
       "{{ 文件转移到萌娘共享",
       "{{文件轉移到萌娘共享",
       "{{模板:文件转移到萌娘共享",
       "{{模板:文件轉移到萌娘共享",
       "{{template: 文件转移到萌娘共享",
       "{{template:文件轉移到萌娘共享",
       "[[分类:需要删除执行员删除的页面",
       "[[分類:需要刪除執行員刪除的頁面",
       "[[category:需要删除执行员删除的页面",
       "[[category:需要刪除執行員刪除的頁面",
     ];
     var text1 = textarea.value;
     text1 = text1.replace(/<\/?(?:nowiki|noinclude)>/g, "");
     text1 = text1.replace(/<(onlyinclude|includeonly)>.*?<\/\1>/g, "");
     var text2 = textarea.value;
     text2 = text2.replace(/<\/?(?:onlyinclude|includeonly)>/g, "");
     text2 = text2.replace(/<(nowiki|noinclude)>.*?<\/\1>/g, "");
     var results = [];
     for (var i = 0, l = filters.length; i < l; i++) {
       var regExp = new RegExp(filters[i].replace(/\[/g, "\\["), "i");
       if (regExp.test(text1) || regExp.test(text2)) { results.push(filters[i]); }
     }
     if (results.length > 0) {
       var messageDialog = new OO.ui.MessageDialog();
       var windowManager = new OO.ui.WindowManager();
       $("body").append(windowManager.$element);
       windowManager.addWindows([messageDialog]);
       messageDialog.title.$label.html("H萌娘提醒您<br>您的编辑包含禁止内容!");
       messageDialog.message.$label.html("<br>您提交的内容包含以下部分,被禁止提交:<br><br><ul>" + results.map(function(result) {
         return "<li>" + result + "</li>";
       }).join("") + '</ul><br><br>如果您认为您的编辑无误,请在自行保存编辑内容后到<a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://www.hmoegirl.com/Talk:讨论版">讨论版</a>提问。');
       windowManager.openWindow(messageDialog, {
         actions: [{
           action: "accept",
           label: "我知道了",
           flags: "primary",
         }],
       });
       event.preventDefault();
       event.stopImmediatePropagation();
       event.stopPropagation();
       return false;
     }
   }
 
   function antiAbuse(textarea, submitButton, form) {
     mw.loader.using(["oojs-ui"]).then(function() {
       if (submitButton) {
         submitButton.addEventListener("click", function(e) {
           antiAbuseListener(textarea, e);
         }, captureSupported ? {
           capture: true,
         } : true);
       }
       if (form) {
         form.addEventListener("submit", function(e) {
           antiAbuseListener(textarea, e);
         }, captureSupported ? {
           capture: true,
         } : true);
       }
     });
   }
   /* 函数执行体 */
   $(function() {
     //Template:heimu在safari上的暴力workaround
     mw.loader.using("jquery.client", function() {
       if ($.client.profile().name === "safari") {
         $(".heimu").on("click", function() {
           $(this).toggleClass("off");
         });
       }
     });
     //Extension:MultimediaViewer的半透明化修改
     if ($("img[srcset][data-file-width][data-file-height]")[0]) { multimediaViewer(); }
     // Add "mainpage" class to the body element
     if (mw.config.get("wgMainPageTitle") === mw.config.get("wgPageName") && mw.config.get("wgAction") === "view") { $("body").addClass("mainpage"); }
     //重复文件列表区分图片和音频
     if ($(".mw-special-ListDuplicatedFiles").length && $(".mw-spcontent > p").length > 1) { duplicatedFileList(); }
     //需要时载入对应的 scripts
     if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Search") { mw.loader.load("/index.php?title=MediaWiki:Common.js/edit.js&action=raw&ctype=text/javascript"); }
     //子页面页顶链接
     if (mw.config.get("wgPageName").indexOf("/") !== -1 && (mw.config.get("wgNamespaceIds").special !== mw.config.get("wgNamespaceNumber") || mw.config.get("wgPageName").indexOf("Special:移动页面") !== -1) && !window._unsubpage) { subpage_links(); }
     //跨站重定向页顶链接
     mw.loader.using("mediawiki.Uri").then(function() {
       if (new mw.Uri().query.rdfrom && new mw.Uri(new mw.Uri().query.rdfrom).query.title && new mw.Uri(new mw.Uri().query.rdfrom).query.redirect === "no") { crossDomain_link(); }
     });
     //编辑请求
     if (["edit", "submit"].indexOf(mw.config.get("wgAction")) !== -1 && !!$(".permissions-errors, #wpTextbox1[readonly]")[1] && mw.config.get("wgUserName")) { editRequest(); }
     //修复代码编辑器$.ucFirst引用错误
     $.extend({
       ucFirst: function(_s) {
         var s = _s + "";
         return s.charAt(0).toUpperCase() + s.substring(1);
       },
     });
     //注释内列表
     $(".reference-text > ul,.reference-text > ol").each(function() {
       if (this.parentElement.childNodes[0] === this) { $(this).addClass("listInRef"); }
     });
     //列表侧边距
     setInterval(function() {
       $(".mw-parser-output ul, .mw-parser-output ol").not(".margin-left-set").each(function() {
         if (/none.+none/i.test($(this).css("list-style")) || $(this).is(".gallery")) {
           if ($(this).parent().is("li") && $(this).parent().parent().is("ul,ol")) { $(this).css("margin-left", "1.2em"); } else { $(this).css("margin-left", "0.2em"); }
         } else if ($(this).is("ol")) {
           var l = $(this).children("li").length;
           if ($(this).attr("start")) { l += parseInt($(this).attr("start")); }
           $(this).css("margin-left", (l + "").length * 0.5 + 1.2 + "em");
         } else { $(this).css("margin-left", "1.2em"); }
         $(this).addClass("margin-left-set");
       });
     }, 200);
     //修正hash跳转错误
     if ($(".mw-collapsible")[0]) {
       mw.loader.using("jquery.makeCollapsible", function() {
         $(".mw-collapsible").makeCollapsible();
         var hash = location.hash;
         location.hash = "";
         location.hash = hash;
       });
     }
     //防滥用即将删除
     if (!mw.config.get("wgUserGroups").includes("sysop") && !mw.config.get("wgUserGroups").includes("patroller")) {
       setInterval(function() {
         if ($(".Wikiplus-InterBox")[0]) {
           var targetBox = $(".Wikiplus-InterBox");
           if (targetBox.data("isTrusted") !== true) {
             targetBox.data("isTrusted", true);
             targetBox.css("z-index", 100);
             antiAbuse($("#Wikiplus-Quickedit")[0], $("#Wikiplus-Quickedit-Submit")[0], undefined);
             var events = $._data($("#Wikiplus-Quickedit")[0], "events");
             if (events && events.keydown) {
               events.keydown.sort(function(a, b) {
                 return a.guid - b.guid;
               });
               events.keydown[0].handler = function(e) {
                 if (e.ctrlKey && e.which === 83) {
                   if (e.shiftKey) {
                     $("#Wikiplus-Quickedit-MinorEdit").click();
                   }
                   if (antiAbuseListener($("#Wikiplus-Quickedit")[0], e) !== false) {
                     $("#Wikiplus-Quickedit-Submit").click();
                     e.preventDefault();
                     e.stopPropagation();
                   }
                 }
               };
             }
           }
         }
         if ($("form#editform")[0]) {
           var targetForm = $("form#editform");
           if (targetForm.data("isTrusted") !== true) {
             targetForm.data("isTrusted", true);
             antiAbuse($("#wpTextbox1")[0], $("#wpSave")[0], targetForm[0]);
           }
         }
       }, 1000);
     }
   //R18警告
   function r18Warning() {
     var content = $('<div id="x18"><div id="x18Context"><div id="x18Title"><div id="x18Icon"></div></div><div class="x18Button"></div></div></div>');
     if (!window.localStorage.getItem('x18')) { //如果没有x18记录
       $('body').css('overflow', 'hidden'); //禁止滚屏
       $('#mw-content-text').css({
         'opacity': 0
       });
   //禁止偷看
       content.prependTo('body').find('.x18Button').append('<div id="x18Yes">是</div><div id="x18No" class="x18Button">否</div>')
         .end().find('#x18Title').append('你是否已年满十八岁?')
         .end().delay(400).queue(function() {
           $(this).css({
             'opacity': 1
           }); //显示警告信息
           $(this).dequeue();
         });
       $('#x18Yes').on('click', function() {
         window.localStorage.setItem('x18', true); //记录x18
         $('#mw-content-text').css('opacity', 1).removeAttr('style'); //显示内容
         $("#x18").remove(); //移除警告信息
         $('body').removeAttr('style'); //允许滚屏
       });
       $('#x18No').on('click', function() {
         window.location.replace(window.location.origin + '/' + mw.config.get('wgMainPageTitle')); //不给你看
       });
     } else $("#x18").remove(); //如果有x18记录
   }
   $(function() {
     tabs();
     r18Warning();
   });
})();
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量以防止冲突
// </nowiki>

2020年4月10日 (五) 11:57的版本

Template-info.svg 模板文档  [查看] [编辑] [历史] [刷新]
Cat ico20.png
注意以下内容最初引自萌娘百科的同名页面,世界观可能与H萌并不相同。内容经过双方不同人员的修改后,可能会有巨大差异。骗你的啦,实际内容几乎一模一样的说QAQ
注意以下内容最初引自萌娘百科的同名页面,世界观可能与H萌并不相同。内容经过双方不同人员的修改后,可能会有巨大差异。骗你的啦,实际内容几乎一模一样的说QAQ

本模板参照维基百科的{{About}}模板进行编写,按照萌娘百科的消歧义方针帮助:消歧义页进行了较多改动。

用法

兼容旧式消歧义框的用法

  • {{About|本条目描述=《心跳文学部》的登场角色|另一含义=《NEKOPARA》的作者|另一条目名=sayori}}
  • {{About|本条目描述=《绯弹的亚里亚》的登场角色神崎·H·亚里亚|消歧义页=亚里亚}}

简单调用方法

  • {{About|本页用法|其他用法1|其他条目1}}(常见情况,只有2个用法)→
  • {{About|本页用法| |消歧义条目}}(留空参数2可以自动填写说明)→
  • {{About|本页用法|其他用法1|其他条目1|and|其他条目2}}(”and“不能改成中文)→
  • {{About|本页用法|其他用法1|其他条目1#子章节{{!}}其他条目1标题}}(使用{{!}}代替竖线来显示不同标题)→
  • {{About|本页用法|其他用法1|其他条目1|其他用法2|其他条目2|and|其他条目3}}(随意组合;表达较长时建议使用{{Otheruseslist}})→
  • {{About|本页用法|用法1|条目1|用法2|条目2|用法3|条目3|用法4|条目4}}(最多接受9个参数;此时请建立消歧义页并使用上述第2种最简短的用法)→
  • {{About| |其他用法1|其他条目1}}(可以不说明本页用法,留空参数1即可)→
  • {{About|本页用法|其他用法1|其他条目1|1|消歧义条目}}(如果除了消歧义页外还要列出其他用法,可以在倒数第二个参数使用”1“)→

其他说明

  • {{About|本章用法|其他用法1|其他条目1|section=yes}}(如果在章节下使用,请在最后添加一个section参数,赋予任意非空值,比如yes或1)→
  • {{About|本章用法|其他用法1|其他条目1|pre=在上方加提示。}}(如果要在这行说明上方添加提示,请添加pre或者”前“参数)→
  • {{About|本章用法|其他用法1|其他条目1|post=在下方加提示。}}(如果要在这行说明下方添加提示,请添加post或者”后“参数)→
  • {{About|本章用法|其他用法1|其他条目1|pre=上方无效。|post=下方有效。}}(不能在上下方同时添加提示)→
  • {{About|一个弹幕视频网站|绰号为“{{Ruby|{{lj|ビリビリ}}|BIRI BIRI}}”的虚拟角色|御坂美琴|offset=6}}(通过 offset 参数向下移动图标,默认值 -2)→

错误示例

  • {{About|本页用法|其他用法1|其他条目1| |其他条目2}}(部分参数空缺导致后方参数被忽略)→
  • {{About|本页用法|其他用法1}}(缺少参数直接报错)→

其他

  • 在编辑时使用本模板请务必预览结果。
  • 条目较多或者表述很长时请使用{{Otheruseslist}}。