MediaWiki:DRN-wizard.js#L-189

//

// 2020-03-09 - deconverted from Gadget, is only used on 1 page and is now being called direct from Wikipedia:Dispute resolution noticeboard/request

/**

* This is the main object that holds the state for everything

*/

function drw() {

//Keep track of what step we are on

this.wizard_step = 0;

//Has the admin attempted to resolve this on the talk page

this.talkpage = false;

//Title of Article

this.article_title = '';

//Description of dispute

this.dispute_description = '';

//Involved users

this.involved_users = [mw.config.get( 'wgUserName' )];

//Previous forums

this.previous_forums = '';

//Desired Outcome

this.desired_outcome = '';

//Page where the report will be posted

this.post_link = '';

// Draw text box

this.drawTitleInput = function() {

//Appends to $( '#drwContent1' )

$( '#drwContent1' ).append( '

Location of dispute

' );

$( '#drwContent1' ).append( '

Please provide the name of the article or page where the dispute is located.
For example, if the dispute was on the article Australia, enter in Australia in the box, not Australia or https://en.wikipedia.org/wiki/Australia' );

var inputbox = $( document.createElement( 'input' ) );

inputbox.attr( {

type: 'text',

name: 'article_title',

value: this.article_title

} );

inputbox.change( function() {

gDRW.article_title = this.value.replace( 'https://', 'http://' ).replace( 'http://en.wikipedia.org/wiki/', ).replace( '_', ' ' ).replace( '', ).replace( '', '' );

} );

$( '#drwContent1' ).append( inputbox );

};

// Draw description textarea

this.drawDescriptionInput = function() {

//Appends to $( '#drwContent1' )

$( '#drwContent1' ).append( '

Dispute overview

' );

$( '#drwContent1' ).append( '

Can you give us an explanation of what is going on? What is the issue you are bringing to dispute resolution?

' );

var desc = $( document.createElement( 'textarea' ) );

desc.attr( {

rows: 6,

cols: 60,

maxlength: 2000

} );

desc.text( this.dispute_description );

desc.change( function() {

gDRW.dispute_description = this.value;

} );

desc.on( 'keyup', function() {

$( '#taCount' ).text( '' + this.value.length + ' / 2000' );

} );

$( '#drwContent1' ).append( desc );

$( '#drwContent1' ).append( $( '

' + this.dispute_description.length + ' / 2000

' ) );

};

// Involved users

this.drawUserInput = function() {

//Appends to $( '#drwContent1' )

$( '#drwContent1' ).append( '

Users involved

' );

$( '#drwContent1' ).append( '

Who else is involved in the dispute? Enter them into the below box, without the User:, separated by commas: e.g. Example, Example2. (Please remember to notify them of this discussion)

' );

var inputbox = $( document.createElement( 'input' ) );

inputbox.attr( {

type: 'text',

name: 'involved_users',

value: this.involved_users.join( ', ' )

} );

inputbox.change( function() {

gDRW.involved_users = this.value.split( ',' ).map( function ( involved_user ) { return involved_user.trim(); } );

} );

$( '#drwContent1' ).append( inputbox );

};

// Draw previous forums

this.drawPreviousInput = function() {

//Appends to $( '#drwContent1' )

$( '#drwContent1' ).append( '

Resolving the dispute

' );

$( '#drwContent1' ).append( '

What other steps have you tried to resolve the dispute so far. Please provide a link to where these discussions have occurred, separated by a comma or new line. For example:
' );

$( '#drwContent1' ).append('

' );+

$( '#drwContent1' ).append( 'At a minimum, recent extensive discussion needs to have taken place on the talk page of the page in question.
Note: If a suitable discussion link is not provided, your request may be automatically closed.

' );

var desc = $( document.createElement( 'textarea' ) );

desc.attr( {

rows: 3,

cols: 60,

maxlength: 500

} );

desc.text( this.previous_forums );

desc.change( function() {

gDRW.previous_forums = this.value;

} );

desc.on( 'keyup', function() {

$( '#pcCount' ).text( '' + this.value.length + ' / 500' );

} );

$( '#drwContent1' ).append( desc );

$( '#drwContent1' ).append( $( '

' + this.previous_forums.length + ' / 500

' ) );

};

// Draw outcome textarea

this.drawOutcomeInput = function() {

//Appends to $( '#drwContent1' )

$( '#drwContent1' ).append( '

How do you think we can help resolve the dispute?

' );

var desc = $( document.createElement( 'textarea' ) );

desc.attr( {

rows: 5,

cols: 60,

maxlength: 500

} );

desc.text( this.desired_outcome );

desc.change( function() {

gDRW.desired_outcome = this.value;

} );

desc.on( 'keyup', function() {

$( '#ocCount' ).text( '' + this.value.length + ' / 500' );

} );

$( '#drwContent1' ).append( desc );

$( '#drwContent1' ).append( $( '

' + this.desired_outcome.length + ' / 500

' ) );

};

// Draw the summary content

this.drawDRWSummary = function() {

//Appends to $( '#drwContent1' )

//$( '#drwContent1' ).append( list );

//Article Title

$( '#drwContent1' ).append( '

Location of dispute

' );

$( '#drwContent1' ).append( $( '

' ).text( this.article_title ) );

//Dispute Description

$( '#drwContent1' ).append( '

Dispute overview

' );

$( '#drwContent1' ).append( $( '

' ).text( this.dispute_description ) );

//Users involved

$( '#drwContent1' ).append( '

Users involved

' );

$( '#drwContent1' ).append( $( '

' ).text( this.involved_users.join(', ') ) );

//Previous forums

$( '#drwContent1' ).append( '

Resolving the dispute

' );

$( '#drwContent1' ).append( '

Previous steps to resolve the dispute

' );

$( '#drwContent1' ).append( $( '

' ).text( this.previous_forums ) );

//Desired Outcome

$( '#drwContent1' ).append( '

How you think we can help resolve the dispute?

' );

$( '#drwContent1' ).append( $( '

' ).text( this.desired_outcome ) );

};

// Generate a WikiText string, representing the report.

// Returns a string of wikitext

this.getWikitextReport = function() {

//Returns string of wikitext for submission to DR page

var report = "{{DR case status}}\n{{subst:DNAU|28}}\n{{drn filing editor|{{subst:REVISIONUSER}}|~~~~~}}\n\n";

//On Talk Page

report += "Have you discussed this on a talk page?\n";

report += '\n' + ( ( this.talkpage ) ? 'Yes, I have discussed this issue on a talk page already.' : 'no' ) + '\n\n';

//Article Title

report += "Location of dispute\n";

var articleArray = this.article_title.split( ',' );

for ( var articleIndex = 0; articleIndex < articleArray.length; articleIndex++ )

{

report += '* {{pagelinks|' + articleArray[ articleIndex ] + '}}\n';

}

//Involved users

report += "Users involved\n";

var userIndex;

for ( userIndex = 0; userIndex < this.involved_users.length; userIndex++ )

{

var user = this.involved_users[ userIndex ];

user = user.trim();

if ( user ) {

report += '* {{User|' + user + '}}\n';

}

}

//Dispute Description

report += "Dispute overview\n";

report += '\n'+ this.dispute_description + '\n\n';

//Previous forums

report += "How have you tried to resolve this dispute before coming here?\n";

report += '\n'+ this.previous_forums + '\n\n';

//Desired Outcome

report += "How do you think we can help resolve the dispute?\n";

report += '\n' + this.desired_outcome + '\n\n';

//User statements

var currentUser = mw.config.get( 'wgUserName' );

for ( userIndex = 0; userIndex < this.involved_users.length; userIndex++ ) {

var user = this.involved_users[ userIndex ];

if ( user != currentUser ) {

report += '==== Summary of dispute by ' + user + " ====\n

Please keep it brief - less than 2000 characters if possible, it helps us help you quicker.
\n\n";

}

}

//Discussion

report += '=== ' + this.article_title + " discussion ===\n

Please keep discussion to a minimum before being opened by a volunteer. Continue on article talk page if necessary.
";

return report;

};

// Returns an html string, representing the progress bar, based on the

// objects state.

this.getProgressBar = function() {

var s1_active = ( this.wizard_step == 1 ) ? ' pr-active' : '';

var s2_active = ( this.wizard_step == 2 ) ? ' pr-active' : '';

var s3_active = ( this.wizard_step == 3 ) ? ' pr-active' : '';

var s4_active = ( this.wizard_step == 4 ) ? ' pr-active' : '';

var signupbox = '

    ';

    signupbox += '

  • 1Preliminary
  • ';

    signupbox += '

  • ';

    signupbox += '

  • 2Type of dispute
  • ';

    signupbox += '

  • ';

    signupbox += '

  • 3Description
  • ';

    signupbox += '

  • ';

    signupbox += '

  • 4Summary
  • ';

    signupbox += '

  • ';

    signupbox += '

';

return signupbox;

};

this.getArticleTitle = function() {

return this.article_title;

};

this.getDisputeDescription = function() {

return this.dispute_description;

};

}

/**

* The various "show...()" functions display each of the 'screens' in the wizard

*/

function showStep1() {

gDRW.wizard_step = 1;

$( '#drwProgressBar' ).html( gDRW.getProgressBar() );

$( '#drwContent1' ).html(

'

Request dispute resolution

' +

'

' +

'Hi there. This form can be used to file a request at the dispute resolution noticeboard, a venue for resolving disputes over article content between two or more editors. ' +

'It is unable to address disputes primarily concerning user conduct - they should be discussed with the users involved first, and failing that directed here. ' +

'If you have any questions please ask one of our volunteers for guidance.' +

'

In brief: dispute resolution should be used when you:

' +

'

    ' +

    '

  • Have a dispute with another editor and need help resolving it
  • ' +

    '

  • Are willing to discuss the issues in a calm and civil manner
  • ' +

    '

  • Are open to the idea of compromising with the other editors to resolve the dispute
  • ' +

    '

' +

'

This process can:

' +

'

    ' +

    '

  • Help provide suggestions on content
  • ' +

    '

  • Provide editors with guidance on applicable policies and guidelines to the dispute
  • ' +

    '

  • Mediate discussions and assist editors work towards a consensus on the disputed content
  • ' +

    '

  • Provide a structured environment with oversight, to allow editors to work together with experienced input
  • ' +

    '

' +

'

This process cannot:

' +

'

    ' +

    '

  • Block other users from editing (either everywhere or specific pages)
  • ' +

    '

  • Remove content that you don\'t like from articles
  • ' +

    '

  • Force another editor to do something
  • ' +

    '

  • Address disputes that are currently under discussion somewhere else (such as Requests for Comment or Arbitration)
  • ' +

    '

    ' +

    '

    Has this issue been discussed extensively on the article talk page? (If you don\'t know what an article talk page is, answer "Not yet".)

    '

    );

    var buttons = 'Yes, it has.';

    buttons += ' Not yet.';

    $( '#drwButtons' ).html( buttons );

    $( '#yesContentClickButton' ).click( yesContentClick );

    $( '#showCancelButton' ).click( showCancel );

    }

    function showStep2() {

    gDRW.wizard_step = 2;

    $( '#drwProgressBar' ).html( gDRW.getProgressBar() );

    $( '#drwContent1' ).html(

    '

    Types of dispute

    ' +

    '

    This forum is designed to only assist with issues regarding the content of articles and isn\'t able to assist with concerns about other editors\' behaviour. Is this an issue only about another editor\'s behaviour?.

    '

    );

    var buttons = 'Yes, it is about another user.';

    buttons += ' No, it is not.';

    $( '#drwButtons' ).html( buttons );

    $( '#yesConductClickButton' ).click( showConductCancel );

    $( '#showContentDisputeForm' ).click( showStep3 );

    }

    function showStep3( errorMsg ) {

    gDRW.wizard_step = 3;

    $( '#drwProgressBar' ).html( gDRW.getProgressBar() );

    var intro = '';

    if ( typeof errorMsg === 'string' ) {

    intro = '

    ' + errorMsg + '

    ';

    }

    intro +=

    '

    ' +

    'Here, briefly describe the current situation - where the dispute is happening, what is the dispute and what are you hoping to get out of dispute resolution. ' +

    '(Basically, how can we help resolve the issue?)' +

    '

    ' +

    '

    ' +

    'Take note of the character limits as they are there to help focus the discussion.' +

    '

    ';

    $( '#drwContent1' ).html( intro );

    gDRW.drawTitleInput();

    gDRW.drawDescriptionInput();

    gDRW.drawUserInput();

    gDRW.drawPreviousInput();

    gDRW.drawOutcomeInput();

    var buttons = 'Back';

    buttons += ' Cancel';

    buttons += ' Next';

    $( '#drwButtons' ).html( buttons );

    $( '#showStep1Button' ).click( showStep1 );

    $( '#showCancelButton' ).click( showCancel );

    $( '#showStep4Button' ).click( showStep4 );

    }

    function showStep4() {

    var inputErrors = [];

    //Check that vars were filled

    if ( gDRW.article_title === '' ) {

    inputErrors.push( 'Location of dispute' );

    }

    if ( gDRW.dispute_description === '' ) {

    inputErrors.push( 'Dispute overview' );

    }

    if ( gDRW.previous_forums === '' ) {

    inputErrors.push( 'Previous steps' );

    }

    if ( gDRW.desired_outcome === '' ) {

    inputErrors.push( 'Desired outcome' );

    }

    if ( inputErrors.length > 0 ) {

    return showStep3( 'All fields are required. Missing values for: ' + inputErrors.join( ', ' ) );

    }

    gDRW.wizard_step = 4;

    $( '#drwProgressBar' ).html( gDRW.getProgressBar() );

    $( '#drwContent1' ).html( '

    Here\'s a summary of what you\'ve told us. Quickly check that it\'s all correct before you submit your request, and we will file the dispute for you and give you a link to the discussion.

    ' );

    gDRW.drawDRWSummary();

    var buttons = 'Edit';

    buttons += ' Cancel';

    buttons += ' Save';

    $( '#drwButtons' ).html( buttons );

    $( '#showStep3Button' ).click( showStep3 );

    $( '#showCancelButton' ).click( showCancel );

    $( '#doSubmitButton' ).click( doSubmit );

    }

    function showResult( status ) {

    $( '#drwProgressBar' ).text( '' );

    if ( status == 'ok' ) {

    //Show thankyou

    $( '#drwContent1' ).html( '

    Success!

    Thank you for filing a request for dispute resolution

    ' );

    $( '#drwContent1' ).append( $( 'Click here to go view your request.' ).attr( { href: mw.config.get( 'wgArticlePath' ).replace( '$1', gDRW.post_link ) } ) );

    $( '#drwButtons' ).html( '' );

    } else if ( status == 'error' ) {

    //Show error

    $( '#drwContent1' ).html( '

    Error

    Sorry, there was an error attaching your request. Maybe try it again?

    ' );

    $( '#drwButtons' ).html( 'Back to Summary' );

    $( '#showStep4Button' ).click( showStep4 );

    } else {

    $( '#drwContent1' ).html( '

    Error

    Something went wrong!

    ' );

    $( '#drwButtons' ).html( '' );

    }

    }

    function showCancel() {

    gDRW.wizard_step = 0;

    $( '#drwProgressBar' ).html( gDRW.getProgressBar() );

    $( '#drwContent1' ).html(

    '

    ' +

    'It\'s best to discuss your concerns with the other users on the talk page of the article before seeking dispute resolution. ' +

    'You can find instructions on how to do this at this page, or you can place {{helpme}} on your own talk page, and a volunteer will come by your page to help.' +

    '

    '

    );

    $( '#drwButtons' ).html( 'Start Over' );

    $( '#showStep1Button' ).click( showStep1 );

    }

    function showConductCancel() {

    gDRW.wizard_step = 0;

    $( '#drwProgressBar' ).html( gDRW.getProgressBar() );

    $( '#drwContent1' ).html(

    '

    ' +

    'We can only assist with content disputes. If you have concerns about the conduct of another editor, you will need to bring this to the Administrator\'s Noticeboard.' +

    '

    '

    );

    $( '#drwButtons' ).html( 'Start Over' );

    $( '#showStep1Button' ).click( showStep1 );

    }

    /**

    * Do the final step of the DRW and post the report to the appropriate page

    */

    function doSubmit() {

    //Notify user that we are doing the update

    $( '#drwProgressBar' ).html( '

    saving report
    ' );

    $( '#drwContent1' ).html( '

    Posting Report....

    ' );

    //Decide on the page to update

    var DRPage = 'Wikipedia:Dispute_resolution_noticeboard'; //The default page to post this

    /**

    * Decide where to post this dispute resolution report. In the end, DRPage needs to hold

    * the title of the page where we post the report.

    *

    * gDRW.dispute_type is set the short name (index) of the user-selected dispute type

    * gDRW.previous_forums[ 'xxx' ] will be true if the use ticked the 'xxx' checkbox in the previous forums

    */

    //Set the post-page on the DRW object

    gDRW.post_link = DRPage + '#' + gDRW.article_title.replace( ' ', '_' );

    //Compose Report

    var report = gDRW.getWikitextReport();

    //Add new section to designated page

    var edittoken = mw.user.tokens.get( 'csrfToken' );

    var date = new Date();

    var dateString = date.toLocaleDateString();

    var summary = gDRW.article_title;

    addNewSection( DRPage, summary, report, edittoken );

    }

    /**

    * Event handler functions

    */

    function setDisputeForum( box ) {

    //alert( 'Setting ' + gDRW.forum_labels[ box.value ] + ' to true' );

    gDRW.previous_forums[ box.value ] = box.checked;

    var linkboxid = 'link_' + box.value;

    if ( box.checked ) {

    $( '#' + linkboxid ).show();

    } else {

    $( '#' + linkboxid ).hide();

    }

    }

    function updateLink( box ) {

    gDRW.forum_links[ box.name ] = box.value;

    }

    function yesContentClick() {

    gDRW.talkpage = true;

    showStep2();

    }

    /**

    * Taken almost verbatim from https://www.mediawiki.org/wiki/API:Edit

    */

    function addNewSection( pagetitle, summary, content, editToken ) {

    $.ajax( {

    url: mw.util.wikiScript( 'api' ),

    data: {

    format: 'json',

    action: 'edit',

    title: pagetitle,

    section: 'new',

    summary: summary,

    text: content,

    token: editToken

    },

    dataType: 'json',

    type: 'POST',

    success: function( data ) {

    if ( data && data.edit && data.edit.result == 'Success' ) {

    //window.location.reload(); // reload page if edit was successful

    showResult( 'ok' );

    } else if ( data && data.error ) {

    alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );

    showResult( 'error' );

    } else {

    alert( 'Error: Unknown result from API.' );

    showResult( 'error2' );

    }

    },

    error: function( xhr ) {

    alert( 'Error: Request failed.' );

    }

    } );

    }

    /**

    * Initialization function. Test if we should place the DRW on the current page.

    * Looks for a

    on the page.

    */

    function runDRW() {

    if ( $( '#myDRW' ).length ){

    //importStylesheet( 'MediaWiki:Gadget-DRN-wizard.css' ); //CSS Styles for the DRW

    //Setup the App's workspace

    $( '#myDRW' ).html( '' );

    $( '#myDRW' ).append( $( '

    ' ) );

    $( '#drw_main' ).append( '

    ' );

    $( '#drw_main' ).append( '

    ' );

    $( '#drw_main' ).append( '

    ' );

    showStep1(); //Show the first page

    }

    }

    var gDRW = new drw();

    $( document ).ready( runDRW );

    // JavaScript Document

    //