16,874
个编辑
LLWiki正在建设中,欢迎加入我们!
小 (// Edit via Wikiplus) |
小 |
||
(未显示同一用户的31个中间版本) | |||
//<nowiki>
/**
* Cat-a-lot
* @author Perhelion (2017)
* 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
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-
'cat-a-lot-
'cat-a-lot-edit-question': wgULS('请输入编辑摘要:','請輸入編輯摘要:'),
// Progress
'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}}
'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',
// 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',
// Actions
'cat-a-lot-move': 'Move',
'cat-a-lot-add': 'Add',
'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',
// Summaries (project language):
'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': '
};
mw.messages.set( msgs );
var args = Array.prototype.slice.call( arguments, 0 );
args[ 0 ] = 'cat-a-lot-' + args[ 0 ];
return
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
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:
/* 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:
},
init: function () {
// 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 );
$head = $( '<div>' )
.attr( 'id', 'cat_a_lot_head' )
.text( 'Cat-a-lot' )
.appendTo( $head );
if ( this.origin && !non ) {
}
reCat = new RegExp( '^\\s*' + CAL.localizedRegex( 'Category' ) + ':', '' );
$searchInput.on( 'keypress', function ( e ) {
} ) );
}
} );
},
}
$( '<a>' )
.text( msg( 'all' ) )
.on( 'click', function () {
}
$selectNone = $( '<a>' )
.text( msg( 'none' ) )
.on( 'click', function () {
$( this ).toggleClass( 'cat_a_lot_enabled' );
// Load autocomplete on demand
if ( !CAL.executed ) {
$.when( mw.loader.using( [
'mediawiki.api',
'mediawiki.jqueryMsg'
} else { CAL.run(); }
} );
this.localCatName = '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':
try {
return decodeURIComponent( $a.attr( 'href' ) )
.match( /
} 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(
} );
},
toggleAll: function ( select ) {
if ( typeof select === 'string' &&
if ( this.pageLabels
{ this.pageLabels.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 (
// 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 +=
}
return regexName.replace( /([\\\^\$\.\?\*\+\(\)])/g, '\\$1' )
fallback = fallback.toLowerCase();
var canonical =
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 ] ===
return
},
regexCatBuilder: function ( category ) {
var catname = this.localizedRegex(
// 繁简转换
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(
// 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*', '
},
// Remove {{Uncategorized}} (also with comment). No need to replace it with anything.
removeUncat: function ( text ) {
return
},
doCleanup: function ( text ) {
return
},
// 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(
function replaceByBlanks( match ) {
/**
* @brief Adds the new Category by searching the right insert point,
*
* @param [string] wikitext
* @param [string] toAdd
// Try shorten summary
if ( preM || usgM ) {
sumCmt =
sumCmt + ' (CatAlot)' : preM + sumCmt + usgM;
}
.addClass( 'cat_a_lot_done' )
.find( '.ui-dialog-buttonpane button span' ).eq( 0 )
.text( mw.msg( '
var rep = this.domCounter.parent()
.height( 'auto' )
/**
* @brief set parameters for API call,
*
* @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(
CAL.showProgress();
CAL.getTargetCat( pages, targetcat, mode );
createCatLinks: function ( symbol, list, table ) {
list.sort();
var button =
for ( var c = 0; c < list.length; c++ ) {
var $tr = $( '<tr>' ),
$buttons.push( $( '<a>' )
.text(
.on( 'click', function () {
CAL.doSomething( this, 'remove' );
$resultList.css( {
maxHeight: Math.min( this.setHeight, $( window ).height() - $container.position().top
height: ''
} );
mw.cookie.set( 'catAlotO', null );
}
},
for ( var i = 0; i < this.defaults.length; i++ ) {
var v = this.defaults[ i ];
v.value = this.settings[ v.name ] =
v.label = msg( v.label_i18n );
if ( v.select_i18n ) {
defaults: [ {
name: 'watchlist',
'default': 'preferences'
}, {
name: 'minor',
'default': false
}, {
name: 'editpages',
'default': project !== 'commonswiki', // on Commons false
forcerestart: true
}, {
name: 'docleanup',
'default': false
}, {
name: 'subcatcount',
min: 5,
max: 500,
forcerestart: true
}, {
name: 'uncat',
'default':
}, {
name: 'button',
'default': true
} ]
/* eslint-enable camelcase */
// The gadget is not immediately needed, so let the page load normally
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:
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 ) {
};
var userlang = mw.config.get( 'wgUserLanguage' )
if ( userlang !== 'en' ) { loadLocalization( userlang, maybeLaunch ); }
// if ( $.inArray( contlang, [ 'en', userlang ] ) === -1 ) { loadLocalization( contlang, maybeLaunch ); }
maybeLaunch();
}
}
/**
}( jQuery, mediaWiki ) );
//
|