MediaWiki:LAPI.js: Difference between revisions

Content deleted Content added
Update to latest version from Commons
mNo edit summary
Line 24:
*/
 
// Global: wgServer, wgScript, wgUserLanguage
// Global: importScript (from wiki.js, for MediaWiki:AjaxSubmit.js)
 
Line 1,119 ⟶ 1,118:
if (!file_div) return null; // Catch page without file...
var imgs = file_div.getElementsByTagName ('img');
title = title || mw.config.get('wgTitle');
for (var i = 0; i < imgs.length; i++) {
var src = decodeURIComponent (imgs[i].getAttribute ('src', 2)).replace ('%26', '&');
Line 1,135 ⟶ 1,134:
// This is a bit tricky to get right, because wgScript can be a substring prefix of
// wgArticlePath, or vice versa.
var script = mw.config.get('wgScript') + '?';
if (href.startsWith (script) || href.startsWith (mw.config.get('wgServer') + script) || mw.config.get('wgServer').startsWith('//') && href.startsWith (document.___location.protocol + mw.config.get('wgServer') + script)) {
// href="/w/index.php?title=..."
return href.getParamValue ('title');
}
// Now try wgArticlePath: href="/wiki/..."
var prefix = mw.config.get('wgArticlePath').replace ('$1', "");
if (!href.startsWith (prefix)) prefix = mw.config.get('wgServer') + prefix; // Fully expanded URL?
if (!href.startsWith (prefix) && prefix.startsWith ('//')) prefix = document.___location.protocol + prefix; // Protocol-relative wgServer?
if (href.startsWith (prefix))
return decodeURIComponent (href.substring (prefix.length));
// Do we have variants?
var variants = mw.config.get('wgVariantArticlePath');
if (typeof (wgVariantArticlePath) != 'undefined'
if && wgVariantArticlePath(variants && wgVariantArticlePathvariants.length > 0)
{
var re =
new RegExp (wgVariantArticlePathvariants.escapeRE().replace ('\\$2', "[^\\/]*").replace ('\\$1', "(.*)"));
var m = re.exec (href);
if (m && m.length > 1) return decodeURIComponent (m[m.length-1]);
}
// Finally alternative action paths
var actions = mw.config.get('wgActionPaths');
if (typeof (wgActionPaths) != 'undefined' && wgActionPaths) {
if (actions) {
for (var i=0; i < wgActionPaths.length; i++) {
for (var p i=0; wgActionPaths[i] < actions.length; i++) {
var p = actions[i];
if (p && p.length > 0) {
p = p.replace('$1', "");
if (!href.startsWith (p)) p = mw.config.get('wgServer') + p;
if (!href.startsWith (p) && p.startsWith('//')) p = document.___location.protocol + p;
if (href.startsWith (p))
Line 1,378:
LAPI.Ajax.getPage = function (page, action, params, success, failure)
{
var uri = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent (page)
+ (action ? '&action=' + action : "");
LAPI.Ajax.get (uri, params, success, failure, {overrideMimeType : 'application/xml'});
Line 1,491:
}
}
var uri = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php' + (action ? '?action=' + action : "");
LAPI.Ajax.get (
uri, params
Line 1,525:
(as_preview ? '\<div style="border:1px solid red; padding:0.5em;"\>'
+ '\<div class="previewnote"\>'
+ '\{\{MediaWiki:Previewnote/' + (user_language || mw.config.get('wgUserLanguage')) +'\}\}'
+ '\<\/div>\<div\>\n'
: "")
+ wikitext
+ (as_preview ? '\<\/div\>\<div style="clear:both;"\>\<\/div\>\<\/div\>' : "")
,title: on_page || mw.config.get('wgPageName') || "API"
};
}
params.prop = 'text';
params.uselang = user_language || mw.config.get('wgUserLanguage'); // see bugzilla 22764
if (cache && /^\d+$/.test(cache=cache.toString())) {
params.maxage = cache;
Line 1,561:
 
if (typeof window.jQuery == 'undefined' || typeof window.mediaWiki == 'undefined' || typeof window.mediaWiki.loader == 'undefined') {
// Assume old-stlye
if (typeof window.injectSpinner != 'undefined') {
LAPI.Ajax.injectSpinner = window.injectSpinner;
Line 2,013:
}
, true
, mw.config.get('wgUserLanguage') || null
, mw.config.get('wgPageName') || null
);
return true;