“MediaWiki:Gadget-Cat-a-lot.js”的版本间差异

删除2,185字节 、​ 2022年4月5日 (二) 01:06
无编辑摘要
 
(未显示同一用户的22个中间版本)
//<nowiki>
/**
* Cat-a-lot
 
* READ THIS PAGE IF YOU WANT TO TRANSLATE OR USE THIS ON ANOTHER SITE:
* [http://commons.wikimedia.org/wiki/MediaWiki:Gadget-Cat-a-lot.js/translating]
*/
 
'use strict';
 
var formattedNSns = mw.config.get( 'wgFormattedNamespaceswgNamespaceNumber' ),
ns = mw.config.get( 'wgNamespaceNumber' ),
nsIDs = mw.config.get( 'wgNamespaceIds' ),
userGrp = mw.config.get( 'wgUserGroups' ),
// new: added 2012-09-19. Please translate.
// Use user language for i18n
'cat-a-lot-watchlistprefuncatpref': 'Watchlist移除 preference concerning files edited with Cat-a-lot{{Uncategorized}}',
'cat-a-lot-watch_prefcomment-label': wgULS('According to your general preferences自定义编辑摘要','自定義編輯摘要'),
'cat-a-lot-edit-question': wgULS('请输入编辑摘要:','請輸入編輯摘要:'),
'cat-a-lot-watch_nochange': 'Do not change watchstatus',
'cat-a-lot-watch_watch': 'Watch pages edited with Cat-a-lot',
'cat-a-lot-watch_unwatch': 'Remove pages while editing with Cat-a-lot from your watchlist',
'cat-a-lot-minorpref': 'Mark edits as minor (if you generally mark your edits as minor, this won’t change anything)',
'cat-a-lot-editpagespref': 'Allow categorising pages (including categories) that are not files',
'cat-a-lot-docleanuppref': 'Remove {{Check categories}} and other minor cleanup',
'cat-a-lot-uncatpref': 'Remove {{Uncategorized}}',
'cat-a-lot-subcatcountpref': 'Sub-categories to show at most',
'cat-a-lot-config-settings': 'Preferences',
'cat-a-lot-buttonpref': 'Use buttons instead of text-links',
'cat-a-lot-comment-label': '自定义编辑摘要',
'cat-a-lot-edit-question': '请输入编辑摘要:',
 
// Progress
// 'cat-a-lot-loading': 'Loading …',
'cat-a-lot-editing': 'Editing page',
'cat-a-lot-of': 'of ',
'cat-a-lot-skipped-already': 'The following {{PLURAL:$1|1=page was|$1 pages were}} skipped, because the page was already in the category:',
'cat-a-lot-skipped-not-found': 'The following {{PLURAL:$1|1=page was|$1 pages were}} skipped, because the old category could not be found:',
'cat-a-lot-skipped-server': 'The following {{PLURAL:$1|1=page|$1 pages}} couldn’tcouldn‘t be changed, since there were problems connecting to the server:',
'cat-a-lot-all-done': 'All pages are processed.',
'cat-a-lot-done': 'Done!', // mw.msg("Feedback-close")
'cat-a-lot-removed-cat': 'Removed from category $1',
'cat-a-lot-return-to-page': 'Return to page',
// 'cat-a-lot-cat-not-found': 'Category not found.',
 
// as in 17 files selected
'cat-a-lot-files-selected': '{{PLURAL:$1|1=One file|$1 files}} selected.',
'cat-a-lot-pe_file': '$1 {{PLURAL:$1|page|pages}} of $2 affected',
'cat-a-lot-parent-cat': 'Has parent-category: ',
'cat-a-lot-sub-cat': 'Has sub-category: ',
 
// Actions
'cat-a-lot-add': 'Add',
'cat-a-lot-remove-from-cat': 'Remove',
'cat-a-lot-overcat': wgULS('检测过度分类','檢測過度分類'),
'cat-a-lot-enter-name': 'Enter category name',
'cat-a-lot-select': 'Select',
'cat-a-lot-all': 'all',
'cat-a-lot-none': 'none',
// 'cat-a-lot-none-selected': 'No files selected!', 'Ooui-selectfile-placeholder'
 
