“MediaWiki:Common.js/edit.js”的版本间的差异

来自侠行天下-维基百科
跳到导航 跳到搜索
 
第1行: 第1行:
/* Any JavaScript here will be loaded for all users on every page load. */
+
//<source lang="javascript">
/* Any JavaScript here will be loaded for all users on edit page load. */
 
$(function() {
 
    $(".mw-summary-preset-item a").closest('.oo-ui-fieldLayout-header').width($('#wpSummary').width());
 
    $(".mw-summary-preset-item a").on("click", function() {
 
        $('[name="wpSummary"]').val($('[name="wpSummary"]').val() + " " + $(this).html());
 
    });
 
  
    // .wikiEditor-ui-controls 颜色修正
+
/*
    $('.wikiEditor-ui-controls').css('background-color', $('#content').css('background-color'));
 
  
    //编辑提示检查
+
== 編輯工具欄 ==
    if ($(".editOptions > #wpSummary")[0]) $(".CheckNewSectionOn").hide(); else $(".CheckNewSectionOff").hide();
+
*/
  
    // Customized File Insertion dialog
+
/**
    // Copyright 2017 The Little Moe New LLC. All rights reserved.
+
* tip for custom edittools
    mw.loader.using([ "oojs", "oojs-ui" ]).then(function() {
+
*
        $("#wpTextbox1").on("wikiEditor-toolbar-doneInitialSections", function() {
+
* Maintainers: fdcn@zh.wikipedia
            function FileInsertionDialog(config) {
+
*/
                FileInsertionDialog.super.call(this, config);
+
if ( mw.config.get( 'wgAction' ) === 'edit' && $("span.oo-ui-fieldLayout-header")) {
            }
+
$("span.oo-ui-fieldLayout-header").css("max-width","none"); // 一行显示编辑摘要
            OO.inheritClass(FileInsertionDialog, OO.ui.ProcessDialog);
+
}
            // Name
+
 
            FileInsertionDialog.static.name = "fileInsertionDialog";
+
$( function(){
            FileInsertionDialog.static.title = mw.msg("wikieditor-toolbar-tool-file-title");
+
//在提交新段落時,讓主題欄在特定情況下失效
            FileInsertionDialog.static.actions = [ {
+
if(document.getElementById('no-new-title') && document.editform.wpSection.value=="new") {
                flags:"primary",
+
if(summaryinput=document.getElementById("wpSummary")) {
                label:mw.msg("wikieditor-toolbar-tool-file-insert"),
+
                        summaryinput.disabled=true;
                action:"insert"
+
                        summaryinput.value='';
            }, {
 
                flags:"safe",
 
                label:mw.msg("wikieditor-toolbar-tool-file-cancel")
 
            } ];
 
            // Initialization
 
            FileInsertionDialog.prototype.initialize = function() {
 
                FileInsertionDialog.super.prototype.initialize.call(this);
 
                this.panel = new OO.ui.PanelLayout({
 
                    padded:true,
 
                    expanded:false
 
                });
 
                this.fileMetaContent = new OO.ui.FieldsetLayout();
 
                this.alignmentContent = new OO.ui.FieldsetLayout();
 
                this.formatContent = new OO.ui.FieldsetLayout();
 
                this.fileNameInput = new OO.ui.TextInputWidget({
 
                    indicator:"required"
 
                });
 
                this.fileNameField = new OO.ui.FieldLayout(this.fileNameInput, {
 
                    label:mw.msg("wikieditor-toolbar-file-target"),
 
                    align:"top"
 
                });
 
                this.fileTitleInput = new OO.ui.TextInputWidget();
 
                this.fileTitleField = new OO.ui.FieldLayout(this.fileTitleInput, {
 
                    label:mw.msg("wikieditor-toolbar-file-caption"),
 
                    align:"top"
 
                });
 
                this.sizeInput = new OO.ui.TextInputWidget();
 
                this.sizeField = new OO.ui.FieldLayout(this.sizeInput, {
 
                    label:mw.msg("wikieditor-toolbar-file-size"),
 
                    align:"top"
 
                });
 
                this.fileMetaContent.addItems([ this.fileNameField, this.fileTitleField, this.sizeField ]);
 
                var alignOptionDefault = new OO.ui.ButtonOptionWidget({
 
                    data:"default",
 
                    label:mw.msg("wikieditor-toolbar-file-default"),
 
                    title:mw.msg("wikieditor-toolbar-file-default")
 
                });
 
                var alignOptionNone = new OO.ui.ButtonOptionWidget({
 
                    data:"none",
 
                    label:mw.msg("wikieditor-toolbar-file-format-none"),
 
                    title:mw.msg("wikieditor-toolbar-file-format-none")
 
                });
 
                var magicWords = mw.config.get("wgWikiEditorMagicWords");
 
                var alignOptionMid = new OO.ui.ButtonOptionWidget({
 
                    data:"center",
 
                    label:magicWords.img_center,
 
                    title:magicWords.img_center
 
                });
 
                var alignOptionLeft = new OO.ui.ButtonOptionWidget({
 
                    data:"left",
 
                    label:magicWords.img_left,
 
                    title:magicWords.img_left
 
                });
 
                var alignOptionRight = new OO.ui.ButtonOptionWidget({
 
                    data:"right",
 
                    label:magicWords.img_right,
 
                    title:magicWords.img_right
 
                });
 
                this.alignmentSelect = new OO.ui.ButtonSelectWidget({
 
                    items:[ alignOptionNone, alignOptionDefault, alignOptionMid, alignOptionLeft, alignOptionRight ]
 
                });
 
                this.alignmentField = new OO.ui.FieldLayout(this.alignmentSelect, {
 
                    label:mw.msg("wikieditor-toolbar-file-float"),
 
                    align:"top"
 
                });
 
                this.alignmentContent.addItems([ this.alignmentField ]);
 
                var formatOptionThumbnail = new OO.ui.ButtonOptionWidget({
 
                    data:"thumbnail",
 
                    label:magicWords.img_thumbnail,
 
                    title:magicWords.img_thumbnail
 
                });
 
                var formatOptionFramed = new OO.ui.ButtonOptionWidget({
 
                    data:"framed",
 
                    label:magicWords.img_framed,
 
                    title:magicWords.img_framed
 
                });
 
                var formatOptionFrameless = new OO.ui.ButtonOptionWidget({
 
                    data:"frameless",
 
                    label:magicWords.img_frameless,
 
                    title:magicWords.img_frameless
 
                });
 
                var formatOptionNone = new OO.ui.ButtonOptionWidget({
 
                    data:"default",
 
                    label:magicWords.img_none,
 
                    title:magicWords.img_none
 
                });
 
                this.formatSelect = new OO.ui.ButtonSelectWidget({
 
                    items:[ formatOptionThumbnail, formatOptionFramed, formatOptionFrameless, formatOptionNone ]
 
                });
 
                this.formatField = new OO.ui.FieldLayout(this.formatSelect, {
 
                    label:mw.msg("wikieditor-toolbar-file-format"),
 
                    align:"top"
 
                });
 
                this.formatContent.addItems([ this.formatField ]);
 
                this.panel.$element.append(this.fileMetaContent.$element);
 
                this.panel.$element.append(this.alignmentContent.$element);
 
                this.panel.$element.append(this.formatContent.$element);
 
                this.$body.append(this.panel.$element);
 
                this.fileNameInput.connect(this, {
 
                    change:"onFileNameChange"
 
                });
 
            };
 
            // Specify the dialog height (or don"t to use the automatically generated height).
 
            FileInsertionDialog.prototype.getBodyHeight = function() {
 
                return this.panel.$element.outerHeight(true);
 
            };
 
            // Name validation
 
            FileInsertionDialog.prototype.onFileNameChange = function(value) {
 
                this.actions.setAbilities({
 
                    insert:!!value.length
 
                });
 
            };
 
            // Default state initialization
 
            FileInsertionDialog.prototype.getSetupProcess = function(data) {
 
                data = data || {};
 
                return FileInsertionDialog.super.prototype.getSetupProcess.call(this, data).next(function() {
 
                    this.actions.setAbilities({
 
                        insert:false
 
                    });
 
                    this.fileNameInput.setValue("");
 
                    this.fileTitleInput.setValue("");
 
                    this.sizeInput.setValue("");
 
                    this.alignmentSelect.selectItemByData("default");
 
                    this.formatSelect.selectItemByData("thumbnail");
 
                }, this);
 
            };
 
            // Context setup
 
            FileInsertionDialog.prototype.setContext = function(context) {
 
                this.editorContext = context;
 
            };
 
            // Specify processes to handle the actions.
 
            FileInsertionDialog.prototype.getActionProcess = function(action) {
 
                if (action === "insert") {
 
                    return new OO.ui.Process(function() {
 
                        this.insertImage();
 
                    }, this);
 
 
                 }
 
                 }
                // Fallback to parent handler
+
}
                return FileInsertionDialog.super.prototype.getActionProcess.call(this, action);
+
});
            };
+
 
            // Handles image insertion.
+
( function( $, mw ) { $( function() {
            FileInsertionDialog.prototype.insertImage = function() {
+
    if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
                if (!this.editorContext) return;
+
        if ( $( '#no-new-title' ).length ) {
                var fileName, caption, fileFloat, fileFormat, fileSize, fileTitle, options, fileUse, hasPxRgx = /.+px$/, magicWordsI18N = mw.config.get("wgWikiEditorMagicWords");
+
            $( '#wpSummary' ).attr( 'disabled', true );
                fileName = this.fileNameInput.getValue();
+
        }
                caption = this.fileTitleInput.getValue();
+
        return;
                fileSize = this.sizeInput.getValue();
+
    }
                fileFloat = this.alignmentSelect.getSelectedItem().data;
+
    $( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
                fileFormat = this.formatSelect.getSelectedItem().data;
+
        e.preventDefault();
                // Append px to end to size if not already contains it
+
        var $this = $( this ), summary = $( '#wpSummary' ).val();
                if (fileSize !== "" && !hasPxRgx.test(fileSize)) {
+
        var $item = $this.parent( '.mw-summary-preset-item' );
                    fileSize += "px";
+
        summary = summary.replace( /\s+$/g, '' );
                }
+
        if ( summary != '' ) {
                if (fileName !== "") {
+
            summary += ' ';
                    fileTitle = new mw.Title(fileName);
+
        }
                    // Append file namespace prefix to filename if not already contains it
+
        summary += $item.attr( 'title' ) || $this.text();
                    if (fileTitle.getNamespaceId() !== 6) {
+
        $this.replaceWith( $this.contents() );
                        fileTitle = new mw.Title(fileName, 6);
+
        $( '#wpSummary' ).val( summary );
                    }
+
    } );
                    fileName = fileTitle.toText();
+
} ); } )( jQuery, mediaWiki );
                }
+
 
                options = [ fileSize, fileFormat, fileFloat ];
+
/*
                // Filter empty values
+
 
                options = $.grep(options, function(val) {
+
== 强制预览 ==
                    return val.length && val !== "default";
+
[[mw:Manual:Force preview]]
                });
+
*/
                if (caption.length) {
+
 
                    options.push(caption);
+
// -------------------------------------------------------------------------------
                }
+
//  Force Preview  JavaScript code - Start
                fileUse = options.length === 0 ? fileName :fileName + "|" + options.join("|");
+
//
                $.wikiEditor.modules.toolbar.fn.doAction(this.editorContext, {
+
//  To allow any group to bypass being forced to preview,
                    type:"replace",
+
//  enter the group name in the permittedGroups array.
                    options:{
+
//  E.g.
                        pre:"[[",
+
//    var permittedGroups = [];                      // force everyone
                        peri:fileUse,
+
//    var permittedGroups = [ "user"];                // permit logged-in users
                        post:"]]",
+
//    var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat
                        ownline:true
+
// -------------------------------------------------------------------------------
                    }
+
var permittedGroups = [ 'confirmed', 'autoconfirmed' ];
                });
+
                this.close();
+
Array.prototype.intersects = function() {
            };
+
// --------------------------------------------------------
            // Remove legacy file insertion
