• 正在查找将来过去时的官方设定集?不如看看万界大百科吧!
  • 《将来过去时》第一部分 现在 魔科纪元的少年少女 即将正式发布!
  • 让我偷偷看一眼小鱼君的博客……
  • 服务器已成功迁移到 阿里云(杭州)

“MediaWiki:Gadget-InPageEdit.js”的版本间的差异

来自小鱼君和他的朋友们
(//InPageEdit)
标签InPageEdit
(//InPageEdit)
标签InPageEdit
第5行: 第5行:
 
  * Description: Let you edit page without open new tab. And edit Navebox via navbar, edit section via section edit link etc.
 
  * Description: Let you edit page without open new tab. And edit Navebox via navbar, edit section via section edit link etc.
 
  **/
 
  **/
 +
 
function InPageEdit(option) {
 
function InPageEdit(option) {
 
   // 只能存在一个窗口
 
   // 只能存在一个窗口
第10行: 第11行:
 
    $('#InPageEdit').remove();
 
    $('#InPageEdit').remove();
 
   }
 
   }
  // 开始执行任务
+
 
  $('body').addClass('action-in-page-edit');
 
 
 
   // Variables
 
   // Variables
 
   var origintext,
 
   var origintext,
第26行: 第25行:
 
   if (inPageEditTags === undefined || inPageEditTags === ''){inPageEditTags = ''}
 
   if (inPageEditTags === undefined || inPageEditTags === ''){inPageEditTags = ''}
  
 +
  // Debug
 
   console.info('[InPageEdit]\n'+'ninPageEditTarget = ' + inPageEditTarget + '\n' + 'inPageEditSection = ' + inPageEditSection + '\n' + 'inPageEditReason = ' + inPageEditReason + '\n' + 'inPageEditTags = ' + inPageEditTags + '\n' + 'inPageEditRefresh = ' + inPageEditRefresh);
 
   console.info('[InPageEdit]\n'+'ninPageEditTarget = ' + inPageEditTarget + '\n' + 'inPageEditSection = ' + inPageEditSection + '\n' + 'inPageEditReason = ' + inPageEditReason + '\n' + 'inPageEditTags = ' + inPageEditTags + '\n' + 'inPageEditRefresh = ' + inPageEditRefresh);
 +
 +
  // 开始执行任务
 +
  $('body').addClass('action-in-page-edit');
 +
  // Create area
 +
  Modal(
 +
  '<div id="InPageEdit">' +
 +
  '<textarea id="newcontent" style="width:100%;min-height:300px;max-height:1200px"></textarea>' +
 +
 +
  '<div id="button-area">' + '<div id="normal"><button id="cancle-btn">取消</button> <button id="preview-btn">预览</button> <label><input type="checkbox" id="is-minor"/> 小编辑</label> <div style="float:right"><input id="reason" placeholder="编辑摘要"> <button id="submit-btn">提交</button></div></div>' +
 +
 +
  '<center id="confirm" style="display:none;clear:both"><span id="code"></span><br/><button id="no">否</button> <button id="yes">是</button></center>' +
 +
 +
  '</div>' +
 +
 +
  '<center id="info-area" style="display:none;"></center>' +
 +
 +
  '<h1>预览</h1>' + '<div id="preview-area" style="padding:8px; border:2px dotted #aaa"></div>' +
 +
 +
  '</div>','<span id="inPageEdit-edit-title">inPageEditTitlePlaceholder</span>',{closeBtn:false});
 +
  $('#popup-window-bg').unbind();
  
 
   if (inPageEditSection === 'none') {
 
   if (inPageEditSection === 'none') {
第56行: 第76行:
 
   });
 
   });
 
   function ajaxArea() {
 
   function ajaxArea() {
   // Create area & hide article
+
 
    $('#mw-content-text').hide();
+
    $('#InPageEdit #reason').val(inPageEditReason);
   $('#mw-content-text').before(
 
    '<div id="InPageEdit">' +
 
 
    '<h1 id="edit-title">in-page-edit-title</h1>' +
 
    '<textarea id="newcontent" style="width:100%;min-height:300px;max-height:1200px"></textarea>' +
 
 
    '<div id="button-area">' +
 
    '<div id="normal"><button id="cancle-btn">取消</button> <button id="preview-btn">预览</button> <label><input type="checkbox" id="is-minor"/> 小编辑</label> <div style="float:right"><input id="reason" placeholder="编辑摘要" value="'+inPageEditReason+'"> <button id="submit-btn">提交</button></div></div>' +
 
 
    '<center id="confirm" style="display:none;clear:both"><span id="code"></span><br/><button id="no">否</button> <button id="yes">是</button></center>' +
 
 
    '</div>' +
 
 
    '<center id="info-area" style="display:none;"></center>' +
 
 
    '<h1>预览</h1>' +
 
    '<div id="preview-area" style="padding:8px; border:2px dotted #aaa"></div>' +
 
 
    '</div>'
 
   );
 
 
    $('#InPageEdit #newcontent').val(origintext);
 
    $('#InPageEdit #newcontent').val(origintext);
    $('#InPageEdit #edit-title').html('正在编辑:' + decodeURIComponent(inPageEditTarget)+Section);
+
    $('#inPageEdit-edit-title').html('正在编辑:' + decodeURIComponent(inPageEditTarget)+Section);
 
  
 
  
 
    // Cancle
 
    // Cancle
第89行: 第89行:
 
     $('#InPageEdit #confirm #yes').click(function(){
 
     $('#InPageEdit #confirm #yes').click(function(){
 
      $('body').removeClass('action-in-page-edit');
 
      $('body').removeClass('action-in-page-edit');
      $('#InPageEdit').remove();
+
      $('#popup-window-bg, #popup-window').remove();
     $('#mw-content-text').show();
 
 
     });
 
     });
 
    });
 
    });
