Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/// User:PerfektesChaos/js/wikiExport/d.js
/// 2018-08-24 PerfektesChaos@de.wikipedia
// Export Wiki pages into local files, collaborate with browser add-on
// ResourceLoader: compatible;
// dependencies: mediawiki.api, mediawiki.user, mediawiki.util,
// jquery.client
/// Fingerprint: #0#0#
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/// <nowiki>
/* global window:false */
/* jshint forin:false,
bitwise:true, curly:true, eqeqeq:true, latedef:true,
laxbreak:true,
nocomma:true, strict:true, undef:true, unused:true */
( function ( mw, $ ) {
"use strict";
var VERSION = -0.09,
WEX;
if ( typeof mw.libs.wikiExport !== "object" ||
! mw.libs.wikiExport ) {
mw.libs.wikiExport = { };
}
WEX = mw.libs.wikiExport;
WEX.vsn = VERSION;
WEX.type = "wikiExport";
WEX.support = "|mediawiki|wikimedia|wikipedia|"
+ "wikibooks|wikinews|wikisource|wiktionary|";
if ( ! WEX.api ) {
WEX.api = { };
}
if ( ! WEX.dialog ) {
WEX.dialog = { };
}
WEX.wgNamespaceNumber = mw.config.get( "wgNamespaceNumber" );
// User options:
// .pages Array with Arrays [ns, title]
// .preset object with form data initialization
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
WEX.api.factory = function ( apply ) {
// Create XML data and request file storing
// Precondition:
// apply -- revisions object (non-nil)
// Postcondition:
// Returns Array [0] number of valid revisions
// [1] XML sequence
// [2] extremal timestamp
// Uses:
// this
// .api.flip()
// .api.follow()
// 2013-08-26 PerfektesChaos@de.wikipedia
var i, rv, story, t,
k = 0,
n = apply.length,
s = "";
for ( i = 0; i < n; i++ ) {
rv = apply[ i ];
story = rv[ "*" ];
if ( story && rv.user ) {
k++;
s = s + "<revision>\n"
+ " <id>" + rv.revid + "</id>\n"
+ " <parentid>"
+ ( rv.parentid ? rv.parentid : 0 )
+ "</parentid>\n"
+ " <timestamp>" + rv.timestamp + "</timestamp>\n"
+ " <contributor><username>"
+ this.flip( rv.user )
+ "</username></contributor>\n";
if ( rv.minor !== undefined ) {
s = s + " <minor/>\n";
}
if ( rv.comment ) {
s = s + " <comment>" + this.flip( rv.comment )
+ "</comment>\n";
}
s = s + " <text xml:space='preserve' bytes='0'>"
+ this.flip( story ).replace( /\"/g, """ )
+ "</text>\n"
+ "</revision>\n\n";
t = rv.timestamp;
}
} // for i
return [ k, s, t ];
}; // .api.factory()
WEX.api.failed = function ( about, add ) {
// API retrieval failed
// Precondition:
// about -- reason
// Postcondition:
// message is displayed
// Uses:
// .dialog.flop()
// Remark: Used as event handler -- 'this' is not WEX.api
// 2013-08-20 PerfektesChaos@de.wikipedia
var s = "API error";
if ( about ) {
s = s + "\n\n" + about;
}
if ( add ) {
if ( add.error ) {
if ( add.error.info ) {
s = s + "\n" + add.error.info;
}
}
}
WEX.dialog.flop( s );
}; // .api.failed()
WEX.api.fetch = function () {
// Start (new) ajax request
// Postcondition:
// Returns false for captured event processing
// Uses:
// > mw.Api
// > .api.loop
// > .dialog.loop
// > .api.request
// > .api.rvcontinue
// >< .job.next
// .api.first()
// (.api.found)
// (.api.failed)
// Remark: Used as event handler -- 'this' is not WEX.api
// 2015-06-11 PerfektesChaos@de.wikipedia
var query;
if ( WEX.api.loop && WEX.dialog.loop ) {
if ( ! WEX.api.request ) {
WEX.api.first();
}
if ( WEX.api.rvcontinue !== WEX.job.next ) {
WEX.job.next = WEX.api.rvcontinue;
query = new mw.Api();
query.get( WEX.api.request,
WEX.api.script ).done( WEX.api.found )
.fail( WEX.api.failed );
}
}
return false;
}; // .api.fetch()
WEX.api.first = function () {
// Initialize API dialog data
// Uses:
// this
// > .job.pageName
// > .job.revCount
// > .job.interLanguage
// > .job.wikiProject
// > document
// > .dialog.$wrapper
// > .dialog.push
// >< .job.revNumber
// < .job.pageNameEnc
// < .api.rvcontinue
// < .api.request
// < .job.domain
// < .job.ident
// < .job.multiple
// < .job.next
// < .dialog.loop
// < .api.loop
// mw.util.wikiUrlencode()
// mw.config.get()
// jQuery.find()
// jQuery.text()
// DOM.setAttribute()
// .dialog.flop()
// 2015-06-25 PerfektesChaos@de.wikipedia
var dial, s,
lapsus = false;
WEX.job.pageNameEnc = mw.util.wikiUrlencode( WEX.job.pageName );
WEX.job.revCount = parseInt( WEX.job.revCount, 10 );
this.rvcontinue = -1;
this.request =
{ action: "query",
// OBSOLETE: query-continue --> continue
// rawcontinue: true, // LEGACY
"continue": "", // NEW
prop: "revisions",
titles: WEX.job.pageName,
rvdir: "newer",
rvlimit: WEX.job.revCount,
rvprop: "ids|flags|timestamp|user|comment|content"
};
s = WEX.job.startAfter;
if ( s ) {
switch ( s.substr( 0, 1 ) ) {
case "=" :
this.request.rvstartid = s.substr( 2 );
break;
case "2" :
if ( s.length === 19 ) {
s = s + "Z";
}
this.request.rvstart = s;
break;
} // switch .job.startAfter.substr( 0, 1 )
}
s = WEX.job.stopBefore;
if ( s ) {
switch ( s.substr( 0, 1 ) ) {
case "=" :
this.request.rvendid = s.substr( 2 );
if ( this.request.rvstartid ) {
lapsus =
( this.request.rvendid <= this.request.rvstartid );
}
break;
case "2" :
if ( s.length === 19 ) {
s = s + "Z";
}
this.request.rvend = s;
if ( this.request.rvstart ) {
lapsus =
( this.request.rvend <= this.request.rvstart );
}
break;
} // switch .job.stopBefore.substr( 0, 1 )
}
if ( WEX.job.revNumber ) {
WEX.job.revNumber = parseInt( WEX.job.revNumber, 10 );
if ( WEX.job.revNumber < WEX.job.revCount ) {
this.request.rvlimit = WEX.job.revNumber;
}
}
s = mw.config.get( "wgServer" );
WEX.job.domain = "//" + WEX.job.interLanguage + "."
+ WEX.job.wikiProject
+ ( s.indexOf( ".beta.wmflabs." ) > 0
? ".beta.wmflabs.org"
: ".org" );
if ( WEX.job.domain !== s ) {
// CORS; not protocol relative
this.request.origin = window.document.location.protocol
+ mw.config.get( "wgServer" );
this.script = { url: WEX.job.domain + "/w/api.php" };
}
dial = WEX.dialog;
WEX.job.multiple = 0;
WEX.job.ident = dial.$wrapper.find( "#WEX_job" ).text();
WEX.job.next = -1;
if ( lapsus ) {
dial.loop = false;
dial.flop( "END < START" );
} else if ( WEX.job.ident && WEX.dialog.push ) {
dial = dial.push;
dial.setAttribute( "data-suite", WEX.job.ident );
dial.setAttribute( "data-domain", WEX.job.domain );
dial.setAttribute( "data-page", WEX.job.pageName );
dial.setAttribute( "data-pagee", WEX.job.pageNameEnc );
if ( this.request.rvstart ) {
dial.setAttribute( "data-start", this.request.rvstart );
} else if ( this.request.rvstartid ) {
dial.setAttribute( "data-start", this.request.rvstartid );
}
if ( WEX.job.storeName ) {
dial.setAttribute( "data-store", WEX.job.storeName );
}
} else {
dial.loop = false;
dial.flop( "Job ID missing" );
}
WEX.api.loop = WEX.dialog.loop;
}; // .api.first()
WEX.api.flip = function ( adjust ) {
// Escape characters disturbing XML
// Precondition:
// adjust -- string
// Postcondition:
// Returns escaped string
// 2013-08-20 PerfektesChaos@de.wikipedia
return adjust.replace( /&/g, "&" )
.replace( /</g, "<" )
.replace( />/g, ">" );
}; // .api.flip()
WEX.api.follow = function () {
// Fire data push event to add-on
// Uses:
// > .dialog.push
// .flash()
// 2013-08-20 PerfektesChaos@de.wikipedia
WEX.flash( WEX.dialog.push, "wikiexportPush", false );
}; // .api.follow()
WEX.api.found = function ( arrived ) {
// Postprocess page content after ajax request
// Precondition:
// arrived -- JSON result of ajax query
// Uses:
// > .dialog.push
// > .job.revNumber
// > .api.loop
// > .api.stop
// >< .job
// >< .job.luxury
// >< .multiple
// >< .api.request
// < .api.rvcontinue
// < .job.ns
// < .job.pageid
// < .job.canonical
// < .job.lock
// .dialog.flop()
// .dialog.found()
// .api.factory()
// DOM.setAttribute()
// .api.follow()
// Remark: Used as event handler -- 'this' is not WEX.api
// 2015-07-09 PerfektesChaos@de.wikipedia
var el, pid,
q = ( typeof arrived === "object" );
WEX.api.loop = false;
if ( WEX.api.request.rvstart ) {
delete WEX.api.request.rvstart;
}
if ( WEX.api.request.rvstartid ) {
delete WEX.api.request.rvstartid;
}
if ( q ) {
q = arrived[ "query-continue" ];
// OBSOLETE: query-continue --> continue
if ( q ) {
q = q.revisions;
if ( q ) {
WEX.api.request.rvcontinue = q.rvcontinue;
WEX.api.rvcontinue = q.rvcontinue;
WEX.api.loop = true;
}
} else {
if ( WEX.api.request.rvcontinue ) {
delete WEX.api.request.rvcontinue;
}
if ( WEX.api.rvcontinue ) {
delete WEX.api.rvcontinue;
}
}
if ( typeof arrived[ "continue" ] === "object" ) {
$.extend( WEX.api.request, arrived[ "continue" ] );
WEX.api.rvcontinue = WEX.api.request.rvcontinue;
WEX.api.loop = true;
} else {
if ( typeof WEX.api.request.rvcontinue === "number" ) {
delete WEX.api.request.rvcontinue;
}
if ( typeof WEX.api.rvcontinue === "number" ) {
delete WEX.api.rvcontinue;
}
}
q = arrived.query;
if ( q ) {
q = q.pages;
if ( q ) {
for ( pid in q ) {
if ( pid === "-1" ) {
WEX.dialog.flop( "Page missing" );
q = false;
} else {
q = q[ pid ];
}
if ( q ) {
el = WEX.dialog.push;
if ( ! WEX.job.luxury ) {
WEX.job.ns = q.ns;
WEX.job.pageid = q.pageid;
WEX.job.canonical = q.title;
WEX.dialog.found();
WEX.job.luxury = true;
}
q = q.revisions;
if ( q ) {
q = WEX.api.factory( q );
if ( q[ 2 ] ) {
el.setAttribute( "data-timestamp", q[ 2 ] );
}
WEX.job.multiple += q[ 0 ];
el.setAttribute( "data-number", q[ 0 ] );
el.setAttribute( "data-XML", q[ 1 ] );
}
if ( WEX.job.revNumber ) {
if ( WEX.job.revNumber <=
WEX.job.multiple + WEX.job.revCount ) {
WEX.api.request.rvlimit =
WEX.job.revNumber - WEX.job.multiple;
WEX.api.loop =
( WEX.api.request.rvlimit > 0 );
}
}
if ( ! WEX.api.loop ) {
el.setAttribute( "data-last", "1" );
if ( WEX.api.stop ) {
el.setAttribute( "data-abort", WEX.api.stop );
}
}
WEX.api.follow();
}
break; // for pid
} // for pid in q
}
}
}
}; // .api.found()
WEX.dialog.gui = [
[ "baseDir", "button", true, "folder" ],
[ "start", "button", false, "forward" ],
[ "abort", "button", false, "flop" ],
[ "comHTTPS", "checkbox", null, false ],
[ "wikiProject", "input", 10, "filled" ],
[ "interLanguage", "input", 8, "filled" ],
[ "pageName", "input", 50, "filled" ],
[ "startAfter", "input", 19, "fence" ],
[ "stopBefore", "input", 19, "fence" ],
[ "revNumber", "input", 5, "figure" ],
[ "storeName", "input", 50, "filled" ],
[ "shortJob", "input", 10, "filled" ],
[ "revCount", "input", 5, "figure" ],
[ "fileSize", "input", 5, "figure" ],
[ "revLimit", "input", 5, "figure" ]
]; // 2013-09-10
WEX.dialog.fence = function ( dummy, $accept ) {
// Consider limiting version, set to appropriate string
// Precondition:
// about -- element keyword [currently unused]
// $accept -- GUI element
// Postcondition:
// Reset, if necessary
// Uses:
// this
// > .support
// >< .dialog.reSt
// jQuery.val()
// 2013-08-20 PerfektesChaos@de.wikipedia
var s;
if ( $accept && $accept.length ) {
if ( ! this.reSt ) {
this.reSt = "^("
+ "=[1-9][0-9]{1,10}"
+ "|"
+ "20[0-2][0-9]"
+ "("
+ "[01][0-9][0-3][0-9]{7,7}"
+ "|"
+ "-[01][0-9]-[0-3][0-9]"
+ "([tT][012][0-9]"
+ "(:[0-5][0-9]"
+ "(:[0-5][0-9]"
+ "[A-Za-z]?"
+ ")?"
+ ")?"
+ ")?"
+ ")"
+ ")$";
this.reSt = new RegExp( this.reSt );
}
s = $accept.val().trim();
if ( this.reSt.test( s ) ) {
if ( s.indexOf( "-" ) > 0 ) {
s = s.toUpperCase();
switch ( s.length ) {
case 10 :
s = s + "T00"; // fall through
case 13 :
s = s + ":00"; // fall through
case 16 :
s = s + ":00";
} // switch s.length
}
} else {
s = "";
}
$accept.val( s );
}
}; // .dialog.fence()
WEX.dialog.figure = function ( dummy, $accept ) {
// Inspect number, set to empty string if not positive integer
// Precondition:
// about -- element keyword [currently unused]
// $accept -- GUI element
// Postcondition:
// Reset, if necessary
// Uses:
// jQuery.val()
// 2013-08-20 PerfektesChaos@de.wikipedia
var v;
if ( $accept && $accept.length ) {
v = $accept.val();
v = parseInt( v, 10 );
if ( isNaN( v ) ) {
v = "";
} else if ( v < 1 ) {
v = "";
} else {
v = "" + Math.floor( v );
}
$accept.val( v );
}
}; // .dialog.figure()
WEX.dialog.filled = function ( about, $accept ) {
// Inspect project request, set to appropriate string
// Precondition:
// about -- element keyword
// $accept -- GUI element
// Postcondition:
// Reset, if necessary
// Uses:
// this
// > .support
// > .dialog.$buttonStart
// >< .dialog.reTime
// jQuery.val()
// mw.config.get()
// jQuery.attr()
// 2013-09-01 PerfektesChaos@de.wikipedia
var s, v;
if ( $accept && $accept.length ) {
v = $accept.val().trim();
s = v.toLowerCase();
switch ( about ) {
case "wikiProject" :
if ( WEX.support.indexOf( "|" + s + "|" ) < 0 ) {
s = "wikipedia";
}
break;
case "interLanguage" :
if ( ! /^[a-z][a-z]+(-[a-z]+)?$/.test( s ) ) {
s = mw.config.get( "wgContentLanguage" );
}
break;
case "shortJob" :
s = s.replace( /[^a-z]/g, "" );
break;
case "pageName" :
case "storeName" :
s = v;
if ( /[|{}#<>]/.test( v )
|| v.indexOf( "[" ) >= 0
|| v.indexOf( "]" ) >= 0 ) {
s = "";
} else {
s = v;
}
if ( about === "pageName" ) {
this.$buttonStart.attr( "disabled",
( s.length === 0 ) );
}
break;
} // switch wgAction
$accept.val( s );
}
}; // .dialog.filled()
WEX.dialog.fire = function () {
// Initialize form
// Uses:
// > mw.util.$content
// > document
// < .dialog.$wrapper
// jQuery.find()
// jQuery.attr()
// .dialog.form()
// .flash()
// Remark: Used as event handler -- 'this' is not WEX.dialog
// 2013-08-20 PerfektesChaos@de.wikipedia
WEX.dialog.$wrapper = mw.util.$content.find( "#WEX_Wrapper" );
if ( WEX.dialog.$wrapper.length ) {
WEX.dialog.$wrapper.attr( "style", null );
WEX.dialog.form();
WEX.flash( window.document, "wikiexportBegin", false );
}
}; // .dialog.fire()
WEX.dialog.fired = function ( action ) {
// Execute gadget action
// Precondition:
// action -- identifier
// Postcondition:
// Local processing and event dispatched to privileged level
// Uses:
// this
// > .dialog.gui
// .figure()
// .folder()
// Remark: Used as event handler -- 'this' is not WEX.dialog
// 2013-08-20 PerfektesChaos@de.wikipedia
var e, i,
n = this.gui.length;
for ( i = 0; i < n; i++ ) {
e = this.gui[ i ];
if ( e[ 0 ] === action ) {
break; // for i
}
} // for i
if ( i < n ) {
if ( e[ 3 ] ) {
WEX.dialog[ e[ 3 ] ]( action, e[ 4 ] );
}
}
}; // .dialog.fired()
WEX.dialog.flat = function () {
// Hide undesired content from regular page
// Uses:
// mw.util.addCSS()
// 2013-08-20 PerfektesChaos@de.wikipedia
var s = ".cn-fundraiser-banner,"
+ "#mw-js-message,"
+ "#siteNotice,"
+ "#fundraising\n"
+ "#ca-nstab-user,"
+ "#ca-view,"
+ "#ca-history,"
+ "#ca-move,"
+ "#ca-ve-edit,"
+ ".vectorMenu\n,"
+ ".noarticletext,"
+ "DIV.mw-tos-summary,"
+ "SPAN#wpSummaryLabel,"
+ "DIV#editpage-copywarn,"
+ "A#mw-editform-cancel,"
+ ".editHelp,"
+ "A[target=\"helpwindow\"],\n"
+ "INPUT#wpDiff,"
+ "INPUT#wpSave,"
+ "INPUT#wpSummary,"
+ ".editCheckboxes,"
+ ".cancelLink,"
+ ".imeselector,"
+ ".imeselector-toggle,"
+ "#enhanced-diff-live-button,"
+ "#wikEdEditHelp,"
+ "#wikEdLocalDiff,"
+ "#wikEdSummaryInputWrapper,"
+ "#thresholdSave\n"
+ "{display: none ! important;}";
mw.util.addCSS( s );
}; // .dialog.flat()
WEX.dialog.flop = function ( about ) {
// Kill "Export" action; stop API requests
// Precondition:
// about -- additional information, if any
// Uses:
// this
// > .dialog.$buttonAbort
// < .api.stop
// < .dialog.loop
// jQuery.find()
// jQuery.attr()
// jQuery.text()
// 2013-09-01 PerfektesChaos@de.wikipedia
var s,
date = new Date(),
$e = this.$wrapper.find( "#WEX_log" );
this.$buttonAbort.attr( "disabled", true );
WEX.api.stop = ( about ? about : "[abort]" );
$e.attr( "style", "background-color: #DC143C" );
s = $e.text();
s = ( s ? s + "\n\n" : "" )
+ "=====================================================\n\n"
+ date.toLocaleString();
s = s + " " + WEX.api.stop;
$e.text( s );
WEX.dialog.loop = false;
}; // .dialog.flop()
WEX.dialog.focus = function () {
// Enable [Export] button and put focus there.
// Uses:
// > .dialog.$buttonStart
// 2013-08-20 PerfektesChaos@de.wikipedia
this.$buttonStart.attr( "disabled", false );
this.$buttonStart.focus();
}; // .dialog.focus()
WEX.dialog.folder = function () {
// Change directory selection
// Postcondition:
// Request launched
// Uses:
// > document
// >< .dialog.directory
// DOM.getElementById()
// .flash()
// Remark: Used as event handler -- 'this' is not WEX.dialog
// 2013-08-20 PerfektesChaos@de.wikipedia
if ( ! WEX.dialog.directory ) {
WEX.dialog.directory
= window.document.getElementById( "WEX_gadget_baseDir" );
}
WEX.flash( WEX.dialog.directory, "wikiexportButton", "ChangeDir" );
}; // .dialog.folder()
WEX.dialog.form = function () {
// Initialize form
// Uses:
// this
// > .dialog.gui
// > .dialog.$wrapper
// > document
// >< .preset
// < .dialog.$buttonStart
// < .dialog.$buttonAbort
// .dialog.flat()
// jQuery.find()
// jQuery.insertAfter()
// jQuery.remove()
// jQuery.attr()
// jQuery.val()
// 2013-08-20 PerfektesChaos@de.wikipedia
var e, i, spec, src, $e, $subst,
lock = true,
n = this.gui.length;
this.flat();
if ( ! WEX.preset ) {
WEX.preset = { };
}
for ( i = 0; i < n; i++ ) {
e = this.gui[ i ];
spec = e[ 0 ];
$subst = this.$wrapper.find( "#WEX_subst_" + spec );
if ( $subst.length ) {
src = " id='WEX_gadget_" + spec + "' ";
switch ( e[ 1 ] ) {
case "button" :
src = "<button type='button'" + src
+ "style='background-color: #80FFFF'"
+ " onclick='mw.libs.wikiExport.dialog."
+ "fired(\"" + spec + "\")'"
+ ( e[ 2 ] ? "" : " disabled" )
+ ">"
+ $subst.text()
+ "</button>";
break;
case "checkbox" :
src = "<input" + src
+ "type='checkbox' />";
break;
case "input" :
src = "<input" + src
+ "type='text'"
+ " size='" + e[ 2 ] + "'"
+ " class='noime'"
+ " onchange='mw.libs.wikiExport.dialog."
+ "fired(\"" + spec + "\")'"
+ " />";
break;
default :
src = false;
} // switch e[1]
if ( src ) {
$e = $( src );
$e.insertAfter( $subst );
$subst.remove();
e.push( $e );
switch ( e[ 1 ] ) {
case "button" :
switch ( spec ) {
case "start" :
this.$buttonStart = $e;
if ( ! lock ) {
$e.attr( "disabled", false );
}
break;
case "abort" :
this.$buttonAbort = $e;
break;
} // switch spec
break;
case "input" :
if ( WEX.preset[ spec ] ) {
$e.val( WEX.preset[ spec ] );
if ( spec === "pageName" ) {
lock = false;
$e.focus();
}
}
break;
} // switch e[1]
}
}
} // for i
this.$wrapper.find( "#WEX_gadget_comHTTPS" )
.attr( "disabled", true );
}; // .dialog.form()
WEX.dialog.forward = function () {
// Perform "Export" action; request API start
// Uses:
// this
// > .dialog.gui
// > .dialog.$buttonAbort
// > .dialog.$wrapper
// < .job
// < .dialog.push
// < .api.loop
// < .dialog.loop
// jQuery.attr()
// jQuery.val()
// mw.config.get()
// jQuery.text()
// jQuery.find()
// DOM.getElementById()
// DOM.addEventListener()
// .api.follow()
// .dialog.flash()
// .dialog.flop()
// (.api.fetch)
// 2013-09-01 PerfektesChaos@de.wikipedia
var e, i, s, v, $e,
n = this.gui.length;
this.$buttonStart.attr( "disabled", true );
WEX.job = { };
for ( i = 0; i < n; i++ ) {
e = this.gui[ i ];
$e = e[ 4 ];
if ( $e && $e.length ) {
if ( e[ 1 ] !== "button" ) {
s = e[ 0 ];
v = $e.val();
if ( v === "" ) {
switch ( s ) {
case "wikiProject" :
v = "wikipedia";
break;
case "interLanguage" :
v = mw.config.get( "wgContentLanguage" );
break;
case "shortJob" :
case "revCount" :
v = $( "#WEX_default_" + s ).text();
break;
} // switch e[0]
$e.val( v );
}
e.push( v );
WEX.job[ s ] = v;
}
$e.attr( "disabled", true );
}
} // for i
$e = this.$wrapper.find( "#WEX_log" );
$e.attr( "style", "background-color: #80FFFF" );
$e.text( "\n\n" );
this.push = window.document.getElementById( "WEX_gadget_start" );
if ( this.push ) {
WEX.api.loop = true;
this.loop = true;
window.document.addEventListener( "wikiexportFetch",
WEX.api.fetch,
true );
WEX.api.follow();
this.$buttonAbort.attr( "disabled", false );
} else {
this.flop( "Lost [start]" );
}
}; // .dialog.forward()
WEX.dialog.found = function () {
// Equip page with export page specification
// Uses:
// this
// > .dialog.$wrapper
// > .job.ns
// > .job.canonical
// > .job.pageNameEnc
// > .job.pageid
// >< .dialog.$details
// jQuery.find()
// jQuery.attr()
// jQuery.append()
// jQuery.remove()
// 2013-08-20 PerfektesChaos@de.wikipedia
var d, $e;
if ( ! this.$details ) {
this.$details = this.$wrapper.find( "#WEX_details" );
if ( this.$details.length ) {
d = WEX.job;
this.$details.attr( "style", null );
if ( d.ns ) {
$e = this.$details.find( "#WEX_namespace" );
$e.attr( "style", null );
$e.append( $( "<span>ns: <code>"
+ d.ns + "</code></span>" ) );
}
if ( d.canonical ) {
$e = this.$details.find( "#WEX_canonical" );
$e.attr( "style", null );
$e.append( $( "<span>" + d.canonical + "</span>" ) ) ;
}
if ( d.pageNameEnc !== d.canonical ) {
$e = this.$details.find( "#WEX_pageNameEnc" );
$e.attr( "style", null );
$e.append( $( "<span>" + d.pageNameEnc + "</span>" ) ) ;
}
if ( d.pageid ) {
$e = this.$details.find( "#WEX_pageid" );
$e.attr( "style", null );
$e.append( $( "<code>" + d.pageid + "</code>" ) );
}
}
}
}; // .dialog.found()
WEX.fire = function () {
// Start page processing; check whether situation is interesting
// Uses:
// > .pages
// > .wgNamespaceNumber
// <.wgTitle
// mw.config.get()
// mw.loader.using()
// (.first)
// Remark: Used as event handler -- 'this' is not WEX
// 2013-08-20 PerfektesChaos@de.wikipedia
var i, n, p;
if ( typeof WEX.pages === "object" ) {
WEX.wgTitle = mw.config.get( "wgTitle" );
n = WEX.pages.length;
for ( i = 0; i < n; i++ ) {
p = WEX.pages[ i ];
if ( p[ 0 ] === WEX.wgNamespaceNumber ) {
if ( p[ 1 ] === WEX.wgTitle ) {
mw.loader.using( [ "mediawiki.api",
"mediawiki.user",
"mediawiki.util",
"jquery.client" ],
WEX.first );
break;
}
}
} // for i
}
}; // .fire()
WEX.first = function () {
// Initialize environment
// Precondition:
// Resources have been loaded; page is expected to be supported
// Uses:
// > jQuery.client
// mw.hook()
// (.dialog.fire)
// Remark: Used as event handler -- 'this' is not WEX
// 2013-08-20 PerfektesChaos@de.wikipedia
var client = $.client.profile();
if ( client ) {
if ( client.name === "firefox" ) { // client.name.indexOf()
mw.hook( "wikipage.content" ).add( WEX.dialog.fire );
}
}
}; // .first()
WEX.flash = function ( assign, action, add ) {
// Create and dispatch event
// Precondition:
// assign -- DOM element
// action -- event identifier
// add -- action attribute, or false
// Uses:
// > document
// DOM.createEvent()
// DOM.setAttribute()
// DOM.initEvent()
// DOM.dispatchEvent()
// 2013-09-10 PerfektesChaos@de.wikipedia
var event = window.document.createEvent( "Events" );
if ( assign && event ) {
if ( add ) {
assign.setAttribute( "data-action", add );
}
event.initEvent( action, true, false );
assign.dispatchEvent( event );
}
}; // .flash()
WEX.flush = function () {
// Clear form, enable buttons and fields again
// Uses:
// > .dialog.gui
// > .dialog.$buttonAbort
// > .dialog.$wrapper
// jQuery.val()
// jQuery.attr()
// jQuery.find()
// 2013-09-12 PerfektesChaos@de.wikipedia
var e, i, $e,
n = WEX.dialog.gui.length;
for ( i = 0; i < n; i++ ) {
e = WEX.dialog.gui[ i ];
$e = e[ 4 ];
if ( $e && $e.length ) {
if ( e[ 1 ] === "input" ) {
$e.val( "" );
}
$e.attr( "disabled", null );
}
} // for i
WEX.dialog.$buttonAbort.attr( "disabled", true );
WEX.dialog.$wrapper.find( "#WEX_log" ).empty();
}; // .flush()
WEX.focus = function () {
// Enable [Export] button and put focus there.
// Uses:
// .dialog.focus()
// 2013-08-20 PerfektesChaos@de.wikipedia
WEX.dialog.focus();
}; // .focus()
if ( ! WEX.loaded ) {
WEX.loaded = true;
if ( WEX.pages ) {
if ( WEX.wgNamespaceNumber === 2 ||
WEX.wgNamespaceNumber === 4 ) {
WEX.fire();
}
}
mw.loader.state( { "ext.gadget.wikiExport": "ready" } );
}
}( window.mediaWiki, window.jQuery ) );
// Emacs
// Local Variables:
// coding: utf-8-dos
// fill-column: 80
// End: