Skip to content

Commit

Permalink
util: + unwrapJQ
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed May 28, 2024
1 parent 404fb7a commit d7d95d1
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 67 deletions.
4 changes: 2 additions & 2 deletions i18n/ia/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
"deputy.ia.listing.re.unverified": "Permission unverified as of this tagging; article will need to be deleted if that does not change.",
"deputy.ia.listing.re.viable": "Viable rewrite proposed; rewrite on temp page can be merged into the article.",

"deputy.ia.report.intro": "You are reporting to <b>{{wikilink:$1}}</b>",
"deputy.ia.report.page": "Currently reporting <b>{{wikilink:$1}}</b>",
"deputy.ia.report.intro": "You are reporting to <b>[[$1]]</b>",
"deputy.ia.report.page": "Currently reporting <b>[[$1]]</b>",
"deputy.ia.report.lead": "Lead section",
"deputy.ia.report.end": "End of page",
"deputy.ia.report.section": "$1: $2",
Expand Down
6 changes: 3 additions & 3 deletions i18n/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"deputy.about.openSource": "Source",
"deputy.about.contact": "Contact",
"deputy.about.credit": "Deputy was made with the help of the English Wikipedia Copyright Cleanup WikiProject and the Wikimedia Foundation.",
"deputy.about.license": "Deputy is licensed under the <a href=\"$1\">Apache License 2.0</a>. The source code for Deputy is available on <a href=\"$2\">GitHub</a>, and is free for everyone to view and suggest changes.",
"deputy.about.thirdParty": "Deputy is bundled with third party libraries to make development easier. All libraries have been vetted for user security and license compatibility. For more information, see the <a href=\"$1\">\"Licensing\"</a> section on Deputy's README.",
"deputy.about.license": "Deputy is licensed under the [$1 Apache License 2.0]. The source code for Deputy is available on [$2 GitHub], and is free for everyone to view and suggest changes.",
"deputy.about.thirdParty": "Deputy is bundled with third party libraries to make development easier. All libraries have been vetted for user security and license compatibility. For more information, see the [$1 Licensing] section on Deputy's README.",
"deputy.about.buildInfo": "Deputy v$1 ($2), committed $3.",
"deputy.about.footer": "Made with love, coffee, and the tears of copyright editors.",

Expand All @@ -15,7 +15,7 @@

"deputy.settings.wikiEditIntro.title": "This is a Deputy configuration page",
"deputy.settings.wikiEditIntro.current": "Deputy's active configuration comes from this page. Changing this page will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.other": "This is a valid Deputy configuration page, but the configuration is currently being loaded from {{wikilink:$1}}. If this becomes the active configuration page, changing it will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.other": "This is a valid Deputy configuration page, but the configuration is currently being loaded from [[$1]]. If this becomes the active configuration page, changing it will affect the settings of all Deputy users on this wiki. Edit responsibly, and avoid making significant changes without prior discussion.",
"deputy.settings.wikiEditIntro.edit.current": "Modify configuration",
"deputy.settings.wikiEditIntro.edit.other": "Modify this configuration",
"deputy.settings.wikiEditIntro.edit.otherCurrent": "Modify the active configuration",
Expand Down
1 change: 0 additions & 1 deletion src/modules/ia/ui/ListingActionLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { h } from 'tsx-dom';
import type CopyrightProblemsListing from '../models/CopyrightProblemsListing';
import type CopyrightProblemsSession from '../models/CopyrightProblemsSession';
import ListingResponsePanel from './ListingResponsePanel';
import DeputyLanguage from '../../../DeputyLanguage';