+
// Returns true if any element in the argument array
            $("#wpTextbox1").wikiEditor("removeFromToolbar", {
+
//  is the same as an element in this array
                section:"main",
+
// --------------------------------------------------------
                group:"insert",
+
if ( !arguments.length ) return false;
                tool:"file"
+
 
            });
+
var array2 = arguments[0];
            $("#wpTextbox1").wikiEditor("addToToolbar", {
+
 
                section:"main",
+
var len1 = this.length;
                group:"insert",
+
var len2 = array2.length;
                tools:{
+
if ( len2 == 0 ) return false;
                    "file-alt":{
+
 
                        label:mw.msg("wikieditor-toolbar-tool-file-title"),
+
for ( var i = 0; i < len1; i++ ) {
                        type:"button",
+
for ( var j = 0; j < len2; j++ ) {
                        icon:"insert-file.png",
+
if ( this[i] === array2[j] ) return true;
                        offset:[ 2, -1438 ],
+
}
                        action:{
+
}
                            type:"callback",
+
return false;
                            execute:function(context) {
+
};
                                var windowManager = new OO.ui.WindowManager();
+
                                $("body").append(windowManager.$element);
+
function forcePreview() {
                                var fileInsertionDialog = new FileInsertionDialog();
+
if ( mw.config.get( "wgAction" ) != "edit" ) return;
                                fileInsertionDialog.setContext(context);
+
if ( mw.config.get( "wgUserGroups" ).intersects( permittedGroups ) ) return;
                                windowManager.addWindows([ fileInsertionDialog ]);
+
// Doesn't work correctly with live preview
                                windowManager.openWindow(fileInsertionDialog);
+
if ( mw.user.options.get( "uselivepreview" ) == "1" ) return;
                            }
+
var saveButton = document.getElementById( "wpSave" );
                        }
+
if ( !saveButton ) return;
                    }
+
saveButton.disabled = true;
                }
+
// disable the OOUI button
            });
