User:PerfektesChaos/js/editorContent
JavaScript gadget – use advanced text editor depending on the current situation and user requirements.
Usage
[edit]- If your project has registered this as a gadget, just activate on your Preferences page.
- Otherwise include the following lines into your common.js or skin dependant like vector.js:
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/editorContent/r.js&action=raw&bcache=1&maxage=604800&ctype=text/javascript",
"text/javascript");
Effects
[edit]The gadget selects the appropriate editor among various choices, and will avoid conflicts between competing tools.
Currently there are considered:
- WikEd
- CodeEditor (Ace; mw:Extension:CodeEditor)
- VisualEditor
Another advantage is to avoid loading of the nearly 600 kB Code of WikEd on every displayed page, even if the page is not edited now. Just to conclude that there is no editing, or the current browser does not support WikEd. The same goes for any other tool.
The defaults on a glance:
{ CodeEditor: { css: "\\.css$",
javascript: "\\.js$",
lua: [ "/sandbox[^/]*/Module:", 2 ]
},
VisualEditor: false,
WikEd: true
}
Rules
[edit]A “rule” is either
true
(respective default)false
(turn off explicitly)- string (Regular expression, which is to be matched by the current page name; might be an empty string)
- Array of a string as before and some numbers of namespaces, from which one has to be met.
Particular Editors
[edit]CodeEditor
[edit]Precondition by namespace number:
- > 0
- even
- not 828
If the precondition is not satisfied, no further rule comes into effect.
For every single mode
(programming language) to be considered a keyword is to be defined together with a rule.
The CodeEditor integration at MediaWiki was equipped recently with the following mode
capabilities:
- css
- Default:
true
- Meaning: page name terminated by
.css
(lowercase letters) - javascript
- Default:
true
- Meaning: page name terminated by
.js
(lowercase letters) - json
- Currently no general rule known.
- lua
- Default:
true
- Meaning: rule (user space sandbox subpage)
[ "/sandbox[^/]*/Module:", 2 ]
Any other keyword automatically causes loading of the RL module with additional mode
support. Example (after user configuration of the opt
object):
mw.libs.editorContent.opt.CodeEditor = { c_cpp: "\\.cpp$" };
The same action will be taken, if the global configuration variable wgCodeEditorCurrentLanguage
was found; independent of the rules the CodeEditor will be loaded.
If more than one rule is matching and different keywords will result, choice and behaviour cannot be predicted.
The general statement .opt.CodeEditor = false;
wlll exclude the CodeEditor from user defined loading (with exception of Module: namespace 828
).
VisualEditor
[edit]The VisualEditor is supposed to be activated explicitly by the user, or can be turned off by preferences. If that is not possible one day, any link to VE can be hidden to avoid misclicks.
- VisualEditor “Edit” link will be removed if any kind of non-wikitext content is detected.
- CSS and Javascript sources are assumed if page title is terminated by
.css
or.js
“extension”.
- CSS and Javascript sources are assumed if page title is terminated by
WikEd
[edit]Precondition by browser type:
WikEd must not be loaded by preferences page in advance for any visited page.
- The default value
true
loads WikEd, if not CodeEditor is used automatically or on non-documentation pages in Module: namespace828
(page name ends with/doc
). - The specification
false
won’t activate WikEd.
wikiEditor
[edit]No actions possible here.
User options
[edit]Individual configuration is possible: Insert the lines below into your common.js etc. (best before mw.loader.load, if present):
if ( typeof mw.libs.editorContent !== "object" ) {
mw.libs.editorContent = {};
}
mw.libs.editorContent.opt = { editor1: rule1,
editor2: rule2
};
Codes
[edit]Source code |
|
ResourceLoader |
|
Namespaces | ≥ 0
|
mw.libs
|
editorContent
|
Other languages
[edit]This gadget is prepared for multilingual support.
- If you like a version in your own language, please forward translations to me:
- This documentation page.
- Name of the standard template sandbox (and Module: namespace).