第119行: 第118行:
 
      $('#InPageEdit #newcontent').attr('readonly','readonly');
 
      $('#InPageEdit #newcontent').attr('readonly','readonly');
 
      $('#InPageEdit #button-area').hide();
 
      $('#InPageEdit #button-area').hide();
      $('#InPageEdit #info-area').show().html('<div style="font-weight:bold;color:green;min-height: 50px;line-height: 50px;font-size: 36px;"> 正在提交&nbsp;<img src="https://wjghj.cn/images/9/98/Windows-loading.gif" style="height:36px;width:auto" /></div>');
+
      $('#InPageEdit #info-area').show().html('正在提交&nbsp;<span id="spinner"></span>');
 
  
 
  
 
      // Do post request
 
      // Do post request
第146行: 第145行:
 
      }
 
      }
 
      new mw.Api().post(varSubmit).done(function() {
 
      new mw.Api().post(varSubmit).done(function() {
       $('#InPageEdit #info-area').html('<div style="font-weight:bold;color:green;min-height: 50px;line-height: 50px;font-size: 36px;"> 发布成功</div>');
+
       $('#InPageEdit #info-area').html('发布成功');
       location.reload();
+
       window.location.reload();
 
      }).fail(function(){
 
      }).fail(function(){
 
       // Show elements
 
       // Show elements
第154行: 第153行:
 
       $('#InPageEdit #button-area, #InPageEdit #button-area #normal').show();
 
       $('#InPageEdit #button-area, #InPageEdit #button-area #normal').show();
 
       $('#InPageEdit #confirm').hide();
 
       $('#InPageEdit #confirm').hide();
       Modal('<span class="error">Error post your request.</span>','InPageEdit Error');
+
       alert('InPageEdit: Error post your request.');
 
       $('#InPageEdit #info-area').hide().html('');
 
       $('#InPageEdit #info-area').hide().html('');
 
      });
 
      });
第187行: 第186行:
 
    if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1)!=='/') return;
 
    if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1)!=='/') return;
 
    // Not url start with 'index.php?title=FOO'
 
    // Not url start with 'index.php?title=FOO'
    if (params.title === undefined) params.title = url.split('/wiki/')['1'];
+
    if (params.title === undefined) params.title = url.split('com/').pop().split('?')['0'];
 
    if (params.section === undefined) params.section = 'none';
 
    if (params.section === undefined) params.section = 'none';
  
