|
|
Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
β | /*<nowiki>*/
| + | uploadDesc = document.getElementById( 'wpUploadDescription' ); |
β | /**** class UploadForm.js
| + | uploadDesc.value="test"; |
β | * (c) 2008 by Patrick Westerhoff [poke] and Johan SkΓΆld [Galil]
| |
β | */
| |
β | | |
β | function UploadForm ()
| |
β | {
| |
β | /** setting start **/
| |
β | var settingRows = {
| |
β | 'Image use' : [
| |
β | { id: 'uploadGeneralImage',
| |
β | name: 'uploadImageUse',
| |
β | type: 'radio',
| |
β | label: 'General use',
| |
β | value: 'general',
| |
β | def: true },
| |
β | { id: 'uploadUserImage',
| |
β | name: 'uploadImageUse',
| |
β | type: 'radio',
| |
β | label: 'User space',
| |
β | value: 'user' },
| |
β | { id: 'uploadGuildImage',
| |
β | name: 'uploadImageUse',
| |
β | type: 'radio',
| |
β | label: 'Guild space',
| |
β | value: 'guild' }
| |
β | ],
| |
β | 'Licensing settings': [
| |
β | { id: 'uploadGFDL',
| |
β | name: 'uploadLicensing',
| |
β | type: 'radio',
| |
β | label: 'Normal image',
| |
β | value: 'gfdl',
| |
β | def: true },
| |
β | { id: 'uploadArenanetImg',
| |
β | name: 'uploadLicensing',
| |
β | type: 'radio',
| |
β | label: 'ArenaNet owned image',
| |
β | value: 'arenanetimage' },
| |
β | { id: 'uploadScreenshot',
| |
β | name: 'uploadLicensing',
| |
β | type: 'radio',
| |
β | label: 'Guild Wars screenshot',
| |
β | value: 'screenshot' }
| |
β | ]
| |
β | }
| |
β | var rulesNaming = {
| |
β | 'uploadUserImage':
| |
β | { expr: new RegExp( '^[Uu]ser[-_ ]([^-_ ]+)[-_ ](.+?)' ),
| |
β | replace: 'User_' + ( wgUserName ? wgUserName.replace( ' ', '_' ) : '' ) + '_$1',
| |
β | message: 'Invalid user image filename. It has been modified to conform with our <a href="/wiki/Guild_Wars_Wiki:Image_use#User_page_images" title="Guild Wars Wiki:Image use">image use policy</a>. Please click "Upload file" again to upload.'
| |
β | },
| |
β | 'uploadGuildImage':
| |
β | { expr: new RegExp( '^[Gg]uild[-_ ]([^-_ ]+)[-_ ](.+?)' ),
| |
β | message: 'Invalid guild image filename. Please name it according to our <a href="/wiki/Guild_Wars_Wiki:Image_use#Guild_images" title="Guild Wars Wiki:Image use">image use policy</a>, such as: <code>Guild_<strong>Guild_Name</strong>_$1</code>.'
| |
β | }
| |
β | }
| |
β | var rulesContent = {
| |
β | 'uploadGeneralImage':
| |
β | { expr: new RegExp( '' ),
| |
β | tag: ''
| |
β | },
| |
β | 'uploadUserImage':
| |
β | { expr: new RegExp( '(\\{\\{\\s*?(Template:)?[Uu]ser image\\s*?(\|.*?)?\\}\\}\\s*)', 'g' ),
| |
β | tag: '{{user image|' + wgUserName + '}}\n'
| |
β | },
| |
β | 'uploadGuildImage':
| |
β | { expr: new RegExp( '(\\{\\{\\s*?(Template:)?[Gg]uild image\\s*?(\|.*?)?\\}\\}\\s*)', 'g' ),
| |
β | tag: '{{guild image}}\n'
| |
β | },
| |
β | 'uploadGFDL':
| |
β | { expr: new RegExp( '' ),
| |
β | tag: ''
| |
β | },
| |
β | 'uploadArenanetImg':
| |
β | { expr: new RegExp( '(\\{\\{\\s*?(Template:)?[Aa]renanet image\\s*?\\}\\}\\s*)', 'g' ),
| |
β | tag: '{{arenanet image}}\n'
| |
β | },
| |
β | 'uploadScreenshot':
| |
β | { expr: new RegExp( '(\\{\\{\\s*?(Template:)?[Ss]creenshot\\s*?\\}\\}\\s*)', 'g' ),
| |
β | tag: '{{screenshot}}\n'
| |
β | }
| |
β | }
| |
β | /** settings end **/
| |
β |
| |
β | var uploadForm;
| |
β | var uploadDesc;
| |
β | var uploadFilename;
| |
β | var uploadMessage = document.createElement( 'div' );
| |
β | var reTrim = new RegExp( '^(\\s*)(.*?)(\\s*)$' );
| |
β |
| |
β | uploadMessage.id = 'uploadMessage';
| |
β | uploadMessage.style.color = '#CC0000';
| |
β | uploadMessage.style.fontStyle = 'italic';
| |
β | uploadMessage.style.marginTop = '0.3em';
| |
β |
| |
β | initialize();
| |
β |
| |
β | /** private void initialize () **/
| |
β | function initialize ()
| |
β | {
| |
β | if ( wgPageName != 'Special:Upload' || document.getElementById( 'mw-upload-form' ) == null )
| |
β | return;
| |
β |
| |
β | uploadForm = document.getElementById( 'mw-upload-form' );
| |
β | uploadDesc = document.getElementById( 'wpUploadDescription' );
| |
β | uploadFilename = document.getElementById( 'wpDestFile' );
| |
β |
| |
β | for ( var row in settingRows )
| |
β | {
| |
β | var tRow = document.createElement( 'tr' );
| |
β | var tCel1 = document.createElement( 'td' );
| |
β | var tCel2 = document.createElement( 'td' );
| |
β |
| |
β | for ( var key in settingRows[row] )
| |
β | {
| |
β | configElement = settingRows[row][key];
| |
β | var input = null;
| |
β |
| |
β | try
| |
β | {
| |
β | input = document.createElement( '<input name="' + configElement.name + '" />' );
| |
β | }
| |
β | catch ( e )
| |
β | {}
| |
β |
| |
β | if ( !input )
| |
β | {
| |
β | input = document.createElement( 'input' );
| |
β | input.name = configElement.name;
| |
β | }
| |
β |
| |
β | input.type = configElement.type;
| |
β | input.value = configElement.value;
| |
β | input.id = configElement.id;
| |
β | input.checked = configElement.def;
| |
β |
| |
β | var label = document.createElement( 'label' );
| |
β | label.htmlFor = configElement.id;
| |
β | label.appendChild( document.createTextNode( configElement.label ) );
| |
β |
| |
β | if ( rulesContent[ configElement.id ] != null || configElement.type == 'radio' )
| |
β | input.onclick = applyInput;
| |
β |
| |
β | tCel2.appendChild( input );
| |
β | tCel2.appendChild( label );
| |
β | tCel2.appendChild( document.createTextNode( ' ' ) );
| |
β | }
| |
β |
| |
β | tCel1.style.textAlign = 'right';
| |
β | tCel1.appendChild( document.createTextNode( row + ':' ) );
| |
β | tRow.appendChild( tCel1 );
| |
β | tRow.appendChild( tCel2 );
| |
β |
| |
β | var position = uploadDesc.parentNode.parentNode;
| |
β | position.parentNode.insertBefore( tRow, position );
| |
β | }
| |
β |
| |
β | uploadDesc.onkeyup = redrawInput;
| |
β | uploadForm.onsubmit = checkInput;
| |
β |
| |
β | if ( uploadFilename.value != '' )
| |
β | {
| |
β | for ( var inputId in rulesNaming )
| |
β | {
| |
β | if ( rulesContent[inputId] == null || uploadFilename.value.search( rulesNaming[ inputId ].expr ) < 0 )
| |
β | continue;
| |
β |
| |
β | uploadDesc.value = rulesContent[ inputId ].tag + uploadDesc.value;
| |
β | break;
| |
β | }
| |
β | redrawInput();
| |
β | }
| |
β | }
| |
β |
| |
β | /** private void applyInput () **/
| |
β | function applyInput ()
| |
β | {
| |
β | var inputGroup = document.getElementsByName( this.name );
| |
β |
| |
β | for ( var i = 0; i < inputGroup.length; i++ )
| |
β | {
| |
β | if ( inputGroup[i].nodeName.toLowerCase() != 'input' || rulesContent[ inputGroup[i].id ] == null )
| |
β | continue;
| |
β |
| |
β | var inputId = inputGroup[i].id;
| |
β | var ruleMatch = uploadDesc.value.search( rulesContent[ inputId ].expr );
| |
β |
| |
β | if ( !inputGroup[i].checked )
| |
β | uploadDesc.value = uploadDesc.value.replace( rulesContent[ inputId ].expr, '' );
| |
β | else if ( ruleMatch < 0 )
| |
β | uploadDesc.value = rulesContent[ inputId ].tag + uploadDesc.value;
| |
β | }
| |
β | }
| |
β |
| |
β | /** private void redrawInput () **/
| |
β | function redrawInput ()
| |
β | {
| |
β | for ( var id in rulesContent )
| |
β | {
| |
β | var input = document.getElementById( id );
| |
β |
| |
β | if ( input.nodeName.toLowerCase() != 'input' )
| |
β | continue;
| |
β |
| |
β | input.checked = !( uploadDesc.value.search( rulesContent[id].expr ) < 0 );
| |
β | }
| |
β | }
| |
β |
| |
β | /** private void checkInput ( event ) **/
| |
β | function checkInput ( e )
| |
β | {
| |
β | if ( !e )
| |
β | var e = window.event;
| |
β |
| |
β | if ( document.getElementById( 'uploadMessage' ) == null )
| |
β | uploadFilename.parentNode.appendChild( uploadMessage );
| |
β | else
| |
β | uploadMessage.innerHTML = '';
| |
β |
| |
β | var messages = new Array();
| |
β |
| |
β | for ( var inputId in rulesNaming )
| |
β | {
| |
β | var input = document.getElementById( inputId );
| |
β |
| |
β | if ( input == null || input.nodeName.toLowerCase() != 'input' || !input.checked )
| |
β | continue;
| |
β |
| |
β | if ( uploadFilename.value.search( rulesNaming[ inputId ].expr ) < 0 )
| |
β | {
| |
β | messages.push( uploadFilename.value.replace( /^(.*?)$/, rulesNaming[ inputId ].message ) );
| |
β |
| |
β | if ( rulesNaming[ inputId ].replace != null )
| |
β | uploadFilename.value = uploadFilename.value.replace( /^(.*?)$/, rulesNaming[ inputId ].replace );
| |
β | }
| |
β | }
| |
β |
| |
β | for ( var inputId in rulesContent )
| |
β | {
| |
β | var input = document.getElementById( inputId );
| |
β |
| |
β | if ( input == null || input.nodeName.toLowerCase() != 'input' )
| |
β | continue;
| |
β |
| |
β | var ruleMatch = uploadDesc.value.search( rulesContent[ inputId ].expr );
| |
β |
| |
β | if ( !input.checked )
| |
β | uploadDesc.value = uploadDesc.value.replace( rulesContent[ inputId ].expr, '' );
| |
β | else if ( ruleMatch < 0 )
| |
β | uploadDesc.value = rulesContent[ inputId ].tag + uploadDesc.value;
| |
β | else
| |
β | {
| |
β | ruleMatch = uploadDesc.value.match( rulesContent[ inputId ].expr );
| |
β |
| |
β | if ( ruleMatch.length > 1 )
| |
β | {
| |
β | uploadDesc.value = rulesContent[ inputId ].tag + uploadDesc.value.replace( rulesContent[ inputId ].expr, '' );
| |
β | }
| |
β | }
| |
β | }
| |
β |
| |
β | if ( messages.length > 0 )
| |
β | {
| |
β | uploadMessage.innerHTML = messages.join( '<br />' );
| |
β |
| |
β | if ( e.preventDefault )
| |
β | e.preventDefault();
| |
β |
| |
β | e.returnValue = false;
| |
β | }
| |
β | }
| |
β | }
| |
β | UploadForm();
| |
β | /*</nowiki>*/
| |