Skip to content

Commit 6a12e09

Browse files
wiki-config: better handling
1 parent 211fdd2 commit 6a12e09

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

i18n/settings/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"deputy.setting.wiki.ia.subpageFormat.description": "The format to use for subpages of the root page. This is a moment.js format string.",
125125
"deputy.setting.wiki.ia.preload.name": "Preload",
126126
"deputy.setting.wiki.ia.preload.description": "Defines the page content to preload the page with if a given subpage does not exist yet. This should be an existing page on-wiki. Leave blank to avoid using a preload entirely.",
127-
"deputy.setting.wiki.ia.listingWikitext": "Listing wikitext",
127+
"deputy.setting.wiki.ia.listingWikitext.name": "Listing wikitext",
128128
"deputy.setting.wiki.ia.listingWikitext.description": "Defines the wikitext that will be used when adding listings to a noticeboard page. You may use \"$1\" to denote the page being reported, and \"$2\" for user comments (which shouldn't contain the signature).",
129129
"deputy.setting.wiki.ia.listingWikitextMatch.name": "Regular expression for listings",
130130
"deputy.setting.wiki.ia.listingWikitextMatch.description": "A regular expression that will be used to parse and detect listings on a given noticeboard page. Since its usage is rather technical, this value should be edited by someone with technical knowledge of regular expressions. This regular expression must provide three captured groups: group \"$1\" will catch any bullet point, space, or prefix, \"$2\" will catch the page title ONLY if the given page matches \"{{int:deputy.setting.wiki.ia.listingWikitext.name}}\" or \"{{int:deputy.setting.wiki.ia.batchListingWikitext.name}}\", and \"$3\" will catch the page title ONLY IF the page wasn't caught in \"$2\" (such as in cases where there is only a bare link to the page).",