第194行: 第193行:
 
  
 
  
 
    if (params.action === 'edit' && target !== undefined && section !== 'new') {
 
    if (params.action === 'edit' && target !== undefined && section !== 'new') {
     $(this).after($('<a>').attr({
+
     $(this).after(
     'href': 'javascript:void(0)',
+
     $('<a>',{
     'class': 'in-page-edit-article-link',
+
      'href': 'javascript:void(0)',
      'data-target': target,
+
      'class': 'in-page-edit-article-link'
      'data-section': section
+
      })
    }).text('[ 快速编辑]').click(function (){
+
      .text('快速编辑')
     if (section === 'none') {
+
     .click(function (){
      InPageEdit({target:target, reason:' //InPageEdit', tags:'in-page-edit|in-page-edit-outer'});
+
      if (section === 'none') {
     } else {
+
       InPageEdit({target:target, reason:' //InPageEdit', tags:'in-page-edit|in-page-edit-outer'});
      InPageEdit({target:target, reason:' //InPageEdit', section: section, tags:'in-page-edit|in-page-edit-outer'});
+
      } else {
 +
       InPageEdit({target:target, reason:' //InPageEdit - Section'+section, section: section, tags:'in-page-edit|in-page-edit-outer'});
 +
      }
 
      }
 
      }
     }));
+
     ));
 
    }
 
    }
 
   });
 
   });
});
+
   $('.mw-editsection .in-page-edit-article-link').before(' | ');
/** Add special page **/
+
   $('.in-page-edit-article-link:not(.mw-editsection)').before('[').after(']');
$(function() {
 
   $('.mw-special-Specialpages .mw-specialpages-list:nth-of-type(10) ul').append('<li><a href="/wiki/Special:空白页面/QuickEdit">快速编辑</a></li>');
 
  if (wgPageName === 'Speial:Quickedit' || wgPageName === 'Special:QuickEdit' || wgPageName === 'Special:快速编辑') {
 
   location.href = '/wiki/Special:空白页面/QuickEdit';
 
   } else if (wgPageName === 'Special:空白页面/QuickEdit' ) {
 
   $('title').text('Special: 快速编辑 | 小鱼君和他的朋友们 | Wjghj Project');
 
   $('#firstHeading').text('进行快速编辑');
 
   $('#mw-content-text').before(
 
    '<br/><div id="inputArea"><input id="requestPage" /> <button id="requestBtn">加载</button> <button id="randomBtn">随机</button></div>'
 
   ).html('');
 
   $('#inputArea #randomBtn').click(function(){
 
    new mw.Api().get({
 
     action:'query',
 
     list:'random',
 
     rnnamespace:'0|4|14'
 
    }).done(function(data){
 
     $('#inputArea #requestPage').val(data.query.random[0].title);
 
    });
 
   });
 
   $('#inputArea #requestBtn').click(function(){
 
    var requestPage = $('#inputArea #requestPage').val();
 
    if (requestPage !== ''||requestPage !== undefined) {
 
     InPageEdit({target:requestPage,reason:' //InPageEdit',tags:'in-page-edit-editor|in-page-edit-outer'});
 
    }
 
   });
 
  }
 
 
});
 
});

2019年10月10日 (四) 11:12的版本

/**
 * MediaWiki JS Plugin: In Page Edit
 * Author: 机智的小鱼君
 * Url: https://github.com/Dragon-Fish/wjghj-wiki/edit/master/Gadgets/in-page-edit
 * Description: Let you edit page without open new tab. And edit Navebox via navbar, edit section via section edit link etc.
 **/