+
$('#wpSave').attr('aria-disabled', 'true');
        });
+
$('#wpSaveWidget').attr('aria-disabled', 'true');
    });
+
$('#wpSaveWidget').removeClass('oo-ui-widget-enabled');
 +
$('#wpSaveWidget').addClass('oo-ui-widget-disabled');
 +
saveButton.value = saveButton.value + wgULS( '(请先预览)', '(請先預覽)' );
 +
saveButton.style.fontWeight = "normal";
 +
var previewButton = document.getElementById( "wpPreview" );
 +
if ( previewButton ) {
 +
previewButton.style.fontWeight = "bold";
 +
}
 +
}
 +
 
 +
jQuery(document).ready( forcePreview );
 +
// -----------------------------------------------------
 +
//  Force Preview  JavaScript code - End
 +
// -----------------------------------------------------
 +
 
 +
/*
 +
 
 +
== 取消修訂編輯摘要修正 ==
 +
*/
 +
/**
 +
  fix edit summary prompt for undo
 +
  this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged
 +
  this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
 +
*/
 +
$ (function () {
 +
var autoSummary=document.getElementsByName('wpAutoSummary')[0];
 +
if (document.location.search.indexOf("undo=") != -1 && autoSummary)
 +
{ autoSummary.value=''; }
 +
});
 +
 
 +
/*
 +
 
 +
== WP:DYKC編輯時取消編輯摘要空段落標示 ==
 +
*/
 +
$( function(){
 +
var $wpSummary=$("#editform #wpSummary"), $wpTextbox1=$("#editform #wpTextbox1");
 +
if($wpSummary.length==0 || $wpTextbox1.length==0) return;
 +
var wpSummary=$wpSummary.get(0), wpTextbox1=$wpTextbox1.get(0);
 +
var keyReg= /(?:\n|.)*\|\s*article\s*= *([\S ]*)(?:\n|.)*/m ;
 +
if(wpSummary.value.indexOf("  ")>=0) wpSummary.value="";
 +
if(mw.config.get("wgPageName")!="Wikipedia:新条目推荐/候选") return;
 +
if(wpSummary.value=="/"+"*  *"+"/ " && wpTextbox1.value.match(keyReg) ){}else return;
 +
var temp=wpTextbox1.value.replace(keyReg, '$1');
 +
if(!temp) return;
 +
wpSummary.value=wpSummary.defaultValue="\/"+"* "+temp+" *"+"\/ ";
 
});
 
});
  
