MediaWiki:Gadget-button-editorial.js

From WikiLectures

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* <pre> */

/* ============== Gadget-editorial.js =================================
       description:   gadget adds editorial buttons
                      to the edit toolbar
   ================================================================== */

// editorial section
var customizeToolbar = function() {
    // create section "Editorial tools"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'sections': {
        'editorial': {
          'type': 'toolbar',
          'label': 'Editorial tools'
        }
      }
    } );


    // groups of buttons to "Editorial tools"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'groups': {
        'edittemp': {
          'label': 'Editorial process'
        },
        'edituser': {
          'label': 'Users'
        },
        'editcheck': {
          'label': 'Check'
        }
      }
    } );

    // add button "Editorial process"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'edittemp',
      'tools': {
        'edittemplate': {
          label: 'Editorial process',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/P_writing_icon.svg/22px-P_writing_icon.svg.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "{{Editorial process\n|sources\n|citation\n|breakdown_headings\n|categories_portals\n|synonyms\n|images_licenses\n|wikilinks\n|grammar_typography\n}}"
            }
          }
        }
      }
    } );

    // button "Editorial sugnature"
    GTPR_nynejsiDatum = new Date();
    GTPR_casovaZnacka = GTPR_nynejsiDatum.getDate() + ". " + (GTPR_nynejsiDatum.getMonth() + 1) + ". " + GTPR_nynejsiDatum.getFullYear();
    GTPR_redakcniPodpis = " = " + wgUserName + ", " + GTPR_casovaZnacka;
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'edittemp',
      'tools': {
        'editsign': {
          label: 'Editorial signature',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/b/b8/Text_signature.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: GTPR_redakcniPodpis
            }
          }
        }
      }
    } );

    // add button "Welcome"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'edituser',
      'tools': {
        'editwelcome': {
          label: 'Welcome',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/7/7b/User_add.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "{{Welcome}}\n--~~~~"
            }
          }
        }
      }
    } );

    // add button "Timestamp"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'editcheck',
      'tools': {
        'editstamp': {
          label: 'Timestamp',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/6/6d/Time_add.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "{{subst:REVISIONTIMESTAMP}}"
            }
          }
        }
      }
    } );

    // add button "oldid"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'editcheck',
      'tools': {
        'editoldid': {
          label: 'OldID - editorial check',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/8/81/Note_edit.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "|" + wgCurRevisionId
            }
          }
        }
      }
    } );

    // add button "Suspicious account"
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'edituser',
      'tools': {
        'editsuspacc': {
          label: 'Suspicious account',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/a/a6/User_delete.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "{{Suspicious account|{{subst:REVISIONTIMESTAMP}}}}\n--~~" + "~~"
            }
          }
        }
      }
    } );


    // button "Spam"

    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'edituser',
      'tools': {
        'editsuspacc': {
          label: 'Spam (talk page warning)',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/No-spam.svg/22px-No-spam.svg.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: "{{Spam}}\n--~~" + "~~"
            }
          }
        }
      }
    } );


    // add buton "Copyright violation"
    GTC_nynejsiDatum = new Date();
    GTC_nynejsiDatum.setDate(GTC_nynejsiDatum.getDate() + 14);
    GTC_casovaZnacka = GTC_nynejsiDatum.getFullYear() + '' + ((GTC_nynejsiDatum.getMonth() + 1) < 10 ? "0" : "") + (GTC_nynejsiDatum.getMonth() + 1) + '' + (GTC_nynejsiDatum.getDate() < 10 ? "0" : "") + GTC_nynejsiDatum.getDate();

    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'editorial',
      'group': 'edituser',
      'tools': {
        'editcopyvio': {
          label: 'Copyright violation (copyvio)',
          type: 'button',
          icon: 'http://upload.wikimedia.org/wikipedia/commons/e/e7/Toolbaricon_hidden.png',
          action: {
            type: 'encapsulate',
            options: {
              pre: '{{Process|reason=copyvio|date=' + GTC_casovaZnacka + '}}'
            }
          }
        }
      }
    } );

}



/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options', function () {
		// This can be the string "0" if the user disabled the preference ([[bugzilla:52542#c3]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 && mw.user.options.get( 'showtoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor.toolbar' ),
				$.ready
			).then( customizeToolbar );
		}
	} );
}
/* </pre> */