// Summaries (project language):
'cat-a-lot-pref-save-summary': 'Updating user preferences',
'cat-a-lot-summary-add': 'Adding [[Category:$1]]',
'cat-a-lot-summary-copy': 'Copying from [[Category:$1]] to [[Category:$2]]',
'cat-a-lot-summary-move': 'Moving from [[Category:$1]] to [[Category:$2]]',
'cat-a-lot-summary-remove': 'Removing from [[Category:$1]]',
'cat-a-lot-prefix-summary': '使用Cat-a-lot小工具',
'cat-a-lot-using-summary': ' using Cat-a-lot'
};
mw.messages.set( msgs );
var args = Array.prototype.slice.call( arguments, 0 );
args[ 0 ] = 'cat-a-lot-' + args[ 0 ];
return ( args.length === 1 ) ?
mw.message( args[ 0 ] ).plain() :
mw.message.apply( mw.message, args ).parse();
 
init: function () {
// Prevent historical double marker (maybe remove in future)
if ( /Cat-?a-?lot/i.test( msgs[ 'cat-a-lot-pref-save-summary' ] ) ) { mw.messages.set( { 'cat-a-lot-prefix-summary': '', 'cat-a-lot-using-summary': '' } ); } else {
mw.messages.set( {
'cat-a-lot-pref-save-summary': msgs[ 'cat-a-lot-prefix-summary' ] + msgs[ 'cat-a-lot-pref-save-summary' ] + msgs[ 'cat-a-lot-using-summary' ]
} );
}
 
// TODO: better extern project support for possible change-tag? (needs currently change after init)
if ( project === 'commonswiki' ) { mw.messages.set( { 'cat-a-lot-using-summary': '' } ); } else { // Reset
.text( 'Cat-a-lot' )
.appendTo( $head );
$container.one( 'mouseover', function () { // Try load on demand earliest as possible
mw.loader.load( [ 'jquery.ui'] );
} );
 
if ( this.origin && !non ) {
}
 
reCat = new RegExp( '^\\s*' + CAL.localizedRegex( 14, 'Category' ) + ':', '' );
/*
if ( ( mw.util.getParamValue( 'withJS' ) === 'MediaWiki:Gadget-Cat-a-lot.js' &&
!mw.util.getParamValue( 'withCSS' ) ) ||
mw.loader.getState( 'ext.gadget.Cat-a-lot' ) === 'registered' ) {
mw.loader.load( mw.config.get( 'wgServer' ) + '/mediawiki/index.php?title=MediaWiki:Gadget-Cat-a-lot.css&action=raw&ctype=text/css', 'text/css' );
// importStylesheet( 'MediaWiki:Gadget-Cat-a-lot.css' );
}
*/
 
reCat = new RegExp( '^\\s*' + CAL.localizedRegex( 14, 'Category' ) + ':', '' );
 
$searchInput.on( 'keypress', function ( e ) {
} ) );
}
 
} );
},
}
$( '<a>' )
// .attr( 'id', 'cat_a_lot_select_all' )
.text( msg( 'all' ) )
.on( 'click', function () {
}
$selectNone = $( '<a>' )
// .attr( 'id', 'cat_a_lot_select_none' )
.text( msg( 'none' ) )
.on( 'click', function () {
$( this ).toggleClass( 'cat_a_lot_enabled' );
// Load autocomplete on demand
mw.loader.using( 'jquery.ui', initAutocomplete ();
 
if ( !CAL.executed ) {
$.when( mw.loader.using( [
'jquery.ui',
'jquery.ui',
'jquery.ui',
'mediawiki.api',
'mediawiki.jqueryMsg'
} else { CAL.run(); }
} );
this.localCatName = formattedNS[ 14 ] + 'Category:';
mw.loader.using( 'mediawiki.cookie', function () { // Let catAlot stay open
var val = mw.cookie.get( 'catAlotO' );
this.labels = this.labels.add( $( 'table.searchResultImage' ).find( 'tr>td:eq(1)' ) );
if ( this.settings.editpages ) { this.labels = this.labels.add( 'div.mw-search-result-heading' ); }
 
break;
case 'category':
file = file.length ? file : label.find( 'a[title]' );
var title = file.attr( 'title' ) ||
CAL.getTitleFromLink( file ) ||
CAL.getTitleFromLink( label.find( 'a' ) ) ||
CAL.getTitleFromLink( label.parent().find( 'a' ) ); // TODO needs optimization
if ( title.indexOf( formattedNS[ 2 ] + 'User:' ) ) { return [ [ title, label ] ]; }
} );
},
},
 
localizedRegex: function ( namespaceNumber, fallback ) {
// Copied from HotCat, thanks Lupo.
var wikiTextBlank = '[\\t _\\xA0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]+';
var ll = ii.toLowerCase();
var ul = ii.toUpperCase();
regexName += ( ll === ul ) ? ii : '[' + ll + ul + ']';
}
return regexName.replace( /([\\\^\$\.\?\*\+\(\)])/g, '\\$1' )
 
fallback = fallback.toLowerCase();
var canonical = formattedNS[ namespaceNumber ].toLowerCase()'category';
var RegexString = createRegexStr( canonical );
if ( fallback && canonical !== fallback ) { RegexString += '|' + createRegexStr( fallback ); }
 
for ( var catName in nsIDs ) { if ( typeof catName === 'string' && catName.toLowerCase() !== canonical && catName.toLowerCase() !== fallback && nsIDs[ catName ] === namespaceNumberns ) { RegexString += '|' + createRegexStr( catName ); } }
 
return ( '(?:' + RegexString + ')' );
},
 
regexCatBuilder: function ( category ) {
var catname = this.localizedRegex( 14, 'Category' );
}
// 繁简转换
if ( window.CatALotSourceCat && window.CatALotSourceCat.includes( category.replace(/_/g, ' ') ) ) {
category = window.CatALotSourceCat;
} else { category = [category]; }
 
// Build a regexp string for matching the given category:
// trim leading/trailing whitespace and underscores
category = category.map(ele => ele.replace( /^[\s_]+|[\s_]+$/g, '' ));
 
// escape regexp metacharacters (= any ASCII punctuation except _)
category = category.map(ele => mw.util.escapeRegExp( categoryele ));
 
// any sequence of spaces and underscores should match any other
category = category.map(ele => ele.replace( /[\s_]+/g, '[\\s_]+' ));
 
// Make the first character case-insensitive:
//var first = category.substr( 0, 1 );
//if ( first.toUpperCase() !== first.toLowerCase() ) { category = '[' + first.toUpperCase() + first.toLowerCase() + ']' + category.substr( 1 ); }
 
// Compile it into a RegExp that matches MediaWiki category syntax (yeah, it looks ugly):
// XXX: the first capturing parens are assumed to match the sortkey, if present, including the | but excluding the ]]
return new RegExp( '\\[\\[[\\s_]*' + catname + '[\\s_]*:[\\s_]*(?:' + category.join('|') + ')[\\s_]*(\\|[^\\]]*(?:\\][^\\]]+)*)?\\]\\]\\s*', 'ggi' );
},
 
// Remove {{Uncategorized}} (also with comment). No need to replace it with anything.
removeUncat: function ( text ) {
return ( this.settings.uncat ? text.replace( /\{\{\s*[Uu]ncategorized\s*[^}]*\}\}\s*(<!--.*?-->\s*)?/, '' ) : text );
},
 
