User:Dragoniez/PrivateSandbox
PrivateSandbox is a user script that creates a private sandbox for you on Special:PrivateSandbox (or Special:PS).
Similar scripts have been authored by different users, such as en:User:SD0001/private-sandbox.js, but this version features its compatibility with:
- WikiEditor
- Multiple profiles
- Realtime preview
- [TODO] Syntax highlighting (will be available when CodeMirror v6 is deployed)
Please note the following before installing this script:
- Do not open the private sandbox in multiple tabs within the same project. Doing so can result in data corruption due to potential overwriting of data from another tab.
- Consider using the Wikitext extension for Visual Studio Code instead. This script has to export its data on every page load, and if your saved data is large, you might experience slower page loads.
Installation
[edit]Add the following to your user common.js (on the project where you want to use the script). You can also install it into global.js on Meta. Note that the script data will be saved per project, even if you install it globally. (source code)
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Dragoniez/PrivateSandbox.js&action=raw&ctype=text/javascript');
Note also that since this script operates only on the designated special page, it is most efficient and resource-friendly to enclose the loader line in an if
block to restrict the script's execution, as shown below. (recommended, but shouldn't be used with the generatePortletLink
config)
if (mw.config.get('wgNamespaceNumber') === -1 && /^(PrivateSandbox|PS)$/i.test(mw.config.get('wgTitle'))) {
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Dragoniez/PrivateSandbox.js&action=raw&ctype=text/javascript');
}
Configurations
[edit]If you would like to customize the script's configurations, install the script as follows and change the values as needed:
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Dragoniez/PrivateSandbox.js&action=raw&ctype=text/javascript');
window.privateSandboxConfig = {
lang: '',
expandPreview: false,
showDeleter: false,
generatePortletLink: false
};
config name | default value | accepted values | explanation |
---|---|---|---|
lang | language in your preferences (falls back to English) |
'en' , 'ja' |
The language to use on the interface If you're interested in contributing to new translations, please refer to #Translations. |
expandPreview | false |
true , false |
Whether to expand the preview tab by default |
showDeleter | false |
true , false |
Whether to display the "Delete data" button |
generatePortletLink | false |
true , false |
Whether to generate a portlet link to Special:PrivateSandbox Note: When setting this to true , do not enclose your loader line in a if block as described above
|
Translations
[edit]PrivateSandbox currently supports en
and ja
for its interface. If you would like support for another language, please translate the following and submit your translations to the talk page.
Translation source
|
---|
{
'message-load-interface': 'Loading the interface...',
'message-load-failed': 'Failed to load the interface.',
'message-load-welcome': 'Welcome to the private sandbox! Create your first profile to get started.',
'message-load-updated': 'Welcome to the new private sandbox! The private sandbox now supports profile management, and your old data have been saved as profile "1".',
'message-unload': 'You have unsaved changes. Are you sure you want to leave the page?',
'label-profiles': 'Profiles',
'label-profiles-select': 'Select profile:',
'label-profiles-edit': 'Edit profile:',
'label-profiles-edit-placeholder': 'Enter a profile name',
'label-profiles-edit-help': 'The profile name must consist only of alphanumeric characters, underscores, and hyphens (<code>a-zA-Z0-9_-</code>).',
'title-profiles-empty': 'Enter a profile name.',
'title-profiles-invalidchars': 'The profile name must consist only of alphanumeric characters, underscores, and hyphens.',
'title-profiles-toomanychars': 'The byte length of the profile name must be 255 or less.',
'label-profiles-button-create': 'Create',
'label-profiles-button-rename': 'Rename',
'label-profiles-button-delete': 'Delete',
'message-profiles-create-done': 'Created profile "$1".',
'message-profiles-rename-done': 'Renamed profile "$1" to "$2".',
'message-profiles-rename-confirm': 'Are you sure you want to rename profile "$1" to "$2"?',
'message-profiles-delete-done': 'Deleted profile "$1".',
'message-profiles-delete-confirm': 'Are you sure you want to delete profile "$1"?',
'label-profiles-save-help': 'Changes need to be manually saved.',
'title-editor-disabled': 'Create a profile to use the editor.',
'label-profiles-save': 'Save',
'title-profiles-save': 'Save this profile',
'label-profiles-saveall': 'Save all',
'title-profiles-saveall': 'Save all the profiles',
'label-profiles-listunsaved': 'List unsaved',
'title-profiles-listunsaved': 'Show a list of unsaved profiles',
'label-deletedata': 'Delete data',
'title-deletedata': 'Delete all data managed by PrivateSandbox',
'message-deletedata-confirm': 'This action cannot be undone. Are you sure you want to delete all data?',
'message-deletedata-doing': 'Deleting all data...',
'message-deletedata-done': 'Deleted all the data. Please close this page once.',
'message-deletedata-failed': 'Failed to delete the data. Please try again.',
'message-predeletedata-failed': 'The procedure has been canceled because PrivateSandbox failed to fetch the newest profiles in the pre-deletion process. Please try again in a few minutes. (See the browser console for the details of this error.)',
'title-dialog-listunsaved': 'Unsaved profiles',
'label-dialog-listunsaved-deleteditem': 'deleted',
'message-presave-failed': 'The procedure has been canceled because PrivateSandbox failed to fetch the newest profiles in the pre-saving process. Please try again in a few minutes. (See the browser console for the details of this error.)',
'message-conflict-created': 'Created elsewhere',
'message-conflict-modified': 'Modified elsewhere',
'message-conflict-deleted': 'Deleted elsewhere',
'message-conflict-alert1': 'PrivateSandbox has detected edit conflicts in the following profiles:',
'message-conflict-alert2': 'This occurs when new changes are saved in another tab after opening PrivateSandbox in the current tab. To prevent any potential data corruption, it is highly recommended that you press "Cancel", emigrate your changes in this tab to the tab where the changes above were made, and close PrivateSandbox in this tab. If it is okay to overwrite the newest profiles with the data on this page, close all other tabs that have opened PrivateSandbox and press "OK". This will refresh the current tab when the saving process is finished.',
'title-conflict': 'Edit conflict',
'message-save-doing': 'Saving...',
'message-save-done': 'Saved the profile(s).',
'message-save-failed': 'Failed to save the profile(s). Please see the browser console for details.',
'label-preview': 'Preview',
'message-preview-failed': 'Failed to fetch preview.',
'title-preview-expand': 'Expand the preview tab',
'title-preview-collapse': 'Collapse the preview tab',
'title-preview-disabled': 'Create a profile to use the preview tab.'
}
|