恪別𡧲版𢯢𢷮𧵑「MediaWiki:Common.js」
交面
Keepout2010 (討論 | 㨂𢵰) 空固縿略𢯢𢷮 |
Keepout2010 (討論 | 㨂𢵰) 空固縿略𢯢𢷮 |
||
| 𣳔1: | 𣳔1: | ||
/* | mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () { | ||
/* Đầu hàm gọi lại mw.loader.using() */ | |||
*/ | |||
/* Kết các đoạn mã lưu bên ngoài */ | |||
mw. | if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) { | ||
// Mã chỉ dành riêng cho trang sửa đổi | |||
importScript("MediaWiki:Common.js/edit.js"); | |||
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) { | |||
// Mã chỉ dành riêng cho danh sách theo dõi | |||
importScript( 'MediaWiki:Common.js/watchlist.js' ); | |||
} | |||
/** | |||
* Sửa bố cục Trang Chính | |||
* | |||
* Miêu tả: Thêm một liên kết bổ sung đến danh sách đầy đủ các phiên bản ngôn ngữ hiện có. | |||
* Bảo trì: [[:en:User:AzaToth]], [[:en:User:R. Koot]], [[:en:User:Alex Smotrov]] | |||
*/ | |||
if ( mw.config.get( 'wgPageName' ) === 'Trang_Chính' || mw.config.get( 'wgPageName' ) === 'Thảo_luận:Trang_Chính' ) { | |||
$( function () { | |||
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/w/index.php?title=List_of_Wikipedias&uselang=vi', | |||
'Danh sách đầy đủ', 'interwiki-completelist', 'Danh sách đầy đủ các phiên bản Wikipedia' ); | |||
} ); | |||
} | |||
/** | |||
* Đổi hướng User:Name/skin.js và skin.css sang trang skin hiện tại | |||
* @source mediawiki.org/wiki/Snippets/Redirect_skin.js | |||
* @rev 3 | |||
*/ | |||
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) { | |||
var titleParts = mw.config.get( 'wgPageName' ).split( '/' ); | |||
// Make sure there was a part before and after the slash | |||
// And that the latter is 'skin.js' or 'skin.css' | |||
if ( titleParts.length == 2 ) { | |||
var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' ); | |||
if ( titleParts[1] === 'skin.js' ) { | |||
window.location.href = mw.util.getUrl( userSkinPage + '.js' ); | |||
} else if ( titleParts[1] === 'skin.css' ) { | |||
window.location.href = mw.util.getUrl( userSkinPage + '.css' ); | |||
} | |||
} | |||
} | |||
/** | |||
* addPortletLink sang mw.util | |||
* | |||
* @deprecated: Hãy dùng mw.util.addPortletLink thay thế. | |||
*/ | |||
mw.log.deprecate( window, 'addPortletLink', function () { | |||
return mw.util.addPortletLink.apply( mw.util, arguments ); | |||
}, 'Hãy dùng mw.util.addPortletLink() thay thế' ); | |||
/** | |||
* Trích xuất thông số URL từ URL hiện tại | |||
* | |||
* @deprecated: Hãy dùng mw.util.getParamValue và thoát ký tự đàng hoàng | |||
*/ | |||
mw.log.deprecate( window, 'getURLParamValue', function () { | |||
return mw.util.getParamValue.apply( mw.util, arguments ); | |||
}, 'Hãy dùng mw.util.getParamValue() thay thế' ); | |||
/** | |||
* Kiểm tra một phân tử HTML có lớp nào đó hay không | |||
* | * | ||
* | * @deprecated: Hãy dùng $(element).hasClass() thay thế. | ||
* | */ | ||
* | mw.log.deprecate( window, 'hasClass', function ( element, className ) { | ||
* | return $( element ).hasClass( className ); | ||
}, 'Hãy dùng jQuery.hasClass() thay thế' ); | |||
/** | |||
* Thông số URL &withCSS= và &withJS= | |||
* | |||
* Cho phép các mã script tùy chọn từ không gian MediaWiki không cần sửa tập tin | |||
* cá nhân như .css or .js. | |||
* | |||
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL | |||
* @rev 5 | |||
*/ | */ | ||
// CSS | |||
var extraCSS = mw.util.getParamValue( 'withCSS' ); | |||
if ( extraCSS ) { | |||
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) { | |||
importStylesheet( extraCSS ); | |||
} else { | |||
mw.notify( 'Chỉ cho phép tải bảng kiểu từ không gian tên MediaWiki.', { title: 'Giá trị withCSS không hợp lệ' } ); | |||
} | |||
} | |||
// JS | |||
var extraJS = mw.util.getParamValue( 'withJS' ); | |||
if ( extraJS ) { | |||
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) { | |||
importScript( extraJS ); | |||
} else { | |||
mw.notify( 'Chỉ cho phép tải kịch bản từ không gian tên MediaWiki.', { title: 'Giá trị withJS không hợp lệ' } ); | |||
} | |||
} | |||
/* Tải kịch bản dành cho Internet Explorer */ | |||
if ( $.client.profile().name === 'msie' ) { | |||
importScript( 'MediaWiki:Common.js/IEFixes.js' ); | |||
} | |||
/* Sửa kết xuất phông chữ Unicode trên Windows XP */ | |||
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) { | |||
mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' + | |||
'.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' ); | |||
} | |||
/** Liên kết interwiki đến các bài chọn lọc *************************************** | |||
* | |||
* Chức năng: Chuyển dấu chấm trước các liên kết liên wiki của các bài chọn lọc | |||
* thành dấu sao | |||
* Người bảo trì: [[:en:User:R. Koot]] | |||
*/ | |||
function LinkFA() { | function LinkFA() { | ||
if ( document.getElementById( | if ( document.getElementById( "p-lang" ) ) { | ||
var InterwikiLinks = document.getElementById( | var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" ); | ||
for ( var i = 0; i < InterwikiLinks.length; i++ ) { | for ( var i = 0; i < InterwikiLinks.length; i++ ) { | ||
var className = InterwikiLinks[i].className.match(/interwiki-[-\w]+/); | |||
if ( document.getElementById( className + | if ( document.getElementById( className + "-fa" ) && InterwikiLinks[i].className.indexOf( "badge-featuredarticle" ) === -1 ) { | ||
InterwikiLinks[i].className += | InterwikiLinks[i].className += " FA"; | ||
InterwikiLinks[i].title = | InterwikiLinks[i].title = "Liên kết này dẫn đến bài chọn lọc."; | ||
} else if ( document.getElementById( className + | } else if ( document.getElementById( className + "-ga" ) && InterwikiLinks[i].className.indexOf( "badge-goodarticle" ) === -1 ) { | ||
InterwikiLinks[i].className += | InterwikiLinks[i].className += " GA"; | ||
InterwikiLinks[i].title = | InterwikiLinks[i].title = "Liên kết này dẫn đến bài chất lượng tốt."; | ||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
mw.hook("wikipage.content").add(LinkFA); | |||
mw.hook( | |||
/** | |||
* Biểu tượng trên cùng góc phải. | |||
* | |||
* @source: //www.mediawiki.org/wiki/Snippets/Top_icons | |||
* @rev: 2 | |||
*/ | |||
mw.hook("wikipage.content").add(function () { | |||
$( '.right-uppermost' ).prependTo( '#firstHeading' ).show(); | |||
}); | |||
/** Bảng ẩn/hiện ********************************************************* | |||
* | |||
* Chức năng: Cho phép bản mẫu có thể ẩn đi lại, chỉ hiện tiêu đề. Xem | |||
* [[:en:Wikipedia:NavFrame]]. | |||
* Người bảo trì: | |||
*/ | |||
var autoCollapse = 2; | |||
var collapseCaption = "ẩn"; | |||
var expandCaption = "hiện"; | |||
window.collapseTable = function (tableIndex, fast) { | |||
var toggleLink = $("#collapseButton" + tableIndex); | |||
var table = $("#collapsibleTable" + tableIndex); | |||
if ( !table.length || !toggleLink.length ) { | |||
return false; | |||
} | |||
var rows = table.find("tr"); | |||
var slidingOptions = { | |||
duration: fast ? 0 : undefined | |||
}; | |||
if (toggleLink.text() === collapseCaption) { | |||
rows.slice(1).fadeOut(slidingOptions); | |||
toggleLink.text(expandCaption); | |||
} | |||
else { | |||
if (rows.first().is(":hidden")) { | |||
rows.slice(1).fadeOut(slidingOptions); | |||
} | } | ||
else { | |||
rows.slice(1).fadeIn(slidingOptions); | |||
} | } | ||
toggleLink.text(collapseCaption); | |||
} | } | ||
}; | |||
function createCollapseButtons() { | |||
/* chỉ thêm nút nếu có hàng đầu để ấy */ | |||
var tables = $("table.collapsible:has(tr th)"); | |||
tables.each(function (i, table) { | |||
$(table).attr("id", "collapsibleTable" + i); | |||
var header = $(table).find("tr th").first(); | |||
header.addClass("collapsible-header"); | |||
var toggleLink = $(mw.html.element("a", { | |||
id: "collapseButton" + i, | |||
href: "#" | |||
})); | |||
toggleLink.css("color", header.css("color")); | |||
toggleLink.append(collapseCaption); | |||
header.click(function (evt) { | |||
var target = $(evt.target); | |||
if (target.is(toggleLink) || !(target.is("a") || target.parents("a").length)) { | |||
window.collapseTable(i); | |||
evt.preventDefault(); | |||
} | |||
}); | |||
var toggleButton = $(mw.html.element("span", { | |||
"class": "collapseButton" // kiểu mẫu được định rõ trong Common.css | |||
})); | |||
toggleButton.append("["); | |||
toggleButton.append(toggleLink); | |||
toggleButton.append("]"); | |||
header.prepend(toggleButton); | |||
}); | |||
tables.each(function (i, table) { | |||
if ($(table).hasClass("collapsed") || | |||
(tables.length >= autoCollapse && $(table).hasClass("autocollapse")) || | |||
$(table).hasClass("innercollapse") && $(table).parents(".outercollapse").length) { | |||
window.collapseTable(i, true /* fast */); | |||
} | } | ||
}); | |||
} | |||
mw.hook("wikipage.content").add(createCollapseButtons); | |||
/** Thanh Chuyển hướng Động **************************************************** | |||
* | |||
* Chức năng: Xem [[:en:Wikipedia:NavFrame]]. | |||
* Người bảo trì: | |||
*/ | |||
/** | |||
* Thêm nút hiện/ẩn vào thanh chuyển hướng. | |||
*/ | |||
function createNavigationBarToggleButton() { | |||
// thiết lập các từ trong ngôn ngữ của chúng ta | |||
var hideText = "[" + collapseCaption + "]"; | |||
var showText = "[" + expandCaption + "]"; | |||
$("div.NavFrame").each(function (i, frame) { | |||
var isCollapsed = $(this).hasClass("collapsed"); | |||
$(mw.html.element("a", { | |||
"class": "NavToggle" | |||
}, isCollapsed ? showText : hideText)).appendTo($(this).find(".NavHead")); | |||
$(this).find(".NavContent").makeCollapsible({ | |||
collapsed: isCollapsed, | |||
$customTogglers: $(this).find(".NavHead, .NavToggle") | |||
}).on("beforeExpand.mw-collapsible", function (evt) { | |||
$(this).parents(".NavFrame").find(".NavToggle").text(hideText); | |||
}).on("beforeCollapse.mw-collapsible", function (evt) { | |||
$(this).parents(".NavFrame").find(".NavToggle").text(showText); | |||
}); | |||
}); | |||
} | |||
/** | |||
* Thêm nút hiện/ẩn vào thanh chuyển hướng navbox. | |||
*/ | |||
function createNavigationBarToggleButton() { | |||
// thiết lập các từ trong ngôn ngữ của chúng ta | |||
var hideText = "[" + collapseCaption + "]"; | |||
var showText = "[" + expandCaption + "]"; | |||
$("div.NavFrame").each(function (i, frame) { | |||
var isCollapsed = $(this).hasClass("collapsed"); | |||
$(mw.html.element("a", { | |||
"class": "NavToggle" | |||
}, isCollapsed ? showText : hideText)).appendTo($(this).find(".NavHead")); | |||
$(this).find(".NavContent").makeCollapsible({ | |||
collapsed: isCollapsed, | |||
$customTogglers: $(this).find(".NavHead, .NavToggle") | |||
}).on("beforeExpand.mw-collapsible mw-collapsed", function (evt) { | |||
$(this).parents(".NavFrame").find(".NavToggle").text(hideText); | |||
}).on("beforeCollapse.mw-collapsible mw-collapsed", function (evt) { | |||
$(this).parents(".NavFrame").find(".NavToggle").text(showText); | |||
}); | |||
}); | |||
} | |||
mw.hook("wikipage.content").add(function () { | |||
mw.loader.using("jquery.makeCollapsible", createNavigationBarToggleButton); | |||
}); | |||
/** Viết lại tựa bài và bỏ dòng "Hạn chế kỹ thuật" khi hiển thị một số tựa bài *************************************** | |||
Hàm dước bản mẫu {{tựa sai}} sử dụng | |||
Hàm này tìm | |||
<div id="RealTitleBanner"> | |||
<span id="RealTitle">titre</span> | |||
</div> | |||
Nếu có thành phần id="DisableRealTitle" thì tắt hàm | |||
*/ | |||
function rewritePageH1() { | |||
var realTitleBanner = document.getElementById('RealTitleBanner'); | |||
if (realTitleBanner && mw.config.get("wgNamespaceNumber") === 0) { | |||
if (!document.getElementById('DisableRealTitle')) { | |||
var realTitle = document.getElementById('RealTitle'); | |||
var h1 = document.getElementsByTagName('h1')[0]; | |||
if (realTitle && h1) { | |||
var titleText = realTitle.innerHTML; | |||
if (titleText === '') h1.style.display = 'none'; | |||
else { | |||
h1.innerHTML = titleText; | |||
document.title = document.title.replace(mw.config.get("wgPageName").replace(/_/g, " "), | |||
realTitle.textContent); | |||
} | |||
realTitleBanner.style.display = 'none'; | |||
} | } | ||
} | } | ||
} | |||
} | |||
mw.hook("wikipage.content").add(rewritePageH1); | |||
/** | |||
* Gắn bảng giới thiệu vào đầu [[Trợ giúp:Chỗ thử]]. | |||
*/ | |||
mw.hook("wikipage.content").add(function () { | |||
if (mw.config.get("wgPageName") != "Trợ_giúp:Chỗ_thử" || | |||
mw.config.get("wgAction") != "view" || $("#sandbox-intro").length) { | |||
return; | |||
} | |||
var purgeLink = mw.html.element("a", { | |||
href: mw.util.getUrl("Trợ_giúp:Chỗ_thử", { | |||
action: "edit", | |||
oldid: "15257082", | |||
summary: "Tẩy trống chỗ thử", | |||
minor: "yes" | |||
}) | |||
}, "xóa định kỳ"); | |||
var editText = mw.html.element("b", { | |||
"style": "white-space: nowrap;" | |||
}, $("#ca-ve-edit").text()); | |||
var intro = $(mw.html.element("div", { | |||
"class": "plainlinks toccolours", | |||
id: "sandbox-intro" | |||
}, new mw.html.Raw("Đây là trang bạn có thể thử thoải mái cách soạn bài " + | |||
"trong Wikipedia. Nội dung ở đây sẽ bị " + purgeLink + | |||
". Để bắt đầu sửa đổi trang này, hãy nhấn chuột vào thẻ " + | |||
editText + " ở trên."))); | |||
$("#mw-content-text").wrapInner("<div class='sandbox'></div>").prepend(intro); | |||
}); | |||
/** | |||
* Chọn chế độ sửa đổi theo cookie khi bấm liên kết đỏ. | |||
*/ | |||
mw.hook("wikipage.content").add(function () { | |||
if (mw.cookie.get("VEE", "") === "wikitext") { | |||
$(".noarticletext, .searchresults h2").find("a").each(function (idx, elt) { | |||
var uri = new mw.Uri(elt.href); | |||
if ("veaction" in uri.query) { | |||
uri.query.action = uri.query.veaction; | |||
elt.href = uri.toString(); | |||
} | |||
}); | |||
} | |||
}); | |||
/** | |||
* WikiMiniAtlas | |||
* | |||
* Description: WikiMiniAtlas is a popup click and drag world map. | |||
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button. | |||
* The script itself is located on meta because it is used by many projects. | |||
* See [[Meta:WikiMiniAtlas]] for more information. | |||
* Maintainers: [[:en:User:Dschwen]] | |||
*/ | |||
( function () { | |||
var require_wikiminiatlas = false; | |||
var coord_filter = /geohack/; | |||
$( document ).ready( function() { | |||
$( 'a.external.text' ).each( function( key, link ) { | |||
if ( link.href && coord_filter.exec( link.href ) ) { | |||
require_wikiminiatlas = true; | |||
// break from loop | |||
return false; | |||
} | |||
} ); | |||
if ( $( 'div.kmldata' ).length ) { | |||
require_wikiminiatlas = true; | |||
} | } | ||
if ( require_wikiminiatlas ) { | |||
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' ); | |||
} | |||
} ); | |||
} )(); | |||
var wma_settings = | |||
{ | |||
buttonImage: '//upload.wikimedia.org/wikipedia/commons/thumb/5/55/WMA_button2b.png/17px-WMA_button2b.png' | |||
}; | |||
/* Cố định liên kết "Tải tập tin lên" | |||
*/ | |||
mw.hook("wikipage.content").add(function() { | |||
$("#t-upload a").attr("href", mw.util.getUrl("Wikipedia:Tải tập tin lên")); | |||
}); | |||
/** Thông báo sửa đổi ma thuật **************************************************** | |||
* | |||
* Mô tả: Thêm thông báo sửa đổi cho trang định hướng và TSNDS. | |||
* Maintainers: [[User:RockMFR]] | |||
*/ | |||
function addEditIntro( name ) { | |||
$( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) { | |||
el.href = $( this ).attr( 'href' ) + '&editintro=' + name; | |||
} ); | |||
} | |||
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) { | |||
$( function () { | |||
if ( document.getElementById( 'disambig' ) ) { | |||
addEditIntro( 'Bản_mẫu:Disambig_editintro' ); | |||
} | |||
} ); | |||
} | |||
$( function () { | |||
var cats = mw.config.get('wgCategories'); | |||
if ( !cats ) { | |||
return; | |||
} | |||
if ( $.inArray( 'Nhân vật còn sống', cats ) !== -1 || $.inArray( 'Nhân vật có thể còn sống', cats ) !== -1 ) { | |||
addEditIntro( 'Bản_mẫu:BLP_editintro' ); | |||
} | |||
} ); | |||
} | |||
/** | |||
* Cho phép hiện/ẩn phần tử tùy công cụ Biên dịch nội dung được kích hoạt. | |||
*/ | |||
mw.hook("wikipage.content").add(function () { | |||
if (parseInt(mw.user.options.get("cx")) === 1) { | |||
$(document.documentElement).addClass("cx-available"); | |||
} | |||
}); | }); | ||
/* | /** | ||
* Chức năng: Ở lại máy chủ an toàn càng nhiều càng tốt | |||
* Người bảo trì: [[:en:User:TheDJ]] | |||
*/ | |||
if ( document.location && document.location.protocol && document.location.protocol === 'https:' ) { | |||
/* Các máy chủ an toàn mới */ | |||
importScript( 'MediaWiki:Common.js/secure new.js' ); | |||
} | |||
// | // Kết quả từ Wikidata | ||
// [[ | // [[:Tập tin:Wdsearch script screenshot.png]] | ||
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === ' | if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' || ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) { | ||
importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript"); | importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript"); | ||
} | } | ||
/* Kết hàm gọi lại mw.loader.using() */ | |||
} ); | |||
/* ĐỪNG THÊM MÃ DƯỚI DÒNG NÀY */ | |||
番版𣅶19:54、𣈜25𣎃12𢆥2018
mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () {
/* Đầu hàm gọi lại mw.loader.using() */
/* Kết các đoạn mã lưu bên ngoài */
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
// Mã chỉ dành riêng cho trang sửa đổi
importScript("MediaWiki:Common.js/edit.js");
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
// Mã chỉ dành riêng cho danh sách theo dõi
importScript( 'MediaWiki:Common.js/watchlist.js' );
}
/**
* Sửa bố cục Trang Chính
*
* Miêu tả: Thêm một liên kết bổ sung đến danh sách đầy đủ các phiên bản ngôn ngữ hiện có.
* Bảo trì: [[:en:User:AzaToth]], [[:en:User:R. Koot]], [[:en:User:Alex Smotrov]]
*/
if ( mw.config.get( 'wgPageName' ) === 'Trang_Chính' || mw.config.get( 'wgPageName' ) === 'Thảo_luận:Trang_Chính' ) {
$( function () {
mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/w/index.php?title=List_of_Wikipedias&uselang=vi',
'Danh sách đầy đủ', 'interwiki-completelist', 'Danh sách đầy đủ các phiên bản Wikipedia' );
} );
}
/**
* Đổi hướng User:Name/skin.js và skin.css sang trang skin hiện tại
* @source mediawiki.org/wiki/Snippets/Redirect_skin.js
* @rev 3
*/
if ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgNamespaceNumber' ) === 2 ) {
var titleParts = mw.config.get( 'wgPageName' ).split( '/' );
// Make sure there was a part before and after the slash
// And that the latter is 'skin.js' or 'skin.css'
if ( titleParts.length == 2 ) {
var userSkinPage = titleParts[0] + '/' + mw.config.get( 'skin' );
if ( titleParts[1] === 'skin.js' ) {
window.location.href = mw.util.getUrl( userSkinPage + '.js' );
} else if ( titleParts[1] === 'skin.css' ) {
window.location.href = mw.util.getUrl( userSkinPage + '.css' );
}
}
}
/**
* addPortletLink sang mw.util
*
* @deprecated: Hãy dùng mw.util.addPortletLink thay thế.
*/
mw.log.deprecate( window, 'addPortletLink', function () {
return mw.util.addPortletLink.apply( mw.util, arguments );
}, 'Hãy dùng mw.util.addPortletLink() thay thế' );
/**
* Trích xuất thông số URL từ URL hiện tại
*
* @deprecated: Hãy dùng mw.util.getParamValue và thoát ký tự đàng hoàng
*/
mw.log.deprecate( window, 'getURLParamValue', function () {
return mw.util.getParamValue.apply( mw.util, arguments );
}, 'Hãy dùng mw.util.getParamValue() thay thế' );
/**
* Kiểm tra một phân tử HTML có lớp nào đó hay không
*
* @deprecated: Hãy dùng $(element).hasClass() thay thế.
*/
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
return $( element ).hasClass( className );
}, 'Hãy dùng jQuery.hasClass() thay thế' );
/**
* Thông số URL &withCSS= và &withJS=
*
* Cho phép các mã script tùy chọn từ không gian MediaWiki không cần sửa tập tin
* cá nhân như .css or .js.
*
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
* @rev 5
*/
// CSS
var extraCSS = mw.util.getParamValue( 'withCSS' );
if ( extraCSS ) {
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
importStylesheet( extraCSS );
} else {
mw.notify( 'Chỉ cho phép tải bảng kiểu từ không gian tên MediaWiki.', { title: 'Giá trị withCSS không hợp lệ' } );
}
}
// JS
var extraJS = mw.util.getParamValue( 'withJS' );
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
importScript( extraJS );
} else {
mw.notify( 'Chỉ cho phép tải kịch bản từ không gian tên MediaWiki.', { title: 'Giá trị withJS không hợp lệ' } );
}
}
/* Tải kịch bản dành cho Internet Explorer */
if ( $.client.profile().name === 'msie' ) {
importScript( 'MediaWiki:Common.js/IEFixes.js' );
}
/* Sửa kết xuất phông chữ Unicode trên Windows XP */
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
'.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
}
/** Liên kết interwiki đến các bài chọn lọc ***************************************
*
* Chức năng: Chuyển dấu chấm trước các liên kết liên wiki của các bài chọn lọc
* thành dấu sao
* Người bảo trì: [[:en:User:R. Koot]]
*/
function LinkFA() {
if ( document.getElementById( "p-lang" ) ) {
var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
for ( var i = 0; i < InterwikiLinks.length; i++ ) {
var className = InterwikiLinks[i].className.match(/interwiki-[-\w]+/);
if ( document.getElementById( className + "-fa" ) && InterwikiLinks[i].className.indexOf( "badge-featuredarticle" ) === -1 ) {
InterwikiLinks[i].className += " FA";
InterwikiLinks[i].title = "Liên kết này dẫn đến bài chọn lọc.";
} else if ( document.getElementById( className + "-ga" ) && InterwikiLinks[i].className.indexOf( "badge-goodarticle" ) === -1 ) {
InterwikiLinks[i].className += " GA";
InterwikiLinks[i].title = "Liên kết này dẫn đến bài chất lượng tốt.";
}
}
}
}
mw.hook("wikipage.content").add(LinkFA);
/**
* Biểu tượng trên cùng góc phải.
*
* @source: //www.mediawiki.org/wiki/Snippets/Top_icons
* @rev: 2
*/
mw.hook("wikipage.content").add(function () {
$( '.right-uppermost' ).prependTo( '#firstHeading' ).show();
});
/** Bảng ẩn/hiện *********************************************************
*
* Chức năng: Cho phép bản mẫu có thể ẩn đi lại, chỉ hiện tiêu đề. Xem
* [[:en:Wikipedia:NavFrame]].
* Người bảo trì:
*/
var autoCollapse = 2;
var collapseCaption = "ẩn";
var expandCaption = "hiện";
window.collapseTable = function (tableIndex, fast) {
var toggleLink = $("#collapseButton" + tableIndex);
var table = $("#collapsibleTable" + tableIndex);
if ( !table.length || !toggleLink.length ) {
return false;
}
var rows = table.find("tr");
var slidingOptions = {
duration: fast ? 0 : undefined
};
if (toggleLink.text() === collapseCaption) {
rows.slice(1).fadeOut(slidingOptions);
toggleLink.text(expandCaption);
}
else {
if (rows.first().is(":hidden")) {
rows.slice(1).fadeOut(slidingOptions);
}
else {
rows.slice(1).fadeIn(slidingOptions);
}
toggleLink.text(collapseCaption);
}
};
function createCollapseButtons() {
/* chỉ thêm nút nếu có hàng đầu để ấy */
var tables = $("table.collapsible:has(tr th)");
tables.each(function (i, table) {
$(table).attr("id", "collapsibleTable" + i);
var header = $(table).find("tr th").first();
header.addClass("collapsible-header");
var toggleLink = $(mw.html.element("a", {
id: "collapseButton" + i,
href: "#"
}));
toggleLink.css("color", header.css("color"));
toggleLink.append(collapseCaption);
header.click(function (evt) {
var target = $(evt.target);
if (target.is(toggleLink) || !(target.is("a") || target.parents("a").length)) {
window.collapseTable(i);
evt.preventDefault();
}
});
var toggleButton = $(mw.html.element("span", {
"class": "collapseButton" // kiểu mẫu được định rõ trong Common.css
}));
toggleButton.append("[");
toggleButton.append(toggleLink);
toggleButton.append("]");
header.prepend(toggleButton);
});
tables.each(function (i, table) {
if ($(table).hasClass("collapsed") ||
(tables.length >= autoCollapse && $(table).hasClass("autocollapse")) ||
$(table).hasClass("innercollapse") && $(table).parents(".outercollapse").length) {
window.collapseTable(i, true /* fast */);
}
});
}
mw.hook("wikipage.content").add(createCollapseButtons);
/** Thanh Chuyển hướng Động ****************************************************
*
* Chức năng: Xem [[:en:Wikipedia:NavFrame]].
* Người bảo trì:
*/
/**
* Thêm nút hiện/ẩn vào thanh chuyển hướng.
*/
function createNavigationBarToggleButton() {
// thiết lập các từ trong ngôn ngữ của chúng ta
var hideText = "[" + collapseCaption + "]";
var showText = "[" + expandCaption + "]";
$("div.NavFrame").each(function (i, frame) {
var isCollapsed = $(this).hasClass("collapsed");
$(mw.html.element("a", {
"class": "NavToggle"
}, isCollapsed ? showText : hideText)).appendTo($(this).find(".NavHead"));
$(this).find(".NavContent").makeCollapsible({
collapsed: isCollapsed,
$customTogglers: $(this).find(".NavHead, .NavToggle")
}).on("beforeExpand.mw-collapsible", function (evt) {
$(this).parents(".NavFrame").find(".NavToggle").text(hideText);
}).on("beforeCollapse.mw-collapsible", function (evt) {
$(this).parents(".NavFrame").find(".NavToggle").text(showText);
});
});
}
/**
* Thêm nút hiện/ẩn vào thanh chuyển hướng navbox.
*/
function createNavigationBarToggleButton() {
// thiết lập các từ trong ngôn ngữ của chúng ta
var hideText = "[" + collapseCaption + "]";
var showText = "[" + expandCaption + "]";
$("div.NavFrame").each(function (i, frame) {
var isCollapsed = $(this).hasClass("collapsed");
$(mw.html.element("a", {
"class": "NavToggle"
}, isCollapsed ? showText : hideText)).appendTo($(this).find(".NavHead"));
$(this).find(".NavContent").makeCollapsible({
collapsed: isCollapsed,
$customTogglers: $(this).find(".NavHead, .NavToggle")
}).on("beforeExpand.mw-collapsible mw-collapsed", function (evt) {
$(this).parents(".NavFrame").find(".NavToggle").text(hideText);
}).on("beforeCollapse.mw-collapsible mw-collapsed", function (evt) {
$(this).parents(".NavFrame").find(".NavToggle").text(showText);
});
});
}
mw.hook("wikipage.content").add(function () {
mw.loader.using("jquery.makeCollapsible", createNavigationBarToggleButton);
});
/** Viết lại tựa bài và bỏ dòng "Hạn chế kỹ thuật" khi hiển thị một số tựa bài ***************************************
Hàm dước bản mẫu {{tựa sai}} sử dụng
Hàm này tìm
<div id="RealTitleBanner">
<span id="RealTitle">titre</span>
</div>
Nếu có thành phần id="DisableRealTitle" thì tắt hàm
*/
function rewritePageH1() {
var realTitleBanner = document.getElementById('RealTitleBanner');
if (realTitleBanner && mw.config.get("wgNamespaceNumber") === 0) {
if (!document.getElementById('DisableRealTitle')) {
var realTitle = document.getElementById('RealTitle');
var h1 = document.getElementsByTagName('h1')[0];
if (realTitle && h1) {
var titleText = realTitle.innerHTML;
if (titleText === '') h1.style.display = 'none';
else {
h1.innerHTML = titleText;
document.title = document.title.replace(mw.config.get("wgPageName").replace(/_/g, " "),
realTitle.textContent);
}
realTitleBanner.style.display = 'none';
}
}
}
}
mw.hook("wikipage.content").add(rewritePageH1);
/**
* Gắn bảng giới thiệu vào đầu [[Trợ giúp:Chỗ thử]].
*/
mw.hook("wikipage.content").add(function () {
if (mw.config.get("wgPageName") != "Trợ_giúp:Chỗ_thử" ||
mw.config.get("wgAction") != "view" || $("#sandbox-intro").length) {
return;
}
var purgeLink = mw.html.element("a", {
href: mw.util.getUrl("Trợ_giúp:Chỗ_thử", {
action: "edit",
oldid: "15257082",
summary: "Tẩy trống chỗ thử",
minor: "yes"
})
}, "xóa định kỳ");
var editText = mw.html.element("b", {
"style": "white-space: nowrap;"
}, $("#ca-ve-edit").text());
var intro = $(mw.html.element("div", {
"class": "plainlinks toccolours",
id: "sandbox-intro"
}, new mw.html.Raw("Đây là trang bạn có thể thử thoải mái cách soạn bài " +
"trong Wikipedia. Nội dung ở đây sẽ bị " + purgeLink +
". Để bắt đầu sửa đổi trang này, hãy nhấn chuột vào thẻ " +
editText + " ở trên.")));
$("#mw-content-text").wrapInner("<div class='sandbox'></div>").prepend(intro);
});
/**
* Chọn chế độ sửa đổi theo cookie khi bấm liên kết đỏ.
*/
mw.hook("wikipage.content").add(function () {
if (mw.cookie.get("VEE", "") === "wikitext") {
$(".noarticletext, .searchresults h2").find("a").each(function (idx, elt) {
var uri = new mw.Uri(elt.href);
if ("veaction" in uri.query) {
uri.query.action = uri.query.veaction;
elt.href = uri.toString();
}
});
}
});
/**
* WikiMiniAtlas
*
* Description: WikiMiniAtlas is a popup click and drag world map.
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
* The script itself is located on meta because it is used by many projects.
* See [[Meta:WikiMiniAtlas]] for more information.
* Maintainers: [[:en:User:Dschwen]]
*/
( function () {
var require_wikiminiatlas = false;
var coord_filter = /geohack/;
$( document ).ready( function() {
$( 'a.external.text' ).each( function( key, link ) {
if ( link.href && coord_filter.exec( link.href ) ) {
require_wikiminiatlas = true;
// break from loop
return false;
}
} );
if ( $( 'div.kmldata' ).length ) {
require_wikiminiatlas = true;
}
if ( require_wikiminiatlas ) {
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
}
} );
} )();
var wma_settings =
{
buttonImage: '//upload.wikimedia.org/wikipedia/commons/thumb/5/55/WMA_button2b.png/17px-WMA_button2b.png'
};
/* Cố định liên kết "Tải tập tin lên"
*/
mw.hook("wikipage.content").add(function() {
$("#t-upload a").attr("href", mw.util.getUrl("Wikipedia:Tải tập tin lên"));
});
/** Thông báo sửa đổi ma thuật ****************************************************
*
* Mô tả: Thêm thông báo sửa đổi cho trang định hướng và TSNDS.
* Maintainers: [[User:RockMFR]]
*/
function addEditIntro( name ) {
$( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
} );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
$( function () {
if ( document.getElementById( 'disambig' ) ) {
addEditIntro( 'Bản_mẫu:Disambig_editintro' );
}
} );
$( function () {
var cats = mw.config.get('wgCategories');
if ( !cats ) {
return;
}
if ( $.inArray( 'Nhân vật còn sống', cats ) !== -1 || $.inArray( 'Nhân vật có thể còn sống', cats ) !== -1 ) {
addEditIntro( 'Bản_mẫu:BLP_editintro' );
}
} );
}
/**
* Cho phép hiện/ẩn phần tử tùy công cụ Biên dịch nội dung được kích hoạt.
*/
mw.hook("wikipage.content").add(function () {
if (parseInt(mw.user.options.get("cx")) === 1) {
$(document.documentElement).addClass("cx-available");
}
});
/**
* Chức năng: Ở lại máy chủ an toàn càng nhiều càng tốt
* Người bảo trì: [[:en:User:TheDJ]]
*/
if ( document.location && document.location.protocol && document.location.protocol === 'https:' ) {
/* Các máy chủ an toàn mới */
importScript( 'MediaWiki:Common.js/secure new.js' );
}
// Kết quả từ Wikidata
// [[:Tập tin:Wdsearch script screenshot.png]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' || ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
importScriptURI("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}
/* Kết hàm gọi lại mw.loader.using() */
} );
/* ĐỪNG THÊM MÃ DƯỚI DÒNG NÀY */