Wikipedysta:Matma Rex/redirs.js

//
//
//poprawa linków do redirectów v. 0.2 by Saper, Matma Rex
//
//

if(typeof dodajOpis=='undefined') //powinna już być taka funkcja, ale gdyby nie...
{
	function dodajOpis(opis)
	{
		var wpS = document.editform.wpSummary;
		if (wpS.value != '' && wpS.value.charAt(wpS.value.length-2) != '/')
		{
			wpS.value += ', ' + opis
		}
		else
		{
			wpS.value += opis
		}
	}
}

function removeDupes(a)
{ //http://www.martienus.com/code/javascript-remove-duplicates-from-array.html
   var r = []
   o:for(var i = 0, n = a.length; i < n; i++)
	 {
      for(var x = 0, y = r.length; x < y; x++)
			{
				if(r[x]==a[i]) continue o
			}
			
      r[r.length] = a[i]
   }
   return r
}

/*
	mintAjax 1.2.4.2
	www.mintajax.pl
	Copyright 2007 Piotr Korzeniewski
	Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
importScript('Wikipedysta:Matma Rex/mintAjaxRequest.js')

if(typeof wpsk=='undefined')
{
	wpsk_nobutton=true
	importScript('Wikipedysta:BartekChom/wpsk.js')
}


var paras={}

function getLocationParas()
{
	parameters = location.search.split("&")
	
	for (i in parameters)
	{
		parameters[i] = parameters[i].split("=")
		
		if(parameters[i].length==2)
		{
			paras[unescape(parameters[i][0])] = unescape(parameters[i][1])
		}
	}
}

function replaceRedirs()
{
	var req = mint.Request()
	req.getJSON = true
	req.OnSuccess = function()
	{
		rs=this.responseJSON.query.redirects
		wpT=document.getElementById('wpTextbox1')
		txt=wpsk.m.linkowatoSzablonowate(wpT.value)
		count=0
		
		for(i in rs)
		{			
			re1=new RegExp('\\[\\[('+rs[i].from+')\\]\\](\\w+|)\\b','gi')
			re2=new RegExp('\\[\\['+rs[i].from+'\\|','gi')
			
			txt_=txt.replace(re1,'[['+rs[i].to+'|$1$2]]')
			if(txt==txt_) txt_=txt.replace(re2,'[['+rs[i].to+'|')
			
			if(txt!=txt_)
			{
				count++
				txt=txt_
			}
		}
		
		wpT.value=txt
		
		if(count>0)
		{
			if(count==1) dodajOpis('poprawa linku do przekierowania')
			else dodajOpis('poprawa linków do '+count+' przekierowań')
		}
	}
	
	rList=paras.fixredir||''
	if(rList!='') req.Send(location.protocol + "//" + location.host + "/w/api.php?action=query&redirects&format=json&titles=" + escape(paras.fixredir))
}

function makeRedirsList()
{
	el=document.getElementById('bodyContent') || document.getElementById('article')
	links=el.getElementsByTagName('a')
	redirs=[]
	
	for(i in links)
	{
		if (links[i].className == 'mw-redirect')
		{
			redirs.push(links[i].title)
		}
	}
	
	redirs=removeDupes(redirs)
	redirsTxt=redirs.join('|')
	
	if(redirsTxt!='')
	{
		dl=document.links
		for(i in dl)
		{
			if(dl[i].href && dl[i].href.indexOf("action=edit")!=-1 && dl[i].className!="new")
			{
				dl[i].href += "&fixredir=" + escape(redirsTxt)
			}
		}
	}
}

function redirsButton(anyRedirs)
{
	editform=document.getElementById('editform')
	toolbar=document.getElementById('toolbar')

	var button=document.createElement('span')
	
	if(anyRedirs)
	{
		button.innerHTML='<a title="Popraw linki do przekierowań" href="https://profillengkap.com/pl/javascript:replaceRedirs()">#R</a>'
	}
	else
	{
		button.title='Brak linków do przekierowań na tej stronie'
		button.innerHTML='#R'
	}
	

	if(toolbar) toolbar.appendChild(button)
	else editform.parentNode.insertBefore(button,editform)
}

$(getLocationParas)

if(mw.config.get('wgAction')=='edit') addOnloadHook(function()
{
a=( (paras.fixredir && paras.fixredir!='') ? true : false )
redirsButton(a)
}
)
else addOnloadHook(makeRedirsList)

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Kembali kehalaman sebelumnya