Skip to content

Commit

Permalink
bugfixes and i18n strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Sep 29, 2022
1 parent 3edf684 commit 9324dca
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 13 deletions.
1 change: 1 addition & 0 deletions i18n/core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"deputy.content.assessed.comma": ", ",
"deputy.content.assessed.finished": "$1 finished",
"deputy.content.assessed.reworked": "$1 reworked",
"deputy.content.assessed.sectionClosed": "section closed",
"deputy.content.reformat": "Reformatting section",

"deputy.session.start": "start CCI session",
Expand Down
22 changes: 22 additions & 0 deletions i18n/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"deputy.settings.wikiEditIntro.edit.otherCurrent": "Modify the active configuration",
"deputy.settings.wikiEditIntro.edit.protected": "This page's protection settings do not allow you to edit the page.",

"deputy.settings.wikiOutdated": "Outdated configuration",
"deputy.settings.wikiOutdated.help": "Deputy has detected a change in this wiki's configuration for all Deputy users. We've automatically downloaded the changes for you, but you have to reload to apply the changes.",
"deputy.settings.wikiOutdated.reload": "Reload",

"deputy.settings.dialog.title": "Deputy Preferences",
"deputy.settings.dialog.unimplemented": "A way to modify this setting has not yet been implemented. Check back later!",
"deputy.settings.saved": "Preferences saved. Please refresh the page to see changes.",
Expand Down Expand Up @@ -78,6 +82,12 @@

"deputy.setting.wiki.cci.enabled.name": "Enable contributor copyright investigations assistant",
"deputy.setting.wiki.cci.enabled.description": "Enables the CCI workflow assistant. This allows Deputy to replace the contribution survey found on CCI case pages with a graphical interface which works with other tabs to make the CCI workflow easier.",
"deputy.setting.wiki.cci.rootPage.name": "Root page",
"deputy.setting.wiki.cci.rootPage.description": "The main page that holds all subpages containing valid contribution copyright investigation cases.",
"deputy.setting.wiki.cci.collapseTop.name": "Collapsible wikitext (top)",
"deputy.setting.wiki.cci.collapseTop.description": "Placed just below a section heading when closing a contributor survey section. Use \"$1\" to denote user comments and signature. On the English Wikipedia, this is {{collapse top}}. Other wikis may have an equivalent template. This should go hand in hand with \"{{int:deputy.setting.wiki.cci.collapseBottom.name}}\", as they are used as a pair.",
"deputy.setting.wiki.cci.collapseBottom.name": "Collapsible wikitext (bottom)",
"deputy.setting.wiki.cci.collapseBottom.description": "Placed at the end of a section when closing a contributor survey section. On the English Wikipedia, this is {{collapse bottom}}. Other wikis may have an equivalent template.",

"deputy.setting.wiki.ante": "ANTE",

Expand All @@ -94,6 +104,18 @@
"deputy.setting.wiki.ia.subpageFormat.description": "The format to use for subpages of the root page. This is a moment.js format string.",
"deputy.setting.wiki.ia.preload.name": "Preload",
"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.",
"deputy.setting.wiki.ia.listingWikitext": "Listing wikitext",
"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).",
"deputy.setting.wiki.ia.listingWikitextMatch.name": "Regular expression for listings",
"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).",
"deputy.setting.wiki.ia.batchListingWikitext.name": "Batch listing wikitext",
"deputy.setting.wiki.ia.batchListingWikitext.description": "Defines the wikitext that will be used when adding batch listings to a noticeboard page. You may use \"$1\" to denote the page being reported, and \"$2\" for the list of pages (as determined by \"{{int:deputy.setting.wiki.ia.batchListingPageWikitext.name}}\") and \"$3\" for user comments (which doesn't contain the signature).",
"deputy.setting.wiki.ia.batchListingPageWikitext.name": "Batch listing page wikitext",
"deputy.setting.wiki.ia.batchListingPageWikitext.description": "Wikitext to use for every row of text in \"{{int:deputy.setting.wiki.ia.batchListingWikitext.name}}\". No line breaks are automatically added; these must be added into this string.",
"deputy.setting.wiki.ia.hideTemplate.name": "Content hiding wikitext (top)",
"deputy.setting.wiki.ia.hideTemplate.description": "Wikitext to hide offending content with. On the English Wikipedia, this is a usage of {{copyvio}}. Other wikis may have an equivalent template. This should go hand in hand with \"{{int:deputy.setting.wiki.ia.hideTemplateBottom.name}}\", as they are used as a pair.",
"deputy.setting.wiki.ia.hideTemplateBottom.name": "Content hiding wikitext (bottom)",
"deputy.setting.wiki.ia.hideTemplateBottom.description": "Placed at the end of hidden content to hide only part of a page. On the English Wikipedia, this is {{copyvio/bottom}}. Other wikis may have an equivalent template.",
"deputy.setting.wiki.ia.responses.name": "Responses",
"deputy.setting.wiki.ia.responses.description": "Quick responses for copyright problems listings. Used by clerks to resolve specific listings or provide more information about the progress of a given listing."
}
7 changes: 7 additions & 0 deletions src/config/WikiConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
collapseTop, copyvioBottom, copyvioTop,
listingWikitext
} from '../wiki/TemplatePolyfills';
import ConfigurationReloadBanner from '../ui/config/ConfigurationReloadBanner';

