페미위키:개선요청의 토론 주제

시각편집기와 원본편집기에 {{주}} 사용 메뉴 추가

이 주제는 낙엽1124님에 의해 숨겨졌습니다
이유: 더욱 개선의 여지가 있음
6
낙엽1124 (토론기여)
이 게시글은 낙엽1124님에 의해 숨겨졌습니다 (기록)

현재 시각 편집기에 {{주}}를 사용하는 별도 메뉴가 존재하지 않습니다.

그래서 시각편집기에 다음 동영상에서 보시는 것과 같은 메뉴가 추가되는 스크립트(붙임 1번)를 만들었습니다(동영상을 찍고 스크립트를 좀 더 수정해서 살짝 다르긴 합니다).

해당 스크립트를 미디어위키:common.js에 추가 요청드립니다.

붙임 1번
//시각편집기에 {{주}} 입력 툴 넣기
function addCommentTemplateToolToVisualEditor() {
  //'주'틀을 입력해 주는 커맨드 만들기
  function commentTemplate() {}
  function CommentTemplate() {
    CommentTemplate.parent.call( this, 'commentTemplate' );
  }
  OO.inheritClass( CommentTemplate, ve.ui.Command );

  CommentTemplate.prototype.execute = function( surface ) {
    var surfaceModel = surface.getModel(),
      //선택된 것이 있으면 뒤로 이동하고 틀을 추가
      widget = surfaceModel.getFragment().collapseToEnd().insertContent(
      [
        {
          type: 'mwTransclusionInline',
          attributes: {
            mw: {
              parts: [
                {
                  template: {
                    target: {
                      href: '틀:주',
                      wt: '주'
                    }
                  }
                }
              ]
            }
          }
        },
      { type: '/mwTransclusionInline' }
      ]
    );
    return true;
  };
  //만든 커맨드 등록
  ve.ui.commandRegistry.register( new CommentTemplate() );

  //등록된 커맨드를 실행하는 툴 (메뉴) 만들기
  function CommentTemplateTool() {
    CommentTemplateTool.parent.apply( this, arguments );
  }
  OO.inheritClass( CommentTemplateTool, ve.ui.Tool );

  CommentTemplateTool.static.name = 'commentTemplate';
  CommentTemplateTool.static.group = 'object';
  CommentTemplateTool.static.title = '부연 설명';
  CommentTemplateTool.static.icon = 'reference';
  CommentTemplateTool.static.commandName = 'commentTemplate';
  CommentTemplateTool.static.modelClasses = ve.ui.toolFactory.lookup('reference').static.modelClasses;
  CommentTemplateTool.static.autoAddToCatchall = false;

  CommentTemplateTool.prototype.onUpdateState = function() {
    CommentTemplateTool.parent.prototype.onUpdateState.apply( this, arguments );
    this.setActive( false );
  };

  //만든 툴 등록
  ve.ui.toolFactory.register( CommentTemplateTool );
  
  //등록된 툴을 메뉴에 넣기
  var toolbarGroups = ve.init.mw.Target.static.toolbarGroups;
  toolbarGroups[ 4 ].include.push( 'commentTemplate' );
  
  //기존 툴 레이블 변경
  toolbarGroups[ 4 ].label='각주';
  ve.ui.toolFactory.lookup('reference').static.title='출처';
  ve.ui.toolFactory.lookup('reference/existing').static.title='출처 재사용';
}
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).done( function() {
  mw.libs.ve.addPlugin( function() {
    mw.loader.using( [ 'ext.visualEditor.core' ] ).done( function() {
        addCommentTemplateToolToVisualEditor();
    } );
  } );
} );

//위키편집기에 {{주}} 입력 툴 넣기
var addCommentTemplateToolToWikiEditor = function () {
  //툴바에 {{주|}}로 감싸주는 툴 추가
  $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    'section': 'main',
    'group': 'insert',
    'tools': {
      'comment': {
        label: '부연 설명',
        type: 'button',
        icon: {},
        offset: [2, -1798],
        action: {
          type: 'encapsulate',
          options: {
            pre: "{{주|",
            peri: "여기에 각주 내용을 적어 주세요",
            post: "}}"
          }
        }
      }
    }
  } );
};
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
  mw.loader.using( 'user.options' ).then( function () {
    if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
      $.when(
        mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
      ).then( addCommentTemplateToolToWikiEditor );
    }
  } );
}

//위키편집기 기존 메뉴 이름 바꾸기(왠지 작동 안함)
//https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization#Modifying_things
// $( '#wpTextbox1' ).on( 'wikiEditor-toolbar-buildSection-main', function( event, section ) {
//   console.log('on wikiEditor-toolbar-buildSection-main');
//   delete section.groups.insert.tools.reference.labelMsg;
//   section.groups.insert.tools.reference.label = '출처';
//   //배열 내용은 확인해보면 바뀌어 있는데 정작 메뉴는 바뀌지 않습니다.
// } );

(6/13 추가)원본편집기 편집 도구 모음에도 추가했습니다.

WhatisI (토론기여)

어? 그거 인용 메뉴에서 골라서 쓸 수 있지 않았나요? 저는 그렇게 썼었는데..;;;

낙엽1124 (토론기여)

어 진짜네요..? 그래도 스텝을 하나 줄여준달까요...

WhatisI (토론기여)

어차피 시각편집기는 처음 위키 쓰는 사람들이 쓰니까 편하게 찾을 수 있는데 도움이 되겠네요.

낙엽1124 (토론기여)

악성코드 아니예요 추가좀..ㅠㅠㅠㅜ

낙엽1124 (토론기여)

음 근데 제 코드가 좀 개떡같긴 하조 조만간 정리하고 주석이라도 더 달아볼테니 ...부디 긍정적인 검토를...