MediaWiki Webサイトで読みやすいため、現在の安定バージョン(1.16.x)のラインには組み込みのjQueryライブラリが付属しており、そのコードは
この欲求の最初の衝動は、jQueryがデフォルトで設定されているページコード内にあることの不便さを自然に、そしてほぼ避けられない形で実現することです。 すべての
function editZeroSection(){ var body = document.getElementById('bodyContent') if (!body) return var h2s = body.getElementsByTagName('H2') var h2 = h2s[0] if (!h2) return if (h2.parentNode.id == 'toctitle') h2 = h2s[1] if (!h2) return var span = h2.firstChild if (!span || span.className != 'editsection') return var zero = span.cloneNode(true) body.insertBefore(zero, body.firstChild) var a = zero.getElementsByTagName('a')[0] if (a.href.indexOf('§ion=T') == -1 ) a.title = a.title.replace(/:.*$/,': 0') else a.title = ' : 0' a.setAttribute('href', wgScript + '?title='+encodeURIComponent(wgPageName) + '&action=edit§ion=0') }
jQueryファンは、このライブラリが関数の作成者公式の指示に従い 、LocalSettings.phpファイルに適切なコードを追加することにより
// Include jQuery function wfIncludeJQuery() { global $wgOut; $wgOut->includeJQuery(); } $wgExtensionFunctions[] = 'wfIncludeJQuery';
「MediaWiki:Common.js」ページを編集する権限を持つWiki管理者は、jQueryのローカル関数の書き換えを開始し、 まず、jQueryの歴史に精通すると、
第二に、既存のスクリプト
$(function(){ $.localScroll({ hash: true, onAfter: function(target){ location = '#' + ( target.id || target.name ); } }); });
自動目次を備えたMediaWikiエンジンWikiの場合、このような動作の改善は非常に貴重です。
この段階では、イベントの過程で、新しいバージョンのjQueryライブラリとすべての必要なプラグインの両方を含むファイル(何よりも、サーバーへの余分なリクエストに時間を浪費しない
そのような配置は技術的に達成可能ですか? はい、かなり達成可能です。 そのためには、ファイル「LocalSettings.php」から、前の段階で追加された
「MediaWiki:jQuery.js」を各ウィキページに接続するMediaWiki拡張コードを作成するタスクは、長い間解決されました。その答え(コード)は次のとおりです(MITライセンスを含む)。
<?php /* * jQuery.php - Adds jQuery script to the <head> . . . </head> * @author Mithgol the Webmaster * @version 0.2 * @copyright Copyright (C) 2010 Mithgol the Webmaster * @license The MIT License - http://www.opensource.org/licenses/mit-license.php * --------------------------------------------------------------------------------------- * Copyright (c) 2010 Mithgol the Webmaster * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * ----------------------------------------------------------------------- * Version notes: * version 0.2: * erase MediaWiki's internal jQuery call, which lacks plugins * version 0.1: * initial release * ----------------------------------------------------------------------- */ # Confirm MW environment if (defined('MEDIAWIKI')) { # Credits $wgExtensionCredits['other'][] = array( 'name' => 'jQuery', 'author' => 'Mithgol the Webmaster', 'url' => 'http://traditio.ru/wiki/JQuery_%D0%B4%D0%BB%D1%8F_MediaWiki', 'description' => 'Adds jQuery to the list of scripts (HEAD element).', 'version' => '0.2' ); function jQueryMyHook( &$output, &$skin ) { $output->mScripts = "\t\t". '<script type="text/javascript" src="/w/index.php?title=MediaWiki:jQuery.js&action=raw&ctype=text/javascript"></script>'. "\n" . preg_replace('/<script src="\/w\/skins\/common\/jquery\.min\.js\?\d+"><\/script>/', '<!-- jQuery double, erased -->', $output->mScripts); return true; } $wgHooks['BeforePageDisplay'][] = 'jQueryMyHook'; } # End MW Environment wrapper ?>
バイトファイルファイル「MediaWiki:jQuery.js」に入力する場合、jQuery名形式の
/* MediaWiki: * 1) /skins/common/edit.js * 2) /skins/common/preview.js * , jQuery $j. * : */ $j=$;
明らかに、この同義語はjQueryライブラリコード自体の後に作成されることを願っています。
上記の拡張は、2010年にロシアの