/**
* Wiki-wide configuration. This is applied to all users of the wiki, and has
Expand Down Expand Up @@ -346,6 +347,12 @@ export default class WikiConfiguration extends ConfigurationBase {
// Only mark outdated after saving, so we don't indirectly cause a save operation
// to cancel.
this.outdated = true;

// Attempt to add site notice.
document.getElementById( 'siteNotice' )?.insertAdjacentElement(
'afterend',
ConfigurationReloadBanner()
);
}, () => { /* silent fail */ } );
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/modules/ia/ui/NewCopyrightProblemsListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import delink from '../../../wiki/util/delink';
import getObjectValues from '../../../util/getObjectValues';
import { CompletionAction } from '../../shared/CompletionAction';
import purge from '../../../wiki/util/purge';
import { blockExit, unblockExit } from '../../../util/blockExit';

/**
*
Expand Down Expand Up @@ -77,6 +78,7 @@ function NewCopyrightProblemsListingPanel( props: { button: any } ): JSX.Element
* @return A panel for reporting multiple pages
*/
function NewCopyrightProblemsBatchListingPanel( props: { button: any } ) {
blockExit( 'ia-ncpbl' );
const cancelButton = new OO.ui.ButtonWidget( {
label: mw.msg( 'deputy.cancel' ),
flags: [ 'destructive' ]
Expand Down Expand Up @@ -242,6 +244,7 @@ function NewCopyrightProblemsBatchListingPanel( props: { button: any } ) {
mw.notify( mw.msg( 'deputy.ia.listing.new.batchListed' ), {
type: 'success'
} );
unblockExit( 'ia-ncpbl' );
removeElement( el as HTMLElement );
props.button.setDisabled( false );

Expand All @@ -265,6 +268,7 @@ function NewCopyrightProblemsBatchListingPanel( props: { button: any } ) {

cancelButton.on( 'click', () => {
props.button.setDisabled( false );
unblockExit( 'ia-ncpbl' );
removeElement( el as HTMLElement );
} );

Expand Down
4 changes: 3 additions & 1 deletion src/session/DeputyRootSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ export default class DeputyRootSession {
heading: ContributionSurveyHeading
): Promise<void> {
const el = new DeputyContributionSurveySection( casePage, heading );
await el.prepare();
if ( !( await el.prepare() ) ) {
return;
}

const sectionName = sectionHeadingName( heading );
this.sections.push( el );
Expand Down
2 changes: 1 addition & 1 deletion src/ui/DeputyUIElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface DeputyUIElement {
* Prepare for element injection. This entails changing a few things, such as
* hiding MediaWiki-rendered components, etc.
*/
prepare?: () => PromiseOrNot<void>;
prepare?: () => PromiseOrNot<boolean | void>;

/**
* Renders the element. This must return an HTMLElement that can be appended
Expand Down
41 changes: 41 additions & 0 deletions src/ui/config/ConfigurationReloadBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { h } from 'tsx-dom';
import '../../types';
import unwrapWidget from '../../util/unwrapWidget';
import swapElements from '../../util/swapElements';

/**
* @return A MessageWidget for reloading a page with an outdated configuration.
*/
export default function ConfigurationReloadBanner(): JSX.Element {
const r = 'deputy-' + Math.random().toString().slice( 2 );

const messageBox = new OO.ui.MessageWidget( {
classes: [
'deputy', 'dp-mb'
],
type: 'info',
label: new OO.ui.HtmlSnippet( ( <span>
<b>{
mw.msg( 'deputy.settings.wikiOutdated' )
}</b><br/>{
mw.msg( 'deputy.settings.wikiOutdated.help' )
}<br/>
<span id={r}></span>
</span> ).innerHTML )
} );

const reloadButton = new OO.ui.ButtonWidget( {
flags: [ 'progressive', 'primary' ],
label: mw.msg( 'deputy.settings.wikiOutdated.reload' )
} );
reloadButton.on( 'click', async () => {
window.location.reload();
} );

const box = unwrapWidget( messageBox );
swapElements( box.querySelector( `#${r}` ), unwrapWidget( reloadButton ) );

box.style.fontSize = 'calc(1em * 0.875)';

return box;
}
45 changes: 34 additions & 11 deletions src/ui/root/DeputyContributionSurveySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
* Sets the comments of a section.
*/
set comments( value: string ) {
if ( this._section?.closingComments == null ) {
if ( this._section == null ) {
throw new Error( 'Section has not been loaded yet.' );
}
this._section.closingComments = value;
Expand Down Expand Up @@ -121,7 +121,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
/**
* @return The edit summary for this section's changes.
*/
get editComment(): string {
get editSummary(): string {
if ( this.modified ) {
const modified = this.rows.filter( ( row ) => row.modified );
let worked = 0;
Expand All @@ -145,7 +145,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
if ( assessed > 0 ) {
message.push(
mw.msg(
'deputy.content.assessed.assessed',
'deputy.content.assessed',
`${assessed}`, `${worked}`
)
);
Expand All @@ -161,7 +161,13 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
);
}

return message.join( mw.msg( 'deputy.content.assessed.comma' ) );
if ( !this._section.originallyClosed && this.closed ) {
// Now closed.
message.push( mw.msg( 'deputy.content.assessed.sectionClosed' ) );
}

const m = message.join( mw.msg( 'deputy.content.assessed.comma' ) );
return m[ 0 ].toUpperCase() + m.slice( 1 );
} else {
return mw.msg( 'deputy.content.reformat' );
}
Expand Down Expand Up @@ -203,16 +209,25 @@ export default class DeputyContributionSurveySection implements DeputyUIElement

/**
* Perform any required pre-render operations.
*
* @return `true` if prepared successfully.
* `false` if not (invalid section, already closed, etc.)
*/
async prepare(): Promise<void> {
async prepare(): Promise<boolean> {
const firstList = this.sectionElements.find( ( el ) => el.tagName === 'UL' );

if ( firstList == null ) {
// Not a valid section! Might be closed already.
return false;
}

this.originalList = firstList.parentElement.removeChild( firstList ) as HTMLElement;

const rowElements: Record<string, HTMLLIElement> = {};
for ( let i = 0; i < this.originalList.children.length; i++ ) {
const li = this.originalList.children.item( i );
if ( li.tagName !== 'LI' ) {
return;
return false;
}
const anchor: HTMLElement = li.querySelector( 'a:first-of-type' );
// Avoid enlisting if the anchor can't be found (invalid row).
Expand Down Expand Up @@ -244,6 +259,8 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
}
this.wikitextLines.push( rowElement );
}

return true;
}

/**
Expand Down Expand Up @@ -310,7 +327,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
pageid: this.casePage.pageId,
section: sectionId,
text: this.wikitext,
summary: decorateEditSummary( this.editComment )
summary: decorateEditSummary( this.editSummary )
} ).then( function ( data ) {
return data;
}, function ( code, data ) {
Expand Down Expand Up @@ -414,10 +431,13 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
}
}

this._section = null;
await this.getSection( wikitext );
await this.prepare();
oldHeading.insertAdjacentElement( 'afterend', this.render() );
if ( !this._section.closed ) {
this._section = null;
await this.getSection( wikitext );
await this.prepare();
oldHeading.insertAdjacentElement( 'afterend', this.render() );
}

removeElement( oldHeading );
}
}, ( error ) => {
Expand Down Expand Up @@ -450,6 +470,9 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
closingCommentsField.toggle( v );
this.toggleClosingComments( v );
} );
this.closingComments.on( 'change', ( v: string ) => {
this.comments = v;
} );

( window as any ).test = this;

Expand Down

0 comments on commit 9324dca

Please sign in to comment.