function InPageEdit(option) {
  // 只能存在一个窗口
  if ($('#InPageEdit').length > 0) {
    $('#InPageEdit').remove();
  }

  // Variables
  var origintext,
      inPageEditTarget = option.target,
      inPageEditSection = option.section,
      inPageEditReason = option.reason,
      inPageEditTags = option.tags,
      inPageEditRefresh = option.refresh;
  if (inPageEditTarget === undefined || inPageEditTarget === ''){inPageEditTarget = mw.config.get('wgPageName')}else{inPageEditTarget = decodeURIComponent(inPageEditTarget)}
  if (inPageEditSection === undefined || inPageEditSection === ''){inPageEditSection = 'none'}
  if (inPageEditReason === undefined || inPageEditReason === ''){inPageEditReason = ''}
  if (inPageEditRefresh === undefined || inPageEditRefresh == 'true' || inPageEditRefresh == '1'){inPageEditRefresh = true;}
  if (inPageEditTags === undefined || inPageEditTags === ''){inPageEditTags = ''}

  // Debug
  console.info('[InPageEdit]\n'+'ninPageEditTarget = ' + inPageEditTarget + '\n' + 'inPageEditSection = ' + inPageEditSection + '\n' + 'inPageEditReason = ' + inPageEditReason + '\n' + 'inPageEditTags = ' + inPageEditTags + '\n' + 'inPageEditRefresh = ' + inPageEditRefresh);

  // 开始执行任务
  $('body').addClass('action-in-page-edit');
  // Create area
  Modal(
  '<div id="InPageEdit">' +
  '<textarea id="newcontent" style="width:100%;min-height:300px;max-height:1200px"></textarea>' +

  '<div id="button-area">' + '<div id="normal"><button id="cancle-btn">取消</button> <button id="preview-btn">预览</button> <label><input type="checkbox" id="is-minor"/> 小编辑</label> <div style="float:right"><input id="reason" placeholder="编辑摘要"> <button id="submit-btn">提交</button></div></div>' +

  '<center id="confirm" style="display:none;clear:both"><span id="code"></span><br/><button id="no">否</button> <button id="yes">是</button></center>' +

  '</div>' +

  '<center id="info-area" style="display:none;"></center>' +

  '<h1>预览</h1>' + '<div id="preview-area" style="padding:8px; border:2px dotted #aaa"></div>' +

  '</div>','<span id="inPageEdit-edit-title">inPageEditTitlePlaceholder</span>',{closeBtn:false});
  $('#popup-window-bg').unbind();

  if (inPageEditSection === 'none') {
    varGet = {
      action: "parse",
      page: inPageEditTarget,
      prop: "wikitext",
      format: "json"
    }
    Section = ''
  } else {
    varGet = {
      action: "parse",
      page: inPageEditTarget,
      section: inPageEditSection,
      prop: "wikitext",
      format: "json"
    }
    Section = '#'+inPageEditSection
  }
 
  new mw.Api().get(varGet).then(function(data) {
    origintext = data.parse.wikitext['*'];
    ajaxArea()
  }).fail(function() {
    origintext = '<!-- ⚠ 警告:无法获取页面内容,新建页面请删除此行。 -->\n';
    console.error('[InPageEdit] Can’t get page content.');
    ajaxArea()
  });
  function ajaxArea() {

    $('#InPageEdit #reason').val(inPageEditReason);
    $('#InPageEdit #newcontent').val(origintext);
    $('#inPageEdit-edit-title').html('正在编辑:' + decodeURIComponent(inPageEditTarget)+Section);
 
    // Cancle
    $('#InPageEdit #cancle-btn').click(function() {
      $('#InPageEdit #button-area #normal').hide();
      $('#InPageEdit #confirm').show(); $('#InPageEdit #confirm button').unbind();
      $('#InPageEdit #confirm #code').text('确定取消编辑?');
      $('#InPageEdit #confirm #no').click(function(){$('#InPageEdit #button-area #normal').show();$('#InPageEdit #confirm').hide();});
      $('#InPageEdit #confirm #yes').click(function(){
        $('body').removeClass('action-in-page-edit');
        $('#popup-window-bg, #popup-window').remove();
      });
    });
 
    // Preview
    $('#InPageEdit #preview-btn').click(function() {
      new mw.Api().post({
        action: "parse",
        text: $('#InPageEdit #newcontent').val(),
        prop: "text",
        preview: true,
        format: "json"
      }).then(function(data) {
        var previewcontent = data.parse.text['*'];
 
        $('#InPageEdit #preview-area').html(previewcontent);
      });
    });
 
    // Submit
    $('#InPageEdit #submit-btn').click(function() {
      $('#InPageEdit #button-area #normal').hide();
      $('#InPageEdit #confirm').show(); $('#InPageEdit #confirm button').unbind();
      $('#InPageEdit #confirm #code').text('确定发布编辑?');
      $('#InPageEdit #confirm #no').click(function(){$('#InPageEdit #button-area #normal').show();$('#InPageEdit #confirm').hide();});
      $('#InPageEdit #confirm #yes').click(function(){
        // Hide elements
        $('#InPageEdit #newcontent').attr('readonly','readonly');
        $('#InPageEdit #button-area').hide();
        $('#InPageEdit #info-area').show().html('正在提交&nbsp;<span id="spinner"></span>');
 
        // Do post request
        var isMinor = $('#InPageEdit #is-minor').prop('checked');
        if (inPageEditSection === 'none') {
          varSubmit = {
            action: 'edit',
            text: $('#InPageEdit #newcontent').val(),
            title: inPageEditTarget,
            minor: isMinor,
            tags: inPageEditTags,
            summary: $('#InPageEdit #reason').val(),
            token: mw.user.tokens.get('editToken')
          }
        } else {
          varSubmit = {
            action: 'edit',
            text: $('#InPageEdit #newcontent').val(),
            title: inPageEditTarget,
            section: inPageEditSection,
            minor: isMinor,
            tags: inPageEditTags,
            summary: $('#InPageEdit #reason').val(),
            token: mw.user.tokens.get('editToken')
          }
        }
        new mw.Api().post(varSubmit).done(function() {
          $('#InPageEdit #info-area').html('发布成功');
          window.location.reload();
        }).fail(function(){
          // Show elements
          $('#InPageEdit #submit-btn').html('Retry');
          $('#InPageEdit #newcontent').attr('readonly',false);
          $('#InPageEdit #button-area, #InPageEdit #button-area #normal').show();
          $('#InPageEdit #confirm').hide();
          alert('InPageEdit: Error post your request.');
          $('#InPageEdit #info-area').hide().html('');
        });
      });
    });
  }
}
 