src/config/WikiConfiguration.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class WikiConfiguration extends ConfigurationBase {
7171

7272
if ( configPage ) {
7373
return new WikiConfiguration(
74-
configPage.title,
74+
new mw.Title( configPage.title.title, configPage.title.namespace ),
7575
JSON.parse( configPage.wt ),
7676
configPage.editable
7777
);
@@ -91,7 +91,8 @@ export default class WikiConfiguration extends ConfigurationBase {
9191
...await ( async () => {
9292
const content = await getPageContent( sourcePage, {
9393
prop: 'revisions|info',
94-
intestactions: 'edit'
94+
intestactions: 'edit',
95+
fallbacktext: '{}'
9596
} );
9697

9798
return {
@@ -203,7 +204,7 @@ export default class WikiConfiguration extends ConfigurationBase {
203204
displayOptions: { type: 'checkbox' }
204205
} ),
205206
rootPage: new Setting<string, mw.Title>( {
206-
serialize: ( v ) => v.getPrefixedText(),
207+
serialize: ( v ) => v?.getPrefixedText(),
207208
deserialize: ( v ) => new mw.Title( v ),
208209
defaultValue: null,
209210
displayOptions: { type: 'page' }
@@ -231,7 +232,7 @@ export default class WikiConfiguration extends ConfigurationBase {
231232
displayOptions: { type: 'checkbox' }
232233
} ),
233234
rootPage: new Setting<string, mw.Title>( {
234-
serialize: ( v ) => v.getPrefixedText(),
235+
serialize: ( v ) => v?.getPrefixedText(),
235236
deserialize: ( v ) => new mw.Title( v ),
236237
defaultValue: null,
237238
displayOptions: { type: 'page' }
@@ -241,7 +242,7 @@ export default class WikiConfiguration extends ConfigurationBase {
241242
displayOptions: { type: 'text' }
242243
} ),
243244
preload: new Setting<string, string>( {
244-
serialize: ( v ) => v.trim().length === 0 ? null : v.trim(),
245+
serialize: ( v ) => ( v?.trim()?.length ?? 0 ) === 0 ? null : v.trim(),
245246
defaultValue: null,
246247
displayOptions: { type: 'page' }
247248
} ),

src/ui/config/WikiConfigurationEditIntro.tsx

+20-29
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
11
import unwrapWidget from '../../util/unwrapWidget';
22
import { h } from 'tsx-dom';
33
import WikiConfiguration from '../../config/WikiConfiguration';
4-
import swapElements from '../../util/swapElements';
54
import { spawnConfigurationDialog } from './ConfigurationDialog';
65
import normalizeTitle from '../../wiki/util/normalizeTitle';
6+
import DeputyMessageWidget from '../shared/DeputyMessageWidget';
77

88
/**
9-
* @param config The current configuration
9+
* @param config The current configuration (actively loaded, not the one being viewed)
1010
* @return An HTML element consisting of an OOUI MessageWidget
1111
*/
1212
export default function WikiConfigurationEditIntro( config: WikiConfiguration ): JSX.Element {
13-
const r = 'deputy-' + Math.random().toString().slice( 2 );
1413
const current = config.onConfigurationPage();
1514

16-
const messageBox = new OO.ui.MessageWidget( {
17-
classes: [
18-
'deputy', 'dp-mb'
19-
],
20-
type: 'info',
21-
label: new OO.ui.HtmlSnippet( ( <span>
22-
<b>{
23-
mw.msg( 'deputy.settings.wikiEditIntro.title' )
24-
}</b><br/>{
25-
current ?
26-
mw.msg( 'deputy.settings.wikiEditIntro.current' ) :
27-
<span dangerouslySetInnerHTML={
28-
mw.message(
29-
'deputy.settings.wikiEditIntro.other',
30-
config.sourcePage.getPrefixedText()
31-
).parse()
32-
} />
33-
}<br/>
34-
<span id={r}></span>
35-
</span> ).innerHTML )
36-
} );
37-
3815
let buttons: any[];
3916
if ( current ) {
4017
const editCurrent = new OO.ui.ButtonWidget( {
@@ -52,7 +29,7 @@ export default function WikiConfigurationEditIntro( config: WikiConfiguration ):
5229
const editCurrent = new OO.ui.ButtonWidget( {
5330
flags: [ 'progressive', 'primary' ],
5431
label: mw.msg( 'deputy.settings.wikiEditIntro.edit.otherCurrent' ),
55-
disabled: config.editable,
32+
disabled: !config.editable,
5633
title: config.editable ?
5734
undefined : mw.msg( 'deputy.settings.wikiEditIntro.edit.protected' )
5835
} );
@@ -72,10 +49,24 @@ export default function WikiConfigurationEditIntro( config: WikiConfiguration ):
7249
buttons = [ editCurrent, editOther ];
7350
}
7451

52+
const messageBox = DeputyMessageWidget( {
53+
classes: [
54+
'deputy', 'dp-mb'
55+
],
56+
type: 'info',
57+
title: mw.msg( 'deputy.settings.wikiEditIntro.title' ),
58+
message: current ?
59+
mw.msg( 'deputy.settings.wikiEditIntro.current' ) :
60+
<span dangerouslySetInnerHTML={
61+
mw.message(
62+
'deputy.settings.wikiEditIntro.other',
63+
config.sourcePage.getPrefixedText()
64+
).parse()
65+
} />,
66+
actions: buttons
67+
} );
68+
7569
const box = unwrapWidget( messageBox );
76-
swapElements( box.querySelector( `#${r}` ), <span>
77-
{ buttons.map( b => unwrapWidget( b ) ) }
78-
</span> );
7970

8071
box.classList.add( 'deputy', 'deputy-wikiConfig-intro' );
8172

src/wiki/util/getPageContent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ export default function (
2727
rvlimit: '1',
2828
...extraOptions
2929
} ).then( ( data ) => {
30+
const fallbackText = extraOptions.fallbacktext;
31+
3032
if ( data.query.pages[ 0 ].revisions == null ) {
31-
return null;
33+
if ( fallbackText ) {
34+
return Object.assign( fallbackText, {
35+
page: data.query.pages[ 0 ]
36+
} );
37+
} else {
38+
return null;
39+
}
3240
}
41+
3342
return Object.assign(
3443
data.query.pages[ 0 ].revisions[ 0 ].slots.main.content,
3544
{

0 commit comments

Comments
 (0)