阅读更多:https://zh.moegirl.org/MediaWiki:Common.js/edit.js
+
 
本文引自萌娘百科(https://zh.moegirl.org/),文字内容遵守【知识共享 署名-非商业性使用-相同方式共享 3.0】协议。
+
/* Check for any client-side simplified/traditional Chinese conversion */
 +
var checkAntiConv = function() {
 +
    var $ac = $('#wpAntiConv');
 +
    if ($ac.length && $ac.val() != '\u6c49\u6f22') {
 +
        var text = $('#wpTextbox1').val();
 +
        var section = $('input[name=wpSection]').val();
 +
        var basetimestamp = $('input[name=wpEdittime]').val();
 +
        var starttimestamp = $('input[name=wpStarttime]').val();
 +
        $('#editform :input').attr({disabled:true,readOnly:true});
 +
        mw.loader.using(['mediawiki.notify','mediawiki.notification'],function(){
 +
            mw.notify(wgULS(
 +
                '系统检测到您使用了客户端繁简转换软件,且此软件对文本框中的内容进行了转换。请关闭此软件后重新打开编辑界面,再进行编辑。',
 +
                '系統檢測到您使用了用戶端繁簡轉換軟體,且此軟體對文字方塊中的內容進行了轉換。請關閉此軟體後重新打開編輯介面,再進行編輯。'
 +
            ),{autoHide:false});
 +
        });
 +
    } else {
 +
        setTimeout(checkAntiConv, 1000);
 +
    }
 +
};
 +
setTimeout(checkAntiConv, 1000);
 +
//</source>

2018年5月26日 (六) 13:34的版本

//<source lang="javascript">

/*

== 編輯工具欄 ==
*/

/**
 * tip for custom edittools
 * 
 * Maintainers: fdcn@zh.wikipedia
 */
if ( mw.config.get( 'wgAction' ) === 'edit' && $("span.oo-ui-fieldLayout-header")) {
	$("span.oo-ui-fieldLayout-header").css("max-width","none"); // 一行显示编辑摘要
}

$( function(){
	//在提交新段落時,讓主題欄在特定情況下失效
	if(document.getElementById('no-new-title') && document.editform.wpSection.value=="new") {
		if(summaryinput=document.getElementById("wpSummary")) {
                        summaryinput.disabled=true;
                        summaryinput.value='';
                }
	}
});

( function( $, mw ) { $( function() {
    if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
        if ( $( '#no-new-title' ).length ) {
            $( '#wpSummary' ).attr( 'disabled', true );
        }
        return;
    }
    $( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
        e.preventDefault();
        var $this = $( this ), summary = $( '#wpSummary' ).val();
        var $item = $this.parent( '.mw-summary-preset-item' );
        summary = summary.replace( /\s+$/g, '' );
        if ( summary != '' ) {
            summary += ' ';
        }
        summary += $item.attr( 'title' ) || $this.text();
        $this.replaceWith( $this.contents() );
        $( '#wpSummary' ).val( summary );
    } );
} ); } )( jQuery, mediaWiki );

/*

== 强制预览 ==
[[mw:Manual:Force preview]]
*/

// -------------------------------------------------------------------------------
//  Force Preview  JavaScript code - Start
//
//  To allow any group to bypass being forced to preview, 
//  enter the group name in the permittedGroups array.
//  E.g.
//    var permittedGroups = [];                       // force everyone
//    var permittedGroups = [ "user"];                // permit logged-in users 
//    var permittedGroups = [ "sysop", "bureaucrat"]; // permit sysop, bureaucrat 
// -------------------------------------------------------------------------------
var permittedGroups = [ 'confirmed', 'autoconfirmed' ];
 
