MediaWiki:Common.js
Görünüm
Not: Yayımladıktan sonra değişiklikleri görmeniz için tarayıcınızın önbelleğini temizlemeniz gerekebilir.
- Firefox / Safari: Shift tuşuna basılıyken Yeniden Yükle'ye tıklayın ya da Ctrl-F5 ya da Ctrl-R tıklayın (Mac için ⌘-R)
- Google Chrome: Ctrl-Shift-R'ye basın. (Mac için ⌘-Shift-R)
- Edge: Ctrl basılıyken Yenile'ye tıklayın ya da Ctrl-F5'e basın.
1|/* İşlem Rehberi PageForms: adım numaralarını otomatik sırala. */
2|(function () {
3| var isProcedureForm = mw.config.get('wgCanonicalSpecialPageName') === 'FormEdit' &&
4| (mw.config.get('wgTitle') || '').indexOf('İşlem Rehberi') !== -1;
5| if (!isProcedureForm) {
6| return;
7| }
8|
9| function renumberSteps() {
10| var fields = Array.prototype.filter.call(document.querySelectorAll('input'), function (field) {
11| return field.name.indexOf('İşlem Adımı[') === 0 && field.name.slice(-4) === '[no]';
12| });
13| fields.forEach(function (field, index) {
14| field.value = String(index + 1);
15| field.setAttribute('value', String(index + 1));
16| });
17| }
18|
19| document.addEventListener('click', function (event) {
20| var text = (event.target.closest('button') || event.target).textContent || '';
21| if (text.indexOf('örneği ekle') !== -1 || text.indexOf('örneği kaldır') !== -1 || text.indexOf('Adım ekle') !== -1) {
22| window.setTimeout(function () {
23| renumberSteps();
24| bindImagePreviews();
25| }, 250);
26| }
27| }, true);
28|
29| var form = document.querySelector('form');
30| if (form) {
31| form.addEventListener('submit', renumberSteps, true);
32| }
33| window.setTimeout(renumberSteps, 50);
34|
35| /* Ekran görüntüsü alanında mevcut dosyayı seçince küçük önizleme göster. */
36| function previewBox(select) {
37| var span = select.closest('.comboboxSpan') || select.parentNode;
38| var box = span.querySelector('.islem-image-preview');
39| if (!box) {
40| box = document.createElement('div');
41| box.className = 'islem-image-preview';
42| box.style.cssText = 'margin-top:8px;min-height:20px;';
43| span.appendChild(box);
44| }
45| return box;
46| }
47|
48| function showExistingPreview(select) {
49| var value = (select.getAttribute('data-value') || select.value || '').replace(/^File:/i, '');
50| var span = select.closest('.comboboxSpan');
51| if (!span) return;
52| var image = span.querySelector('.simpleupload_prv');
53| if (!image) {
54| image = document.createElement('img');
55| image.className = 'simpleupload_prv';
56| span.insertBefore(image, span.firstChild);
57| }
58| if (!value) {
59| image.style.display = 'none';
60| return;
61| }
62| image.src = mw.util.getUrl('Special:Redirect/file/' + encodeURIComponent(value)) + '?width=800';
63| image.alt = value;
64| image.style.cssText = 'display:block;max-width:800px;max-height:450px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;margin:8px 0;';
65| }
66|
67| function showLocalPreview(input) {
68| var select = input.closest('.comboboxSpan') && input.closest('.comboboxSpan').querySelector('select');
69| if (!select || !input.files || !input.files[0]) return;
70| var oldImage = select.closest('.comboboxSpan').querySelector('.simpleupload_prv');
71| if (oldImage) oldImage.style.display = 'none';
72| var box = previewBox(select);
73| box.textContent = '';
74| var image = document.createElement('img');
75| image.src = URL.createObjectURL(input.files[0]);
76| image.alt = input.files[0].name;
77| image.style.cssText = 'display:block;max-width:800px;max-height:450px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;';
78| box.appendChild(image);
79| }
80|
81| function decorateFileSuggestions() {
82| document.querySelectorAll('.oo-ui-menuSelectWidget[role="listbox"] .oo-ui-optionWidget').forEach(function (item) {
83| if (item.querySelector('.islem-file-thumb')) return;
84| var label = item.querySelector('.oo-ui-labelElement-label');
85| var name = label && (label.textContent || '').trim();
86| if (!name || /^(Seç|Select)/i.test(name)) return;
87| var image = document.createElement('img');
88| image.className = 'islem-file-thumb';
89| image.alt = '';
90| image.src = mw.util.getUrl('Special:Redirect/file/' + encodeURIComponent(name)) + '?width=100';
91| image.style.cssText = 'width:80px;height:80px;object-fit:contain;vertical-align:middle;margin-right:10px;border:1px solid #c8ccd1;background:#fff;';
92| item.style.minHeight = '88px';
93| item.insertBefore(image, item.firstChild);
94| });
95| }
96|
97| function bindImagePreviews() {
98| decorateFileSuggestions();
99| document.querySelectorAll('.simpleupload_prv').forEach(function (image) {
100| image.style.cssText = 'display:block;max-width:800px;max-height:450px;width:auto;height:auto;border:1px solid #a2a9b1;padding:3px;background:#fff;margin:8px 0;';
101| });
102| document.querySelectorAll('input.pf-string-type--value[autocompletesettings="File"]').forEach(function (select) {
103| if (select.dataset.previewBound) return;
104| select.dataset.previewBound = '1';
105| select.addEventListener('change', function () { showExistingPreview(select); });
106| select.addEventListener('input', function () { window.setTimeout(function () { showExistingPreview(select); }, 100); });
107| if (select.value) showExistingPreview(select);
108| });
109| document.querySelectorAll('input[type="file"]').forEach(function (input) {
110| if (input.dataset.previewBound) return;
111| input.dataset.previewBound = '1';
112| input.addEventListener('change', function () { showLocalPreview(input); });
113| });
114| }
115|
116| bindImagePreviews();
117| if (window.MutationObserver) {
118| new MutationObserver(bindImagePreviews).observe(document.body, { childList: true, subtree: true });
119| }
120|}());
121|
122|/* Dış bağlantıları güvenli biçimde yeni sekmede aç. İç wiki bağlantılarına dokunma. */
123|(function () {
124| function openExternalLinksInNewTab() {
125| document.querySelectorAll('a.external, a.extiw').forEach(function (link) {
126| if (link.hostname && link.hostname !== window.location.hostname) {
127| link.target = '_blank';
128| link.rel = 'noopener noreferrer';
129| }
130| });
131| }
132|
133| mw.hook('wikipage.content').add(openExternalLinksInNewTab);
134| document.addEventListener('DOMContentLoaded', openExternalLinksInNewTab);
135|}());
136|
137|/* Kanun maddeleri: numara arama, filtreleme ve ilgili maddeye odaklanma. */
138|(function () {
139| function initLawArticleSearch() {
140| var lists = document.querySelectorAll('.hk-law-articles-list');
141| if (!lists.length) return;
142|
143| lists.forEach(function (list) {
144| if (list.dataset.searchReady === '1') return;
145| list.dataset.searchReady = '1';
146|
147| var box = document.createElement('div');
148| box.className = 'hk-law-article-search';
149| box.innerHTML = '<label for="hk-law-article-query">Madde numarasına git:</label>' +
150| '<input id="hk-law-article-query" type="search" inputmode="numeric" placeholder="Örn. 285" autocomplete="off">' +
151| '<button type="button">Git</button>' +
152| '<span class="hk-law-article-search-status" aria-live="polite"></span>';
153| list.parentNode.insertBefore(box, list);
154|
155| var input = box.querySelector('input');
156| var button = box.querySelector('button');
157| var status = box.querySelector('.hk-law-article-search-status');
158| var links = Array.prototype.slice.call(list.querySelectorAll('a'));
159|
160| function clearState() {
161| links.forEach(function (link) {
162| link.hidden = false;
163| link.classList.remove('hk-law-article-focus');
164| });
165| }
166|
167| function goToArticle() {
168| var value = (input.value || '').trim().replace(/^madde\s*/i, '');
169| if (!value) { clearState(); status.textContent = ''; return; }
170| filterArticles();
171| var target = links.find(function (link) {
172| return (link.textContent || '').trim().toLowerCase() === ('madde ' + value).toLowerCase();
173| });
174| if (!target) return;
175| target.classList.add('hk-law-article-focus');
176| target.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
177| status.textContent = 'Madde ' + value + ' bulundu.';
178| }
179|
180| function filterArticles() {
181| var value = (input.value || '').trim().replace(/^madde\s*/i, '').toLowerCase();
182| if (!value) { clearState(); status.textContent = ''; return; }
183| var matches = links.filter(function (link) {
184| var number = (link.textContent || '').replace(/^madde\s*/i, '').trim().toLowerCase();
185| return number.indexOf(value) === 0;
186| });
187| links.forEach(function (link) {
188| link.hidden = matches.indexOf(link) === -1;
189| link.classList.remove('hk-law-article-focus');
190| });
191| status.textContent = matches.length ? matches.length + ' uygun madde gösteriliyor.' : 'Madde bulunamadı.';
192| }
193|
194| button.addEventListener('click', goToArticle);
195| input.addEventListener('keydown', function (event) {
196| if (event.key === 'Enter') goToArticle();
197| if (event.key === 'Escape') { input.value = ''; clearState(); status.textContent = ''; }
198| });
199| input.addEventListener('input', filterArticles);
200| });
201| }
202|
203| mw.hook('wikipage.content').add(initLawArticleSearch);
204| document.addEventListener('DOMContentLoaded', initLawArticleSearch);
205|}());
/* Eksik kanun maddelerini PageForms ekranına yönlendir; Lua'da pahalı exists çağrısı yapma. */
(function () {
function routeMissingLawArticles() {
document.querySelectorAll('.hk-law-articles[data-law-title]').forEach(function (container) {
if (container.dataset.formRoutingReady === '1') return;
container.dataset.formRoutingReady = '1';
var law = container.getAttribute('data-law-title') || '';
container.querySelectorAll('.hk-law-articles-list a.new').forEach(function (link) {
var text = (link.textContent || '').trim();
var match = text.match(/^Madde\s+(\d+)$/i);
if (!match || !law) return;
var article = match[1];
var target = 'Special:FormEdit/Kanun Maddesi/' + law + '/Madde ' + article;
link.href = mw.util.getUrl(target, {
'Kanun Maddesi[kanun]': law,
'Kanun Maddesi[madde]': article
});
link.classList.add('hk-law-article-form-link');
link.title = 'Madde sayfasını oluştur';
});
});
}
mw.hook('wikipage.content').add(routeMissingLawArticles);
document.addEventListener('DOMContentLoaded', routeMissingLawArticles);
}());