-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ed1d3f
commit f25a44d
Showing
9 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// #if _DEV | ||
import warn from '../util/warn'; | ||
|
||
/** | ||
* Loads a module in development. Only works in development contexts. | ||
* | ||
* @param moduleCode | ||
*/ | ||
export default async function dynamicDevModuleLoad( moduleCode: string ) { | ||
warn( 'Dynamically loading a module from localhost. This may be bad!' ); | ||
return new Promise( ( res, rej ) => mw.loader.getScript( | ||
`http://localhost:45000/deputy-${ moduleCode }.js` | ||
).then( res, rej ) ); | ||
} | ||
// #endif _DEV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import getPageExists from '../wiki/util/getPageExists'; | ||
|
||
/** | ||
* Load a module from a string. | ||
* | ||
* @param moduleName | ||
*/ | ||
export default async function dynamicModuleLoad( moduleName: string ) { | ||
/** | ||
* This is a very sensitive variable! | ||
* | ||
* Ensure that not anyone can modify these. This usually comes as interface admin | ||
* protection or userspace protection. | ||
* | ||
* LOADING FROM PAGES THAT CAN BE EDITED BY ANYONE CAN LEAD TO SECURITY | ||
* IMPLICATIONS! | ||
*/ | ||
const expectedLocations = [ | ||
`MediaWiki:Gadget-${ moduleName }-core.js`, | ||
`MediaWiki:Gadget-${ moduleName }.js`, | ||
`MediaWiki:Gadget-Deputy-${ moduleName }-core.js`, | ||
`MediaWiki:Gadget-Deputy-${ moduleName }.js`, | ||
`MediaWiki:${ moduleName }-core.js`, | ||
`MediaWiki:${ moduleName }.js`, | ||
`User:Chlod/Scripts/Deputy/${ moduleName }-core.js`, | ||
`User:Chlod/Scripts/Deputy/${ moduleName }.js` | ||
// Security implications of this TBD. | ||
// `Gadget:${ moduleName }-core.js`, | ||
// `Gadget:${ moduleName }.js` | ||
]; | ||
|
||
// Check which of those has something in it. | ||
const ape = await getPageExists( expectedLocations ); | ||
if ( ape.length > 0 ) { | ||
// Page exists! Load it. | ||
return new Promise( ( res, rej ) => { | ||
mw.loader.getScript( mw.util.getUrl( ape[ 0 ] ) ).then( res, rej ); | ||
} ); | ||
} else { | ||
// Nothing got loaded. | ||
return Promise.reject( new Error( 'Could not find a script to load.' ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.