מדיה ויקי:Gadget-quickLinker.js: הבדלים בין גרסאות בדף

מ case insensitive
מ החלפת קישורים
שורה 23: שורה 23:
function createQuickEditorDialog(searchRes){
function createQuickEditorDialog(searchRes){
function QuickEditorDialog( config ) {
function QuickEditorDialog( config ) {
  this.contextRgx = new RegExp('.*[^\[](' + mw.RegExp.escape(titleNoBrackets) +')(?!\]\]).*', 'i');
  this.contextRgx = new RegExp('(.*[^\[])(' + mw.RegExp.escape(titleNoBrackets) +')((?!\]\]).*)', 'i');
  this.contextRgxLink = new RegExp('(.*\\[\\[)([^\\]]+?)\\|(' + mw.RegExp.escape(titleNoBrackets) +')(\\]\\].*)', 'i');
  this.pageI = -1;
  this.pageI = -1;
  this.searchData = null;
  this.searchData = null;
שורה 87: שורה 88:
if (this.curPage)
if (this.curPage)
{
{
var api = new mw.Api(), pagename = this.curPage;
var api = new mw.Api(), pagename = this.curPage;
api.postWithToken('edit', {
api.postWithToken('csrf', {
action: 'edit',
action: 'edit',
title: this.curPage,
title: this.curPage,
שורה 104: שורה 104:


QuickEditorDialog.prototype.nextPage = function ( ) {
QuickEditorDialog.prototype.nextPage = function ( ) {
var m, contextPre, contextPost, contextInner, contextInnerOld, newContext;
this.pageI++;
this.pageI++;
if (this.searchData.pageids.length==this.pageI)
if (this.searchData.pageids.length==this.pageI)
שורה 110: שורה 111:
return;
return;
}
}
var page = this.searchData.pages[this.searchData.pageids[this.pageI]];
var page = this.searchData.pages[this.searchData.pageids[this.pageI]],
pagecontent = page.revisions[0]['*'];


var pagecontent = page.revisions[0]['*'];
if (m = this.contextRgx.exec(pagecontent)) {
if ((page.title!=mw.config.get('wgTitle')) && (m = this.contextRgx.exec(pagecontent))) {
contextPost = m[3];
var context = m[0], candidateLink = m[1];
contextInner = (m[2] == mw.config.get('wgTitle')) ? '[['+mw.config.get('wgTitle')+']]' : '[['+mw.config.get('wgTitle')+'|' + m[2] + ']]';
var contextPre = context.substr(0, context.indexOf(candidateLink)),
contextInnerOld = '';
contextPost = context.substr(contextPre.length+candidateLink.length),
}
contextInner = (candidateLink == mw.config.get('wgTitle')) ? '[['+mw.config.get('wgTitle')+']]' : '[['+mw.config.get('wgTitle')+'|' + candidateLink + ']]',
else if (m = this.contextRgxLink.exec(pagecontent)) {
newContext = contextPre+contextInner+contextPost;
contextPost = m[3] == mw.config.get('wgTitle')? m[4] : '|' + m[3] + m[4];
this.content.$element.html('<h1>'+page.title+'</h1><p>'+contextPre+'<b>'+contextInner+'</b>'+contextPost+'</p>');
contextInner = mw.config.get('wgTitle');
contextInnerOld = '<s>' + m[2] + (m[3] == mw.config.get('wgTitle')? '|' : '') + '</s>';
}
if ((page.title!=mw.config.get('wgTitle')) && m) {
var context = m[0];
contextPre = m[1];
newContext = contextPre+contextInner+contextPost;
this.content.$element.html('<h1>'+page.title+'</h1><p>'+contextPre+contextInnerOld+'<b>'+contextInner+'</b>'+contextPost+'</p>');
this.curPage = page.title;
this.curPage = page.title;
this.text = pagecontent.replace(context, newContext)
this.text = pagecontent.replace(context, newContext)