moderator-toolbox-nxg-for-reddit / util/wiki/wikiMigration

util/wiki/wikiMigration

Functions

bootstrapFreshSub()

bootstrapFreshSub(subreddit): Promise<WikiMigrationResult>

Defined in: extension/data/util/wiki/wikiMigration.ts:666

Creates the toolbox-nxg config page for a subreddit with no toolbox data at all: the default config plus compatibilityWrites: false. The usernotes manifest and notes index stay lazily created on their first save - one wiki edit is all a fresh sub costs. Mod-gated like migrateSubredditToNxg.

Recursion invariant: runs from inside doResolveWikiLayout while the in-flight resolution promise is held; nothing here may call resolveWikiLayout or helpers that do.

Parameters

subreddit

string

The subreddit to bootstrap.

Returns

Promise<WikiMigrationResult>

A per-page outcome report; a non-empty failed list means nothing was created and the layout cache was left untouched.


copyNxgToLegacy()

copyNxgToLegacy(subreddit): Promise<WikiMigrationResult>

Defined in: extension/data/util/wiki/wikiMigration.ts:700

Reverse copy: NXG pages -> legacy pages. Used when 6.x compatibility is turned back on after a period of NXG-only writes, so 6.x mods resume with current data. The NXG pages are never modified.

Parameters

subreddit

string

The subreddit to copy.

Returns

Promise<WikiMigrationResult>

A per-page outcome report; a non-empty failed list means the run aborted.


hasWikiWritePermission()

hasWikiWritePermission(subreddit): Promise<boolean>

Defined in: extension/data/util/wiki/wikiMigration.ts:211

Returns true when the current user can edit the subreddit’s wiki. Being listed as a moderator is not enough: alumni and no-permission moderators still appear in the moderated-subs listing but cannot write wiki pages.

Parameters

subreddit

string

The subreddit to check.

Returns

Promise<boolean>

Throws

When the current user or the moderator listing cannot be fetched.


migrateSubredditToNxg()

migrateSubredditToNxg(subreddit, compatibilityWrites?): Promise<WikiMigrationResult>

Defined in: extension/data/util/wiki/wikiMigration.ts:458