/**
*
Expand Down
27 changes: 9 additions & 18 deletions src/modules/ia/ui/SinglePageWorkflowDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import equalTitle from '../../../util/equalTitle';
import msgEval from '../../../wiki/util/msgEval';
import CCICaseInputWidget from './CCICaseInputWidget';
import changeTag from '../../../config/changeTag';
import unwrapJQ from '../../../util/unwrapJQ';

export interface SinglePageWorkflowDialogData {
page: TitleLike;
Expand Down Expand Up @@ -148,26 +149,16 @@ function initSinglePageWorkflowDialog() {
initialize() {
super.initialize();

const intro = <div
class="ia-report-intro"
dangerouslySetInnerHTML={
mw.message(
'deputy.ia.report.intro',
CopyrightProblemsPage.getCurrentListingPage().getPrefixedText()
).parse()
}
/>;
const intro = unwrapJQ( <div class="ia-report-intro" />, mw.message(
'deputy.ia.report.intro',
CopyrightProblemsPage.getCurrentListingPage().getPrefixedText()
).parseDom() );
intro.querySelector( 'a' ).setAttribute( 'target', '_blank' );

const page = <div
class="ia-report-intro"
dangerouslySetInnerHTML={
mw.message(
'deputy.ia.report.page',
this.page.getPrefixedText()
).parse()
}
/>;
const page = unwrapJQ( <div class="ia-report-intro" />, mw.message(
'deputy.ia.report.page',
this.page.getPrefixedText()
).parseDom() );
page.querySelector( 'a' ).setAttribute( 'target', '_blank' );

this.fieldsetLayout = new OO.ui.FieldsetLayout( {
Expand Down
33 changes: 15 additions & 18 deletions src/ui/config/ConfigurationAboutTabPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import deputyVersion, {
gitVersion
} from '../../DeputyVersion';
import type WikiConfiguration from '../../config/WikiConfiguration';
import unwrapJQ from '../../util/unwrapJQ';

interface ConfigurationGroupTabPanelOptions extends OO.ui.TabPanelLayout.ConfigOptions {

Expand Down Expand Up @@ -81,27 +82,23 @@ function initConfigurationGroupTabPanel() {
} ) )
}</a>
</div>
<p dangerouslySetInnerHTML={ mw.msg( 'deputy.about.credit' ) }/>
<p dangerouslySetInnerHTML={ mw.msg( 'deputy.about.license',
{unwrapJQ( <p/>, mw.message( 'deputy.about.credit' ).parseDom() )}
{unwrapJQ( <p/>, mw.message( 'deputy.about.license',
'https://www.apache.org/licenses/LICENSE-2.0',
'https://github.com/ChlodAlejandro/deputy'
) }/>
<p dangerouslySetInnerHTML={ mw.msg( 'deputy.about.thirdParty',
).parseDom() ) }
{unwrapJQ( <p/>, mw.message( 'deputy.about.thirdParty',
'https://github.com/ChlodAlejandro/deputy#licensing'
) }/>
<p
style={{ fontSize: '0.9em', color: 'darkgray' }}
dangerouslySetInnerHTML={ mw.msg(
'deputy.about.buildInfo',
gitVersion as string,
gitBranch as string,
new Date( gitDate as string ).toLocaleString()
) }
/>
<p
style={{ fontSize: '0.9em', color: 'darkgray' }}
dangerouslySetInnerHTML={ mw.msg( 'deputy.about.footer' ) }
/>
).parseDom() )}
{unwrapJQ( <p style={{ fontSize: '0.9em', color: 'darkgray' }} />, mw.message(
'deputy.about.buildInfo',
gitVersion as string,
gitBranch as string,
new Date( gitDate as string ).toLocaleString()
).parseDom() )}
{ unwrapJQ( <p style={{ fontSize: '0.9em', color: 'darkgray' }} />, mw.message(
'deputy.about.footer'
).parseDom() ) }
</div> );
}

Expand Down
1 change: 0 additions & 1 deletion src/ui/config/ConfigurationReloadBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { h } from 'tsx-dom';
import '../../types';
import unwrapWidget from '../../util/unwrapWidget';
import DeputyMessageWidget from '../shared/DeputyMessageWidget';
Expand Down
11 changes: 5 additions & 6 deletions src/ui/config/WikiConfigurationEditIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import WikiConfiguration from '../../config/WikiConfiguration';
import { spawnConfigurationDialog } from './ConfigurationDialog';
import normalizeTitle from '../../wiki/util/normalizeTitle';
import DeputyMessageWidget from '../shared/DeputyMessageWidget';
import unwrapJQ from '../../util/unwrapJQ';

/**
* @param config The current configuration (actively loaded, not the one being viewed)
Expand Down Expand Up @@ -57,12 +58,10 @@ export default function WikiConfigurationEditIntro( config: WikiConfiguration ):
title: mw.msg( 'deputy.settings.wikiEditIntro.title' ),
message: current ?
mw.msg( 'deputy.settings.wikiEditIntro.current' ) :
<span dangerouslySetInnerHTML={
mw.message(
'deputy.settings.wikiEditIntro.other',
config.sourcePage.getPrefixedText()
).parse()
} />,
unwrapJQ( <span/>, mw.message(
'deputy.settings.wikiEditIntro.other',
config.sourcePage.getPrefixedText()
).parseDom() ),
actions: buttons
} );

Expand Down
21 changes: 9 additions & 12 deletions src/ui/root/DeputyFinishedContributionSurveyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nsId from '../../wiki/util/nsId';
import type { Moment } from 'moment';
import { guessTrace } from '../../models/DeputyTrace';
import warn from '../../util/warn';
import unwrapJQ from '../../util/unwrapJQ';

/**
* Displayed when a ContributionSurveyRow has no remaining diffs. Deputy is not able
Expand Down Expand Up @@ -88,7 +89,7 @@ export default class DeputyFinishedContributionSurveyRow {
const talkPage = userPage.getTalkPage();
const contribsPage = new mw.Title( 'Special:Contributions/' + this.author );

const params: string[] = [
const params: ( string|JSX.Element )[] = [
( <span>
<a
target="_blank"
Expand All @@ -108,7 +109,7 @@ export default class DeputyFinishedContributionSurveyRow {
title={ contribsPage.getPrefixedText() }
>{ mw.msg( 'deputy.revision.contribs' ) }</a></span>
</span>
</span> ).outerHTML
</span> )
];

if ( this.timestamp ) {
Expand All @@ -119,16 +120,12 @@ export default class DeputyFinishedContributionSurveyRow {
);
}

return <i
dangerouslySetInnerHTML={
mw.message(
this.timestamp ?
'deputy.session.row.checkedComplete' :
'deputy.session.row.checked',
...params
).text()
}
/>;
return unwrapJQ( <i/>, mw.message(
this.timestamp ?
'deputy.session.row.checkedComplete' :
'deputy.session.row.checked',
...params
).parseDom() );
} else {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/root/DeputyReviewDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function initDeputyReviewDialog() {
</div>
);
} else {
// noinspection JSXDomNesting
this.element = swapElements(
this.element,
<table class="diff">
Expand Down
21 changes: 15 additions & 6 deletions src/ui/shared/ChangesList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import '../../types';
import { h } from 'tsx-dom';
import getRevisionURL from '../../wiki/util/getRevisionURL';
import getRevisionDiffURL from '../../wiki/util/getRevisionDiffURL';
import nsId from '../../wiki/util/nsId';
import type { ExpandedRevisionData } from '../../api/ExpandedRevisionData';
import { ContributionSurveyRevision } from '../../models/ContributionSurveyRevision';
import { h } from 'tsx-dom';
import unwrapJQ from '../../util/unwrapJQ';
import { USER_LOCALE } from '../../wiki/Locale';

/**
Expand Down Expand Up @@ -262,10 +262,19 @@ export function ChangesListTags( { tags }: { tags: [string, string][] } ): JSX.E
'deputy.revision.tags',
tags.length.toString()
).text() }</a>{
tags.map( ( v ) => <span
class={ `mw-tag-marker mw-tag-marker-${ v[ 0 ] }` }
dangerouslySetInnerHTML={ v[ 1 ] }
/> )
tags.map( ( v ) => {
// eslint-disable-next-line mediawiki/msg-doc
const tagMessage = mw.message( `tag-${ v }` ).parseDom();
return [
' ',
tagMessage.text() !== '-' && unwrapJQ(
<span
class={ `mw-tag-marker mw-tag-marker-${ v }` }
/>,
tagMessage
)
];
} )
}
</span>;
}
2 changes: 2 additions & 0 deletions src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Requester from './Requester';
import sleep from './sleep';
import swapElements from './swapElements';
import unwrapElement from './unwrapElement';
import unwrapJQ from './unwrapJQ';
import unwrapWidget from './unwrapWidget';
import warn from './warn';
import yesNo from './yesNo';
Expand Down Expand Up @@ -50,6 +51,7 @@ export default {
sleep: sleep,
swapElements: swapElements,
unwrapElement: unwrapElement,
unwrapJQ: unwrapJQ,
unwrapWidget: unwrapWidget,
warn: warn,
yesNo: yesNo
Expand Down
13 changes: 13 additions & 0 deletions src/util/unwrapJQ.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { h } from 'tsx-dom';

/**
* Get the nodes from a JQuery object and wraps it in an element.
*
* @param element The element to add the children into
* @param $j The JQuery object
* @return The original element, now with children
*/
export default function unwrapJQ( element = <span/>, $j: JQuery ): JSX.Element {
$j.each( ( i, e ) => element.append( e ) );
return element;
}

0 comments on commit d7d95d1

Please sign in to comment.