doCleanup: function ( text ) {
return ( this.settings.docleanup ? text.replace( /\{\{\s*[Cc]heck categories\s*(\|?.*?)\}\}/, '' ) : text );
},
 
// zero-width space \u200B, and bidi overrides between the components of a category link (adjacent to the colon,
// or adjacent to and inside of "[[" and "]]").
var findCatsRE = new RegExp( '\\[\\[' + wikiTextBlankOrBidi + this.localizedRegex( 14, 'Category' ) + wikiTextBlankOrBidi + ':[^\\]]+\\]\\]', 'g' );
 
function replaceByBlanks( match ) {
/**
* @brief Adds the new Category by searching the right insert point,
* if there is text after the category section
* @param [string] wikitext
* @param [string] toAdd
// Try shorten summary
if ( preM || usgM ) {
sumCmt = ( sumCmt.length > 250 - preM.length - usgM.length ) ?
sumCmt + ' (CatAlot)' : preM + sumCmt + usgM;
}
/**
* @brief set parameters for API call,
* convert targetcat to string, get selected pages/files
* @param [dom object] targetcat with data
* @param [string] mode action
if ( $( '#cat_a_lot_comment' ).prop( 'checked' ) ) { this.summary = window.prompt( msg( 'edit-question' ), '' ); } // TODO custom pre-value
if ( this.summary !== null ) {
mw.loader.using( [ 'jquery.ui', 'jquery.spinner', 'mediawiki.util' ], function () {
CAL.showProgress();
CAL.getTargetCat( pages, targetcat, mode );
createCatLinks: function ( symbol, list, table ) {
list.sort();
var button = ( this.settings.button && mw.loader.getState( 'jquery.ui' ) === 'ready' ) ? 1 : 0;
for ( var c = 0; c < list.length; c++ ) {
var $tr = $( '<tr>' ),
for ( var i = 0; i < this.defaults.length; i++ ) {
var v = this.defaults[ i ];
v.value = this.settings[ v.name ] = ( this.catALotPrefs[ v.name ] || v['default'] );
v.label = msg( v.label_i18n );
if ( v.select_i18n ) {
defaults: [ {
name: 'watchlist',
'default': 'preferences',
label_i18n: 'watchlistpref',
select_i18n: {
watch_pref: 'preferences',
watch_nochange: 'nochange',
watch_watch: 'watch',
watch_unwatch: 'unwatch'
}
}, {
name: 'minor',
'default': false,
label_i18n: 'minorpref'
}, {
name: 'editpages',
'default': project !== 'commonswiki', // on Commons false
label_i18n: 'editpagespref',
forcerestart: true
}, {
name: 'docleanup',
'default': false,
label_i18n: 'docleanuppref'
}, {
name: 'subcatcount',
min: 5,
max: 500,
label_i18n: 'subcatcountpref',
forcerestart: true
}, {
name: 'uncat',
'default': project === 'commonswiki', // on Commons truefalse
label_i18n: 'uncatpref'
}, {
name: 'button',
'default': true,
label_i18n: 'buttonpref'
} ]
/* eslint-enable camelcase */
 
// The gadget is not immediately needed, so let the page load normally
window.setTimeout$( function () {
non = mw.config.get( 'wgUserName' );
if ( non ) {
},
cache: true,
success: cb,function() {
mw.messages.set( {
'cat-a-lot-summary-add': wgULS('加入分类', '加入分類') + '[[Category:$1]]',
'cat-a-lot-summary-copy': wgULS('分类间复制:从', '分類間複製:從') + '[[Category:$1]]到[[Category:$2]]',
'cat-a-lot-summary-move': wgULS('分类间移动:从', '分類間移動:從') + '[[Category:$1]]到[[Category:$2]]',
'cat-a-lot-summary-remove': wgULS('从分类', '從分類') + '移除:[[Category:$1]]'
} );
cb();
},
error: cb
} );
} );
}
if ( !loadingLocalizations ) { mw.loader.usinginit( [ 'user' ], init, init ); }
};
 
var userlang = mw.config.get( 'wgUserLanguage' ),;
contlang = mw.config.get( 'wgContentLanguage' );
if ( userlang !== 'en' ) { loadLocalization( userlang, maybeLaunch ); }
// if ( $.inArray( contlang, [ 'en', userlang ] ) === -1 ) { loadLocalization( contlang, maybeLaunch ); }
maybeLaunch();
}
}, 400 );
 
/**
 
}( jQuery, mediaWiki ) );
//</nowiki>
16,874

个编辑