MediaWiki:Gadget-HotCat.js: Difference between revisions

Add
(Trying 2.41)
(Add)
Line 540: Line 540:
}
}


var summary = [],
var summary = [];
nameSpace = HC.category_canonical,
var nameSpace = HC.category_canonical;
cat_point = -1, // Position of removed category;
var cat_point = -1; // Position of removed category;
keyChange = ( toRemove && toAdd && toRemove === toAdd && toAdd.length ),
 
matches;
if ( key ) key = '|' + key;
if ( key ) key = '|' + key;
// Remove
 
var keyChange = ( toRemove && toAdd && toRemove === toAdd && toAdd.length );
var matches;
if ( toRemove && toRemove.length ) {
if ( toRemove && toRemove.length ) {
matches = find_category( wikitext, toRemove );
matches = find_category( wikitext, toRemove );
Line 556: Line 557:
};
};
} else {
} else {
var before = wikitext.substring( 0, matches[ 0 ].match.index ),
var before = wikitext.substring( 0, matches[ 0 ].match.index );
after = wikitext.substring( matches[ 0 ].match.index + matches[ 0 ].match[ 0 ].length );
var after = wikitext.substring( matches[ 0 ].match.index + matches[ 0 ].match[ 0 ].length );
if ( matches.length > 1 ) {
if ( matches.length > 1 ) {
// Remove all occurrences in after
// Remove all occurrences in after
Line 564: Line 565:
}
}
if ( toAdd ) {
if ( toAdd ) {
// nameSpace = matches[ 0 ].match[ 1 ] || nameSpace; Canonical namespace should be always preferred
nameSpace = matches[ 0 ].match[ 1 ] || nameSpace;
if ( key === null ) key = matches[ 0 ].match[ 2 ];
if ( key === null ) key = matches[ 0 ].match[ 2 ];
// Remember the category key, if any.
// Remember the category key, if any.
Line 600: Line 601:
}
}
}
}
// Add
if ( toAdd && toAdd.length ) {
if ( toAdd && toAdd.length ) {
matches = find_category( wikitext, toAdd );
matches = find_category( wikitext, toAdd );
if ( matches && matches.length ) {
if ( matches && matches.length ) {
// Already exists
return {
return {
text: wikitext,
text: wikitext,
Line 2,692: Line 2,691:
config.HotCatUseCategoryLinks :
config.HotCatUseCategoryLinks :
HC.use_up_down ) );
HC.use_up_down ) );
HC.listSize = window.hotcat_list_size || config.HotCatListSize || HC.listSize;
HC.listSize = window.hotcat_listSize || config.HotCatListSize || HC.listSize;
if ( conf.wgDBname !== 'commonswiki' ) HC.changeTag = config.HotCatChangeTag || '';
if ( conf.wgDBname !== 'commonswiki' ) HC.changeTag = config.HotCatChangeTag || '';


Line 2,771: Line 2,770:
if ( isNaN( HC.listSize ) || HC.listSize < 5 ) HC.listSize = 5;
if ( isNaN( HC.listSize ) || HC.listSize < 5 ) HC.listSize = 5;


HC.listSize = Math.min( HC.listSize, 30 ); // Max size
HC.listSize = Math.min( HC.listSize, 15 );


// Localize search engine names
// Localize search engine names
14,061

edits