Skip to content

Commit 1299bf5

Browse files
integrate CTE with Deputy
1 parent 726c827 commit 1299bf5

11 files changed

+230
-151
lines changed

i18n/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
"deputy.session.page.earwigRevision": "Earwig's Copyvio Detector (revision)",
8787
"deputy.session.page.earwigUnsupported": "Earwig's Copyvio Detector does not support this wiki.",
8888

89+
"deputy.session.page.tools": "Tools",
90+
8991
"deputy.cte": "'Copied' Notice Editor",
9092

9193
"deputy.cte.edit": "Modify content attribution notices for this page",

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"cover 95% and supports fetch, not IE 11"
7373
],
7474
"dependencies": {
75-
"@chlodalejandro/parsoid": "^2.0.0-rc5",
75+
"@chlodalejandro/parsoid": "^2.0.0-e3c8216d",
7676
"@rollup/plugin-json": "^4.1.0",
7777
"broadcastchannel-polyfill": "^1.0.1",
7878
"idb": "^7.0.1",

src/Deputy.ts

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class Deputy {
145145
this.session = new DeputySession();
146146
await this.session.init();
147147

148+
// Load CTE entry buttons
149+
this.cte.preInit();
150+
148151
console.log( 'Loaded!' );
149152

150153
mw.hook( 'deputy.load' ).fire( this );

src/css/deputy.css

+14-2
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ body.mediawiki.rtl .dp-cs-row-head > :not(:first-child):not(:last-child) {
291291
align-items: center;
292292
}
293293

294+
@media only screen and (max-width: 768px) {
295+
.dp-pageToolbar {
296+
flex-wrap: wrap;
297+
bottom: 0;
298+
left: 0;
299+
border-left: 0;
300+
border-bottom: 0;
301+
border-right: 0;
302+
width: 100%;
303+
}
304+
}
305+
294306
.dp-pt-section {
295307
display: inline-block;
296308
white-space: nowrap;
@@ -333,11 +345,11 @@ body.mediawiki.rtl .dp-cs-row-head > :not(:first-child):not(:last-child) {
333345
width: 5.4em;
334346
}
335347

336-
.dp-pt-analysis .oo-ui-menuSelectWidget {
348+
.dp-pt-menu .oo-ui-menuSelectWidget {
337349
min-width: 300px;
338350
}
339351

340-
.dp-pt-analysis .oo-ui-menuOptionWidget {
352+
.dp-pt-menu .oo-ui-menuOptionWidget {
341353
padding-top: 8px;
342354
padding-bottom: 8px;
343355
}

src/modules/cte/CopiedTemplateEditor.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ declare global {
1313
}
1414

1515
/**
16-
*
16+
* Main class for CopiedTemplateEditor.
1717
*/
1818
export default class CopiedTemplateEditor {
1919

20+
readonly CopiedTemplate = CopiedTemplate;
21+
2022
/**
2123
* An instance of Deputy. This is commonly `window.deputy`. Instantiating this class
2224
* with a Deputy instances enables connection with the Deputy core, which shares the
@@ -29,6 +31,27 @@ export default class CopiedTemplateEditor {
2931
*/
3032
_windowManager: any;
3133

34+
/**
35+
* The `loader` variable is set (in JavaScript) by a CTE loader. This prevents UI
36+
* elements (such as "start" buttons and the toolbox link) from being appended
37+
* to the DOM twice.
38+
*/
39+
loader?: boolean;
40+
41+
/**
42+
* Whether the core has been loaded or not. Set to `true` here, since this is
43+
* obviously the core class.
44+
*/
45+
loaded = true;
46+
/**
47+
* Determines the start state of the start buttons. This depends on `toggleButtons`.
48+
*/
49+
startState: boolean;
50+
/**
51+
* Pencil icon buttons on {{copied}} templates that open CTE.
52+
*/
53+
startButtons: any[] = [];
54+
3255
/**
3356
* @return The responsible window manager for this class.
3457
*/
@@ -44,21 +67,6 @@ export default class CopiedTemplateEditor {
4467
}
4568
}
4669

47-
readonly CopiedTemplate = CopiedTemplate;
48-
49-
/**
50-
* The `loader` variable is set (in JavaScript) by a CTE loader. This prevents UI
51-
* elements (such as "start" buttons and the toolbox link) from being appended
52-
* to the DOM twice.
53-
*/
54-
loader?: boolean;
55-
/**
56-
* Whether the core has been loaded or not. Set to `true` here, since this is
57-
* obviously the core class.
58-
*/
59-
loaded = true;
60-
startButtons: any[] = [];
61-
6270
/**
6371
*
6472
* @param deputy
@@ -130,6 +138,8 @@ export default class CopiedTemplateEditor {
130138
}
131139
}
132140
);
141+
142+
this.startState = true;
133143
}
134144

135145
/**
@@ -175,6 +185,8 @@ export default class CopiedTemplateEditor {
175185
* @param state The new state.
176186
*/
177187
toggleButtons( state?: boolean ) {
188+
this.startState = state ?? !( this.startState || false );
189+
178190
for ( const button of this.startButtons ) {
179191
button.setDisabled( state == null ? !button.isDisabled() : !state );
180192
}

src/ui/page/DeputyPageAnalysisMenu.ts

-116
This file was deleted.
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import EarwigCopyvioDetector from '../../wiki/EarwigCopyvioDetector';
2+
import { DeputyPageMenuOption } from './DeputyPageMenu';
3+
4+
export default () => <DeputyPageMenuOption[]>[
5+
{
6+
icon: 'eye',
7+
label: mw.message( 'deputy.session.page.earwigLatest' ).text(),
8+
action: async ( toolbar ) => {
9+
const url = await EarwigCopyvioDetector.getUrl( toolbar.row.title );
10+
window.open( url, '_blank', 'noopener' );
11+
12+
if ( url == null ) {
13+
mw.notify(
14+
mw.message( 'deputy.session.page.earwigUnsupported' ).text(),
15+
{
16+
type: 'error'
17+
}
18+
);
19+
} else {
20+
window.open( url, '_blank', 'noopener' );
21+
}
22+
}
23+
},
24+
{
25+
icon: 'eye',
26+
label: mw.message( 'deputy.session.page.earwigRevision' ).text(),
27+
condition: ( toolbar ) => toolbar.revision != null,
28+
action: async ( toolbar ) => {
29+
const url = await EarwigCopyvioDetector.getUrl( toolbar.revision );
30+
31+
if ( url == null ) {
32+
mw.notify(
33+
mw.message( 'deputy.session.page.earwigUnsupported' ).text(),
34+
{
35+
type: 'error'
36+
}
37+
);
38+
} else {
39+
window.open( url, '_blank', 'noopener' );
40+
}
41+
}
42+
}
43+
];

0 commit comments

Comments
 (0)