LLWiki正在建设中,欢迎加入我们

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

跳转到导航 跳转到搜索
删除5,082字节 、​ 2022年4月5日 (二) 01:06
无编辑摘要
(// Edit via Wikiplus)
 
(未显示同一用户的31个中间版本)
//<nowiki>
/**
* Cat-a-lot
* @author Perhelion (2017)
 
* Requires [[MediaWiki:Gadget-SettingsManager.js]] and [[MediaWiki:Gadget-SettingsUI.js]] (properly registered) for per-user-settings
*
* 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]
* <nowiki>
*/
 
'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': 'Custom edit comment',
'cat-a-lot-edit-question': 'Why is this change necessary?',
 
// 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-moved-cat': 'Moved to category $1',
'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-move': 'Move',
'cat-a-lot-add': 'Add',
// 'cat-a-lot-remove-from-cat': 'Remove from this category',
'cat-a-lot-overcat': wgULS('Check over-categorization检测过度分类','檢測過度分類'),
'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 [[c:Help:Cat-a-lot|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();
// There is only one Cat-a-lot on one page
var $body, $container, $dataContainer, $searchInputContainer, $searchInput, $resultList, $markCounter, $selections,
$selectFiles, $selectPages, $selectNone, $selectInvert, $settingsWrapper, $settingsLink, $head, $link, $overcat,
commonsURL = 'https://commons.wikimedia.org/w/index.php',
is_rtl = $( 'body' ).hasClass( 'rtl' ),
any items, but that contains links to other categories where stuff should be categorized. If you don't have
that concept on your wiki, set it to null. Use blanks, not underscores. */
disambig_category: 'Disambiguation'null, // Commons and EnWP
/* Any category in this category is deemed a (soft) redirect to some other category defined by a link
* to another non-blacklisted category. If your wiki doesn't have soft category redirects, set this to null.
* If a soft-redirected category contains more than one link to another non-blacklisted category, it's considered
* a disambiguation category instead. */
redir_category: 'Category redirects'null
 
},
 
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( msg( 'select' ) + ':' )
.appendTo( $dataContainer );
$settingsWrapper = $( '<div>' )
.attr( 'id', 'cat_a_lot_settings' )
.appendTo( $dataContainer );
$settingsLink = $( '<a>', {
id: 'cat_a_lot_config_settings',
title: 'Version ' + this.version,
text: msg( 'config-settings' )
} )
.appendTo( $settingsWrapper );
$head = $( '<div>' )
.attr( 'id', 'cat_a_lot_head' )
.text( 'Cat-a-lot' )
.appendTo( $head );
$settingsWrapper.append( $( '<a>', {
href: commonsURL + '?title=Special:MyLanguage/Help:Gadget-Cat-a-lot',
target: '_blank',
style: 'float:right',
title: ( $( '#n-help a' ).attr( 'title' ) || '' ) + ' (v. ' + this.version + ')'
} ).text( '?' ) );
$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( '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' ) + '/w/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 = 'Category:';
$settingsLink
.on( 'click', CAL.manageSettings );
this.localCatName = formattedNS[ 14 ] + ':';
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':
try {
return decodeURIComponent( $a.attr( 'href' ) )
.match( /wikizh\/(.+?)(?:#.+)?$/ )[ 1 ].replace( /_/g, ' ' );
} catch ( ex ) {
return '';
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 ] ]; }
} );
},
 
toggleAll: function ( select ) {
if ( typeof select === 'string' && this.pageLabels[select 0=== ]'files' ) {
if ( this.pageLabels.toggleClass([ 'cat_a_lot_selected',0 true] ); // pages remain unchanged
{ this.pageLabels.toggleClass( 'cat_a_lot_selected' ); }
if ( select === 'files' ) // pages get deselected
{ this.labels.toggleClass( 'cat_a_lot_selected' ); }
} else if ( typeof select === 'string' && select === 'pages' ) {
if ( this.pageLabels[ 0 ] ) // files remain unchanged
{ this.pageLabels.toggleClass( 'cat_a_lot_selected' ); }
} else {
// invert / none / all
},
 
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;
}
.addClass( 'cat_a_lot_done' )
.find( '.ui-dialog-buttonpane button span' ).eq( 0 )
.text( mw.msg( 'Mobilecat-frontenda-lot-return-to-page' ) );
var rep = this.domCounter.parent()
.height( 'auto' )
/**
* @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>' ),
 
$buttons.push( $( '<a>' )
.text( mw.msg( 'Centralnotice-remove-from-cat' ) )
.on( 'click', function () {
CAL.doSomething( this, 'remove' );
 
$resultList.css( {
maxHeight: Math.min( this.setHeight, $( window ).height() - $container.position().top /* - $settingsLink.outerHeight() */ - $selections.outerHeight() - 15 ),
height: ''
} );
mw.cookie.set( 'catAlotO', null );
}
},
 
manageSettings: function () {
mw.loader.using( [ 'ext.gadget.SettingsManager', 'ext.gadget.SettingsUI', 'jquery.ui' ], CAL._manageSettings );
},
 
_manageSettings: function () {
mw.libs.SettingsUI( CAL.defaults, 'Cat-a-lot' )
.show()
.done( function ( s, verbose, loc, settingsOut, $dlg ) {
var mustRestart = false,
_restart = function () {
if ( !mustRestart ) { return; }
$container.remove();
CAL.labels.off( 'click.catALot' );
CAL.init();
},
_saveToJS = function () {
var opt = mw.libs.settingsManager.option( {
optionName: 'catALotPrefs',
value: CAL.settings,
encloseSignature: 'catALot',
encloseBlock: '////////// Cat-a-lot user preferences //////////\n',
triggerSaveAt: /Cat.?A.?Lot/i,
editSummary: msg( 'pref-save-summary' )
} ),
oldHeight = $dlg.height(),
$prog = $( '<div>' );
 
$dlg.css( 'height', oldHeight )
.html( '' );
$prog.css( {
height: Math.round( oldHeight / 8 ),
'margin-top': Math.round( ( 7 * oldHeight ) / 16 )
} )
.appendTo( $dlg );
 
$dlg.parent()
.find( '.ui-dialog-buttonpane button' )
.button( 'option', 'disabled', true );
 
opt.save()
.done( function ( text, progress ) {
$prog.progressbar( {
value: progress
} );
$prog.fadeOut( function () {
$dlg.dialog( 'close' );
_restart();
} );
} )
.progress( function ( text, progress ) {
$prog.progressbar( {
value: progress
} );
// TODO: Add "details" to progressbar
} )
.fail( function ( text ) {
$prog.addClass( 'ui-state-error' );
$dlg.prepend( $( '<p>' )
.text( text ) );
} );
};
$.each( settingsOut, function ( n, v ) {
if ( v.forcerestart && CAL.settings[ v.name ] !== v.value ) { mustRestart = true; }
CAL.settings[ v.name ] = CAL.catALotPrefs[ v.name ] = v.value;
} );
switch ( loc ) {
case 'page':
$dlg.dialog( 'close' );
_restart();
break;
case 'account-publicly':
_saveToJS();
break;
}
} );
},
 
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 ) {
CAL.origin = mw.config.get( 'wgTitle' );
break;
/* 其他namespace无法正常使用
case -1:
CAL.searchmode = {
} );
CAL.origin = parents.eq( n || 0 ).text();
*/
}
 
},
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

个编辑

导航菜单