MediaWiki:Upload.js — различия между версиями

Материал из Мегапедии
Перейти к: навигация, поиск
м (Правки Crush (обсуждение) откачены к версии Arhssaarh)
 
Строка 2: Строка 2:
 
  if (window.wgUploadAutoFill){
 
  if (window.wgUploadAutoFill){
 
   upForm = document.getElementById('mw-upload-form')
 
   upForm = document.getElementById('mw-upload-form')
  upForm.onsubmit = checkUpForm
 
 
  }
 
  }
 
  var desc = document.getElementById('wpUploadDescription')
 
  var desc = document.getElementById('wpUploadDescription')
Строка 48: Строка 47:
 
  }
 
  }
 
}
 
}
function checkUpForm(){
 
upForm = document.getElementById('mw-upload-form')
 
var desc = document.getElementById('wpUploadDescription')
 
var lcns = document.getElementById('wpLicense')
 
var wrn = document.createElement('div')
 
wrn.innerHTML = ''
 
if (lcns.value == '' && /^[^\{\}]*(\{\{(Изображение|Файл)[^\{\}]+\}\}[^\{\}]*)*$/i.exec(desc.value))
 
  wrn.innerHTML += '<li></li>'
 
if (lcns.value != '' && lcns.value != 'subst:ET' && /\{\{Файл/i.exec(desc.value))
 
  wrn.innerHTML += '<li></li>'
 
if (lcns.value == '' && /\{\{Файл\s*((\|\s*)+[\s\wа-яё]+=\s*)*(\|\s*)*\}\}/i.exec(desc.value))
 
  wrn.innerHTML += '<li>Не заполнен шаблон {'+'{Файл}}.</li>'
 
if (lcns.value == '' && /\{\{Файл\s*((\|\s*)+([\wа-яё]+\s*)+=\s*)*(\|\s*)*\}\}/i.exec(desc.value))
 
  wrn.innerHTML += '<li></li>'
 
if (lcns.value == '' && /\{\{Файл\/Хм\s*((\|\s*)+([\wа-яё]+\s*)+=\s*)*(\|\s*)*\}\}/i.exec(desc.value))
 
  wrn.innerHTML += '<li>Не заполнен шаблон {'+'{Файл}}.</li>'
 
if (/\{\{(Файл|Изображение)[^\{\}]*Источник\s*=\s*(из|с|http:\/\/(www\.)?)?\s*(интернет|internet|гугл|google|яндекс|yandex|яху|yahoo|рамблер|rambler)[^\{\}]*\}\}/i.test(desc.value))
 
  wrn.innerHTML += ''
 
if (wrn.innerHTML != ''){
 
  wrn.innerHTML = '' + wrn.innerHTML
 
  wrn.innerHTML += ''
 
  var oldWrn = document.getElementById('jsUploadWarnings')
 
  if (oldWrn) {
 
  return true
 
  }
 
  else {
 
  wrn.style.border = '1px solid red'
 
  wrn.style.background = '#ffe4e1'
 
  wrn.id = 'jsUploadWarnings'
 
  upNode = document.getElementById('mw-htmlform-options').parentNode
 
  upNode.parentNode.insertBefore(wrn, upNode)
 
  }
 
  return false
 
}
 
else {
 
  return true
 
}
 
}
 
 
 
   
 
   
 
/* Hide quick insert */
 
/* Hide quick insert */

Текущая версия на 00:38, 10 мая 2013

function uploadPage(){
 if (window.wgUploadAutoFill){
  upForm = document.getElementById('mw-upload-form')
 }
 var desc = document.getElementById('wpUploadDescription')
 var tmpl = document.getElementById('imageinfo')
 if (wgUploadAutoFill && tmpl && desc && !desc.value) desc.value = tmpl.innerHTML
 appendCSS('a.insertlink { text-decoration: none; }')
 var span = document.getElementById('insertlink-free')
 if (!!span) {
  var a = document.createElement('a')
  a.href = 'javascript:addInfoTemplate("rationale", "imageinfo", 8)'
  a.class = 'insertlink'
  span.parentNode.insertBefore(a, span)
  a.appendChild(span)
 }
 var span = document.getElementById('insertlink-unfree')
 if (!!span) {
  var a = document.createElement('a')
  a.href = 'javascript:addInfoTemplate("imageinfo", "rationale", 16)'
  a.class = 'insertlink'
  span.parentNode.insertBefore(a, span)
  a.appendChild(span)
 }
 var c = document.getElementById('commons-link')
 var c_a = c.lastChild
 c.innerHTML = '<input class="commons-btn" type="button" onclick="window.location.href=\''+c_a.href+'\'" value="'+c_a.text+'"/>'
}
function addInfoTemplate(oldId, newId, rows){
 var desc = document.getElementById('wpUploadDescription')
 var oldTmpl = document.getElementById(oldId)
 var tmpl = document.getElementById(newId)
 if (desc && oldTmpl && desc.value == oldTmpl.innerHTML){
   desc.value = tmpl.innerHTML
   desc.rows = rows
 }
 else if (desc && tmpl && desc.value.indexOf(tmpl.innerHTML.substring(0,8)) == -1){
   desc.value += '\n' + tmpl.innerHTML
   desc.rows = 20
 }
 licList = document.getElementsByTagName('option', document.getElementById('wpLicense'))
 if (newId == 'rationale'){
   licList[licList.length-1].selected='selected'
 }
 else {
   licList[0].selected='selected'
 }
}
 
/* Hide quick insert */
function uploadHideInsert(){
 qIns = document.getElementById('editpage-specialchars')
 qInsCover = document.createElement('div')
 qInsCover.setAttribute('style', qIns.style.cssText)
 if (typeof(qInsCover.style.setAttribute) == 'function') qInsCover.style.setAttribute('style', qIns.style.cssText) // IE
 qInsCover.innerHTML = '<small><span style="border-bottom:1px dotted gray; cursor:help" title="Позволяет быстро вставлять символы разметки в поле описания">Быстрая вставка</span> (<a href="javascript:uploadExpandInsert()">раскрыть блок</a>)</small>'
 qIns.style.display = 'none'
 qIns.parentNode.appendChild(qInsCover)
}
 
function uploadExpandInsert(){
 qInsCover.style.display = 'none'
 qIns.style.display = 'block'
}
 
 
/* Ajax Preview */
function uploadPreviewRun(){
 wpUploadPreview.innerHTML = ''
 injectSpinner(wpUploadPreview,'preview')
 var aj = sajax_init_object()
 aj.onreadystatechange = function(){
  if (aj.readyState!=4 || aj.status!=200) return
  removeSpinner('preview')
  wpUploadPreview.innerHTML = eval('('+aj.responseText+')')['parse']['text']['*']
  wpUploadPreview.scrollIntoView()
 }
 aj.open('GET', '/w/api.php?action=parse&prop=text&pst&format=json&text=' 
  + encodeURIComponent(wpUploadText.value), true)
 aj.send('')
}
 
function uploadPreviewInit(){
 wpUploadText = document.getElementById('wpUploadDescription')
 if (!wpUploadText) return
 var bt = create('input','wpDestFile'); bt.type='button'
 bt.style.cssFloat = bt.style.styleFloat = 'right'
 bt.value = 'Предпросмотр'; bt.onclick = uploadPreviewRun
 wpUploadPreview = create('div','wpLicense')
 function create(type, attachTo){
  var el = document.createElement(type)
  attachTo = document.getElementById(attachTo) || wpUploadText
  attachTo.parentNode.appendChild(el)
  return el
 } 
}
 
 
addOnloadHook(uploadPage)
addOnloadHook(uploadHideInsert)
addOnloadHook(uploadPreviewInit)