Debian Codegraph @

extensions/Cite/modules/ext.cite.wikiEditor.js

raw symbols SCIP
1 'use strict';
2
3 /**
4 * Add Cite-specific functionality to the WikiEditor toolbar.
5 * Adds a button to insert <ref> tags, and adds a help section
6 * about how to use references to WikiEditor's help panel.
7 *
8 * @author Jon Harald Søby
9 */
10
11 mw.hook( 'wikiEditor.toolbarReady' ).add( ( $textarea ) => {
12 /* Add the <ref></ref> button to the toolbar */
13 $textarea.wikiEditor( 'addToToolbar', {
14 section: 'main',
15 group: 'insert',
16 tools: {
17 reference: {
18 label: mw.msg( 'cite-wikieditor-tool-reference' ),
19 filters: [ 'body.ns-subject' ],
20 type: 'button',
21 oouiIcon: 'reference',
22 action: {
23 type: 'encapsulate',
24 options: {
25 pre: '<ref>',
26 post: '</ref>'
27 }
28 }
29 }
30 }
31 } );
32
33 /* Add reference help to the Help section */
34 const parsedRef = function ( number ) {
35 return $( '<sup>' )
36 .addClass( 'reference' )
37 .append(
38 $( '<a>' )
39 .attr( 'href', '#' )
40 .text(
41 mw.message( 'cite-wikieditor-help-content-reference-example-ref-result', mw.language.convertNumber( number ) ).text()
42 )
43 );
44 };
45
46 const helpRows = [
47 {
48 description: { html: mw.message( 'cite-wikieditor-help-content-reference-description' ).parse() },
49 syntax: {
50 html: mw.html.escape(
51 mw.message( 'cite-wikieditor-help-content-reference-example-text1', mw.message( 'cite-wikieditor-help-content-reference-example-ref-normal', mw.message( 'cite-wikieditor-help-content-reference-example-text2', 'https://www.example.org/' ).plain() ).plain() ).plain()
52 )
53 },
54 result: {
55 html: mw.message( 'cite-wikieditor-help-content-reference-example-text1', parsedRef( 1 ) ).parse()
56 }
57 },
58 {
59 description: { html: mw.message( 'cite-wikieditor-help-content-named-reference-description' ).parse() },
60 syntax: {
61 html: mw.html.escape(
62 mw.message( 'cite-wikieditor-help-content-reference-example-text1', mw.message( 'cite-wikieditor-help-content-reference-example-ref-named', mw.message( 'cite-wikieditor-help-content-reference-example-ref-id' ).plain(), mw.message( 'cite-wikieditor-help-content-reference-example-text3', 'https://www.example.org/' ).plain() ).plain() ).plain()
63 )
64 },
65 result: {
66 html: mw.message( 'cite-wikieditor-help-content-reference-example-text1', parsedRef( 2 ) ).parse()
67 }
68 },
69 {
70 description: { html: mw.message( 'cite-wikieditor-help-content-rereference-description' ).parse() },
71 syntax: {
72 html: mw.html.escape(
73 mw.message( 'cite-wikieditor-help-content-reference-example-text1', mw.message( 'cite-wikieditor-help-content-reference-example-ref-reuse', mw.message( 'cite-wikieditor-help-content-reference-example-ref-id' ).plain() ).plain() ).plain()
74 )
75 },
76 result: {
77 html: mw.message( 'cite-wikieditor-help-content-reference-example-text1', parsedRef( 2 ) ).parse()
78 }
79 },
80 {
81 description: { html: mw.message( 'cite-wikieditor-help-content-showreferences-description' ).parse() },
82 syntax: {
83 html: mw.message( 'cite-wikieditor-help-content-reference-example-reflist' ).escaped()
84 },
85 result: {
86 html: '<ol class="references">' +
87 '<li><span class="mw-cite-backlink"><a href="#">' +
88 mw.message( 'cite_reference_backlink_symbol' ).parse() + '</a></span> ' +
89 mw.message( 'cite-wikieditor-help-content-reference-example-text2', window.location.href + '#' ).parse() +
90 '</li>' +
91 '<li><span class="mw-cite-backlink"><a href="#">' +
92 mw.message( 'cite_reference_backlink_symbol' ).parse() +
93 '</a></span> ' +
94 mw.message( 'cite-wikieditor-help-content-reference-example-text3', window.location.href + '#' ).parse() +
95
96 ( mw.config.get( 'wgCiteSubReferencing' ) ?
97 '<ol style="list-style-type: none; padding-left: 0; margin-top: 0;">' +
98 '<li style="margin-left: -1em;">' +
99 '2.1 ' + mw.message( 'cite-wikieditor-help-content-reference-example-extra-details' ).parse() +
100 '</li></ol>' :
101 '' ) +
102
103 '</li></ol>'
104 }
105 }
106
107 ];
108
109 if ( mw.config.get( 'wgCiteSubReferencing' ) ) {
110 const extendedRefObj = {
111 description: {
112 html: mw.message( 'cite-wikieditor-help-content-extended-reference-description' ).parse()
113 },
114 syntax: {
115 html: mw.html.escape(
116 mw.message( 'cite-wikieditor-help-content-reference-example-text1', mw.message( 'cite-wikieditor-help-content-reference-example-ref-extends', mw.message( 'cite-wikieditor-help-content-reference-example-ref-id' ).plain(), mw.message( 'cite-wikieditor-help-content-reference-example-extra-details' ).plain() ).plain() ).plain()
117 )
118 },
119 result: {
120 html: mw.message( 'cite-wikieditor-help-content-reference-example-text1', parsedRef( 2.1 ) ).parse()
121 }
122 };
123
124 // Insert extendedRefObj right after the row for named refs with the description message key
125 // "Additional use of the same reference"
126 const indexOfNamedRefItem = helpRows.findIndex( ( obj ) => mw.message( 'cite-wikieditor-help-content-rereference-description' ).plain() === obj.description.html );
127 helpRows.splice( indexOfNamedRefItem + 1, 0, extendedRefObj );
128 }
129
130 $textarea.wikiEditor( 'addToToolbar', {
131 section: 'help',
132 pages: {
133 references: {
134 label: mw.msg( 'cite-wikieditor-help-page-references' ),
135 layout: 'table',
136 headings: [
137 { html: mw.message( 'wikieditor-toolbar-help-heading-description' ).parse() },
138 { html: mw.message( 'wikieditor-toolbar-help-heading-syntax' ).parse() },
139 { html: mw.message( 'wikieditor-toolbar-help-heading-result' ).parse() }
140 ],
141 rows: helpRows
142 }
143 }
144 } );
145 } );