Array.prototype.intersects = function() {
	// --------------------------------------------------------
	//  Returns true if any element in the argument array
	//  is the same as an element in this array
	// --------------------------------------------------------
	if ( !arguments.length ) return false;

	var array2 = arguments[0];

	var len1 = this.length;
	var len2 = array2.length;
	if ( len2 == 0 ) return false;

	for ( var i = 0; i < len1; i++ ) {
		for ( var j = 0; j < len2; j++ ) {
			if ( this[i] === array2[j] ) return true;
		}
	}
	return false;
};
 
function forcePreview() {
	if ( mw.config.get( "wgAction" ) != "edit" ) return;
	if ( mw.config.get( "wgUserGroups" ).intersects( permittedGroups ) ) return;
	// Doesn't work correctly with live preview
	if ( mw.user.options.get( "uselivepreview" ) == "1" ) return;
	var saveButton = document.getElementById( "wpSave" );
	if ( !saveButton ) return;
	saveButton.disabled = true;
	// disable the OOUI button
	$('#wpSave').attr('aria-disabled', 'true');
	$('#wpSaveWidget').attr('aria-disabled', 'true');
	$('#wpSaveWidget').removeClass('oo-ui-widget-enabled');
	$('#wpSaveWidget').addClass('oo-ui-widget-disabled');
	saveButton.value = saveButton.value + wgULS( '(请先预览)', '(請先預覽)' );
	saveButton.style.fontWeight = "normal";
	var previewButton = document.getElementById( "wpPreview" );
	if ( previewButton ) {
		previewButton.style.fontWeight = "bold";
	}
}

jQuery(document).ready( forcePreview );
// -----------------------------------------------------
//  Force Preview  JavaScript code - End
// -----------------------------------------------------

/*

== 取消修訂編輯摘要修正 ==
*/
/**
  fix edit summary prompt for undo
  this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged
  this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
*/
$ (function () {
	var autoSummary=document.getElementsByName('wpAutoSummary')[0];
	if (document.location.search.indexOf("undo=") != -1 && autoSummary)
	{ autoSummary.value=''; }
});

/*

== WP:DYKC編輯時取消編輯摘要空段落標示 ==
*/
$( function(){
	var $wpSummary=$("#editform #wpSummary"), $wpTextbox1=$("#editform #wpTextbox1");
	if($wpSummary.length==0 || $wpTextbox1.length==0) return;
	var wpSummary=$wpSummary.get(0), wpTextbox1=$wpTextbox1.get(0);
	var keyReg= /(?:\n|.)*\|\s*article\s*= *([\S ]*)(?:\n|.)*/m ;
	if(wpSummary.value.indexOf("  ")>=0) wpSummary.value="";
	if(mw.config.get("wgPageName")!="Wikipedia:新条目推荐/候选") return;
	if(wpSummary.value=="/"+"*  *"+"/ " && wpTextbox1.value.match(keyReg) ){}else return;
	var temp=wpTextbox1.value.replace(keyReg, '$1');
	if(!temp) return;
	wpSummary.value=wpSummary.defaultValue="\/"+"* "+temp+" *"+"\/ ";
});


/* Check for any client-side simplified/traditional Chinese conversion */
var checkAntiConv = function() {
    var $ac = $('#wpAntiConv');
    if ($ac.length && $ac.val() != '\u6c49\u6f22') {
        var text = $('#wpTextbox1').val();
        var section = $('input[name=wpSection]').val();
        var basetimestamp = $('input[name=wpEdittime]').val();
        var starttimestamp = $('input[name=wpStarttime]').val();
        $('#editform :input').attr({disabled:true,readOnly:true});
        mw.loader.using(['mediawiki.notify','mediawiki.notification'],function(){
            mw.notify(wgULS(
                '系统检测到您使用了客户端繁简转换软件,且此软件对文本框中的内容进行了转换。请关闭此软件后重新打开编辑界面,再进行编辑。',
                '系統檢測到您使用了用戶端繁簡轉換軟體,且此軟體對文字方塊中的內容進行了轉換。請關閉此軟體後重新打開編輯介面,再進行編輯。'
            ),{autoHide:false});
        });
    } else {
        setTimeout(checkAntiConv, 1000);
    }
};
setTimeout(checkAntiConv, 1000);
//</source>