MediaWiki:LAPI.js: Difference between revisions

Content deleted Content added
No edit summary
upgrade LAPI
Line 322:
{
if (target === null) return -1;
if (typeof (target.indexOflastIndexOf) == 'function') return target.lastIndexOf (elem, from);
if (typeof (target.length) == 'undefined') return -1;
var l = target.length;
Line 1,145:
var href = lk.getAttribute ('href', 2);
if (!href) return null;
// This is a bit tricky to get right, because wgScript can be a substring prefix of
// First try wgArticlePath: href="/wiki/..."
// wgArticlePath, or vice versa.
var script = wgScript + '?';
if (href.startsWith (script) || href.startsWith (wgServer + script)) {
// href="/w/index.php?title=..."
return href.getParamValue ('title');
}
// FirstNow try wgArticlePath: href="/wiki/..."
var prefix = wgArticlePath.replace ('$1', "");
if (!href.startsWith (prefix)) prefix = wgServer + prefix; // Fully expanded URL?
if (href.startsWith (prefix))
return decodeURIComponent (href.substring (prefix.length));
// Do we have variants?
if (wgVariantArticlePath && wgVariantArticlePath.length > 0) {
if (typeof (wgVariantArticlePath) != 'undefined'
if ( && wgVariantArticlePath && wgVariantArticlePath.length > 0) {
{
var re =
new RegExp (wgVariantArticlePath.escapeRE().replace ('\\$2', "[^\\/]*").replace ('\\$1', "(.*)"));
Line 1,156 ⟶ 1,166:
if (m && m.length > 1) return decodeURIComponent (m[m.length-1]);
}
// Finally alternative action paths
// If that doesn't work, try the script entry point
if (href.startsWithtypeof (wgScriptwgActionPaths) ||!= href.startsWith'undefined' (wgServer&& + wgScript)wgActionPaths) {
for (var action in wgActionPaths) {
// href="/w/index.php?title=..."
var p = wgActionPaths[action];
return href.getParamValue ('title');
if (p && p.length > 0) {
p = p.replace('$1', "");
if (!href.startsWith (p)) p = wgServer + p;
if (href.startsWith (p))
return decodeURIComponent (href.substring (p.length));
}
}
}
return null;
Line 1,426 ⟶ 1,443:
uri, params
, function (request, failureFunc) {
if (is_json && request.responseText.trimLeft().charAt (0) != '{') {
failureFunc (request);
} else {
success (
request
, (is_json ? eval ('(' + request.responseText.trimLeft() + ')') : null)
, original_failure
);
Line 1,457 ⟶ 1,474:
,title: on_page || wgPageName || "API"
,prop : 'text'
,uselang : user_language || wgUserLanguage // see bugzilla 22764
};
if (cache && /^\d+$/.test(cache=cache.toString())) {