مدیاویکی:Gadget-HotCat.js: تفاوت میان نسخهها
بدون خلاصۀ ویرایش |
بدون خلاصۀ ویرایش |
||
| (۶ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد) | |||
| خط ۱: | خط ۱: | ||
/ | /** | ||
HotCat V2.43 | |||
Ajax-based simple Category manager. Allows adding/removing/changing categories on a page view. | |||
Supports multiple category changes, as well as redirect and disambiguation resolution. Also | |||
plugs into the upload form. Search engines to use for the suggestion list are configurable, and | |||
can be selected interactively. | |||
Documentation: https://commons.wikimedia.org/wiki/Help:Gadget-HotCat | |||
List of main authors: https://commons.wikimedia.org/wiki/Help:Gadget-HotCat/Version_history | |||
License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0) | |||
Choose whichever license of these you like best :-) | |||
This code should run on any MediaWiki installation >= MW 1.27. | |||
For use with older versions of MediaWiki, use the archived versions below: | |||
<=1.26: https://commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&oldid=211134664 | |||
*/ | */ | ||
/* eslint-disable vars-on-top, one-var, camelcase, no- | // <nowiki> | ||
/* global | /* eslint-disable vars-on-top, one-var, camelcase, no-alert, curly */ | ||
/* global jQuery, mediaWiki, UFUI, JSconfig, UploadForm */ | |||
/* jslint strict:false, nonew:false, bitwise:true */ | |||
( function ( $, mw ) { | ( function ( $, mw ) { | ||
// Don't use mw.config.get() as that takes a copy of the config, and so doesn't | // Don't use mw.config.get() as that takes a copy of the config, and so doesn't | ||
// account for values changing, e.g. wgCurRevisionId after a VE edit | // account for values changing, e.g. wgCurRevisionId after a VE edit | ||
var conf = mw.config.values | var | ||
conf = mw.config.values, | |||
// when running on mobile domain - do not use wgServer. | |||
wgServer = window.location.host.indexOf('.m.') > -1 ? | |||
'//' + window.location.host : mw.config.get( 'wgServer' ); | |||
) | // Guard against double inclusions (in old IE/Opera element ids become window properties) | ||
if ( ( window.HotCat && !window.HotCat.nodeName ) || | |||
conf.wgAction === 'edit' ) // Not on edit mode | |||
return; | return; | ||
// Configuration stuff. | // Configuration stuff. | ||
window.HotCat = { | var HC = window.HotCat = { | ||
// Localize these messages to the main language of your wiki. | |||
messages: { | messages: { | ||
cat_removed: 'removed [[Category:$1]]', | cat_removed: 'removed [[Category:$1]]', | ||
| خط ۷۵: | خط ۷۳: | ||
// see localization hook below. | // see localization hook below. | ||
multi_error: 'Could not retrieve the page text from the server. Therefore, your category changes ' + | multi_error: 'Could not retrieve the page text from the server. Therefore, your category changes ' + | ||
'cannot be saved. We apologize for the inconvenience.', | |||
// Defaults to '[[' + category_canonical + ':$1]]'. Can be overridden if in the short edit summaries | // Defaults to '[[' + category_canonical + ':$1]]'. Can be overridden if in the short edit summaries | ||
// not the standard category name should be used but, say, a shorter namespace alias. $1 is replaced | // not the standard category name should be used but, say, a shorter namespace alias. $1 is replaced | ||
| خط ۹۴: | خط ۹۲: | ||
// The little modification links displayed after category names. U+2212 is a minus sign; U+2193 and U+2191 are | // The little modification links displayed after category names. U+2212 is a minus sign; U+2193 and U+2191 are | ||
// downward and upward pointing arrows. Do not use ↓ and ↑ in the code! | // downward and upward pointing arrows. Do not use ↓ and ↑ in the code! | ||
links: { change: '(±)', remove: '(\u2212)', add: '(+)', restore: '(×)', undo: '(×)', down: '(\u2193)', up: '(\u2191)' }, | links: { | ||
change: '(±)', | |||
remove: '(\u2212)', | |||
add: '(+)', | |||
restore: '(×)', | |||
undo: '(×)', | |||
down: '(\u2193)', | |||
up: '(\u2191)' | |||
}, | |||
changeTag: conf.wgUserName ? 'HotCat' : '', // if tag is missing, edit is rejected | |||
// The tooltips for the above links | // The tooltips for the above links | ||
tooltips: { | tooltips: { | ||
| خط ۱۱۵: | خط ۱۲۲: | ||
return ( | return ( | ||
ns < 0 || // Special pages; Special:Upload is handled differently | ns < 0 || // Special pages; Special:Upload is handled differently | ||
ns === 10 || // Templates | |||
ns === 828 || // Module (Lua) | |||
ns === 8 || // MediaWiki | |||
ns === 6 && !conf.wgArticleId || // Non-existing file pages | |||
ns === 2 && /\.(js|css)$/.test( conf.wgTitle ) || // User scripts | |||
nsIds && | |||
( ns === nsIds.creator || | |||
ns === nsIds.timedtext || | |||
ns === nsIds.institution ) ); | |||
}, | }, | ||
// A regexp matching a templates used to mark uncategorized pages, if your wiki does have that. | // A regexp matching a templates used to mark uncategorized pages, if your wiki does have that. | ||
// If not, set it to null. | // If not, set it to null. | ||
uncat_regexp: /\{\{\s* | uncat_regexp: /\{\{\s*[Uu]ncategorized\s*[^}]*\}\}\s*(<!--.*?-->\s*)?/g, | ||
// The images used for the little indication icon. Should not need changing. | // The images used for the little indication icon. Should not need changing. | ||
existsYes: '//upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png', | existsYes: '//upload.wikimedia.org/wikipedia/commons/thumb/b/be/P_yes.svg/20px-P_yes.svg.png', | ||
| خط ۱۴۶: | خط ۱۵۱: | ||
parentcat: 'Parent categories' | parentcat: 'Parent categories' | ||
}, | }, | ||
// | |||
// | // Override the decision of whether HotCat should help users by automatically | ||
// | // capitalising the title in the user input text if the wiki has case-sensitive page names. | ||
// | // Basically, this will make an API query to check the MediaWiki configuration and HotCat then sets | ||
// | // this to true for most wikis, and to false on Wiktionary. | ||
// | |||
// MediaWiki | // You can set this directly if there is a problem with it. For example, Georgian Wikipedia (kawiki), | ||
// | // is known to have different capitalisation logic between MediaWiki PHP and JavaScript. As such, automatic | ||
capitalizePageNames: | // case changes in JavaScript by HotCat would be wrong. | ||
capitalizePageNames: null, | |||
// If upload_disabled is true, HotCat will not be used on the Upload form. | // If upload_disabled is true, HotCat will not be used on the Upload form. | ||
upload_disabled: false, | upload_disabled: false, | ||
| خط ۱۶۵: | خط ۱۷۱: | ||
// Stuff changeable by users: | // Stuff changeable by users: | ||
// Background for changed categories in multi-edit mode. Default is a very light salmon pink. | // Background for changed categories in multi-edit mode. Default is a very light salmon pink. | ||
bg_changed: '# | bg_changed: '#FCA', | ||
// If true, HotCat will never automatically submit changes. HotCat will only open an edit page with | // If true, HotCat will never automatically submit changes. HotCat will only open an edit page with | ||
// the changes; users must always save explicitly. | // the changes; users must always save explicitly. | ||
| خط ۱۸۵: | خط ۱۹۱: | ||
use_up_down: true, | use_up_down: true, | ||
// Default list size | // Default list size | ||
listSize: 10, | |||
// If true, single category changes are marked as minor edits. If false, they're not. | // If true, single category changes are marked as minor edits. If false, they're not. | ||
single_minor: true, | single_minor: true, | ||
| خط ۱۹۴: | خط ۲۰۰: | ||
shortcuts: null, | shortcuts: null, | ||
addShortcuts: function ( map ) { | addShortcuts: function ( map ) { | ||
if ( !map ) | if ( !map ) return; | ||
window.HotCat.shortcuts = window.HotCat.shortcuts || {}; | window.HotCat.shortcuts = window.HotCat.shortcuts || {}; | ||
for ( var k in map ) { | for ( var k in map ) { | ||
if ( !map.hasOwnProperty( k ) || typeof k !== 'string' ) | if ( !map.hasOwnProperty( k ) || typeof k !== 'string' ) continue; | ||
var v = map[ k ]; | var v = map[ k ]; | ||
if ( typeof v !== 'string' ) | if ( typeof v !== 'string' ) continue; | ||
k = k.replace( /^\s+|\s+$/g, '' ); | k = k.replace( /^\s+|\s+$/g, '' ); | ||
v = v.replace( /^\s+|\s+$/g, '' ); | v = v.replace( /^\s+|\s+$/g, '' ); | ||
if ( k.length | if ( !k.length || !v.length ) continue; | ||
window.HotCat.shortcuts[ k ] = v; | window.HotCat.shortcuts[ k ] = v; | ||
} | } | ||
| خط ۲۱۲: | خط ۲۲۱: | ||
var ua = navigator.userAgent.toLowerCase(); | var ua = navigator.userAgent.toLowerCase(); | ||
var is_webkit = /applewebkit\/\d+/.test( ua ) && ua.indexOf( 'spoofer' ) < 0; | var is_webkit = /applewebkit\/\d+/.test( ua ) && ua.indexOf( 'spoofer' ) < 0; | ||
var cat_prefix = null; | |||
var noSuggestions = false; | |||
var | |||
function LoadTrigger( needed ) { | |||
// Define methods in a closure so that self reference is available, | |||
if ( | // also allows method calls to be detached. | ||
var self = this; | |||
self.queue = []; | |||
self.needed = needed; | |||
self.register = function ( callback ) { | |||
if ( self.needed <= 0 ) callback(); // Execute directly | |||
if ( | else self.queue.push( callback ); | ||
// | }; | ||
self.loaded = function () { | |||
self.needed--; | |||
if ( self.needed === 0 ) { | |||
// Run queued callbacks once | |||
for ( var i = 0; i < self.queue.length; i++ ) self.queue[ i ](); | |||
self.queue = []; | |||
} | } | ||
}; | }; | ||
} | } | ||
// Used to delay running the HotCat setup until /local_defaults and localizations have been loaded. | |||
var loadTrigger = new LoadTrigger( 2 ); | |||
// Used to | |||
var loadTrigger = new LoadTrigger( 2 ); | |||
function load( uri ) { | function load( uri, callback ) { | ||
var s = document.createElement( 'script' ); | var s = document.createElement( 'script' ); | ||
s. | s.src = uri; | ||
var called = false; | |||
var | |||
s.onload = s.onerror = function () { | |||
if ( !called && callback ) { | |||
called = true; | |||
callback(); | |||
if ( | } | ||
if ( s.parentNode ) { | |||
s.parentNode.removeChild( s ); | |||
if ( | |||
} | } | ||
}; | }; | ||
document.head.appendChild( s ); | |||
} | } | ||
function loadJS( page ) { | function loadJS( page, callback ) { | ||
load( | load( wgServer + conf.wgScript + '?title=' + encodeURIComponent( page ) + '&action=raw&ctype=text/javascript', callback ); | ||
} | } | ||
function loadURI( href ) { | function loadURI( href, callback ) { | ||
var url = href; | var url = href; | ||
if ( url.substring( 0, 2 ) === '//' ) | if ( url.substring( 0, 2 ) === '//' ) url = window.location.protocol + url; else if ( url.substring( 0, 1 ) === '/' ) url = wgServer + url; | ||
load( url, callback ); | |||
load( url ); | |||
} | } | ||
// Load local configurations, overriding the pre-set default values in the HotCat object above. This is always loaded | // Load local configurations, overriding the pre-set default values in the HotCat object above. This is always loaded | ||
// from the wiki where this script is executing, even if this script itself is hotlinked from | // from the wiki where this script is executing, even if this script itself is hotlinked from Commons. This can | ||
// be used to change the default settings, or to provide localized interface texts for edit summaries and so on. | // be used to change the default settings, or to provide localized interface texts for edit summaries and so on. | ||
loadJS( 'MediaWiki:Gadget-HotCat.js/local_defaults' ); | loadJS( 'MediaWiki:Gadget-HotCat.js/local_defaults', loadTrigger.loaded ); | ||
// Load localized UI texts. These are the texts that HotCat displays on the page itself. Texts shown in edit summaries | // Load localized UI texts. These are the texts that HotCat displays on the page itself. Texts shown in edit summaries | ||
| خط ۳۵۶: | خط ۲۸۴: | ||
if ( conf.wgUserLanguage !== 'en' ) { | if ( conf.wgUserLanguage !== 'en' ) { | ||
// Lupo: somebody thought it would be a good idea to add this. So the default is true, and you have to set it to false | // Lupo: somebody thought it would be a good idea to add this. So the default is true, and you have to set it to false | ||
// explicitly if you're not on | // explicitly if you're not on Commons and don't want that. | ||
if ( | if ( window.hotcat_translations_from_commons === undefined ) window.hotcat_translations_from_commons = true; | ||
// Localization hook to localize HotCat messages, tooltips, and engine names for wgUserLanguage. | // Localization hook to localize HotCat messages, tooltips, and engine names for wgUserLanguage. | ||
if ( window.hotcat_translations_from_commons && | if ( window.hotcat_translations_from_commons && wgServer.indexOf( '//commons' ) < 0 ) { | ||
loadURI( '//commons.wikimedia.org/w/index.php?title=' + | loadURI( '//commons.wikimedia.org/w/index.php?title=' + | ||
'MediaWiki:Gadget-HotCat.js/' + conf.wgUserLanguage + | |||
'&action=raw&ctype=text/javascript', loadTrigger.loaded ); | |||
} else { | } else { | ||
// Load translations locally | // Load translations locally | ||
loadJS( 'MediaWiki:Gadget-HotCat.js/' + conf.wgUserLanguage ); | loadJS( 'MediaWiki:Gadget-HotCat.js/' + conf.wgUserLanguage, loadTrigger.loaded ); | ||
} | } | ||
} else { | } else { | ||
| خط ۴۰۰: | خط ۳۲۶: | ||
var namespaceIds = conf.wgNamespaceIds; | var namespaceIds = conf.wgNamespaceIds; | ||
function autoLocalize( namespaceNumber, fallback ) { | function autoLocalize( namespaceNumber, fallback ) { | ||
function | function createRegexpStr( name ) { | ||
if ( !name || name.length | if ( !name || !name.length ) return ''; | ||
var regex_name = ''; | var regex_name = ''; | ||
for ( var i = 0; i < name.length; i++ ) { | for ( var i = 0; i < name.length; i++ ) { | ||
var initial = name. | var initial = name.charAt( i ), | ||
ll = initial.toLowerCase(), | |||
ul = initial.toUpperCase(); | |||
if ( ll === ul ) | if ( ll === ul ) regex_name += initial; else regex_name += '[' + ll + ul + ']'; | ||
} | } | ||
return regex_name | return regex_name | ||
| خط ۴۲۰: | خط ۳۴۳: | ||
fallback = fallback.toLowerCase(); | fallback = fallback.toLowerCase(); | ||
var canonical = formattedNamespaces[ String( namespaceNumber ) ].toLowerCase(); | var canonical = formattedNamespaces[ String( namespaceNumber ) ].toLowerCase(); | ||
var regexp = | var regexp = createRegexpStr( canonical ); | ||
if ( fallback && canonical !== fallback ) | if ( fallback && canonical !== fallback ) regexp += '|' + createRegexpStr( fallback ); | ||
if ( namespaceIds ) { | if ( namespaceIds ) { | ||
for ( var cat_name in namespaceIds ) { | for ( var cat_name in namespaceIds ) { | ||
| خط ۴۳۰: | خط ۳۵۴: | ||
namespaceIds[ cat_name ] === namespaceNumber | namespaceIds[ cat_name ] === namespaceNumber | ||
) { | ) { | ||
regexp += '|' + | regexp += '|' + createRegexpStr( cat_name ); | ||
} | } | ||
} | } | ||
| خط ۴۳۷: | خط ۳۶۱: | ||
} | } | ||
HC.category_canonical = formattedNamespaces[ '14' ]; | |||
HC.category_regexp = autoLocalize( 14, 'category' ); | |||
if ( formattedNamespaces[ '10' ] ) | if ( formattedNamespaces[ '10' ] ) HC.template_regexp = autoLocalize( 10, 'template' ); | ||
// Utility functions. Yes, this duplicates some functionality that also exists in other places, but | // Utility functions. Yes, this duplicates some functionality that also exists in other places, but | ||
// to keep this whole stuff in a single file not depending on any other on-wiki | // to keep this whole stuff in a single file not depending on any other on-wiki JavaScripts, we re-do | ||
// these few operations here. | // these few operations here. | ||
function make( arg, literal ) { | function make( arg, literal ) { | ||
if ( !arg ) | if ( !arg ) return null; | ||
return literal ? document.createTextNode( arg ) : document.createElement( arg ); | return literal ? document.createTextNode( arg ) : document.createElement( arg ); | ||
} | } | ||
function param( name, uri ) { | function param( name, uri ) { | ||
uri = uri || document.location.href; | |||
var re = new RegExp( '[&?]' + name + '=([^&#]*)' ); | var re = new RegExp( '[&?]' + name + '=([^&#]*)' ); | ||
var m = re.exec( uri ); | var m = re.exec( uri ); | ||
if ( m && m.length > 1 ) | if ( m && m.length > 1 ) return decodeURIComponent( m[ 1 ] ); | ||
return null; | return null; | ||
} | } | ||
function title( href ) { | function title( href ) { | ||
if ( !href ) | if ( !href ) return null; | ||
var script = conf.wgScript + '?'; | var script = conf.wgScript + '?'; | ||
if ( href.indexOf( script ) === 0 || href.indexOf( | if ( href.indexOf( script ) === 0 || href.indexOf( wgServer + script ) === 0 || wgServer.substring( 0, 2 ) === '//' && href.indexOf( document.location.protocol + wgServer + script ) === 0 ) { | ||
// href="/w/index.php?title=..." | // href="/w/index.php?title=..." | ||
return param( 'title', href ); | return param( 'title', href ); | ||
| خط ۴۶۶: | خط ۳۹۰: | ||
// href="/wiki/..." | // href="/wiki/..." | ||
var prefix = conf.wgArticlePath.replace( '$1', '' ); | var prefix = conf.wgArticlePath.replace( '$1', '' ); | ||
if ( href.indexOf( prefix ) | if ( href.indexOf( prefix ) ) prefix = wgServer + prefix; // Fully expanded URL? | ||
if ( href.indexOf( prefix ) && prefix.substring( 0, 2 ) === '//' ) prefix = document.location.protocol + prefix; // Protocol-relative wgServer? | |||
if ( href.indexOf( prefix ) | |||
if ( href.indexOf( prefix ) === 0 ) return decodeURIComponent( href.substring( prefix.length ) ); | |||
if ( href.indexOf( prefix ) === 0 ) | |||
} | } | ||
return null; | return null; | ||
| خط ۴۸۲: | خط ۴۰۲: | ||
} | } | ||
function capitalize( str ) { | function capitalize( str ) { | ||
if ( !str || str.length | if ( !str || !str.length ) return str; | ||
return str.substr( 0, 1 ).toUpperCase() + str.substr( 1 ); | return str.substr( 0, 1 ).toUpperCase() + str.substr( 1 ); | ||
} | } | ||
| خط ۵۱۵: | خط ۴۳۶: | ||
// Replace $1, $2, or ${key1}, ${key2}, or $key1, $key2 by values from map. $$ is replaced by a single $. | // Replace $1, $2, or ${key1}, ${key2}, or $key1, $key2 by values from map. $$ is replaced by a single $. | ||
return function ( str, map ) { | return function ( str, map ) { | ||
if ( !map ) | if ( !map ) return str; | ||
return str.replace( re, function ( match, prefix, idx, key, alpha ) { | return str.replace( re, function ( match, prefix, idx, key, alpha ) { | ||
if ( prefix === lead ) | if ( prefix === lead ) return lead; | ||
var k = alpha || key || idx; | var k = alpha || key || idx; | ||
var replacement = typeof map[ k ] === 'function' ? map[ k ]( match, k ) : map[ k ]; | var replacement = typeof map[ k ] === 'function' ? map[ k ]( match, k ) : map[ k ]; | ||
| خط ۵۲۹: | خط ۴۵۰: | ||
var substitute = substituteFactory(); | var substitute = substituteFactory(); | ||
var replaceShortcuts = ( function () { | var replaceShortcuts = ( function () { | ||
var replaceHash = substituteFactory( { indicator: '#', lbrace: '[', rbrace: ']' } ); | var replaceHash = substituteFactory( { | ||
indicator: '#', | |||
lbrace: '[', | |||
rbrace: ']' | |||
} ); | |||
return function ( str, map ) { | return function ( str, map ) { | ||
var s = replaceHash( str, map ); | var s = replaceHash( str, map ); | ||
return | return HC.capitalizePageNames ? capitalize( s ) : s; | ||
}; | }; | ||
}() ); | }() ); | ||
| خط ۵۳۹: | خط ۴۶۴: | ||
var findCatsRE = | var findCatsRE = | ||
new RegExp( '\\[\\[' + wikiTextBlankOrBidi + '(?:' + HC.category_regexp + ')' + wikiTextBlankOrBidi + ':[^\\]]+\\]\\]', 'g' ); | |||
function replaceByBlanks( match ) { | function replaceByBlanks( match ) { | ||
| خط ۵۴۷: | خط ۴۷۲: | ||
function find_category( wikitext, category, once ) { | function find_category( wikitext, category, once ) { | ||
var cat_regex = null; | var cat_regex = null; | ||
if ( | if ( HC.template_categories[ category ] ) { | ||
cat_regex = new RegExp( | cat_regex = new RegExp( | ||
'\\{\\{' + wikiTextBlankOrBidi + '(' + | '\\{\\{' + wikiTextBlankOrBidi + '(' + HC.template_regexp + '(?=' + wikiTextBlankOrBidi + ':))?' + wikiTextBlankOrBidi + | ||
'(?:' + | '(?:' + HC.template_categories[ category ] + ')' + | ||
wikiTextBlankOrBidi + '(\\|.*?)?\\}\\}', | wikiTextBlankOrBidi + '(\\|.*?)?\\}\\}', | ||
'g' | 'g' | ||
| خط ۵۵۸: | خط ۴۸۳: | ||
var initial = cat_name.substr( 0, 1 ); | var initial = cat_name.substr( 0, 1 ); | ||
cat_regex = new RegExp( | cat_regex = new RegExp( | ||
'\\[\\[' + wikiTextBlankOrBidi + '(' + | '\\[\\[' + wikiTextBlankOrBidi + '(' + HC.category_regexp + ')' + wikiTextBlankOrBidi + ':' + wikiTextBlankOrBidi + | ||
( initial === '\\' || ! | ( initial === '\\' || !HC.capitalizePageNames ? | ||
initial : | initial : | ||
'[' + initial.toUpperCase() + initial.toLowerCase() + ']' | '[' + initial.toUpperCase() + initial.toLowerCase() + ']' ) + | ||
cat_name.substring( 1 ).replace( wikiTextBlankRE, wikiTextBlank ) + | cat_name.substring( 1 ).replace( wikiTextBlankRE, wikiTextBlank ) + | ||
wikiTextBlankOrBidi + '(\\|.*?)?\\]\\]', | wikiTextBlankOrBidi + '(\\|.*?)?\\]\\]', | ||
| خط ۵۶۸: | خط ۴۹۲: | ||
); | ); | ||
} | } | ||
if ( once ) | if ( once ) return cat_regex.exec( wikitext ); | ||
var copiedtext = wikitext | var copiedtext = wikitext | ||
.replace( /<!--(\s|\S)*?-->/g, replaceByBlanks ) | .replace( /<!--(\s|\S)*?-->/g, replaceByBlanks ) | ||
| خط ۵۷۵: | خط ۵۰۰: | ||
var curr_match = null; | var curr_match = null; | ||
while ( ( curr_match = cat_regex.exec( copiedtext ) ) !== null ) { | while ( ( curr_match = cat_regex.exec( copiedtext ) ) !== null ) { | ||
result.push( { match: curr_match } ); | result.push( { | ||
match: curr_match | |||
} ); | |||
} | } | ||
result.re = cat_regex; | result.re = cat_regex; | ||
| خط ۵۹۲: | خط ۵۱۹: | ||
var index = -1; | var index = -1; | ||
findCatsRE.lastIndex = 0; | findCatsRE.lastIndex = 0; | ||
while ( findCatsRE.exec( copiedtext ) !== null ) | while ( findCatsRE.exec( copiedtext ) !== null ) index = findCatsRE.lastIndex; | ||
if ( index < 0 ) { | if ( index < 0 ) { | ||
// Find the index of the first interlanguage link... | // Find the index of the first interlanguage link... | ||
var match = null; | var match = null; | ||
if ( !interlanguageRE ) { | if ( !interlanguageRE ) { | ||
// Approximation without API: interlanguage links start with 2 to 3 lower case letters, optionally followed by | |||
// a sequence of groups consisting of a dash followed by one or more lower case letters. Exceptions are "simple" | |||
// and "tokipona". | |||
match = /((^|\n\r?)(\[\[\s*(([a-z]{2,3}(-[a-z]+)*)|simple|tokipona)\s*:[^\]]+\]\]\s*))+$/.exec( copiedtext ); | match = /((^|\n\r?)(\[\[\s*(([a-z]{2,3}(-[a-z]+)*)|simple|tokipona)\s*:[^\]]+\]\]\s*))+$/.exec( copiedtext ); | ||
} else { | } else { | ||
match = interlanguageRE.exec( copiedtext ); | match = interlanguageRE.exec( copiedtext ); | ||
} | } | ||
if ( match ) | if ( match ) index = match.index; | ||
return { idx: index, onCat: false }; | |||
return { | |||
idx: index, | |||
onCat: false | |||
}; | |||
} | } | ||
return { idx: index, onCat: index >= 0 }; | return { | ||
idx: index, | |||
onCat: index >= 0 | |||
}; | |||
} | } | ||
var summary = [] | var summary = [], | ||
nameSpace = HC.category_canonical, | |||
cat_point = -1, // Position of removed category; | |||
keyChange = ( toRemove && toAdd && toRemove === toAdd && toAdd.length ), | |||
matches; | |||
if ( key ) key = '|' + key; | |||
// Remove | |||
if ( toRemove && toRemove.length | if ( toRemove && toRemove.length ) { | ||
matches = find_category( wikitext, toRemove ); | matches = find_category( wikitext, toRemove ); | ||
if ( !matches || matches.length | if ( !matches || !matches.length ) { | ||
return { text: wikitext, summary: summary, error: | return { | ||
text: wikitext, | |||
summary: summary, | |||
error: HC.messages.cat_notFound.replace( /\$1/g, toRemove ) | |||
}; | |||
} 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 ); | |||
if ( matches.length > 1 ) { | if ( matches.length > 1 ) { | ||
// Remove all occurrences in after | |||
matches.re.lastIndex = 0; | matches.re.lastIndex = 0; | ||
after = after.replace( matches.re, '' ); | after = after.replace( matches.re, '' ); | ||
} | } | ||
if ( toAdd ) { | if ( toAdd ) { | ||
nameSpace = matches[ 0 ].match[ 1 ] || nameSpace; | // nameSpace = matches[ 0 ].match[ 1 ] || nameSpace; Canonical namespace should be always preferred | ||
if ( key === null ) | if ( key === null ) key = matches[ 0 ].match[ 2 ]; | ||
// Remember the category key, if any. | |||
} | } | ||
// Remove whitespace (properly): strip whitespace, but only up to the next line feed. | // Remove whitespace (properly): strip whitespace, but only up to the next line feed. | ||
| خط ۶۳۷: | خط ۵۷۷: | ||
// whitespace characters, insert a blank. | // whitespace characters, insert a blank. | ||
var i = before.length - 1; | var i = before.length - 1; | ||
while ( i >= 0 && before.charAt( i ) !== '\n' && before.substr( i, 1 ).search( /\s/ ) >= 0 ) | while ( i >= 0 && before.charAt( i ) !== '\n' && before.substr( i, 1 ).search( /\s/ ) >= 0 ) i--; | ||
var j = 0; | var j = 0; | ||
while ( j < after.length && after.charAt( j ) !== '\n' && after.substr( j, 1 ).search( /\s/ ) >= 0 ) | while ( j < after.length && after.charAt( j ) !== '\n' && after.substr( j, 1 ).search( /\s/ ) >= 0 ) j++; | ||
if ( i >= 0 && before.charAt( i ) === '\n' && ( after.length | |||
if ( i >= 0 ) | if ( i >= 0 && before.charAt( i ) === '\n' && ( !after.length || j < after.length && after.charAt( j ) === '\n' ) ) i--; | ||
if ( i >= 0 ) before = before.substring( 0, i + 1 ); else before = ''; | |||
if ( j < after.length ) after = after.substring( j ); else after = ''; | |||
if ( j < after.length ) | |||
if ( | if ( | ||
before.length | before.length && before.substring( before.length - 1 ).search( /\S/ ) >= 0 && | ||
after.length | after.length && after.substr( 0, 1 ).search( /\S/ ) >= 0 | ||
) { | |||
before += ' '; | before += ' '; | ||
} | } | ||
cat_point = before.length; | cat_point = before.length; | ||
if ( cat_point === 0 && after.length | if ( cat_point === 0 && after.length && after.substr( 0, 1 ) === '\n' ) after = after.substr( 1 ); | ||
wikitext = before + after; | wikitext = before + after; | ||
if ( !keyChange ) { | if ( !keyChange ) { | ||
if ( | if ( HC.template_categories[ toRemove ] ) { summary.push( HC.messages.template_removed.replace( /\$1/g, toRemove ) ); } else { summary.push( HC.messages.cat_removed.replace( /\$1/g, toRemove ) ); } | ||
} | |||
} | |||
} | } | ||
} | } | ||
if ( toAdd && toAdd.length | // Add | ||
if ( toAdd && toAdd.length ) { | |||
matches = find_category( wikitext, toAdd ); | matches = find_category( wikitext, toAdd ); | ||
if ( matches && matches.length | if ( matches && matches.length ) { | ||
return { text: wikitext, summary: summary, error: | // Already exists | ||
return { | |||
text: wikitext, | |||
summary: summary, | |||
error: HC.messages.cat_exists.replace( /\$1/g, toAdd ) | |||
}; | |||
} else { | } else { | ||
var onCat = false; | var onCat = false; | ||
| خط ۶۸۷: | خط ۶۲۸: | ||
var suffix = wikitext.substring( cat_point ); | var suffix = wikitext.substring( cat_point ); | ||
wikitext = wikitext.substring( 0, cat_point ) + ( cat_point > 0 ? '\n' : '' ) + newcatstring + ( !onCat ? '\n' : '' ); | wikitext = wikitext.substring( 0, cat_point ) + ( cat_point > 0 ? '\n' : '' ) + newcatstring + ( !onCat ? '\n' : '' ); | ||
if ( suffix.length | if ( suffix.length && suffix.substr( 0, 1 ) !== '\n' ) wikitext += '\n' + suffix; else wikitext += suffix; | ||
} else { | } else { | ||
if ( wikitext.length | if ( wikitext.length && wikitext.substr( wikitext.length - 1, 1 ) !== '\n' ) wikitext += '\n'; | ||
wikitext += ( wikitext.length ? '\n' : '' ) + newcatstring; | |||
wikitext += ( wikitext.length | |||
} | } | ||
if ( keyChange ) { | if ( keyChange ) { | ||
var k = key || ''; | var k = key || ''; | ||
if ( k.length | if ( k.length ) k = k.substr( 1 ); | ||
summary.push( substitute( | |||
summary.push( substitute( HC.messages.cat_keychange, [ null, toAdd, k ] ) ); | |||
} else { | } else { | ||
summary.push( | summary.push( HC.messages.cat_added.replace( /\$1/g, toAdd ) ); | ||
} | } | ||
if ( | if ( HC.uncat_regexp && !is_hidden ) { | ||
var txt = wikitext.replace( | var txt = wikitext.replace( HC.uncat_regexp, '' ); // Remove "uncat" templates | ||
if ( txt.length !== wikitext.length ) { | if ( txt.length !== wikitext.length ) { | ||
wikitext = txt; | wikitext = txt; | ||
summary.push( | summary.push( HC.messages.uncat_removed ); | ||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
return { text: wikitext, summary: summary, error: null }; | return { | ||
text: wikitext, | |||
summary: summary, | |||
error: null | |||
}; | |||
} | } | ||
| خط ۷۲۱: | خط ۶۶۲: | ||
function evtKeys( e ) { | function evtKeys( e ) { | ||
/* eslint-disable no-bitwise */ | /* eslint-disable no-bitwise */ | ||
var code = 0; | var code = 0; | ||
if ( | if ( e.ctrlKey ) { // All modern browsers | ||
// Ctrl-click seems to be overloaded in FF/Mac (it opens a pop-up menu), so treat cmd-click | |||
// as a ctrl-click, too. | |||
if ( e.ctrlKey || e.metaKey ) | if ( e.ctrlKey || e.metaKey ) code |= 1; | ||
if ( e.shiftKey ) | |||
if ( e.shiftKey ) code |= 2; | |||
} | } | ||
return code; | return code; | ||
} | } | ||
function evtKill( e ) { | function evtKill( e ) { | ||
if ( e.preventDefault ) { | |||
if ( | |||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
| خط ۷۴۶: | خط ۶۸۲: | ||
} | } | ||
var catLine = null | var catLine = null, | ||
onUpload = false, | |||
editors = [], | |||
commitButton = null, | |||
commitForm = null, | |||
multiSpan = null, | |||
pageText = null, | |||
pageTime = null, | |||
pageWatched = false, | |||
watchCreate = false, | |||
watchEdit = false, | |||
minorEdits = false, | |||
editToken = null, | |||
is_rtl = false, | |||
serverTime = null, | |||
lastRevId = null, | |||
pageTextRevId = null, | |||
conflictingUser = null, | |||
newDOM = false; // true if MediaWiki serves the new UL-LI DOM for categories | |||
function | function CategoryEditor() { | ||
this.initialize.apply( this, arguments ); | |||
} | } | ||
function | function setPage( json ) { | ||
if ( ! | var startTime = null; | ||
if ( json && json.query ) { | |||
if ( json.query.pages ) { | |||
var page = json.query.pages[ !conf.wgArticleId ? '-1' : String( conf.wgArticleId ) ]; | |||
if ( page ) { | |||
if ( page.revisions && page.revisions.length ) { | |||
} | // Revisions are sorted by revision ID, hence [ 0 ] is the one we asked for, and possibly there's a [ 1 ] if we're | ||
} | // not on the latest revision (edit conflicts and such). | ||
pageText = page.revisions[ 0 ][ '*' ]; | |||
if ( page.revisions[ 0 ].timestamp ) pageTime = page.revisions[ 0 ].timestamp.replace( /\D/g, '' ); | |||
if ( page.revisions[ 0 ].revid ) pageTextRevId = page.revisions[ 0 ].revid; | |||
if ( page.revisions.length > 1 ) conflictingUser = page.revisions[ 1 ].user; | |||
} | |||
if ( page.lastrevid ) lastRevId = page.lastrevid; | |||
if ( page.starttimestamp ) startTime = page.starttimestamp.replace( /\D/g, '' ); | |||
pageWatched = typeof page.watched === 'string'; | |||
if ( json.query.tokens ) editToken = json.query.tokens.csrftoken; | |||
if ( page.langlinks && ( !json[ 'query-continue' ] || !json[ 'query-continue' ].langlinks ) ) { | |||
// We have interlanguage links, and we got them all. | |||
var re = ''; | |||
for ( var i = 0; i < page.langlinks.length; i++ ) re += ( i > 0 ? '|' : '' ) + page.langlinks[ i ].lang.replace( /([\\^$.?*+()])/g, '\\$1' ); | |||
if ( re.length ) interlanguageRE = new RegExp( '((^|\\n\\r?)(\\[\\[\\s*(' + re + ')\\s*:[^\\]]+\\]\\]\\s*))+$' ); | |||
} | |||
} | |||
} | |||
// Siteinfo | |||
if ( json.query.general ) { | |||
if ( json.query.general.time && !startTime ) startTime = json.query.general.time.replace( /\D/g, '' ); | |||
if ( HC.capitalizePageNames === null ) { | |||
// ResourceLoader's JSParser doesn't like .case, so override eslint. | |||
// eslint-disable-next-line dot-notation | |||
HC.capitalizePageNames = ( json.query.general[ 'case' ] === 'first-letter' ); | |||
} | |||
} | |||
serverTime = startTime; | |||
// Userinfo | |||
if ( json.query.userinfo && json.query.userinfo.options ) { | |||
watchCreate = !HC.dont_add_to_watchlist && json.query.userinfo.options.watchcreations === '1'; | |||
watchEdit = !HC.dont_add_to_watchlist && json.query.userinfo.options.watchdefault === '1'; | |||
minorEdits = json.query.userinfo.options.minordefault === 1; | |||
// If the user has the "All edits are minor" preference enabled, we should honor that | |||
// for single category changes, no matter what the site configuration is. | |||
if ( minorEdits ) HC.single_minor = true; | |||
} | |||
} | |||
} | } | ||
var saveInProgress = false; | |||
function initiateEdit( doEdit, failure ) { | |||
if ( saveInProgress ) return; | |||
saveInProgress = true; | |||
var oldButtonState; | |||
var saveInProgress = false; | |||
function initiateEdit( doEdit, failure ) { | |||
if ( saveInProgress ) | |||
saveInProgress = true; | |||
var oldButtonState; | |||
if ( commitButton ) { | if ( commitButton ) { | ||
oldButtonState = commitButton.disabled; | oldButtonState = commitButton.disabled; | ||
| خط ۸۲۰: | خط ۷۷۱: | ||
function fail() { | function fail() { | ||
saveInProgress = false; | saveInProgress = false; | ||
if ( commitButton ) | if ( commitButton ) commitButton.disabled = oldButtonState; | ||
failure.apply( this, arguments ); | failure.apply( this, arguments ); | ||
} | } | ||
// Must use Ajax here to get the user options and the edit token. | // Must use Ajax here to get the user options and the edit token. | ||
$.getJSON( | |||
getJSON( | wgServer + conf.wgScriptPath + '/api.php?' + | ||
'format=json&action=query&rawcontinue=&titles=' + encodeURIComponent( conf.wgPageName ) + | |||
'&prop=info%7Crevisions%7Clanglinks&inprop=watched&rvprop=content%7Ctimestamp%7Cids%7Cuser&lllimit=500' + | |||
'&rvlimit=2&rvdir=newer&rvstartid=' + conf.wgCurRevisionId + '&meta=siteinfo%7Cuserinfo%7Ctokens&type=csrf&uiprop=options', | |||
function ( json ) { | |||
setPage( json ); | setPage( json ); | ||
doEdit( fail ); | doEdit( fail ); | ||
} | } | ||
).fail( function ( req ) { | |||
fail( req.status + ' ' + req.statusText ); | |||
} ); | } ); | ||
} | } | ||
function multiChangeMsg( count ) { | function multiChangeMsg( count ) { | ||
var msg = | var msg = HC.messages.multi_change; | ||
if ( typeof msg !== 'string' && msg.length ) | if ( typeof msg !== 'string' && msg.length ) | ||
if ( mw.language && mw.language.convertPlural ) { | if ( mw.language && mw.language.convertPlural ) { msg = mw.language.convertPlural( count, msg ); } else { msg = msg[ msg.length - 1 ]; } | ||
return substitute( msg, [ null, String( count ) ] ); | |||
} | |||
function currentTimestamp() { | |||
var now = new Date(); | |||
var ts = String( now.getUTCFullYear() ); | |||
function two( s ) { | |||
return s.substr( s.length - 2 ); | |||
} | } | ||
ts += | |||
two( '0' + ( now.getUTCMonth() + 1 ) ) + | |||
two( '0' + now.getUTCDate() ) + | |||
two( '00' + now.getUTCHours() ) + | |||
two( '00' + now.getUTCMinutes() ) + | |||
two( '00' + now.getUTCSeconds() ); | |||
return ts; | |||
} | } | ||
function performChanges( failure, singleEditor ) { | function performChanges( failure, singleEditor ) { | ||
if ( pageText === null ) { | if ( pageText === null ) { | ||
failure( | failure( HC.messages.multi_error ); | ||
return; | return; | ||
} | } | ||
// Backwards compatibility after message change (added $2 to cat_keychange) | // Backwards compatibility after message change (added $2 to cat_keychange) | ||
if ( | if ( HC.messages.cat_keychange.indexOf( '$2' ) < 0 ) HC.messages.cat_keychange += '"$2"'; | ||
// More backwards-compatibility with earlier HotCat versions: | // More backwards-compatibility with earlier HotCat versions: | ||
if ( ! | if ( !HC.messages.short_catchange ) HC.messages.short_catchange = '[[' + HC.category_canonical + ':$1]]'; | ||
// Create a form and submit it. We don't use the edit API (api.php?action=edit) because | // Create a form and submit it. We don't use the edit API (api.php?action=edit) because | ||
// (a) sensibly reporting back errors like edit conflicts is always a hassle, and | // (a) sensibly reporting back errors like edit conflicts is always a hassle, and | ||
| خط ۸۷۶: | خط ۸۳۷: | ||
// current user, then we set the "oldid" value and switch to diff, which gives the "you are editing an old version; | // current user, then we set the "oldid" value and switch to diff, which gives the "you are editing an old version; | ||
// if you save, any more recent changes will be lost" screen. | // if you save, any more recent changes will be lost" screen. | ||
var | var selfEditConflict = ( lastRevId !== null && lastRevId !== conf.wgCurRevisionId || pageTextRevId !== null && | ||
pageTextRevId !== conf.wgCurRevisionId ) && conflictingUser && conflictingUser === conf.wgUserName; | |||
if ( singleEditor && !singleEditor.noCommit && ! | if ( singleEditor && !singleEditor.noCommit && !HC.no_autocommit && editToken && !selfEditConflict ) { | ||
// If we do have an edit conflict, but not with ourself, that's no reason not to attempt to save: the server side may actually be able to | // If we do have an edit conflict, but not with ourself, that's no reason not to attempt to save: the server side may actually be able to | ||
// merge the changes. We just need to make sure that we do present a diff view if it's a self edit conflict. | // merge the changes. We just need to make sure that we do present a diff view if it's a self edit conflict. | ||
commitForm.wpEditToken.value = editToken; | commitForm.wpEditToken.value = editToken; | ||
action = commitForm.wpDiff; | action = commitForm.wpDiff; | ||
if ( action ) | if ( action ) action.name = action.value = 'wpSave'; | ||
} else { | } else { | ||
action = commitForm.wpSave; | action = commitForm.wpSave; | ||
if ( action ) | if ( action ) action.name = action.value = 'wpDiff'; | ||
} | } | ||
var result = { text: pageText } | var result = { | ||
text: pageText | |||
}, | |||
changed = [], | |||
added = [], | |||
deleted = [], | |||
changes = 0, | |||
toEdit = singleEditor ? [ singleEditor ] : editors, | |||
error = null, | |||
edit, | |||
i; | |||
for ( i = 0; i < toEdit.length; i++ ) { | for ( i = 0; i < toEdit.length; i++ ) { | ||
edit = toEdit[ i ]; | |||
if ( edit.state === CategoryEditor.CHANGED ) { | |||
result = change_category( | result = change_category( | ||
result.text, | result.text, | ||
edit.originalCategory, | |||
edit.currentCategory, | |||
edit.currentKey, | |||
edit.currentHidden ); | |||
if ( !result.error ) { | if ( !result.error ) { | ||
changes++; | changes++; | ||
if ( ! | if ( !edit.originalCategory || !edit.originalCategory.length ) { | ||
added.push( | added.push( edit.currentCategory ); | ||
} else { | } else { | ||
changed.push( { from: | changed.push( { | ||
from: edit.originalCategory, | |||
to: edit.currentCategory | |||
} ); | |||
} | } | ||
} else if ( error === null ) { | } else if ( error === null ) { | ||
| خط ۹۱۳: | خط ۸۸۳: | ||
} | } | ||
} else if ( | } else if ( | ||
edit.state === CategoryEditor.DELETED && edit.originalCategory && edit.originalCategory.length ) { | |||
result = change_category( | |||
result.text, | |||
edit.originalCategory, | |||
result = change_category( result.text, | null, null, false ); | ||
if ( !result.error ) { | if ( !result.error ) { | ||
changes++; | changes++; | ||
deleted.push( | deleted.push( edit.originalCategory ); | ||
} else if ( error === null ) { | } else if ( error === null ) { | ||
error = result.error; | error = result.error; | ||
| خط ۹۲۸: | خط ۸۹۸: | ||
if ( error !== null ) { // Do not commit if there were errors | if ( error !== null ) { // Do not commit if there were errors | ||
action = commitForm.wpSave; | action = commitForm.wpSave; | ||
if ( action ) | if ( action ) action.name = action.value = 'wpDiff'; | ||
} | } | ||
// Fill in the form and submit it | // Fill in the form and submit it | ||
commitForm.wpMinoredit.checked = minorEdits; | commitForm.wpMinoredit.checked = minorEdits; | ||
commitForm.wpWatchthis.checked = conf.wgArticleId | commitForm.wpWatchthis.checked = !conf.wgArticleId && watchCreate || watchEdit || pageWatched; | ||
if ( conf.wgArticleId | if ( conf.wgArticleId || !!singleEditor ) { | ||
// Prepare change-tag save | |||
if ( action && action.value === 'wpSave' ) { | |||
if ( HC.changeTag ) { | |||
commitForm.wpChangeTags.value = HC.changeTag; | |||
HC.messages.using = ''; | |||
HC.messages.prefix = ''; | |||
} | |||
} else { | |||
commitForm.wpAutoSummary.value = HC.changeTag; | |||
} | |||
if ( changes === 1 ) { | if ( changes === 1 ) { | ||
if ( result.summary && result.summary.length | if ( result.summary && result.summary.length ) commitForm.wpSummary.value = HC.messages.prefix + result.summary.join( HC.messages.separator ) + HC.messages.using; | ||
commitForm.wpMinoredit.checked = HC.single_minor || minorEdits; | |||
} else if ( changes ) { | |||
commitForm.wpMinoredit.checked = | |||
} else if ( changes | |||
var summary = []; | var summary = []; | ||
var shortSummary = []; | var shortSummary = []; | ||
// Deleted | // Deleted | ||
for ( i = 0; i < deleted.length; i++ ) | for ( i = 0; i < deleted.length; i++ ) summary.push( '−' + substitute( HC.messages.short_catchange, [ null, deleted[ i ] ] ) ); | ||
if ( deleted.length === 1 ) shortSummary.push( '−' + substitute( HC.messages.short_catchange, [ null, deleted[ 0 ] ] ) ); else if ( deleted.length ) shortSummary.push( '− ' + multiChangeMsg( deleted.length ) ); | |||
if ( deleted.length === 1 ) | |||
// Added | // Added | ||
for ( i = 0; i < added.length; i++ ) | for ( i = 0; i < added.length; i++ ) summary.push( '+' + substitute( HC.messages.short_catchange, [ null, added[ i ] ] ) ); | ||
if ( added.length === 1 ) shortSummary.push( '+' + substitute( HC.messages.short_catchange, [ null, added[ 0 ] ] ) ); else if ( added.length ) shortSummary.push( '+ ' + multiChangeMsg( added.length ) ); | |||
if ( added.length === 1 ) | |||
// Changed | // Changed | ||
var arrow = is_rtl ? '\u2190' : '\u2192'; // left and right arrows. Don't use ← and → in the code. | var arrow = is_rtl ? '\u2190' : '\u2192'; // left and right arrows. Don't use ← and → in the code. | ||
for ( i = 0; i < changed.length; i++ ) { | for ( i = 0; i < changed.length; i++ ) { | ||
if ( changed[ i ].from !== changed[ i ].to ) { | if ( changed[ i ].from !== changed[ i ].to ) { | ||
summary.push( '±' + substitute( | summary.push( | ||
'±' + substitute( HC.messages.short_catchange, [ null, changed[ i ].from ] ) + arrow + | |||
substitute( HC.messages.short_catchange, [ null, changed[ i ].to ] ) | |||
); | |||
} else { | } else { | ||
summary.push( '±' + substitute( | summary.push( '±' + substitute( HC.messages.short_catchange, [ null, changed[ i ].from ] ) ); | ||
} | } | ||
} | } | ||
if ( changed.length === 1 ) { | if ( changed.length === 1 ) { | ||
if ( changed[ 0 ].from !== changed[ 0 ].to ) { | if ( changed[ 0 ].from !== changed[ 0 ].to ) { | ||
shortSummary.push( '±' + substitute( | shortSummary.push( | ||
'±' + substitute( HC.messages.short_catchange, [ null, changed[ 0 ].from ] ) + arrow + | |||
substitute( HC.messages.short_catchange, [ null, changed[ 0 ].to ] ) | |||
); | |||
} else { | } else { | ||
shortSummary.push( '±' + substitute( | shortSummary.push( '±' + substitute( HC.messages.short_catchange, [ null, changed[ 0 ].from ] ) ); | ||
} | } | ||
} else if ( changed.length | } else if ( changed.length ) { | ||
shortSummary.push( '± ' + multiChangeMsg( changed.length ) ); | shortSummary.push( '± ' + multiChangeMsg( changed.length ) ); | ||
} | } | ||
if ( summary.length | if ( summary.length ) { | ||
summary = summary.join( | summary = summary.join( HC.messages.separator ); | ||
if ( summary.length > 200 - | if ( summary.length > 200 - HC.messages.prefix.length - HC.messages.using.length ) summary = shortSummary.join( HC.messages.separator ); | ||
commitForm.wpSummary.value = HC.messages.prefix + summary + HC.messages.using; | |||
commitForm.wpSummary.value = | |||
} | } | ||
} | } | ||
} | } | ||
commitForm.wpTextbox1.value = result.text; | commitForm.wpTextbox1.value = result.text; | ||
commitForm.wpStarttime.value = serverTime || currentTimestamp(); | commitForm.wpStarttime.value = serverTime || currentTimestamp(); | ||
commitForm.wpEdittime.value = pageTime || commitForm.wpStarttime.value; | commitForm.wpEdittime.value = pageTime || commitForm.wpStarttime.value; | ||
if ( selfEditConflict ) | if ( selfEditConflict ) commitForm.oldid.value = String( pageTextRevId || conf.wgCurRevisionId ); | ||
// Submit the form in a way that triggers onsubmit events: commitForm.submit() doesn't. | // Submit the form in a way that triggers onsubmit events: commitForm.submit() doesn't. | ||
commitForm.hcCommit.click(); | commitForm.hcCommit.click(); | ||
} | } | ||
function | function resolveOne( page, toResolve ) { | ||
var i; | var cats = page.categories, | ||
lks = page.links, | |||
is_dab = false, | |||
is_redir = typeof page.redirect === 'string', // Hard redirect? | |||
is_hidden = page.categoryinfo && typeof page.categoryinfo.hidden === 'string', | |||
is_missing = typeof page.missing === 'string', | |||
i; | |||
for ( i = 0; i < toResolve.length; i++ ) { | for ( i = 0; i < toResolve.length; i++ ) { | ||
toResolve[ i ]. | if ( i && toResolve[ i ].dabInputCleaned !== page.title.substring( page.title.indexOf( ':' ) + 1 ) ) continue; | ||
toResolve[ i ]. | // Note: the server returns in page an NFC normalized Unicode title. If our input was not NFC normalized, we may not find | ||
// any entry here. If we have only one editor to resolve (the most common case, I presume), we may simply skip the check. | |||
toResolve[ i ].currentHidden = is_hidden; | |||
toResolve[ i ].inputExists = !is_missing; | |||
toResolve[ i ].icon.src = ( is_missing ? HC.existsNo : HC.existsYes ); | |||
} | } | ||
if ( is_missing ) return; | |||
if ( !is_redir && cats && ( HC.disambig_category || HC.redir_category ) ) { | |||
for ( var c = 0; c < cats.length; c++ ) { | |||
if ( is_missing ) | |||
if ( !is_redir && cats && ( | |||
for ( var c = 0; c < cats.length; c++ ) { | |||
var cat = cats[ c ].title; | var cat = cats[ c ].title; | ||
// Strip namespace prefix | // Strip namespace prefix | ||
if ( cat ) { | if ( cat ) { | ||
cat = cat.substring( cat.indexOf( ':' ) + 1 ).replace( /_/g, ' ' ); | cat = cat.substring( cat.indexOf( ':' ) + 1 ).replace( /_/g, ' ' ); | ||
if ( cat === | if ( cat === HC.disambig_category ) { | ||
is_dab = true; break; | is_dab = true; | ||
} else if ( cat === | break; | ||
is_redir = true; break; | } else if ( cat === HC.redir_category ) { | ||
is_redir = true; | |||
break; | |||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
if ( !is_redir && !is_dab ) | if ( !is_redir && !is_dab ) return; | ||
if ( !lks || lks.length | if ( !lks || !lks.length ) return; | ||
var titles = []; | var titles = []; | ||
for ( i = 0; i < lks.length; i++ ) { | for ( i = 0; i < lks.length; i++ ) { | ||
| خط ۱٬۰۶۸: | خط ۱٬۰۱۳: | ||
lks[ i ].ns === 14 && | lks[ i ].ns === 14 && | ||
// Name not empty | // Name not empty | ||
lks[ i ].title && lks[ i ].title.length | lks[ i ].title && lks[ i ].title.length | ||
) { | ) { | ||
// Internal link to existing thingy. Extract the page name and remove the namespace. | // Internal link to existing thingy. Extract the page name and remove the namespace. | ||
| خط ۱٬۰۷۴: | خط ۱٬۰۱۹: | ||
match = match.substring( match.indexOf( ':' ) + 1 ); | match = match.substring( match.indexOf( ':' ) + 1 ); | ||
// Exclude blacklisted categories. | // Exclude blacklisted categories. | ||
if ( ! | if ( !HC.blacklist || !HC.blacklist.test( match ) ) titles.push( match ); | ||
} | } | ||
} | } | ||
if ( titles.length | if ( !titles.length ) return; | ||
for ( i = 0; i < toResolve.length; i++ ) { | for ( i = 0; i < toResolve.length; i++ ) { | ||
if ( | if ( i && toResolve[ i ].dabInputCleaned !== page.title.substring( page.title.indexOf( ':' ) + 1 ) ) continue; | ||
toResolve[ i ].inputExists = true; // Might actually be wrong if it's a redirect pointing to a non-existing category | toResolve[ i ].inputExists = true; // Might actually be wrong if it's a redirect pointing to a non-existing category | ||
toResolve[ i ].icon.src = | toResolve[ i ].icon.src = HC.existsYes; | ||
if ( titles.length > 1 ) { | if ( titles.length > 1 ) { | ||
toResolve[ i ].dab = titles; | toResolve[ i ].dab = titles; | ||
| خط ۱٬۰۹۶: | خط ۱٬۰۳۷: | ||
function resolveRedirects( toResolve, params ) { | function resolveRedirects( toResolve, params ) { | ||
if ( !params || !params.query || !params.query.pages ) | if ( !params || !params.query || !params.query.pages ) return; | ||
for ( var p in params.query.pages ) | for ( var p in params.query.pages ) resolveOne( params.query.pages[ p ], toResolve ); | ||
} | } | ||
function | function resolveMulti( toResolve, callback ) { | ||
var | var i; | ||
for ( | for ( i = 0; i < toResolve.length; i++ ) { | ||
toResolve[ i ].dab = null; | |||
toResolve[ i ].dabInput = toResolve[ i ].lastInput; | |||
} | } | ||
if ( | if ( noSuggestions ) { | ||
callback( toResolve ); | |||
return; | return; | ||
} | } | ||
// Use %7C instead of |, otherwise Konqueror insists on re-encoding the arguments, resulting in doubly encoded | |||
var | // category names. (That is a bug in Konqueror. Other browsers don't have this problem.) | ||
var args = 'action=query&prop=info%7Clinks%7Ccategories%7Ccategoryinfo&plnamespace=14' + | |||
for ( var i = 0; i < | '&pllimit=' + ( toResolve.length * 10 ) + | ||
'&cllimit=' + ( toResolve.length * 10 ) + | |||
'&format=json&titles='; | |||
for ( i = 0; i < toResolve.length; i++ ) { | |||
var v = toResolve[ i ].dabInput; | |||
v = replaceShortcuts( v, HC.shortcuts ); | |||
toResolve[ i ].dabInputCleaned = v; | |||
args += encodeURIComponent( 'Category:' + v ); | |||
if ( i + 1 < toResolve.length ) args += '%7C'; | |||
} | |||
} | $.getJSON( wgServer + conf.wgScriptPath + '/api.php?' + args, | ||
function ( json ) { | |||
resolveRedirects( toResolve, json ); | |||
callback( toResolve ); | |||
} ).fail( function ( req ) { | |||
if ( !req ) noSuggestions = true; | |||
callback( toResolve ); | |||
} ); | |||
} | |||
function makeActive( which ) { | |||
if ( which.is_active ) return; | |||
for ( var i = 0; i < editors.length; i++ ) | |||
if ( editors[ i ] !== which ) editors[ i ].inactivate(); | |||
which.is_active = true; | |||
if ( which.dab ) { | |||
// eslint-disable-next-line no-use-before-define | |||
showDab( which ); | |||
} else { | |||
// Check for programmatic value changes. | |||
var expectedInput = which.lastRealInput || which.lastInput || ''; | |||
var actualValue = which.text.value || ''; | |||
if ( !expectedInput.length && actualValue.length || expectedInput.length && actualValue.indexOf( expectedInput ) ) { | |||
// Somehow the field's value appears to have changed, and which.lastSelection therefore is no longer valid. Try to set the | |||
// cursor at the end of the category, and do not display the old suggestion list. | |||
which.showsList = false; | |||
var v = actualValue.split( '|' ); | |||
which.lastRealInput = which.lastInput = v[ 0 ]; | |||
if ( v.length > 1 ) which.currentKey = v[ 1 ]; | |||
if ( which.lastSelection ) { | |||
which.lastSelection = { | |||
start: v[ 0 ].length, | |||
end: v[ 0 ].length | |||
}; | |||
} | } | ||
} | } | ||
if ( | if ( which.showsList ) which.displayList(); | ||
if ( which.lastSelection ) { | |||
if ( is_webkit ) { | |||
// WebKit (Safari, Chrome) has problems selecting inside focus() | |||
// See http://code.google.com/p/chromium/issues/detail?id=32865#c6 | |||
window.setTimeout( | |||
function () { | |||
which.setSelection( which.lastSelection.start, which.lastSelection.end ); | |||
if ( | }, | ||
1 ); | |||
} else { | |||
which.setSelection( which.lastSelection.start, which.lastSelection.end ); | |||
} | } | ||
} | } | ||
} | } | ||
} | |||
function showDab( which ) { | |||
if ( !which.is_active ) { | |||
makeActive( which ); | |||
} else { | |||
which.showSuggestions( which.dab, false, null, null ); // do autocompletion, no key, no engine selector | |||
which.dab = null; | |||
} | |||
} | |||
function multiSubmit() { | |||
var toResolve = []; | |||
for ( var i = 0; i < editors.length; i++ ) | |||
if ( editors[ i ].state === CategoryEditor.CHANGE_PENDING || editors[ i ].state === CategoryEditor.OPEN ) toResolve.push( editors[ i ] ); | |||
if ( !toResolve.length ) { | |||
initiateEdit( function ( failure ) { | |||
performChanges( failure ); | |||
}, function ( msg ) { | |||
alert( msg ); | |||
} ); | |||
return; | |||
} | |||
resolveMulti( toResolve, function ( resolved ) { | |||
var firstDab = null; | |||
var dontChange = false; | |||
for ( var i = 0; i < resolved.length; i++ ) { | |||
if ( resolved[ i ].lastInput !== resolved[ i ].dabInput ) { | |||
// We didn't disable all the open editors, but we did asynchronous calls. It is | |||
// theoretically possible that the user changed something... | |||
dontChange = true; | |||
} else { | |||
if ( resolved[ i ].dab ) { | |||
if ( !firstDab ) firstDab = resolved[ i ]; | |||
} else { | |||
if ( resolved[ i ].acceptCheck( true ) ) resolved[ i ].commit(); | |||
} | } | ||
} | } | ||
} | } | ||
if ( firstDab ) { | |||
showDab( firstDab ); | |||
} else if ( !dontChange ) { | |||
initiateEdit( function ( failure ) { | |||
if ( | performChanges( failure ); | ||
}, function ( msg ) { | |||
alert( msg ); | |||
} ); | |||
} | |||
} | } | ||
}, | } ); | ||
} | |||
uri: '/api.php?format=json&action= | |||
handler: function ( queryResult ) { | function setMultiInput() { | ||
if ( queryResult && queryResult. | if ( commitButton || onUpload ) return; | ||
var titles = queryResult. | commitButton = make( 'input' ); | ||
commitButton.type = 'button'; | |||
commitButton.value = HC.messages.commit; | |||
commitButton.onclick = multiSubmit; | |||
if ( multiSpan ) multiSpan.parentNode.replaceChild( commitButton, multiSpan ); else catLine.appendChild( commitButton ); | |||
} | |||
function checkMultiInput() { | |||
if ( !commitButton ) return; | |||
var hasChanges = false; | |||
for ( var i = 0; i < editors.length; i++ ) { | |||
if ( editors[ i ].state !== CategoryEditor.UNCHANGED ) { | |||
hasChanges = true; | |||
break; | |||
} | |||
} | |||
commitButton.disabled = !hasChanges; | |||
} | |||
var suggestionEngines = { | |||
opensearch: { | |||
uri: '/api.php?format=json&action=opensearch&namespace=14&limit=30&search=Category:$1', // $1 = search term | |||
// Function to convert result of uri into an array of category names | |||
handler: function ( queryResult, queryKey ) { | |||
if ( queryResult && queryResult.length >= 2 ) { | |||
var key = queryResult[ 0 ].substring( queryResult[ 0 ].indexOf( ':' ) + 1 ); | |||
var titles = queryResult[ 1 ]; | |||
var exists = false; | |||
if ( !cat_prefix ) cat_prefix = new RegExp( '^(' + HC.category_regexp + '):' ); | |||
for ( var i = 0; i < titles.length; i++ ) { | for ( var i = 0; i < titles.length; i++ ) { | ||
titles[ i ] = titles[ i ] | cat_prefix.lastIndex = 0; | ||
var m = cat_prefix.exec( titles[ i ] ); | |||
if ( m && m.length > 1 ) { | |||
titles[ i ] = titles[ i ].substring( titles[ i ].indexOf( ':' ) + 1 ); // rm namespace | |||
if ( key === titles[ i ] ) exists = true; | |||
} else { | |||
titles.splice( i, 1 ); // Nope, it's not a category after all. | |||
i--; | |||
} | |||
} | } | ||
titles.exists = exists; | |||
if ( queryKey !== key ) titles.normalized = key; | |||
// Remember the NFC normalized key we got back from the server | |||
return titles; | return titles; | ||
} | } | ||
| خط ۱٬۲۰۸: | خط ۱٬۲۲۱: | ||
} | } | ||
}, | }, | ||
internalsearch: { | |||
uri: '/api.php?format=json&action=query& | uri: '/api.php?format=json&action=query&list=allpages&apnamespace=14&aplimit=30&apfrom=$1&apprefix=$1', | ||
handler: function ( queryResult ) { | handler: function ( queryResult ) { | ||
if ( queryResult && queryResult.query && queryResult.query.pages ) { | if ( queryResult && queryResult.query && queryResult.query.allpages ) { | ||
var titles = queryResult.query.allpages; | |||
for ( var i = 0; i < titles.length; i++ ) titles[ i ] = titles[ i ].title.substring( titles[ i ].title.indexOf( ':' ) + 1 ); // rm namespace | |||
return titles; | |||
} | |||
return null; | |||
} | |||
}, | |||
exists: { | |||
uri: '/api.php?format=json&action=query&prop=info&titles=Category:$1', | |||
handler: function ( queryResult, queryKey ) { | |||
if ( queryResult && queryResult.query && queryResult.query.pages && !queryResult.query.pages[ -1 ] ) { | |||
// Should have exactly 1 | |||
for ( var p in queryResult.query.pages ) { | for ( var p in queryResult.query.pages ) { | ||
var title = queryResult.query.pages[ p ].title; | |||
title = title.substring( title.indexOf( ':' ) + 1 ); | |||
var titles = [ title ]; | |||
titles.exists = true; | |||
if ( queryKey !== title ) titles.normalized = title; | |||
// NFC | |||
return titles; | |||
} | } | ||
} | } | ||
return null; | return null; | ||
} | } | ||
} | }, | ||
subcategories: { | |||
uri: '/api.php?format=json&action=query&list=categorymembers&cmtype=subcat&cmlimit=max&cmtitle=Category:$1', | |||
handler: function ( queryResult ) { | |||
if ( queryResult && queryResult.query && queryResult.query.categorymembers ) { | |||
var titles = queryResult.query.categorymembers; | |||
for ( var i = 0; i < titles.length; i++ ) titles[ i ] = titles[ i ].title.substring( titles[ i ].title.indexOf( ':' ) + 1 ); // rm namespace | |||
return titles; | |||
} | |||
return null; | |||
} | |||
}, | |||
parentcategories: { | |||
uri: '/api.php?format=json&action=query&prop=categories&titles=Category:$1&cllimit=max', | |||
handler: function ( queryResult ) { | |||
if ( queryResult && queryResult.query && queryResult.query.pages ) { | |||
for ( var p in queryResult.query.pages ) { | |||
if ( queryResult.query.pages[ p ].categories ) { | |||
var titles = queryResult.query.pages[ p ].categories; | |||
for ( var i = 0; i < titles.length; i++ ) titles[ i ] = titles[ i ].title.substring( titles[ i ].title.indexOf( ':' ) + 1 ); // rm namespace | |||
return titles; | |||
} | |||
} | |||
} | |||
return null; | |||
} | |||
} | |||
}; | }; | ||
var suggestionConfigs = { | var suggestionConfigs = { | ||
searchindex: { name: 'Search index', engines: [ 'opensearch' ], cache: {}, show: true, temp: false, noCompletion: false }, | searchindex: { | ||
pagelist: { name: 'Page list', engines: [ 'internalsearch', 'exists' ], cache: {}, show: true, temp: false, noCompletion: false }, | name: 'Search index', | ||
combined: { name: 'Combined search', engines: [ 'opensearch', 'internalsearch' ], cache: {}, show: true, temp: false, noCompletion: false }, | engines: [ 'opensearch' ], | ||
subcat: { name: 'Subcategories', engines: [ 'subcategories' ], cache: {}, show: true, temp: true, noCompletion: true }, | cache: {}, | ||
parentcat: { name: 'Parent categories', engines: [ 'parentcategories' ], cache: {}, show: true, temp: true, noCompletion: true } | show: true, | ||
temp: false, | |||
noCompletion: false | |||
}, | |||
pagelist: { | |||
name: 'Page list', | |||
engines: [ 'internalsearch', 'exists' ], | |||
cache: {}, | |||
show: true, | |||
temp: false, | |||
noCompletion: false | |||
}, | |||
combined: { | |||
name: 'Combined search', | |||
engines: [ 'opensearch', 'internalsearch' ], | |||
cache: {}, | |||
show: true, | |||
temp: false, | |||
noCompletion: false | |||
}, | |||
subcat: { | |||
name: 'Subcategories', | |||
engines: [ 'subcategories' ], | |||
cache: {}, | |||
show: true, | |||
temp: true, | |||
noCompletion: true | |||
}, | |||
parentcat: { | |||
name: 'Parent categories', | |||
engines: [ 'parentcategories' ], | |||
cache: {}, | |||
show: true, | |||
temp: true, | |||
noCompletion: true | |||
} | |||
}; | }; | ||
CategoryEditor.UNCHANGED = 0; | CategoryEditor.UNCHANGED = 0; | ||
CategoryEditor.OPEN = 1; // Open, but no input yet | CategoryEditor.OPEN = 1; // Open, but no input yet | ||
| خط ۱٬۲۴۲: | خط ۱٬۳۳۰: | ||
CategoryEditor.DELETED = 4; | CategoryEditor.DELETED = 4; | ||
// Support: IE6 | |||
// IE6 sometimes forgets to redraw the list when editors are opened or closed. | // IE6 sometimes forgets to redraw the list when editors are opened or closed. | ||
// Adding/removing a dummy element helps, at least when opening editors. | // Adding/removing a dummy element helps, at least when opening editors. | ||
| خط ۱٬۲۴۷: | خط ۱٬۳۳۶: | ||
function forceRedraw() { | function forceRedraw() { | ||
if ( dummyElement.parentNode ) | if ( dummyElement.parentNode ) document.body.removeChild( dummyElement ); else document.body.appendChild( dummyElement ); | ||
} | |||
} | |||
// Event keyCodes that we handle in the text input field/suggestion list. | // Event keyCodes that we handle in the text input field/suggestion list. | ||
var BS = 8, TAB = 9, RET = 13, ESC = 27, SPACE = 32, PGUP = 33, PGDOWN = 34, UP = 38, DOWN = 40, DEL = 46, IME = 229; | var BS = 8, | ||
TAB = 9, | |||
RET = 13, | |||
ESC = 27, | |||
SPACE = 32, | |||
PGUP = 33, | |||
PGDOWN = 34, | |||
UP = 38, | |||
DOWN = 40, | |||
DEL = 46, | |||
IME = 229; | |||
CategoryEditor.prototype = { | |||
CategoryEditor.prototype = { | |||
initialize: function ( line, span, after, key, is_hidden ) { | initialize: function ( line, span, after, key, is_hidden ) { | ||
| خط ۱٬۳۲۳: | خط ۱٬۳۷۲: | ||
after.parentNode.insertBefore( span, after.nextSibling ); | after.parentNode.insertBefore( span, after.nextSibling ); | ||
after = after.nextSibling; | after = after.nextSibling; | ||
} else { | } else if (line) { | ||
line.appendChild( span ); | line.appendChild( span ); | ||
} | } | ||
} else if ( line.firstChild ) { | } else if ( line && line.firstChild ) { | ||
span.appendChild( make( ' ', true ) ); | span.appendChild( make( ' ', true ) ); | ||
line.appendChild( span ); | line.appendChild( span ); | ||
| خط ۱٬۳۳۳: | خط ۱٬۳۸۲: | ||
this.linkSpan = make( 'span' ); | this.linkSpan = make( 'span' ); | ||
this.linkSpan.className = 'noprint nopopups hotcatlink'; | this.linkSpan.className = 'noprint nopopups hotcatlink'; | ||
var lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.open.bind( this ); | var lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.open.bind( this ); | |||
lk.appendChild( make( HC.links.add, true ) ); | |||
lk.title = HC.tooltips.add; | |||
this.linkSpan.appendChild( lk ); | this.linkSpan.appendChild( lk ); | ||
span = make( newDOM ? 'li' : 'span' ); | span = make( newDOM ? 'li' : 'span' ); | ||
span.className = 'noprint'; | span.className = 'noprint'; | ||
if ( is_rtl ) | if ( is_rtl ) span.dir = 'rtl'; | ||
span.appendChild( this.linkSpan ); | span.appendChild( this.linkSpan ); | ||
if ( after ) { | if ( after ) { | ||
after.parentNode.insertBefore( span, after.nextSibling ); | after.parentNode.insertBefore( span, after.nextSibling ); | ||
} else { | } else if ( line ) { | ||
line.appendChild( span ); | line.appendChild( span ); | ||
} | } | ||
this.normalLinks = null; | this.normalLinks = null; | ||
this.undelLink = null; | this.undelLink = null; | ||
this.catLink = null; | this.catLink = null; | ||
} else { | } else { | ||
if ( is_rtl ) | if ( is_rtl ) span.dir = 'rtl'; | ||
this.isAddCategory = false; | this.isAddCategory = false; | ||
this.catLink = span.firstChild; | this.catLink = span.firstChild; | ||
| خط ۱٬۳۵۷: | خط ۱٬۴۱۲: | ||
// Create change and del links | // Create change and del links | ||
this.makeLinkSpan(); | this.makeLinkSpan(); | ||
if ( !this.originalExists && this.upDownLinks ) | if ( !this.originalExists && this.upDownLinks ) this.upDownLinks.style.display = 'none'; | ||
span.appendChild( this.linkSpan ); | span.appendChild( this.linkSpan ); | ||
} | } | ||
this.originalHidden = is_hidden; | this.originalHidden = is_hidden; | ||
this.line = line; | this.line = line; | ||
this.engine = | this.engine = HC.suggestions; | ||
this.span = span; | this.span = span; | ||
this.currentCategory = this.originalCategory; | this.currentCategory = this.originalCategory; | ||
| خط ۱٬۳۷۴: | خط ۱٬۴۳۰: | ||
this.lastSavedExists = this.originalExists; | this.lastSavedExists = this.originalExists; | ||
this.lastSavedHidden = this.originalHidden; | this.lastSavedHidden = this.originalHidden; | ||
if ( this.catLink && this.currentKey ) | if ( this.catLink && this.currentKey ) this.catLink.title = this.currentKey; | ||
editors[ editors.length ] = this; | editors[ editors.length ] = this; | ||
}, | }, | ||
| خط ۱٬۳۸۳: | خط ۱٬۴۳۸: | ||
this.normalLinks = make( 'span' ); | this.normalLinks = make( 'span' ); | ||
var lk = null; | var lk = null; | ||
if ( this.originalCategory && this.originalCategory.length | if ( this.originalCategory && this.originalCategory.length ) { | ||
lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.remove.bind( this ); | lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.remove.bind( this ); | |||
lk.appendChild( make( HC.links.remove, true ) ); | |||
lk.title = HC.tooltips.remove; | |||
this.normalLinks.appendChild( make( ' ', true ) ); | this.normalLinks.appendChild( make( ' ', true ) ); | ||
this.normalLinks.appendChild( lk ); | this.normalLinks.appendChild( lk ); | ||
} | } | ||
if ( ! | if ( !HC.template_categories[ this.originalCategory ] ) { | ||
lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.open.bind( this ); | lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.open.bind( this ); | |||
lk.appendChild( make( HC.links.change, true ) ); | |||
lk.title = HC.tooltips.change; | |||
this.normalLinks.appendChild( make( ' ', true ) ); | this.normalLinks.appendChild( make( ' ', true ) ); | ||
this.normalLinks.appendChild( lk ); | this.normalLinks.appendChild( lk ); | ||
if ( !noSuggestions && | if ( !noSuggestions && HC.use_up_down ) { | ||
this.upDownLinks = make( 'span' ); | this.upDownLinks = make( 'span' ); | ||
lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.down.bind( this ); | lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.down.bind( this ); | |||
lk.appendChild( make( HC.links.down, true ) ); | |||
lk.title = HC.tooltips.down; | |||
this.upDownLinks.appendChild( make( ' ', true ) ); | this.upDownLinks.appendChild( make( ' ', true ) ); | ||
this.upDownLinks.appendChild( lk ); | this.upDownLinks.appendChild( lk ); | ||
lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.up.bind( this ); | lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.up.bind( this ); | |||
lk.appendChild( make( HC.links.up, true ) ); | |||
lk.title = HC.tooltips.up; | |||
this.upDownLinks.appendChild( make( ' ', true ) ); | this.upDownLinks.appendChild( make( ' ', true ) ); | ||
this.upDownLinks.appendChild( lk ); | this.upDownLinks.appendChild( lk ); | ||
| خط ۱٬۴۱۳: | خط ۱٬۴۸۰: | ||
this.undelLink.className = 'nopopups hotcatlink'; | this.undelLink.className = 'nopopups hotcatlink'; | ||
this.undelLink.style.display = 'none'; | this.undelLink.style.display = 'none'; | ||
lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.restore.bind( this ); | lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.restore.bind( this ); | |||
lk.appendChild( make( HC.links.restore, true ) ); | |||
lk.title = HC.tooltips.restore; | |||
this.undelLink.appendChild( make( ' ', true ) ); | this.undelLink.appendChild( make( ' ', true ) ); | ||
this.undelLink.appendChild( lk ); | this.undelLink.appendChild( lk ); | ||
| خط ۱٬۴۲۱: | خط ۱٬۴۹۱: | ||
invokeSuggestions: function ( dont_autocomplete ) { | invokeSuggestions: function ( dont_autocomplete ) { | ||
if ( this.engine && suggestionConfigs[ this.engine ] && suggestionConfigs[ this.engine ].temp && !dont_autocomplete ) | if ( this.engine && suggestionConfigs[ this.engine ] && suggestionConfigs[ this.engine ].temp && !dont_autocomplete ) this.engine = HC.suggestions; // Reset to a search upon input | ||
this.state = CategoryEditor.CHANGE_PENDING; | this.state = CategoryEditor.CHANGE_PENDING; | ||
var self = this; | var self = this; | ||
window.setTimeout( function () { self.textchange( dont_autocomplete ); }, | window.setTimeout( function () { | ||
self.textchange( dont_autocomplete ); | |||
}, HC.suggest_delay ); | |||
}, | }, | ||
makeForm: function () { | makeForm: function () { | ||
var form = make( 'form' ); | var form = make( 'form' ); | ||
form.method = 'POST'; form.onsubmit = this.accept.bind( this ); | form.method = 'POST'; | ||
form.onsubmit = this.accept.bind( this ); | |||
this.form = form; | this.form = form; | ||
var self = this; | var self = this; | ||
var text = make( 'input' ); text.type = 'text'; text.size = | var text = make( 'input' ); | ||
text.type = 'text'; | |||
text.size = HC.editbox_width; | |||
if ( !noSuggestions ) { | if ( !noSuggestions ) { | ||
// Be careful here to handle IME input. This is browser/OS/IME dependent, but basically there are two mechanisms: | // Be careful here to handle IME input. This is browser/OS/IME dependent, but basically there are two mechanisms: | ||
| خط ۱٬۴۴۵: | خط ۱٬۵۱۹: | ||
// - Older browsers signal composition by keyDown === IME for the first and subsequent keys for a composition. The | // - Older browsers signal composition by keyDown === IME for the first and subsequent keys for a composition. The | ||
// first keyDown !== IME is certainly after the end of the composition. Typically, composition end can also be | // first keyDown !== IME is certainly after the end of the composition. Typically, composition end can also be | ||
// detected by a keyDown IME with a keyUp of space, tab, escape, or return. | // detected by a keyDown IME with a keyUp of space, tab, escape, or return. | ||
text.onkeyup = | text.onkeyup = function ( evt ) { | ||
var key = evt.keyCode || 0; | |||
if ( self.ime && self.lastKey === IME && !self.usesComposition && ( key === TAB || key === RET || key === ESC || key === SPACE ) ) self.ime = false; | |||
if ( self.ime ) return true; | |||
if ( key === UP || key === DOWN || key === PGUP || key === PGDOWN ) { | |||
// In case a browser doesn't generate keypress events for arrow keys... | |||
if ( self.keyCount === 0 ) return self.processKey( evt ); | |||
} else { | |||
if ( key === ESC && self.lastKey !== IME ) { | |||
if ( !self.resetKeySelection() ) { | |||
// No undo of key selection: treat ESC as "cancel". | |||
self.cancel(); | |||
return; | |||
} | } | ||
} | } | ||
return true; | // Also do this for ESC as a workaround for Firefox bug 524360 | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=524360 | |||
text.onkeydown = | self.invokeSuggestions( key === BS || key === DEL || key === ESC ); | ||
} | |||
return true; | |||
}; | |||
text.onkeydown = function ( evt ) { | |||
var key = evt.keyCode || 0; | |||
self.lastKey = key; | |||
self.keyCount = 0; | |||
// DOM Level < 3 IME input | |||
if ( !self.ime && key === IME && !self.usesComposition ) { | |||
// self.usesComposition catches browsers that may emit spurious keydown IME after a composition has ended | |||
self.ime = true; | |||
} else if ( self.ime && key !== IME && !( key >= 16 && key <= 20 || key >= 91 && key <= 93 || key === 144 ) ) { | |||
// Ignore control keys: ctrl, shift, alt, alt gr, caps lock, windows/apple cmd keys, num lock. Only the windows keys | |||
// terminate IME (apple cmd doesn't), but they also cause a blur, so it's OK to ignore them here. | |||
// Note: Safari 4 (530.17) propagates ESC out of an IME composition (observed at least on Win XP). | |||
self.ime = false; | |||
} | |||
if ( self.ime ) return true; | |||
// Handle return explicitly, to override the default form submission to be able to check for ctrl | |||
if ( key === RET ) return self.accept( evt ); | |||
// Inhibit default behavior of ESC (revert to last real input in FF: we do that ourselves) | |||
return ( key === ESC ) ? evtKill( evt ) : true; | |||
}; | |||
// And handle continued pressing of arrow keys | // And handle continued pressing of arrow keys | ||
text.onkeypress = function ( evt ) { self.keyCount++; return self.processKey( evt ); }; | text.onkeypress = function ( evt ) { | ||
$( text ).on( 'focus', function () { makeActive( self ); } ); | self.keyCount++; | ||
return self.processKey( evt ); | |||
}; | |||
$( text ).on( 'focus', function () { | |||
makeActive( self ); | |||
} ); | |||
// On IE, blur events are asynchronous, and may thus arrive after the element has lost the focus. Since IE | // On IE, blur events are asynchronous, and may thus arrive after the element has lost the focus. Since IE | ||
// can get the selection only while the element is active (has the focus), we may not always get the selection. | // can get the selection only while the element is active (has the focus), we may not always get the selection. | ||
// Therefore, use an IE-specific synchronous event on IE... | // Therefore, use an IE-specific synchronous event on IE... | ||
// Don't test for text.selectionStart being defined; | // Don't test for text.selectionStart being defined; | ||
$( text ).on( | $( text ).on( | ||
( | ( text.onbeforedeactivate !== undefined && text.createTextRange ) ? 'beforedeactivate' : 'blur', | ||
this.saveView.bind( this ) ); | |||
// DOM Level 3 IME handling | // DOM Level 3 IME handling | ||
try { | try { | ||
// Setting lastKey = IME provides a fake keyDown for Gecko's single keyUp after a cmposition. If we didn't do this, | // Setting lastKey = IME provides a fake keyDown for Gecko's single keyUp after a cmposition. If we didn't do this, | ||
// cancelling a composition via ESC would also cancel and close the whole category input editor. | // cancelling a composition via ESC would also cancel and close the whole category input editor. | ||
$( text ).on( 'compositionstart', function () { self.lastKey = IME; self.usesComposition = true; self.ime = true; } ); | $( text ).on( 'compositionstart', function () { | ||
$( text ).on( 'compositionend', function () { self.lastKey = IME; self.usesComposition = true; self.ime = false; } ); | self.lastKey = IME; | ||
$( text ).on( 'textInput', function () { self.ime = false; self.invokeSuggestions( false ); } ); | self.usesComposition = true; | ||
self.ime = true; | |||
} ); | |||
$( text ).on( 'compositionend', function () { | |||
self.lastKey = IME; | |||
self.usesComposition = true; | |||
self.ime = false; | |||
} ); | |||
$( text ).on( 'textInput', function () { | |||
self.ime = false; | |||
self.invokeSuggestions( false ); | |||
} ); | |||
} catch ( any ) { | } catch ( any ) { | ||
// Just in case some browsers might produce exceptions with these DOM Level 3 events | // Just in case some browsers might produce exceptions with these DOM Level 3 events | ||
} | } | ||
$( text ).on( 'blur', function () { self.usesComposition = false; self.ime = false; } ); | $( text ).on( 'blur', function () { | ||
self.usesComposition = false; | |||
self.ime = false; | |||
} ); | |||
} | } | ||
this.text = text; | this.text = text; | ||
| خط ۱٬۵۲۲: | خط ۱٬۶۱۳: | ||
if ( !noSuggestions ) { | if ( !noSuggestions ) { | ||
list = make( 'select' ); | list = make( 'select' ); | ||
list.onclick = function () { if ( self.highlightSuggestion( 0 ) ) | list.onclick = function () { | ||
list.ondblclick = function ( e ) { if ( self.highlightSuggestion( 0 ) ) | if ( self.highlightSuggestion( 0 ) ) self.textchange( false, true ); | ||
list.onchange = function () { self.highlightSuggestion( 0 ); self.text.focus(); }; | }; | ||
list.ondblclick = function ( e ) { | |||
if ( self.highlightSuggestion( 0 ) ) self.accept( e ); | |||
}; | |||
list.onchange = function () { | |||
self.highlightSuggestion( 0 ); | |||
self.text.focus(); | |||
}; | |||
list.onkeyup = function ( evt ) { | list.onkeyup = function ( evt ) { | ||
if ( evt.keyCode === ESC ) { | if ( evt.keyCode === ESC ) { | ||
self.resetKeySelection(); | self.resetKeySelection(); | ||
self.text.focus(); | self.text.focus(); | ||
window.setTimeout( function () { self.textchange( true ); }, | window.setTimeout( function () { | ||
self.textchange( true ); | |||
}, HC.suggest_delay ); | |||
} else if ( evt.keyCode === RET ) { | } else if ( evt.keyCode === RET ) { | ||
self.accept( evt ); | self.accept( evt ); | ||
} | } | ||
}; | }; | ||
if ( ! | if ( !HC.fixed_search ) { | ||
var engineSelector = make( 'select' ); | var engineSelector = make( 'select' ); | ||
for ( var key in suggestionConfigs ) { | for ( var key in suggestionConfigs ) { | ||
| خط ۱٬۵۴۱: | خط ۱٬۶۴۰: | ||
var opt = make( 'option' ); | var opt = make( 'option' ); | ||
opt.value = key; | opt.value = key; | ||
if ( key === this.engine ) | if ( key === this.engine ) opt.selected = true; | ||
opt.appendChild( make( suggestionConfigs[ key ].name, true ) ); | opt.appendChild( make( suggestionConfigs[ key ].name, true ) ); | ||
engineSelector.appendChild( opt ); | engineSelector.appendChild( opt ); | ||
| خط ۱٬۵۶۰: | خط ۱٬۶۶۰: | ||
if ( | if ( | ||
onUpload && | onUpload && | ||
window.UFUI !== undefined && | |||
window.UIElements !== undefined && | |||
UFUI.getLabel instanceof Function | |||
) { | ) { | ||
try { | try { | ||
label = UFUI.getLabel( id, true ); | label = UFUI.getLabel( id, true ); | ||
// Extract the plain text. IE doesn't know that Node.TEXT_NODE === 3 | // Extract the plain text. IE doesn't know that Node.TEXT_NODE === 3 | ||
while ( label && label.nodeType !== 3 ) | while ( label && label.nodeType !== 3 ) label = label.firstChild; | ||
} catch ( ex ) { | } catch ( ex ) { | ||
label = null; | label = null; | ||
} | } | ||
} | } | ||
if ( !label || !label.data ) | if ( !label || !label.data ) return defaultText; | ||
return label.data; | return label.data; | ||
} | } | ||
// Do not use type 'submit'; we cannot detect modifier keys if we do | // Do not use type 'submit'; we cannot detect modifier keys if we do | ||
var OK = make( 'input' ); OK.type = 'button'; | var OK = make( 'input' ); | ||
OK.value = button_label( 'wpOkUploadLbl', | OK.type = 'button'; | ||
OK.value = button_label( 'wpOkUploadLbl', HC.messages.ok ); | |||
OK.onclick = this.accept.bind( this ); | OK.onclick = this.accept.bind( this ); | ||
this.ok = OK; | this.ok = OK; | ||
var cancel = make( 'input' ); cancel.type = 'button'; | var cancel = make( 'input' ); | ||
cancel.value = button_label( 'wpCancelUploadLbl', | cancel.type = 'button'; | ||
cancel.value = button_label( 'wpCancelUploadLbl', HC.messages.cancel ); | |||
cancel.onclick = this.cancel.bind( this ); | cancel.onclick = this.cancel.bind( this ); | ||
this.cancelButton = cancel; | this.cancelButton = cancel; | ||
| خط ۱٬۵۹۰: | خط ۱٬۶۹۳: | ||
span.className = 'hotcatinput'; | span.className = 'hotcatinput'; | ||
span.style.position = 'relative'; | span.style.position = 'relative'; | ||
span.appendChild( text ); | span.appendChild( text ); | ||
// IE8/ | // Support: IE8, IE9 | ||
// | // Put some text into this span (a0 is nbsp) and make sure it always stays on the same | ||
// line as the input field, otherwise, IE8/9 miscalculates the height of the span and | |||
// then the engine selector may overlap the input field. | // then the engine selector may overlap the input field. | ||
span.appendChild( make( '\xa0', true ) ); | span.appendChild( make( '\xa0', true ) ); | ||
span.style.whiteSpace = 'nowrap'; | span.style.whiteSpace = 'nowrap'; | ||
if ( list ) | if ( list ) span.appendChild( list ); | ||
if ( this.engineSelector ) | |||
if ( !noSuggestions ) | if ( this.engineSelector ) span.appendChild( this.engineSelector ); | ||
if ( !noSuggestions ) span.appendChild( this.icon ); | |||
span.appendChild( OK ); | span.appendChild( OK ); | ||
span.appendChild( cancel ); | span.appendChild( cancel ); | ||
| خط ۱٬۶۱۲: | خط ۱٬۷۱۶: | ||
display: function ( evt ) { | display: function ( evt ) { | ||
if ( this.isAddCategory && !onUpload ) { | if ( this.isAddCategory && !onUpload && this.line ) { | ||
// eslint-disable-next-line no-new | // eslint-disable-next-line no-new | ||
new CategoryEditor( this.line, null, this.span, true ); // Create a new one | new CategoryEditor( this.line, null, this.span, true ); // Create a new one | ||
| خط ۱٬۶۲۴: | خط ۱٬۷۲۸: | ||
} | } | ||
} | } | ||
if ( !this.form ) | if ( !this.form ) this.makeForm(); | ||
if ( this.list ) this.list.style.display = 'none'; | |||
if ( this.list ) | |||
if ( this.engineSelector ) | if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | ||
this.currentCategory = this.lastSavedCategory; | this.currentCategory = this.lastSavedCategory; | ||
this.currentExists = this.lastSavedExists; | this.currentExists = this.lastSavedExists; | ||
this.currentHidden = this.lastSavedHidden; | this.currentHidden = this.lastSavedHidden; | ||
this.currentKey = this.lastSavedKey; | this.currentKey = this.lastSavedKey; | ||
this.icon.src = | this.icon.src = ( this.currentExists ? HC.existsYes : HC.existsNo ); | ||
this.text.value = this.currentCategory + ( this.currentKey !== null ? '|' + this.currentKey : '' ); | this.text.value = this.currentCategory + ( this.currentKey !== null ? '|' + this.currentKey : '' ); | ||
this.originalState = this.state; | this.originalState = this.state; | ||
| خط ۱٬۶۳۹: | خط ۱٬۷۴۴: | ||
this.inputExists = this.currentExists; | this.inputExists = this.currentExists; | ||
this.state = this.state === CategoryEditor.UNCHANGED ? CategoryEditor.OPEN : CategoryEditor.CHANGE_PENDING; | this.state = this.state === CategoryEditor.UNCHANGED ? CategoryEditor.OPEN : CategoryEditor.CHANGE_PENDING; | ||
this.lastSelection = { start: this.currentCategory.length, end: this.currentCategory.length }; | this.lastSelection = { | ||
start: this.currentCategory.length, | |||
end: this.currentCategory.length | |||
}; | |||
this.showsList = false; | this.showsList = false; | ||
// Display the form | // Display the form | ||
if ( this.catLink ) | if ( this.catLink ) this.catLink.style.display = 'none'; | ||
this.linkSpan.style.display = 'none'; | this.linkSpan.style.display = 'none'; | ||
this.form.style.display = 'inline'; | this.form.style.display = 'inline'; | ||
| خط ۱٬۶۵۷: | خط ۱٬۷۶۶: | ||
var result = this.display( evt ); | var result = this.display( evt ); | ||
var v = this.lastSavedCategory; | var v = this.lastSavedCategory; | ||
if ( v.length | if ( !v.length ) return result; | ||
this.text.readOnly = !!readOnly; | this.text.readOnly = !!readOnly; | ||
this.engine = engine; | this.engine = engine; | ||
| خط ۱٬۶۶۶: | خط ۱٬۷۷۶: | ||
open: function ( evt ) { | open: function ( evt ) { | ||
return this.show( evt, ( this.engine && suggestionConfigs[ this.engine ].temp ) ? | return this.show( evt, ( this.engine && suggestionConfigs[ this.engine ].temp ) ? HC.suggestions : this.engine ); | ||
}, | }, | ||
| خط ۱٬۶۸۵: | خط ۱٬۷۹۵: | ||
this.inactivate(); | this.inactivate(); | ||
this.form.style.display = 'none'; | this.form.style.display = 'none'; | ||
if ( this.catLink ) | if ( this.catLink ) this.catLink.style.display = ''; | ||
this.linkSpan.style.display = ''; | this.linkSpan.style.display = ''; | ||
this.state = this.originalState; | this.state = this.originalState; | ||
| خط ۱٬۶۹۲: | خط ۱٬۸۰۳: | ||
this.currentExists = this.lastSavedExists; | this.currentExists = this.lastSavedExists; | ||
this.currentHidden = this.lastSavedHidden; | this.currentHidden = this.lastSavedHidden; | ||
if ( this.catLink ) | if ( this.catLink ) | ||
if ( this.currentKey && this.currentKey.length | if ( this.currentKey && this.currentKey.length ) { this.catLink.title = this.currentKey; } else { this.catLink.title = ''; } | ||
if ( this.state === CategoryEditor.UNCHANGED ) { | if ( this.state === CategoryEditor.UNCHANGED ) { | ||
if ( this.catLink ) | if ( this.catLink ) this.catLink.style.backgroundColor = 'transparent'; | ||
} else { | } else { | ||
if ( !onUpload ) { | if ( !onUpload ) { | ||
try { | try { | ||
this.catLink.style.backgroundColor = | this.catLink.style.backgroundColor = HC.bg_changed; | ||
} catch ( ex ) {} | } catch ( ex ) {} | ||
} | } | ||
| خط ۱٬۷۱۵: | خط ۱٬۸۲۲: | ||
if ( !newDOM ) { | if ( !newDOM ) { | ||
var next = this.span.nextSibling; | var next = this.span.nextSibling; | ||
if ( next ) | if ( next ) next.parentNode.removeChild( next ); | ||
} | |||
if (this.span && this.span.parentNode) { | |||
this.span.parentNode.removeChild( this.span ); | |||
} | } | ||
for ( var i = 0; i < editors.length; i++ ) { | for ( var i = 0; i < editors.length; i++ ) { | ||
if ( editors[ i ] === this ) { | if ( editors[ i ] === this ) { | ||
| خط ۱٬۷۲۵: | خط ۱٬۸۳۴: | ||
} | } | ||
checkMultiInput(); | checkMultiInput(); | ||
}, | }, | ||
| خط ۱٬۷۴۲: | خط ۱٬۸۴۸: | ||
this.lastSavedHidden = this.originalHidden; | this.lastSavedHidden = this.originalHidden; | ||
this.state = CategoryEditor.UNCHANGED; | this.state = CategoryEditor.UNCHANGED; | ||
if ( !this.currentCategory || this.currentCategory.length | if ( !this.currentCategory || !this.currentCategory.length ) { | ||
// It was a newly added category. Remove the whole editor. | // It was a newly added category. Remove the whole editor. | ||
this.removeEditor(); | this.removeEditor(); | ||
| خط ۱٬۷۴۹: | خط ۱٬۸۵۵: | ||
this.catLink.removeChild( this.catLink.firstChild ); | this.catLink.removeChild( this.catLink.firstChild ); | ||
this.catLink.appendChild( make( this.currentCategory, true ) ); | this.catLink.appendChild( make( this.currentCategory, true ) ); | ||
this.catLink.href = wikiPagePath( | this.catLink.href = wikiPagePath( HC.category_canonical + ':' + this.currentCategory ); | ||
this.catLink.title = this.currentKey || ''; | this.catLink.title = this.currentKey || ''; | ||
this.catLink.className = this.currentExists ? '' : 'new'; | this.catLink.className = this.currentExists ? '' : 'new'; | ||
this.catLink.style.backgroundColor = 'transparent'; | this.catLink.style.backgroundColor = 'transparent'; | ||
if ( this.upDownLinks ) | if ( this.upDownLinks ) this.upDownLinks.style.display = this.currentExists ? '' : 'none'; | ||
checkMultiInput(); | checkMultiInput(); | ||
} | } | ||
| خط ۱٬۷۶۰: | خط ۱٬۸۶۷: | ||
inactivate: function () { | inactivate: function () { | ||
if ( this.list ) | if ( this.list ) this.list.style.display = 'none'; | ||
if ( this.engineSelector ) | |||
if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | |||
this.is_active = false; | this.is_active = false; | ||
}, | }, | ||
| خط ۱٬۷۶۹: | خط ۱٬۸۷۸: | ||
var value = this.text.value.split( '|' ); | var value = this.text.value.split( '|' ); | ||
var key = null; | var key = null; | ||
if ( value.length > 1 ) | if ( value.length > 1 ) key = value[ 1 ]; | ||
var v = value[ 0 ].replace( /_/g, ' ' ).replace( /^\s+|\s+$/g, '' ); | var v = value[ 0 ].replace( /_/g, ' ' ).replace( /^\s+|\s+$/g, '' ); | ||
if ( | if ( HC.capitalizePageNames ) v = capitalize( v ); | ||
this.lastInput = v; | this.lastInput = v; | ||
v = replaceShortcuts( v, | v = replaceShortcuts( v, HC.shortcuts ); | ||
if ( v.length | if ( !v.length ) { | ||
this.cancel(); | this.cancel(); | ||
return false; | return false; | ||
} | } | ||
if ( | if ( !dontCheck && ( | ||
conf.wgNamespaceNumber === 14 && v === conf.wgTitle || HC.blacklist && HC.blacklist.test( v ) ) ) { | |||
this.cancel(); | this.cancel(); | ||
return false; | return false; | ||
| خط ۱٬۸۰۷: | خط ۱٬۹۱۴: | ||
resolved[ 0 ].commit( | resolved[ 0 ].commit( | ||
( resolved[ 0 ].currentCategory !== original ) ? | ( resolved[ 0 ].currentCategory !== original ) ? | ||
HC.messages.cat_resolved.replace( /\$1/g, original ) : | |||
null | null ); | ||
} | } | ||
} | } | ||
| خط ۱٬۸۲۷: | خط ۱٬۹۳۳: | ||
this.catLink.removeChild( this.catLink.firstChild ); | this.catLink.removeChild( this.catLink.firstChild ); | ||
this.catLink.appendChild( make( this.currentCategory, true ) ); | this.catLink.appendChild( make( this.currentCategory, true ) ); | ||
this.catLink.href = wikiPagePath( | this.catLink.href = wikiPagePath( HC.category_canonical + ':' + this.currentCategory ); | ||
this.catLink.className = this.currentExists ? '' : 'new'; | this.catLink.className = this.currentExists ? '' : 'new'; | ||
this.lastSavedCategory = this.currentCategory; | this.lastSavedCategory = this.currentCategory; | ||
| خط ۱٬۸۳۹: | خط ۱٬۹۴۵: | ||
this.catLink.style.display = ''; | this.catLink.style.display = ''; | ||
if ( this.isAddCategory ) { | if ( this.isAddCategory ) { | ||
if ( onUpload ) { | if ( onUpload && this.line ) { | ||
// eslint-disable-next-line no-new | // eslint-disable-next-line no-new | ||
new CategoryEditor( this.line, null, this.span, true ); // Create a new one | new CategoryEditor( this.line, null, this.span, true ); // Create a new one | ||
| خط ۱٬۸۵۱: | خط ۱٬۹۵۷: | ||
// Append an undo link. | // Append an undo link. | ||
var span = make( 'span' ); | var span = make( 'span' ); | ||
var lk = make( 'a' ); lk.href = '#catlinks'; lk.onclick = this.rollback.bind( this ); | var lk = make( 'a' ); | ||
lk.appendChild( make( | lk.href = '#catlinks'; | ||
lk.onclick = this.rollback.bind( this ); | |||
lk.appendChild( make( HC.links.undo, true ) ); | |||
lk.title = HC.tooltips.undo; | |||
span.appendChild( make( ' ', true ) ); | span.appendChild( make( ' ', true ) ); | ||
span.appendChild( lk ); | span.appendChild( lk ); | ||
| خط ۱٬۸۵۹: | خط ۱٬۹۶۸: | ||
if ( !onUpload ) { | if ( !onUpload ) { | ||
try { | try { | ||
this.catLink.style.backgroundColor = | this.catLink.style.backgroundColor = HC.bg_changed; | ||
} catch ( ex ) {} | } catch ( ex ) {} | ||
} | } | ||
} | } | ||
if ( this.upDownLinks ) | if ( this.upDownLinks ) this.upDownLinks.style.display = this.lastSavedExists ? '' : 'none'; | ||
this.linkSpan.style.display = ''; | this.linkSpan.style.display = ''; | ||
this.state = CategoryEditor.CHANGED; | this.state = CategoryEditor.CHANGED; | ||
| خط ۱٬۸۷۷: | خط ۱٬۹۸۷: | ||
( | ( | ||
this.currentKey === this.originalKey || | this.currentKey === this.originalKey || | ||
this.currentKey === null && this.originalKey.length | this.currentKey === null && !this.originalKey.length | ||
) | ) | ||
) || | ) || | ||
conf.wgNamespaceNumber === 14 && this.currentCategory === conf.wgTitle || | conf.wgNamespaceNumber === 14 && this.currentCategory === conf.wgTitle || | ||
HC.blacklist && HC.blacklist.test( this.currentCategory ) | |||
) { | ) { | ||
this.cancel(); | this.cancel(); | ||
return; | return; | ||
} | } | ||
this.close(); | |||
if ( !commitButton && !onUpload ) { | |||
var self = this; | var self = this; | ||
initiateEdit( function ( failure ) { performChanges( failure, self ); }, function ( msg ) { alert( msg ); } ); | initiateEdit( function ( failure ) { | ||
performChanges( failure, self ); | |||
}, function ( msg ) { | |||
alert( msg ); | |||
} ); | |||
} | } | ||
}, | }, | ||
| خط ۱٬۹۱۸: | خط ۲٬۰۳۰: | ||
this.catLink.style.cssText += '; text-decoration : line-through !important;'; | this.catLink.style.cssText += '; text-decoration : line-through !important;'; | ||
try { | try { | ||
this.catLink.style.backgroundColor = | this.catLink.style.backgroundColor = HC.bg_changed; | ||
} catch ( ex ) {} | } catch ( ex ) {} | ||
this.originalState = this.state; | this.originalState = this.state; | ||
| خط ۱٬۹۳۲: | خط ۲٬۰۴۴: | ||
this.originalState = this.state; | this.originalState = this.state; | ||
this.state = CategoryEditor.DELETED; | this.state = CategoryEditor.DELETED; | ||
this.noCommit = noCommit || | this.noCommit = noCommit || HC.del_needs_diff; | ||
var self = this; | var self = this; | ||
initiateEdit( | initiateEdit( | ||
function ( failure ) { performChanges( failure, self ); }, | function ( failure ) { | ||
function ( msg ) { self.state = self.originalState; alert( msg ); } | performChanges( failure, self ); | ||
}, | |||
function ( msg ) { | |||
self.state = self.originalState; | |||
alert( msg ); | |||
} ); | |||
} | } | ||
} | } | ||
| خط ۱٬۹۵۱: | خط ۲٬۰۶۷: | ||
} else { | } else { | ||
try { | try { | ||
this.catLink.style.backgroundColor = | this.catLink.style.backgroundColor = HC.bg_changed; | ||
} catch ( ex ) {} | } catch ( ex ) {} | ||
} | } | ||
| خط ۱٬۹۶۳: | خط ۲٬۰۷۹: | ||
selectEngine: function ( engineName ) { | selectEngine: function ( engineName ) { | ||
if ( !this.engineSelector ) | if ( !this.engineSelector ) return; | ||
for ( var i = 0; i < this.engineSelector.options.length; i++ ) | for ( var i = 0; i < this.engineSelector.options.length; i++ ) this.engineSelector.options[ i ].selected = this.engineSelector.options[ i ].value === engineName; | ||
}, | }, | ||
| خط ۱٬۹۷۲: | خط ۲٬۰۸۶: | ||
var v = this.text.value || ''; | var v = this.text.value || ''; | ||
v = v.replace( /^(\s|_)+/, '' ); // Trim leading blanks and underscores | v = v.replace( /^(\s|_)+/, '' ); // Trim leading blanks and underscores | ||
var re = new RegExp( '^(' + | var re = new RegExp( '^(' + HC.category_regexp + '):' ); | ||
if ( re.test( v ) ) | if ( re.test( v ) ) v = v.substring( v.indexOf( ':' ) + 1 ).replace( /^(\s|_)+/, '' ); | ||
v = v.replace(/\u200E$/, ''); // Trim ending left-to-right mark | |||
if ( HC.capitalizePageNames ) v = capitalize( v ); | |||
// Update the input field if needed, manually restoring the cursor afterwards | |||
// (but not the whole selection, so that further typing does not overwrite anything) | |||
if ( this.text.value !== null && this.text.value !== v ) { | |||
var cursorPos = this.text.selectionStart; | |||
this.text.value = v; | |||
this.text.setSelectionRange( cursorPos, cursorPos ); | |||
} | } | ||
}, | }, | ||
makeCall: function ( url, callbackObj, engine, queryKey, cleanKey ) { | makeCall: function ( url, callbackObj, engine, queryKey, cleanKey ) { | ||
var cb = callbackObj | var cb = callbackObj, | ||
e = engine, | |||
v = queryKey, | |||
z = cleanKey, | |||
thisObj = this; | |||
function done() { | function done() { | ||
cb.callsMade++; | cb.callsMade++; | ||
if ( cb.callsMade === cb.nofCalls ) { | if ( cb.callsMade === cb.nofCalls ) { | ||
if ( cb.exists ) | if ( cb.exists ) cb.allTitles.exists = true; | ||
if ( cb.normalized ) | |||
if ( !cb.dontCache && !suggestionConfigs[ cb.engineName ].cache[ z ] ) | if ( cb.normalized ) cb.allTitles.normalized = cb.normalized; | ||
if ( !cb.dontCache && !suggestionConfigs[ cb.engineName ].cache[ z ] ) suggestionConfigs[ cb.engineName ].cache[ z ] = cb.allTitles; | |||
thisObj.text.readOnly = false; | thisObj.text.readOnly = false; | ||
if ( !cb.cancelled ) | if ( !cb.cancelled ) thisObj.showSuggestions( cb.allTitles, cb.noCompletion, v, cb.engineName ); | ||
if ( cb === thisObj.callbackObj ) | |||
if ( cb === thisObj.callbackObj ) thisObj.callbackObj = null; | |||
cb = undefined; | |||
} | } | ||
} | } | ||
getJSON( | $.getJSON( url, function ( json ) { | ||
var titles = e.handler( json, z ); | |||
if ( titles && titles.length ) { | |||
if ( cb.allTitles === null ) cb.allTitles = titles; else cb.allTitles = cb.allTitles.concat( titles ); | |||
if ( titles.exists ) cb.exists = true; | |||
if ( titles.normalized ) cb.normalized = titles.normalized; | |||
} | } | ||
done(); | |||
} ).fail( function ( req ) { | |||
if ( !req ) noSuggestions = true; | |||
cb.dontCache = true; | |||
done(); | |||
} ); | } ); | ||
}, | }, | ||
| خط ۲٬۰۴۷: | خط ۲٬۱۵۶: | ||
this.currentKey = null; | this.currentKey = null; | ||
} | } | ||
if ( this.lastInput === v && !force ) | if ( this.lastInput === v && !force ) return; // No change | ||
if ( this.lastInput !== v ) | if ( this.lastInput !== v ) checkMultiInput(); | ||
this.lastInput = v; | this.lastInput = v; | ||
this.lastRealInput = v; | this.lastRealInput = v; | ||
// Mark blacklisted inputs. | // Mark blacklisted inputs. | ||
this.ok.disabled = v.length | this.ok.disabled = v.length && HC.blacklist && HC.blacklist.test( v ); | ||
if ( noSuggestions ) { | if ( noSuggestions ) { | ||
// No Ajax: just make sure the list is hidden | |||
if ( this.list ) | if ( this.list ) this.list.style.display = 'none'; | ||
if ( this.engineSelector ) | if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | ||
if ( this.icon ) | if ( this.icon ) this.icon.style.display = 'none'; | ||
return; | return; | ||
} | } | ||
if ( v.length | if ( !v.length ) { | ||
this.showSuggestions( [] ); | |||
return; | |||
} | |||
var cleanKey = v.replace( /[\u200E\u200F\u202A-\u202E]/g, '' ).replace( wikiTextBlankRE, ' ' ); | var cleanKey = v.replace( /[\u200E\u200F\u202A-\u202E]/g, '' ).replace( wikiTextBlankRE, ' ' ); | ||
cleanKey = replaceShortcuts( cleanKey, | cleanKey = replaceShortcuts( cleanKey, HC.shortcuts ); | ||
cleanKey = cleanKey.replace( /^\s+|\s+$/g, '' ); | cleanKey = cleanKey.replace( /^\s+|\s+$/g, '' ); | ||
if ( cleanKey.length | if ( !cleanKey.length ) { | ||
this.showSuggestions( [] ); | |||
return; | |||
} | |||
if ( this.callbackObj ) this.callbackObj.cancelled = true; | |||
var engineName = suggestionConfigs[ this.engine ] ? this.engine : 'combined'; | var engineName = suggestionConfigs[ this.engine ] ? this.engine : 'combined'; | ||
| خط ۲٬۰۷۹: | خط ۲٬۱۹۶: | ||
var engines = suggestionConfigs[ engineName ].engines; | var engines = suggestionConfigs[ engineName ].engines; | ||
this.callbackObj = | this.callbackObj = { | ||
allTitles: null, | |||
callsMade: 0, | |||
nofCalls: engines.length, | |||
noCompletion: dont_autocomplete, | |||
engineName: engineName | |||
}; | |||
this.makeCalls( engines, this.callbackObj, v, cleanKey ); | this.makeCalls( engines, this.callbackObj, v, cleanKey ); | ||
}, | }, | ||
| خط ۲٬۰۸۷: | خط ۲٬۲۰۹: | ||
for ( var j = 0; j < engines.length; j++ ) { | for ( var j = 0; j < engines.length; j++ ) { | ||
var engine = suggestionEngines[ engines[ j ] ]; | var engine = suggestionEngines[ engines[ j ] ]; | ||
var url = | var url = wgServer + conf.wgScriptPath + engine.uri.replace( /\$1/g, encodeURIComponent( cleanKey ) ); | ||
this.makeCall( url, cb, engine, v, cleanKey ); | this.makeCall( url, cb, engine, v, cleanKey ); | ||
} | } | ||
| خط ۲٬۰۹۶: | خط ۲٬۲۱۸: | ||
this.dab = null; | this.dab = null; | ||
this.showsList = false; | this.showsList = false; | ||
if ( !this.list ) | if ( !this.list ) return; | ||
if ( noSuggestions ) { | if ( noSuggestions ) { | ||
if ( this.list ) | if ( this.list ) this.list.style.display = 'none'; | ||
if ( this.engineSelector ) | |||
if ( this.icon ) | if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | ||
if ( this.icon ) this.icon.style.display = 'none'; | |||
this.inputExists = true; // Default... | this.inputExists = true; // Default... | ||
return; | return; | ||
| خط ۲٬۱۰۶: | خط ۲٬۲۳۱: | ||
this.engineName = engineName; | this.engineName = engineName; | ||
if ( engineName ) { | if ( engineName ) { | ||
if ( !this.engineSelector ) | if ( !this.engineSelector ) this.engineName = null; | ||
} else { | } else { | ||
if ( this.engineSelector ) | if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | ||
} | } | ||
if ( queryKey ) { | if ( queryKey ) { | ||
if ( this.lastInput.indexOf( queryKey ) | if ( this.lastInput.indexOf( queryKey ) ) return; | ||
if ( this.lastQuery && this.lastInput.indexOf( this.lastQuery ) === 0 && this.lastQuery.length > queryKey.length ) | if ( this.lastQuery && this.lastInput.indexOf( this.lastQuery ) === 0 && this.lastQuery.length > queryKey.length ) return; | ||
} | } | ||
this.lastQuery = queryKey; | this.lastQuery = queryKey; | ||
| خط ۲٬۱۱۹: | خط ۲٬۲۴۴: | ||
var v = this.text.value.split( '|' ); | var v = this.text.value.split( '|' ); | ||
var key = v.length > 1 ? '|' + v[ 1 ] : ''; | var key = v.length > 1 ? '|' + v[ 1 ] : ''; | ||
v = ( | v = ( HC.capitalizePageNames ? capitalize( v[ 0 ] ) : v[ 0 ] ); | ||
var vNormalized = v; | var vNormalized = v; | ||
var knownToExist = titles && titles.exists; | var knownToExist = titles && titles.exists; | ||
| خط ۲٬۱۲۵: | خط ۲٬۲۵۰: | ||
if ( titles ) { | if ( titles ) { | ||
if ( titles.normalized && v.indexOf( queryKey ) === 0 ) { | if ( titles.normalized && v.indexOf( queryKey ) === 0 ) { | ||
// We got back a different normalization than what is in the input field | |||
vNormalized = titles.normalized + v.substring( queryKey.length ); | vNormalized = titles.normalized + v.substring( queryKey.length ); | ||
} | } | ||
var vLow = vNormalized.toLowerCase(); | var vLow = vNormalized.toLowerCase(); | ||
// Strip blacklisted categories | // Strip blacklisted categories | ||
if ( | if ( HC.blacklist ) { | ||
for ( i = 0; i < titles.length; i++ ) { | for ( i = 0; i < titles.length; i++ ) { | ||
if ( | if ( HC.blacklist.test( titles[ i ] ) ) { | ||
titles.splice( i, 1 ); | titles.splice( i, 1 ); | ||
i--; | i--; | ||
| خط ۲٬۱۴۰: | خط ۲٬۲۶۵: | ||
titles.sort( | titles.sort( | ||
function ( a, b ) { | function ( a, b ) { | ||
if ( a === b ) | if ( a === b ) return 0; | ||
if ( a.indexOf( b ) === 0 ) | |||
if ( b.indexOf( a ) === 0 ) | if ( a.indexOf( b ) === 0 ) return 1; | ||
// a begins with b: a > b | |||
if ( b.indexOf( a ) === 0 ) return -1; | |||
// b begins with a: a < b | |||
// Opensearch may return stuff not beginning with the search prefix! | // Opensearch may return stuff not beginning with the search prefix! | ||
var prefixMatchA = ( a.indexOf( vNormalized ) === 0 ? 1 : 0 ); | var prefixMatchA = ( a.indexOf( vNormalized ) === 0 ? 1 : 0 ); | ||
var prefixMatchB = ( b.indexOf( vNormalized ) === 0 ? 1 : 0 ); | var prefixMatchB = ( b.indexOf( vNormalized ) === 0 ? 1 : 0 ); | ||
if ( prefixMatchA !== prefixMatchB ) | if ( prefixMatchA !== prefixMatchB ) return prefixMatchB - prefixMatchA; | ||
// Case-insensitive prefix match! | // Case-insensitive prefix match! | ||
var aLow = a.toLowerCase(), bLow = b.toLowerCase(); | var aLow = a.toLowerCase(), | ||
bLow = b.toLowerCase(); | |||
prefixMatchA = ( aLow.indexOf( vLow ) === 0 ? 1 : 0 ); | prefixMatchA = ( aLow.indexOf( vLow ) === 0 ? 1 : 0 ); | ||
prefixMatchB = ( bLow.indexOf( vLow ) === 0 ? 1 : 0 ); | prefixMatchB = ( bLow.indexOf( vLow ) === 0 ? 1 : 0 ); | ||
if ( prefixMatchA !== prefixMatchB ) | if ( prefixMatchA !== prefixMatchB ) return prefixMatchB - prefixMatchA; | ||
if ( a < b ) | |||
if ( b < a ) | if ( a < b ) return -1; | ||
if ( b < a ) return 1; | |||
return 0; | return 0; | ||
} | } ); | ||
// Remove duplicates and self-references | // Remove duplicates and self-references | ||
for ( i = 0; i < titles.length; i++ ) { | for ( i = 0; i < titles.length; i++ ) { | ||
if ( i + 1 < titles.length && titles[ i ] === titles[ i + 1 ] || | if ( | ||
i + 1 < titles.length && titles[ i ] === titles[ i + 1 ] || | |||
conf.wgNamespaceNumber === 14 && titles[ i ] === conf.wgTitle | conf.wgNamespaceNumber === 14 && titles[ i ] === conf.wgTitle | ||
) { | ) { | ||
| خط ۲٬۱۶۷: | خط ۲٬۳۰۰: | ||
} | } | ||
} | } | ||
if ( !titles || titles.length | if ( !titles || !titles.length ) { | ||
if ( this.list ) | if ( this.list ) this.list.style.display = 'none'; | ||
if ( this.engineSelector ) | |||
if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | |||
if ( engineName && suggestionConfigs[ engineName ] && !suggestionConfigs[ engineName ].temp ) { | if ( engineName && suggestionConfigs[ engineName ] && !suggestionConfigs[ engineName ].temp ) { | ||
if ( this.icon ) | if ( this.icon ) this.icon.src = HC.existsNo; | ||
this.inputExists = false; | this.inputExists = false; | ||
} | } | ||
| خط ۲٬۱۷۹: | خط ۲٬۳۱۵: | ||
var firstTitle = titles[ 0 ]; | var firstTitle = titles[ 0 ]; | ||
var completed = this.autoComplete( firstTitle, v, vNormalized, key, dontAutocomplete ); | var completed = this.autoComplete( firstTitle, v, vNormalized, key, dontAutocomplete ); | ||
var existing = completed || knownToExist || firstTitle === replaceShortcuts( v, | var existing = completed || knownToExist || firstTitle === replaceShortcuts( v, HC.shortcuts ); | ||
if ( engineName && suggestionConfigs[ engineName ] && !suggestionConfigs[ engineName ].temp ) { | if ( engineName && suggestionConfigs[ engineName ] && !suggestionConfigs[ engineName ].temp ) { | ||
this.icon.src = | this.icon.src = ( existing ? HC.existsYes : HC.existsNo ); | ||
this.inputExists = existing; | this.inputExists = existing; | ||
} | } | ||
| خط ۲٬۱۸۸: | خط ۲٬۳۲۴: | ||
if ( titles.length === 1 ) { | if ( titles.length === 1 ) { | ||
this.list.style.display = 'none'; | this.list.style.display = 'none'; | ||
if ( this.engineSelector ) | if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | ||
return; | return; | ||
} | } | ||
} | } | ||
// (Re-)fill the list | // (Re-)fill the list | ||
while ( this.list.firstChild ) | while ( this.list.firstChild ) this.list.removeChild( this.list.firstChild ); | ||
for ( i = 0; i < titles.length; i++ ) { | for ( i = 0; i < titles.length; i++ ) { | ||
var opt = make( 'option' ); | var opt = make( 'option' ); | ||
| خط ۲٬۲۰۷: | خط ۲٬۳۴۵: | ||
if ( !this.is_active ) { | if ( !this.is_active ) { | ||
this.list.style.display = 'none'; | this.list.style.display = 'none'; | ||
if ( this.engineSelector ) | if ( this.engineSelector ) this.engineSelector.style.display = 'none'; | ||
return; | return; | ||
} | } | ||
var nofItems = ( this.list.options.length > | var nofItems = ( this.list.options.length > HC.listSize ? HC.listSize : this.list.options.length ); | ||
if ( nofItems <= 1 ) | if ( nofItems <= 1 ) nofItems = 2; | ||
this.list.size = nofItems; | this.list.size = nofItems; | ||
this.list.style.align = is_rtl ? 'right' : 'left'; | this.list.style.align = is_rtl ? 'right' : 'left'; | ||
| خط ۲٬۲۳۱: | خط ۲٬۳۷۱: | ||
// Approximate calculation of maximum list size | // Approximate calculation of maximum list size | ||
var maxListHeight = listh; | var maxListHeight = listh; | ||
if ( nofItems < | if ( nofItems < HC.listSize ) maxListHeight = ( listh / nofItems ) * HC.listSize; | ||
function viewport( what ) { | function viewport( what ) { | ||
if ( is_webkit && !document.evaluate ) { | if ( is_webkit && !document.evaluate ) { | ||
// Safari < 3.0 | |||
return window[ 'inner' + what ]; | return window[ 'inner' + what ]; | ||
} | } | ||
var s = 'client' + what; | var s = 'client' + what; | ||
if ( window.opera ) | if ( window.opera ) return document.body[ s ]; | ||
return ( document.documentElement ? document.documentElement[ s ] : 0 ) || document.body[ s ] || 0; | return ( document.documentElement ? document.documentElement[ s ] : 0 ) || document.body[ s ] || 0; | ||
} | } | ||
| خط ۲٬۲۵۲: | خط ۲٬۳۹۱: | ||
// IE >= 8: 0 at the far right, then increasingly positive values. | // IE >= 8: 0 at the far right, then increasingly positive values. | ||
// Webkit: scrollWidth - clientWidth at the far right, then down to zero. | // Webkit: scrollWidth - clientWidth at the far right, then down to zero. | ||
// Opera: don't know... | // Opera: don't know... | ||
if ( result < 0 ) | if ( result < 0 ) result = -result; | ||
if ( !is_webkit ) | |||
if ( !is_webkit ) result = scroll_offset( 'Width' ) - viewport( 'Width' ) - result; | |||
// Now all have webkit behavior, i.e. zero if at the leftmost edge. | // Now all have webkit behavior, i.e. zero if at the leftmost edge. | ||
} | } | ||
| خط ۲٬۲۷۱: | خط ۲٬۴۰۹: | ||
}; | }; | ||
} | } | ||
var t = 0, l = 0; | var t = 0, | ||
l = 0; | |||
do { | do { | ||
t = | t += ( node.offsetTop || 0 ); | ||
l = | l += ( node.offsetLeft || 0 ); | ||
node = node.offsetParent; | node = node.offsetParent; | ||
} while ( node ); | } while ( node ); | ||
| خط ۲٬۲۸۳: | خط ۲٬۴۲۲: | ||
} | } | ||
var textPos = position( this.text ) | var textPos = position( this.text ), | ||
nl = 0, | |||
nt = 0, | |||
offset = 0, | |||
// Opera 9.5 somehow has offsetWidth = 0 here?? Use the next best value... | |||
textBoxWidth = this.text.offsetWidth || this.text.clientWidth; | |||
if ( this.engineName ) { | if ( this.engineName ) { | ||
this.engineSelector.style.zIndex = 5; | this.engineSelector.style.zIndex = 5; | ||
| خط ۲٬۲۹۶: | خط ۲٬۴۳۵: | ||
if ( this.engineSelector.style.display === 'none' ) { | if ( this.engineSelector.style.display === 'none' ) { | ||
this.engineSelector.style[ anchor ] = '-10000px'; | this.engineSelector.style[ anchor ] = '-10000px'; | ||
this.engineSelector.style.top = ' | this.engineSelector.style.top = '0'; | ||
this.engineSelector.style.display = ''; | this.engineSelector.style.display = ''; | ||
offset = this.engineSelector.offsetHeight; | offset = this.engineSelector.offsetHeight; | ||
| خط ۲٬۳۰۶: | خط ۲٬۴۴۵: | ||
} | } | ||
if ( textPos.y < maxListHeight + offset + 1 ) { | if ( textPos.y < maxListHeight + offset + 1 ) { | ||
// The list might extend beyond the upper border of the page. Let's avoid that by placing it | |||
// below the input text field. | |||
nt = this.text.offsetHeight + offset + 1; | nt = this.text.offsetHeight + offset + 1; | ||
if ( this.engineName ) | if ( this.engineName ) this.engineSelector.style.top = this.text.offsetHeight + 'px'; | ||
} else { | } else { | ||
nt = -listh - offset - 1; | nt = -listh - offset - 1; | ||
if ( this.engineName ) | if ( this.engineName ) this.engineSelector.style.top = -( offset + 1 ) + 'px'; | ||
} | } | ||
this.list.style.top = nt + 'px'; | this.list.style.top = nt + 'px'; | ||
| خط ۲٬۳۳۸: | خط ۲٬۴۷۷: | ||
w = view_w; | w = view_w; | ||
this.list.style.width = w + 'px'; | this.list.style.width = w + 'px'; | ||
if ( is_rtl ) | if ( is_rtl ) left = right - w; else right = left + w; | ||
} | } | ||
var relative_offset = 0; | var relative_offset = 0; | ||
if ( left < scroll ) | if ( left < scroll ) relative_offset = scroll - left; else if ( right > scroll + view_w ) relative_offset = -( right - scroll - view_w ); | ||
if ( is_rtl ) relative_offset = -relative_offset; | |||
if ( relative_offset ) this.list.style[ anchor ] = ( nl + relative_offset ) + 'px'; | |||
if ( is_rtl ) | |||
if ( relative_offset | |||
} | } | ||
}, | }, | ||
autoComplete: function ( newVal, actVal, normalizedActVal, key, dontModify ) { | autoComplete: function ( newVal, actVal, normalizedActVal, key, dontModify ) { | ||
if ( newVal === actVal ) | if ( newVal === actVal ) return true; | ||
if ( dontModify || this.ime || !this.canSelect() ) | |||
if ( dontModify || this.ime || !this.canSelect() ) return false; | |||
// If we can't select properly or an IME composition is ongoing, autocompletion would be a major annoyance to the user. | // If we can't select properly or an IME composition is ongoing, autocompletion would be a major annoyance to the user. | ||
if ( newVal.indexOf( actVal ) | if ( newVal.indexOf( actVal ) ) { | ||
// Maybe it'll work with the normalized value (NFC)? | // Maybe it'll work with the normalized value (NFC)? | ||
if ( normalizedActVal && newVal.indexOf( normalizedActVal ) === 0 ) { | if ( normalizedActVal && newVal.indexOf( normalizedActVal ) === 0 ) { | ||
if ( this.lastRealInput === actVal ) | if ( this.lastRealInput === actVal ) this.lastRealInput = normalizedActVal; | ||
actVal = normalizedActVal; | actVal = normalizedActVal; | ||
} else { | } else { | ||
| خط ۲٬۳۸۰: | خط ۲٬۵۱۴: | ||
canSelect: function () { | canSelect: function () { | ||
return this.text.setSelectionRange || | return this.text.setSelectionRange || | ||
this.text.createTextRange || | |||
this.text.selectionStart !== undefined && | |||
this.text.selectionEnd !== undefined; | |||
}, | }, | ||
setSelection: function ( from, to ) { | setSelection: function ( from, to ) { | ||
// this.text must be focused (at least on IE) | // this.text must be focused (at least on IE) | ||
if ( !this.text.value ) | if ( !this.text.value ) return; | ||
if ( this.text.setSelectionRange ) { // e.g. khtml | if ( this.text.setSelectionRange ) { // e.g. khtml | ||
this.text.setSelectionRange( from, to ); | this.text.setSelectionRange( from, to ); | ||
} else if ( | } else if ( this.text.selectionStart !== undefined ) { | ||
if ( from > this.text.selectionStart ) { | if ( from > this.text.selectionStart ) { | ||
this.text.selectionEnd = to; | this.text.selectionEnd = to; | ||
| خط ۲٬۴۰۷: | خط ۲٬۵۴۱: | ||
getSelection: function () { | getSelection: function () { | ||
var from = 0, to = 0; | var from = 0, | ||
to = 0; | |||
// this.text must be focused (at least on IE) | // this.text must be focused (at least on IE) | ||
if ( !this.text.value ) { | if ( !this.text.value ) { | ||
// No text. | // No text. | ||
} else if ( | } else if ( this.text.selectionStart !== undefined ) { | ||
from = this.text.selectionStart; | from = this.text.selectionStart; | ||
to = this.text.selectionEnd; | to = this.text.selectionEnd; | ||
| خط ۲٬۴۲۷: | خط ۲٬۵۶۲: | ||
from = textRng.text.length; | from = textRng.text.length; | ||
} catch ( notFocused ) { | } catch ( notFocused ) { | ||
from = this.text.value.length; to = from; // At end of text | from = this.text.value.length; | ||
to = from; // At end of text | |||
} | } | ||
} | } | ||
} | } | ||
return { start: from, end: to }; | return { | ||
start: from, | |||
end: to | |||
}; | |||
}, | }, | ||
| خط ۲٬۴۴۸: | خط ۲٬۵۸۷: | ||
break; | break; | ||
case PGUP: | case PGUP: | ||
dir = - | dir = -HC.listSize; | ||
break; | break; | ||
case PGDOWN: | case PGDOWN: | ||
dir = | dir = HC.listSize; | ||
break; | break; | ||
case ESC: // Inhibit default behavior (revert to last real input in FF: we do that ourselves) | case ESC: // Inhibit default behavior (revert to last real input in FF: we do that ourselves) | ||
| خط ۲٬۴۵۸: | خط ۲٬۵۹۷: | ||
if ( dir ) { | if ( dir ) { | ||
if ( this.list.style.display !== 'none' ) { | if ( this.list.style.display !== 'none' ) { | ||
// List is visible, so there are suggestions | |||
this.highlightSuggestion( dir ); | this.highlightSuggestion( dir ); | ||
// Kill the event, otherwise some browsers (e.g., Firefox) may additionally treat an up-arrow | // Kill the event, otherwise some browsers (e.g., Firefox) may additionally treat an up-arrow | ||
| خط ۲٬۴۶۵: | خط ۲٬۶۰۴: | ||
} else if ( | } else if ( | ||
this.keyCount <= 1 && | this.keyCount <= 1 && | ||
( !this.callbackObj || this.callbackObj.callsMade === this.callbackObj.nofCalls ) ) { | ( !this.callbackObj || this.callbackObj.callsMade === this.callbackObj.nofCalls ) | ||
) { | |||
// If no suggestions displayed, get them, unless we're already getting them. | // If no suggestions displayed, get them, unless we're already getting them. | ||
this.textchange(); | this.textchange(); | ||
| خط ۲٬۴۷۴: | خط ۲٬۶۱۴: | ||
highlightSuggestion: function ( dir ) { | highlightSuggestion: function ( dir ) { | ||
if ( noSuggestions || !this.list || this.list.style.display === 'none' ) | if ( noSuggestions || !this.list || this.list.style.display === 'none' ) return false; | ||
var curr = this.list.selectedIndex; | var curr = this.list.selectedIndex; | ||
var tgt = -1; | var tgt = -1; | ||
if ( dir === 0 ) { | if ( dir === 0 ) { | ||
if ( curr < 0 || curr >= this.list.options.length ) | if ( curr < 0 || curr >= this.list.options.length ) return false; | ||
tgt = curr; | tgt = curr; | ||
} else { | } else { | ||
tgt = curr < 0 ? 0 : curr + dir; | tgt = curr < 0 ? 0 : curr + dir; | ||
tgt = tgt < 0 ? 0 : tgt; | tgt = tgt < 0 ? 0 : tgt; | ||
if ( tgt >= this.list.options.length ) | if ( tgt >= this.list.options.length ) tgt = this.list.options.length - 1; | ||
} | } | ||
if ( tgt !== curr || dir === 0 ) { | if ( tgt !== curr || dir === 0 ) { | ||
if ( curr >= 0 && curr < this.list.options.length && dir !== 0 ) | if ( curr >= 0 && curr < this.list.options.length && dir !== 0 ) this.list.options[ curr ].selected = false; | ||
this.list.options[ tgt ].selected = true; | this.list.options[ tgt ].selected = true; | ||
// Get current input text | // Get current input text | ||
| خط ۲٬۴۹۶: | خط ۲٬۶۳۷: | ||
if ( !completed || this.list.options[ tgt ].text === this.lastRealInput ) { | if ( !completed || this.list.options[ tgt ].text === this.lastRealInput ) { | ||
this.text.value = this.list.options[ tgt ].text + key; | this.text.value = this.list.options[ tgt ].text + key; | ||
if ( this.canSelect() ) | if ( this.canSelect() ) this.setSelection( this.list.options[ tgt ].text.length, this.list.options[ tgt ].text.length ); | ||
} | } | ||
this.lastInput = this.list.options[ tgt ].text; | this.lastInput = this.list.options[ tgt ].text; | ||
this.inputExists = true; // Might be wrong if from a dab list... | this.inputExists = true; // Might be wrong if from a dab list... | ||
if ( this.icon ) | if ( this.icon ) this.icon.src = HC.existsYes; | ||
this.state = CategoryEditor.CHANGE_PENDING; | this.state = CategoryEditor.CHANGE_PENDING; | ||
} | } | ||
| خط ۲٬۵۰۹: | خط ۲٬۶۴۹: | ||
resetKeySelection: function () { | resetKeySelection: function () { | ||
if ( noSuggestions || !this.list || this.list.style.display === 'none' ) | if ( noSuggestions || !this.list || this.list.style.display === 'none' ) return false; | ||
var curr = this.list.selectedIndex; | var curr = this.list.selectedIndex; | ||
if ( curr >= 0 && curr < this.list.options.length ) { | if ( curr >= 0 && curr < this.list.options.length ) { | ||
| خط ۲٬۵۲۸: | خط ۲٬۶۶۹: | ||
return false; | return false; | ||
} | } | ||
}; // end CategoryEditor.prototype | }; // end CategoryEditor.prototype | ||
function initialize() { | function initialize() { | ||
// User configurations | // User configurations: Do this here, called from the onload handler, so that users can | ||
// override it easily in their own user script files by just declaring variables. JSconfig | // override it easily in their own user script files by just declaring variables. JSconfig | ||
// is some feature used at Wikimedia Commons. | // is some feature used at Wikimedia Commons. | ||
var config = ( | var config = ( window.JSconfig !== undefined && JSconfig.keys ) ? JSconfig.keys : {}; | ||
HC.dont_add_to_watchlist = ( window.hotcat_dont_add_to_watchlist !== undefined ? | |||
!!window.hotcat_dont_add_to_watchlist : | |||
( config.HotCatDontAddToWatchlist !== undefined ? config.HotCatDontAddToWatchlist : | |||
HC.dont_add_to_watchlist ) ); | |||
HC.no_autocommit = ( window.hotcat_no_autocommit !== undefined ? | |||
!!window.hotcat_no_autocommit : ( config.HotCatNoAutoCommit !== undefined ? | |||
config.HotCatNoAutoCommit : | |||
// On talk namespace default autocommit off | |||
( conf.wgNamespaceNumber % 2 ? | |||
true : HC.no_autocommit ) ) ); | |||
HC.del_needs_diff = ( window.hotcat_del_needs_diff !== undefined ? | |||
!!window.hotcat_del_needs_diff : | |||
( config.HotCatDelNeedsDiff !== undefined ? | |||
config.HotCatDelNeedsDiff : | |||
HC.del_needs_diff ) ); | |||
HC.suggest_delay = window.hotcat_suggestion_delay || config.HotCatSuggestionDelay || HC.suggest_delay; | |||
HC.editbox_width = window.hotcat_editbox_width || config.HotCatEditBoxWidth || HC.editbox_width; | |||
HC.suggestions = window.hotcat_suggestions || config.HotCatSuggestions || HC.suggestions; | |||
if ( typeof HC.suggestions !== 'string' || !suggestionConfigs[ HC.suggestions ] ) HC.suggestions = 'combined'; | |||
HC.fixed_search = ( window.hotcat_suggestions_fixed !== undefined ? | |||
!!window.hotcat_suggestions_fixed : ( config.HotCatFixedSuggestions !== undefined ? | |||
config.HotCatFixedSuggestions : HC.fixed_search ) ); | |||
HC.single_minor = ( window.hotcat_single_changes_are_minor !== undefined ? | |||
!!window.hotcat_single_changes_are_minor : | |||
( config.HotCatMinorSingleChanges !== undefined ? | |||
config.HotCatMinorSingleChanges : | |||
HC.single_minor ) ); | |||
HC.bg_changed = window.hotcat_changed_background || config.HotCatChangedBackground || HC.bg_changed; | |||
HC.use_up_down = ( window.hotcat_use_category_links !== undefined ? | |||
!!window.hotcat_use_category_links : | |||
( config.HotCatUseCategoryLinks !== undefined ? | |||
config.HotCatUseCategoryLinks : | |||
if ( typeof | HC.use_up_down ) ); | ||
HC.listSize = window.hotcat_list_size || config.HotCatListSize || HC.listSize; | |||
if ( conf.wgDBname !== 'commonswiki' ) HC.changeTag = config.HotCatChangeTag || ''; | |||
// The next whole shebang is needed, because manual tags get not submitted except of save | |||
if ( HC.changeTag ) { | |||
var eForm = document.editform, | |||
catRegExp = new RegExp( '^\\[\\[(' + HC.category_regexp + '):' ), | |||
oldTxt; | |||
// Returns true if minor change | |||
var isMinorChange = function () { | |||
var newTxt = eForm.wpTextbox1; | |||
if ( !newTxt ) return; | |||
newTxt = newTxt.value; | |||
var oldLines = oldTxt.match( /^.*$/gm ), | |||
newLines = newTxt.match( /^.*$/gm ), | |||
cArr; // changes | |||
var except = function ( aArr, bArr ) { | |||
var result = [], | |||
lArr, // larger | |||
sArr; // smaller | |||
if ( aArr.length < bArr.length ) { | |||
lArr = bArr; | |||
sArr = aArr; | |||
} else { | |||
lArr = aArr; | |||
sArr = bArr; | |||
} | |||
for ( var i = 0; i < lArr.length; i++ ) { | |||
var item = lArr[ i ]; | |||
var ind = $.inArray( item, sArr ); | |||
if ( ind === -1 ) result.push( item ); | |||
else sArr.splice( ind, 1 ); // don't check this item again | |||
// | } | ||
return result.concat( sArr ); | |||
}; | |||
cArr = except( oldLines, newLines ); | |||
if ( cArr.length ) { | |||
cArr = $.grep( cArr, function ( c ) { | |||
c = $.trim( c ); | |||
if ( | return ( c && !catRegExp.test( c ) ); | ||
} ); | |||
} | |||
if ( !cArr.length ) { | |||
oldTxt = newTxt; | |||
return true; | |||
} | |||
}; | |||
if ( conf.wgAction === 'submit' && conf.wgArticleId && eForm && eForm.wpSummary && document.getElementById( 'wikiDiff' ) ) { | |||
var sum = eForm.wpSummary, | |||
sumA = eForm.wpAutoSummary; | |||
if ( sum.value && sumA.value === HC.changeTag ) { // HotCat diff | |||
// MD5 hash of the empty string, as HotCat edit is based on empty sum | |||
sumA.value = sumA.value.replace( HC.changeTag, 'd41d8cd98f00b204e9800998ecf8427e' ); | |||
// Attr creation and event handling is not same in all (old) browsers so use $ | |||
var $ct = $( '<input type="hidden" name="wpChangeTags">' ).val( HC.changeTag ); | |||
$( eForm ).append( $ct ); | |||
oldTxt = eForm.wpTextbox1.value; | |||
$( '#wpSave' ).one( 'click', function () { | |||
if ( $ct.val() ) | |||
sum.value = sum.value.replace( ( HC.messages.using || HC.messages.prefix ), '' ); | |||
} ); | |||
var removeChangeTag = function () { | |||
$( eForm.wpTextbox1 ).add( sum ).one( 'input', function () { | |||
window.setTimeout( function () { | |||
if ( !isMinorChange() ) $ct.val( '' ); | |||
else removeChangeTag(); | |||
}, 500 ); | |||
} ); | |||
}; | |||
removeChangeTag(); | |||
} | } | ||
} | } | ||
} | |||
// Numeric input, make sure we have a numeric value | |||
HC.listSize = parseInt( HC.listSize, 10 ); | |||
if ( isNaN( HC.listSize ) || HC.listSize < 5 ) HC.listSize = 5; | |||
HC.listSize = Math.min( HC.listSize, 30 ); // Max size | |||
// Localize search engine names | |||
if ( HC.engine_names ) { | |||
for ( var key in HC.engine_names ) | |||
if ( suggestionConfigs[ key ] && HC.engine_names[ key ] ) suggestionConfigs[ key ].name = HC.engine_names[ key ]; | |||
} | } | ||
// Catch both native RTL and "faked" RTL through [[MediaWiki:Rtl.js]] | // Catch both native RTL and "faked" RTL through [[MediaWiki:Rtl.js]] | ||
| خط ۲٬۶۳۳: | خط ۲٬۸۱۶: | ||
case 'cologneblue': | case 'cologneblue': | ||
container = document.getElementById( 'quickbar' ); | container = document.getElementById( 'quickbar' ); | ||
/* fall through */ | |||
case 'standard': | case 'standard': | ||
case 'nostalgia': | case 'nostalgia': | ||
if ( !container ) | if ( !container ) container = document.getElementById( 'topbar' ); | ||
var lks = container.getElementsByTagName( 'a' ); | var lks = container.getElementsByTagName( 'a' ); | ||
for ( var i = 0; i < lks.length; i++ ) { | for ( var i = 0; i < lks.length; i++ ) { | ||
if ( param( 'title', lks[ i ].href ) === conf.wgPageName && | if ( | ||
param( 'action', lks[ i ].href ) === 'edit' ) { return true; } | param( 'title', lks[ i ].href ) === conf.wgPageName && | ||
param( 'action', lks[ i ].href ) === 'edit' | |||
) { | |||
return true; | |||
} | |||
} | } | ||
return false; | return false; | ||
| خط ۲٬۶۴۶: | خط ۲٬۸۳۳: | ||
// all modern skins: | // all modern skins: | ||
return document.getElementById( 'ca-edit' ) !== null; | return document.getElementById( 'ca-edit' ) !== null; | ||
} | |||
} | |||
// Legacy stuff | |||
function closeForm() { | |||
// Close all open editors without redirect resolution and other asynchronous stuff. | |||
for ( var i = 0; i < editors.length; i++ ) { | |||
var edit = editors[ i ]; | |||
if ( edit.state === CategoryEditor.OPEN ) { | |||
edit.cancel(); | |||
} else if ( edit.state === CategoryEditor.CHANGE_PENDING ) { | |||
edit.sanitizeInput(); | |||
var value = edit.text.value.split( '|' ); | |||
var key = null; | |||
if ( value.length > 1 ) key = value[ 1 ]; | |||
var v = value[ 0 ].replace( /_/g, ' ' ).replace( /^\s+|\s+$/g, '' ); | |||
if ( !v.length ) { | |||
edit.cancel(); | |||
} else { | |||
edit.currentCategory = v; | |||
edit.currentKey = key; | |||
edit.currentExists = this.inputExists; | |||
edit.close(); | |||
} | |||
} | |||
} | } | ||
} | } | ||
| خط ۲٬۶۵۵: | خط ۲٬۸۶۷: | ||
if ( !ip ) { | if ( !ip ) { | ||
ip = document.getElementById( 'wpDestFile' ); | ip = document.getElementById( 'wpDestFile' ); | ||
while ( ip && ip.nodeName.toLowerCase() !== 'table' ) | while ( ip && ip.nodeName.toLowerCase() !== 'table' ) ip = ip.parentNode; | ||
} | } | ||
if ( !ip ) | if ( !ip ) return; | ||
var reupload = document.getElementById( 'wpForReUpload' ); | var reupload = document.getElementById( 'wpForReUpload' ); | ||
var destFile = document.getElementById( 'wpDestFile' ); | var destFile = document.getElementById( 'wpDestFile' ); | ||
if ( ( reupload && !!reupload.value ) || | if ( | ||
( destFile && ( destFile.disabled || destFile.readOnly ) ) ) { return; | ( reupload && !!reupload.value ) || | ||
( destFile && ( destFile.disabled || destFile.readOnly ) ) | |||
) { | |||
return; // re-upload form... | |||
} | |||
// Insert a table row with two fields (label and empty category bar) | // Insert a table row with two fields (label and empty category bar) | ||
var labelCell = make( 'td' ); | var labelCell = make( 'td' ); | ||
| خط ۲٬۶۷۶: | خط ۲٬۸۹۲: | ||
// Create the label | // Create the label | ||
var label = null; | var label = null; | ||
if ( | if ( window.UFUI && window.UIElements && UFUI.getLabel instanceof Function ) { | ||
try { | try { | ||
label = UFUI.getLabel( 'wpCategoriesUploadLbl' ); | label = UFUI.getLabel( 'wpCategoriesUploadLbl' ); | ||
| خط ۲٬۶۸۸: | خط ۲٬۹۰۱: | ||
if ( !label ) { | if ( !label ) { | ||
labelCell.id = 'hotcatLabel'; | labelCell.id = 'hotcatLabel'; | ||
labelCell.appendChild( make( | labelCell.appendChild( make( HC.categories, true ) ); | ||
} else { | } else { | ||
labelCell.id = 'hotcatLabelTranslated'; | labelCell.id = 'hotcatLabelTranslated'; | ||
| خط ۲٬۶۹۸: | خط ۲٬۹۱۱: | ||
// Change the onsubmit handler | // Change the onsubmit handler | ||
var form = document.getElementById( 'upload' ) || document.getElementById( 'mw-upload-form' ); | var form = document.getElementById( 'upload' ) || document.getElementById( 'mw-upload-form' ); | ||
if ( form ) { | if ( form && ip && ip.insertRow ) { | ||
var newRow = ip.insertRow( -1 ); | var newRow = ip.insertRow( -1 ); | ||
newRow.appendChild( labelCell ); | newRow.appendChild( labelCell ); | ||
| خط ۲٬۷۰۷: | خط ۲٬۹۲۰: | ||
if ( oldSubmit ) { | if ( oldSubmit ) { | ||
if ( typeof oldSubmit === 'string' ) { | if ( typeof oldSubmit === 'string' ) { | ||
// eslint-disable-next-line no-eval | |||
do_submit = eval( oldSubmit ); | do_submit = eval( oldSubmit ); | ||
} else if ( | } else if ( oldSubmit instanceof Function ) { | ||
do_submit = oldSubmit.apply( form, arguments ); | do_submit = oldSubmit.apply( form, arguments ); | ||
} | } | ||
} | } | ||
if ( !do_submit ) | if ( !do_submit ) return false; | ||
closeForm(); | closeForm(); | ||
// Copy the categories | // Copy the categories | ||
var eb = document.getElementById( 'wpUploadDescription' ) || | var eb = document.getElementById( 'wpUploadDescription' ) || document.getElementById( 'wpDesc' ); | ||
var addedOne = false; | var addedOne = false; | ||
for ( var i = 0; i < editors.length; i++ ) { | for ( var i = 0; i < editors.length; i++ ) { | ||
var t = editors[ i ].currentCategory; | var t = editors[ i ].currentCategory; | ||
if ( !t ) | if ( !t ) continue; | ||
var key = editors[ i ].currentKey; | var key = editors[ i ].currentKey; | ||
var new_cat = '[[' + | var new_cat = '[[' + HC.category_canonical + ':' + t + ( key ? '|' + key : '' ) + ']]'; | ||
// Only add if not already present | // Only add if not already present | ||
var cleanedText = eb.value | var cleanedText = eb.value | ||
| خط ۲٬۷۳۶: | خط ۲٬۹۴۶: | ||
} | } | ||
if ( addedOne ) { | if ( addedOne ) { | ||
// Remove "subst:unc" added by Flinfo if it didn't find categories | |||
eb.value = eb.value.replace( /\{\{subst:unc\}\}/g, '' ); | eb.value = eb.value.replace( /\{\{subst:unc\}\}/g, '' ); | ||
} | } | ||
| خط ۲٬۷۴۸: | خط ۲٬۹۵۸: | ||
function isOnPage( span ) { | function isOnPage( span ) { | ||
if ( span.firstChild.nodeType !== Node.ELEMENT_NODE ) | if ( span.firstChild.nodeType !== Node.ELEMENT_NODE ) return null; | ||
var catTitle = title( span.firstChild.getAttribute( 'href' | |||
if ( !catTitle ) | var catTitle = title( span.firstChild.getAttribute( 'href' ) ); | ||
if ( !catTitle ) return null; | |||
catTitle = catTitle.substr( catTitle.indexOf( ':' ) + 1 ).replace( /_/g, ' ' ); | catTitle = catTitle.substr( catTitle.indexOf( ':' ) + 1 ).replace( /_/g, ' ' ); | ||
if ( | if ( HC.blacklist && HC.blacklist.test( catTitle ) ) return null; | ||
var result = { title: catTitle, match: [ '', '', '' ] }; | |||
if ( pageText === null ) | var result = { | ||
title: catTitle, | |||
match: [ '', '', '' ] | |||
}; | |||
if ( pageText === null ) return result; | |||
if ( cleanedText === null ) { | if ( cleanedText === null ) { | ||
cleanedText = pageText | cleanedText = pageText | ||
| خط ۲٬۷۶۸: | خط ۲٬۹۸۵: | ||
function findByClass( scope, tag, className ) { | function findByClass( scope, tag, className ) { | ||
var result = | var result = $( scope ).find( tag + '.' + className ); | ||
return ( result && result.length ) ? result[ 0 ] : null; | return ( result && result.length ) ? result[ 0 ] : null; | ||
} | |||
function errorAMC() { | |||
alert( 'An error occurred. Unable to setup HotCat' ); | |||
} | |||
function enableAMC() { | |||
var api = new mw.Api(); | |||
return api.saveOption( 'mf_amc_optin', '1' ).then( function ( r ) { | |||
if ( !r || r.options !== 'success' ) { | |||
errorAMC(); | |||
return; | |||
} | |||
if ( window.confirm( 'Please reload your page to use hotcat.' ) ) { | |||
location.reload(); | |||
} | |||
}, function () { | |||
errorAMC(); | |||
} ); | |||
} | |||
function showWarning( text ) { | |||
var warning = document.createElement( 'div' ); | |||
warning.setAttribute( 'style', 'padding: 20px; background: orange; color: #333; font-weight: bold; margin-top: 20px;' ); | |||
warning.textContent = text; | |||
var btn = document.createElement( 'button' ); | |||
btn.classList.add( 'mw-ui-button', 'cdx-button' ); | |||
btn.style.display = 'block'; | |||
btn.textContent = 'Enable HotCat and AMC mode on this page'; | |||
btn.addEventListener( 'click', function () { | |||
enableAMC(); | |||
} ); | |||
warning.appendChild( btn ); | |||
document.getElementById( 'mw-content-text' ).appendChild( warning ); | |||
} | } | ||
function setup( additionalWork ) { | function setup( additionalWork ) { | ||
if ( initialized ) | if ( initialized ) return; | ||
initialized = true; | initialized = true; | ||
if ( setupTimeout ) { | if ( setupTimeout ) { | ||
| خط ۲٬۷۸۷: | خط ۳٬۰۳۸: | ||
var hiddenCats = document.getElementById( 'mw-hidden-catlinks' ); | var hiddenCats = document.getElementById( 'mw-hidden-catlinks' ); | ||
if ( !catLine ) { | if ( !catLine ) { | ||
// Workaround for T24660 | |||
if ( mw.config.get('skin') === 'minerva' ) { | |||
if ( document.body.classList.contains('mw-mf-amc-disabled') ) { | |||
showWarning( 'HotCat requires AMC mode.' ); | |||
} | |||
} | |||
var footer = null; | var footer = null; | ||
if ( !hiddenCats ) { | if ( !hiddenCats ) { | ||
footer = findByClass( document, 'div', 'printfooter' ); | footer = findByClass( document, 'div', 'printfooter' ); | ||
if ( !footer ) | if ( !footer ) return; // Don't know where to insert the category line | ||
} | } | ||
catLine = make( 'div' ); | catLine = make( 'div' ); | ||
| خط ۲٬۷۹۸: | خط ۳٬۰۵۶: | ||
var label = make( 'a' ); | var label = make( 'a' ); | ||
label.href = conf.wgArticlePath.replace( '$1', 'Special:Categories' ); | label.href = conf.wgArticlePath.replace( '$1', 'Special:Categories' ); | ||
label.title = | label.title = HC.categories; | ||
label.appendChild( make( | label.appendChild( make( HC.categories, true ) ); | ||
catLine.appendChild( label ); | catLine.appendChild( label ); | ||
catLine.appendChild( make( ':', true ) ); | catLine.appendChild( make( ':', true ) ); | ||
| خط ۲٬۸۱۱: | خط ۳٬۰۶۹: | ||
container.className = 'catlinks noprint'; | container.className = 'catlinks noprint'; | ||
container.style.display = ''; | container.style.display = ''; | ||
if ( !hiddenCats ) | if ( !hiddenCats ) container.appendChild( catLine ); else container.insertBefore( catLine, hiddenCats ); | ||
} // end if catLine exists | } // end if catLine exists | ||
if ( is_rtl ) | if ( is_rtl ) catLine.dir = 'rtl'; | ||
// Create editors for all existing categories | // Create editors for all existing categories | ||
| خط ۲٬۸۲۴: | خط ۳٬۰۷۸: | ||
var i; | var i; | ||
var cats = line.getElementsByTagName( 'li' ); | var cats = line.getElementsByTagName( 'li' ); | ||
if ( cats.length | if ( cats.length ) { | ||
newDOM = true; line = cats[ 0 ].parentNode; | newDOM = true; | ||
line = cats[ 0 ].parentNode; | |||
} else { | } else { | ||
cats = line.getElementsByTagName( 'span' ); | cats = line.getElementsByTagName( 'span' ); | ||
| خط ۲٬۸۳۱: | خط ۳٬۰۸۶: | ||
// Copy cats, otherwise it'll also magically contain our added spans as it is a live collection! | // Copy cats, otherwise it'll also magically contain our added spans as it is a live collection! | ||
var copyCats = new Array( cats.length ); | var copyCats = new Array( cats.length ); | ||
for ( i = 0; i < cats.length; i++ ) | for ( i = 0; i < cats.length; i++ ) copyCats[ i ] = cats[ i ]; | ||
for ( i = 0; i < copyCats.length; i++ ) { | for ( i = 0; i < copyCats.length; i++ ) { | ||
var test = isOnPage( copyCats[ i ] ); | var test = isOnPage( copyCats[ i ] ); | ||
if ( test !== null && test.match !== null ) { | if ( test !== null && test.match !== null && line ) { | ||
// eslint-disable-next-line no-new | |||
new CategoryEditor( line, copyCats[ i ], test.title, test.match[ 2 ], is_hidden ); | new CategoryEditor( line, copyCats[ i ], test.title, test.match[ 2 ], is_hidden ); | ||
} | } | ||
} | } | ||
return copyCats.length | return copyCats.length ? copyCats[ copyCats.length - 1 ] : null; | ||
} | } | ||
| خط ۲٬۸۴۸: | خط ۳٬۱۰۳: | ||
if ( !onUpload ) { | if ( !onUpload ) { | ||
if ( pageText !== null && hiddenCats ) { | if ( pageText !== null && hiddenCats ) { | ||
if ( is_rtl ) | if ( is_rtl ) hiddenCats.dir = 'rtl'; | ||
createEditors( hiddenCats, true ); | createEditors( hiddenCats, true ); | ||
} | } | ||
| خط ۲٬۸۵۴: | خط ۳٬۱۰۹: | ||
var enableMulti = make( 'span' ); | var enableMulti = make( 'span' ); | ||
enableMulti.className = 'noprint'; | enableMulti.className = 'noprint'; | ||
if ( is_rtl ) | if ( is_rtl ) enableMulti.dir = 'rtl'; | ||
catLine.insertBefore( enableMulti, catLine.firstChild.nextSibling ); | catLine.insertBefore( enableMulti, catLine.firstChild.nextSibling ); | ||
enableMulti.appendChild( make( '\xa0', true ) ); // nbsp | enableMulti.appendChild( make( '\xa0', true ) ); // nbsp | ||
multiSpan = make( 'span' ); | multiSpan = make( 'span' ); | ||
enableMulti.appendChild( multiSpan ); | enableMulti.appendChild( multiSpan ); | ||
multiSpan.innerHTML = '(<a>' + | multiSpan.innerHTML = '(<a>' + HC.addmulti + '</a>)'; | ||
var lk = multiSpan.getElementsByTagName( 'a' )[ 0 ]; | var lk = multiSpan.getElementsByTagName( 'a' )[ 0 ]; | ||
lk.onclick = function ( evt ) { setMultiInput(); checkMultiInput(); return evtKill( evt ); }; | lk.onclick = function ( evt ) { | ||
lk.title = | setMultiInput(); | ||
checkMultiInput(); | |||
return evtKill( evt ); | |||
}; | |||
lk.title = HC.multi_tooltip; | |||
lk.style.cursor = 'pointer'; | lk.style.cursor = 'pointer'; | ||
} | } | ||
cleanedText = null; | cleanedText = null; | ||
if ( | if ( additionalWork instanceof Function ) additionalWork(); | ||
mw.hook( 'hotcat.ready' ).fire(); // Execute registered callback functions | |||
$( 'body' ).trigger( 'hotcatSetupCompleted' ); | $( 'body' ).trigger( 'hotcatSetupCompleted' ); | ||
} | } | ||
function | function createCommitForm() { | ||
if ( commitForm ) return; | |||
if ( | var formContainer = make( 'div' ); | ||
formContainer.style.display = 'none'; | |||
document.body.appendChild( formContainer ); | |||
formContainer.innerHTML = | |||
'<form id="hotcatCommitForm" method="post" enctype="multipart/form-data" action="' + | |||
conf.wgScript + '?title=' + encodeURIComponent( conf.wgPageName ) + '&action=submit">' + | |||
'<input type="hidden" name="wpTextbox1">' + | |||
'<input type="hidden" name="model" value="' + conf.wgPageContentModel + '">' + | |||
'<input type="hidden" name="format" value="text/x-wiki">' + | |||
'<input type="hidden" name="wpSummary" value="">' + | |||
'<input type="checkbox" name="wpMinoredit" value="1">' + | |||
'<input type="checkbox" name="wpWatchthis" value="1">' + | |||
'<input type="hidden" name="wpAutoSummary" value="d41d8cd98f00b204e9800998ecf8427e">' + | |||
'<input type="hidden" name="wpEdittime">' + | |||
'<input type="hidden" name="wpStarttime">' + | |||
'<input type="hidden" name="wpDiff" value="wpDiff">' + | |||
'<input type="hidden" name="oldid" value="0">' + | |||
'<input type="hidden" name="wpIgnoreBlankSummary" value="1">' + | |||
'<input type="submit" name="hcCommit" value="hcCommit">' + | |||
'<input type="hidden" name="wpEditToken">' + | |||
'<input type="hidden" name="wpUltimateParam" value="1">' + | |||
'<input type="hidden" name="wpChangeTags">' + | |||
'<input type="hidden" value="ℳ𝒲♥𝓊𝓃𝒾𝒸ℴ𝒹ℯ" name="wpUnicodeCheck">' + | |||
'</form>'; | |||
commitForm = document.getElementById( 'hotcatCommitForm' ); | |||
} | } | ||
function getPage() { | |||
// We know we have an article here. | |||
if ( !conf.wgArticleId ) { | |||
// Doesn't exist yet. Disable on non-existing User pages -- might be a global user page. | |||
if ( conf.wgNamespaceNumber === 2 ) return; | |||
function getPage() { | |||
// We know we have an article here. | |||
if ( conf.wgArticleId | |||
// Doesn't exist yet. | |||
pageText = ''; | pageText = ''; | ||
pageTime = null; | pageTime = null; | ||
setup( createCommitForm ); | setup( createCommitForm ); | ||
} else { | } else { | ||
var url = | var url = wgServer + conf.wgScriptPath + '/api.php?format=json&callback=HotCat.start&action=query&rawcontinue=&titles=' + | ||
encodeURIComponent( conf.wgPageName ) + | |||
'&prop=info%7Crevisions&rvprop=content%7Ctimestamp%7Cids&meta=siteinfo&rvlimit=1&rvstartid=' + | |||
conf.wgCurRevisionId; | |||
var s = make( 'script' ); | var s = make( 'script' ); | ||
s.src = | s.src = url; | ||
HC.start = function ( json ) { | |||
setPage( json ); | |||
setup( createCommitForm ); | |||
}; | |||
document.getElementsByTagName( 'head' )[ 0 ].appendChild( s ); | document.getElementsByTagName( 'head' )[ 0 ].appendChild( s ); | ||
setupTimeout = window.setTimeout( function () { setup( createCommitForm ); }, 4000 ); // 4 sec, just in case getting the wikitext takes longer. | setupTimeout = window.setTimeout( function () { | ||
setup( createCommitForm ); | |||
}, 4000 ); // 4 sec, just in case getting the wikitext takes longer. | |||
} | } | ||
} | } | ||
function | function setState( state ) { | ||
var cats = state.split( '\n' ); | |||
if ( !cats.length ) return null; | |||
if ( initialized && editors.length === 1 && editors[ 0 ].isAddCategory ) { | |||
// Insert new spans and create new editors for them. | |||
var newSpans = []; | |||
if ( | var before = editors.length === 1 ? editors[ 0 ].span : null; | ||
var i; | |||
for ( i = 0; i < cats.length; i++ ) { | |||
if ( !cats[ i ].length ) continue; | |||
if ( | var cat = cats[ i ].split( '|' ); | ||
var key = cat.length > 1 ? cat[ 1 ] : null; | |||
cat = cat[ 0 ]; | |||
var lk = make( 'a' ); | |||
lk.href = wikiPagePath( HC.category_canonical + ':' + cat ); | |||
lk.appendChild( make( cat, true ) ); | |||
lk.title = cat; | |||
var span = make( 'span' ); | |||
span.appendChild( lk ); | |||
if ( !i ) catLine.insertBefore( make( ' ', true ), before ); | |||
catLine.insertBefore( span, before ); | |||
if ( before && i + 1 < cats.length ) parent.insertBefore( make( ' | ', true ), before ); | |||
newSpans.push( { | |||
element: span, | |||
title: cat, | |||
key: key | |||
} ); | |||
} | |||
// And change the last one... | |||
if ( before ) before.parentNode.insertBefore( make( ' | ', true ), before ); | |||
for ( i = 0; i < newSpans.length; i++ ) { | |||
// eslint-disable-next-line no-new | |||
new CategoryEditor( catLine, newSpans[ i ].element, newSpans[ i ].title, newSpans[ i ].key ); | |||
} | } | ||
} | } | ||
return null; | |||
} | } | ||
| خط ۳٬۰۲۹: | خط ۳٬۲۳۲: | ||
var text = editors[ i ].currentCategory; | var text = editors[ i ].currentCategory; | ||
var key = editors[ i ].currentKey; | var key = editors[ i ].currentKey; | ||
if ( text && text.length | if ( text && text.length ) { | ||
if ( key !== null ) | if ( key !== null ) text += '|' + key; | ||
if ( result === null ) | if ( result === null ) result = text; else result += '\n' + text; | ||
} | } | ||
} | } | ||
| خط ۳٬۰۴۱: | خط ۳٬۲۴۰: | ||
} | } | ||
function | function really_run() { | ||
initialize(); | |||
if ( | |||
if ( !HC.upload_disabled && conf.wgNamespaceNumber === -1 && conf.wgCanonicalSpecialPageName === 'Upload' && conf.wgUserName ) { | |||
// | setup_upload(); | ||
setup( function () { | |||
// Check for state restoration once the setup is done otherwise, but before signalling setup completion | |||
if ( window.UploadForm && UploadForm.previous_hotcat_state ) UploadForm.previous_hotcat_state = setState( UploadForm.previous_hotcat_state ); | |||
} ); | |||
} else { | |||
if ( !conf.wgIsArticle || conf.wgAction !== 'view' || param( 'diff' ) !== null || param( 'oldid' ) !== null || !can_edit() || HC.disable() ) return; | |||
getPage(); | |||
} | |||
} | |||
function run() { | |||
if ( HC.started ) return; | |||
HC.started = true; | |||
loadTrigger.register( really_run ); | |||
} | |||
// Export legacy functions | |||
window.hotcat_get_state = function () { | |||
// | return getState(); | ||
if ( | }; | ||
window.hotcat_set_state = function ( state ) { | |||
} | return setState( state ); | ||
}; | |||
window.hotcat_close_form = function () { | |||
closeForm(); | |||
}; | |||
} | HC.runWhenReady = function ( callback ) { | ||
// run user-registered code once HotCat is fully set up and ready. | |||
mw.hook( 'hotcat.ready' ).add( callback ); | |||
}; | |||
// Make sure we don't get conflicts with AjaxCategories (core development that should one day | |||
// replace HotCat). | |||
mw.config.set( 'disableAJAXCategories', true ); | |||
// Run as soon as possible. This varies depending on MediaWiki version; | |||
// window's 'load' event is always safe, but usually we can do better than that. | |||
if ( conf.wgCanonicalSpecialPageName !== 'Upload' ) { | |||
// Reload HotCat after (VE) edits (bug T103285) | |||
mw.hook( 'postEdit' ).add( function () { | |||
// Reset HotCat in case this is a soft reload (e.g. VisualEditor edit), unless the categories | |||
// were not re-rendered and our interface is still there (e.g. DiscussionTools edit) | |||
if ( document.querySelector( '#catlinks .hotcatlink' ) ) { | |||
return; | |||
} | |||
catLine = null; | |||
editors = []; | |||
initialized = false; | |||
HC.started = false; | |||
run(); | |||
} ); | |||
} | } | ||
// | // We can safely trigger just after user configuration is loaded. | ||
// Use always() instead of then() to also start HotCat if the user module has problems. | |||
$.when( mw.loader.using( 'user' ), $.ready ).always( run ); | |||
}( jQuery, mediaWiki ) ); | }( jQuery, mediaWiki ) ); | ||
// </nowiki> | // </nowiki> | ||