/** Add button **/
$(function() {
  if (wgIsArticle === false) {
    console.info('[InPageEdit] Not article page, plugin shut down.');
    return;
  }
  $('.action-view #p-userpagetools ul, #p-views .mw-portlet-body ul').append($('<li>').append($('<a>').addClass('in-page-edit-btn-link').attr('href', 'javascript:void(0)').text('快速编辑').click(function() {
    InPageEdit({target:mw.config.get('wgPageName'), reason:' //InPageEdit', tags:'in-page-edit'})
  })));
});
/** Get links in ariticle **/
$(function() {
  $('#mw-content-text a:not(.new)').each(function(i) {
    if ($(this).attr('href') === undefined) return;
    var url = $(this).attr('href');
        params = {};
    var vars = url.split('?').pop().split("&");
    for (var i=0;i<vars.length;i++) {
      var pair = vars[i].split("=");
      params[pair[0]] = pair[1];
    }
 
    // Not edit link of this wiki
    if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1)!=='/') return;
    // Not url start with 'index.php?title=FOO'
    if (params.title === undefined) params.title = url.split('com/').pop().split('?')['0'];
    if (params.section === undefined) params.section = 'none';

    var target = params.title,
        section = params.section;
 
    if (params.action === 'edit' && target !== undefined && section !== 'new') {
      $(this).after(
        $('<a>',{
          'href': 'javascript:void(0)',
          'class': 'in-page-edit-article-link'
        })
        .text('快速编辑')
        .click(function (){
          if (section === 'none') {
            InPageEdit({target:target, reason:' //InPageEdit', tags:'in-page-edit|in-page-edit-outer'});
          } else {
            InPageEdit({target:target, reason:' //InPageEdit - Section'+section, section: section, tags:'in-page-edit|in-page-edit-outer'});
          }
        }
      ));
    }
  });
  $('.mw-editsection .in-page-edit-article-link').before(' | ');
  $('.in-page-edit-article-link:not(.mw-editsection)').before('[').after(']');
});