Migrates a subreddit’s toolbox data from the legacy paths to toolbox-nxg/*. The legacy pages are never modified, so this is also safe to re-run at any time to fold in 6.x edits or repair deleted NXG pages. Idempotent: existing NXG pages are reconcile-merged (config, usernotes) or overwritten from legacy data.

Recursion invariant: this runs from inside doResolveWikiLayout while the subreddit’s in-flight resolution promise is held. Nothing in this call graph may call resolveWikiLayout, getWikiReadPath, getConfig, or any other layout-resolving helper for the same subreddit - it would await its own resolution and deadlock. All wiki access here uses explicit OLD_/NEW_WIKI_PATHS.

Parameters

subreddit

string

The subreddit to migrate.

compatibilityWrites?

The compat flag to embed in the NXG config and record in the layout cache. Defaults to true (6.x compat on).

compatibilityWrites?

boolean = true

Returns

Promise<WikiMigrationResult>

A per-page outcome report; a non-empty failed list means the run aborted and the layout cache was left untouched.


recoverLegacyDomainTags()

recoverLegacyDomainTags(subreddit): Promise<LegacyDomainTag[]>

Defined in: extension/data/util/wiki/wikiMigration.ts:383

Recovers domain tags from the legacy config page’s revision history (see scanLegacyConfigRevisions): the newest revision carrying any. NXG’s compat mirror omits an empty list, so revisions it wrote after the tags were lost are skipped rather than read as “no tags”.

Parameters

subreddit

string

The subreddit to recover domain tags for.

Returns

Promise<LegacyDomainTag[]>

The recovered tags, or [] when no revision has any.

Throws

On a transient read failure.


recoverLegacyUsernoteColors()

recoverLegacyUsernoteColors(subreddit, keys): Promise<RecoveredTypes>

Defined in: extension/data/util/wiki/wikiMigration.ts:356

Recovers usernote type definitions from the legacy config page’s revision history (see scanLegacyConfigRevisions). Each key takes its newest real definition: seeded ones (placeholders and untouched built-in defaults) are skipped, since NXG’s compat mirror wrote those back to the page after a lossy migration.

Parameters

subreddit

string

The subreddit to recover types for.

keys

string[]

The type keys to find definitions for.

Returns

Promise<RecoveredTypes>

The definitions found (possibly fewer than requested), and whether the subreddit ever had types of its own.

Throws

On a transient read failure.


recoverSplitChoiceTexts()

recoverSplitChoiceTexts(subreddit, texts): Promise<Map<number, string>>

Defined in: extension/data/util/wiki/wikiMigration.ts:409

Finds removal reason text that an earlier build split apart, and the text it should have become.

Builds before the inline {choice: ...} form turned every legacy <select> into a {choice} block on lines of its own, even one written mid-sentence or as a link’s text, and saved that to the NXG page. The 6.x-compat mirror was rewritten from it, so only the legacy page’s revision history still holds the original. A reason is restored only when its current text is exactly what the old conversion produced from a historical reason, so a reason a moderator has edited since, or wrote as a block on purpose, is never touched.

Parameters

subreddit

string

The subreddit whose legacy config history to scan.

texts

readonly string[]

The current NXG reason texts, by index.

Returns

Promise<Map<number, string>>

Restored text keyed by the index of each reason to repair (empty when nothing matches).

Throws

On a transient read failure.


setCompatibilityMode()

setCompatibilityMode(subreddit, enabled): Promise<WikiMigrationResult>

Defined in: extension/data/util/wiki/wikiMigration.ts:843

Toggles 6.x compatibility mode for a subreddit. The NXG pages are always canonical; the flag only controls whether the legacy mirror is maintained. Sequencing keeps both sides intact:

  • Turning on: copy NXG -> legacy first (so 6.x mods resume with current data, and any tombstone is replaced with a real config), then record the flag.

  • Turning off: run one final reconcile-merge from the legacy pages (folding in any outstanding 6.x edits before the mirror is abandoned), then tombstone the legacy toolbox page so 6.x users see the sub has moved.

Clears the toolbox cache on success so all reads re-resolve.

Parameters

subreddit

string

The subreddit to toggle.

enabled

boolean

The new compatibility state.

Returns

Promise<WikiMigrationResult>

The outcome report of the underlying copy; a non-empty failed list means nothing was toggled.


summarizeMigrationResult()

summarizeMigrationResult(result): string

Defined in: extension/data/util/wiki/wikiMigration.ts:80

Turns a migration result into a short human-readable summary line for display in settings UIs.

Parameters

result

WikiMigrationResult

The migration result to summarize.

Returns

string

Type Aliases

WikiMigrationResult

WikiMigrationResult = object

Defined in: extension/data/util/wiki/wikiMigration.ts:66

Per-page outcome report for a migration or reverse-copy run.

Properties

copied

copied: string[]

Defined in: extension/data/util/wiki/wikiMigration.ts:68

Pages successfully written to the destination side.

failed

failed: object[]

Defined in: extension/data/util/wiki/wikiMigration.ts:72

Pages that failed, with the reason. A non-empty list means the run aborted.

page

page: string

reason

reason: string

skipped

skipped: string[]

Defined in: extension/data/util/wiki/wikiMigration.ts:70

Source pages skipped because they don’t exist (no_page).

Variables

noWikiPermissionReason

const noWikiPermissionReason: "you do not have wiki permission on this subreddit" = 'you do not have wiki permission on this subreddit'

Defined in: extension/data/util/wiki/wikiMigration.ts:193

Failure reason recorded when the viewer moderates the sub but lacks the wiki permission.


noWikiWritePermissionReason

const noWikiWritePermissionReason: "no wiki write permission" = 'no wiki write permission'

Defined in: extension/data/util/wiki/wikiMigration.ts:190

Failure reason recorded when Reddit rejects a wiki write with HTTP 403.