Yunqa • The Delphi Inspiration

Delphi Components and Applications

User Tools

Site Tools


wiki:wikitaxi:wikitaxi_import_script

WikiTaxi: Batch Import

Please register and / or log in to edit. Anonymous Wiki edits are disabled to protect against vandalism.

Some people routinely use WikiTaxi as an offline backup for their personal Wiki and need to convert their uncompressed MediaWiki XML dumps to a WikiTaxi *.taxi file on a regular basis. The following script provides a solution to simplify this process.

AutoIt is required to compile the script, and 7-Zip must be installed. Once compiled the script must be placed into the WikiTaxi directory. Then it allows to drag and drop (or select in standalone mode) a MediaWiki *.xml dump file for processing:

  • Run 7-Zip to compress the *.xml file to *.xml.bz2
  • Launch WikiTaxi_Importer.exe, type in the appropriate file names, and import.
  • Invoke WikiTaxi.exe and navigate to the main page.
; Automated MediaWiki XML to WikiTaxi converter. Compile with AutoIt. 
; Requires WikiTaxi in same directory as compiled .exe, also requires 7-Zip installed on PC.

; Match partial Window titles to support different versions of WikiTaxi
Opt("WinTitleMatchMode", 2)

; This will load the Main Page after importing, change to your preference.
$startpage = "Main Page"

; 7-Zip is required
If Not FileExists(@ProgramFilesDir & "\7-zip\7z.exe") Then 
	MsgBox(16, "Required", "7-Zip required! Please install and try again.")
	Exit
EndIf

; Drag and drop enabled
If $CmdLine[0] <> 0 Then 
	; Assume cmdline input is file location
	$wiki_xml = $CmdLine[1]
Else
	; Let user browse to .xml file to choose
	$wiki_xml = FileOpenDialog("Choose XML to convert to WikiTaxi", _
		@WorkingDir, "XML Files (*.xml)")
	If $wiki_xml = "" Then
		; Exit if canceled
		Exit
	EndIf
EndIf

; To make formatting code better for .taxi file
$wiki_taxi = StringTrimRight($wiki_xml, 3) & "taxi" 

; I'd rather not overwrite a Wiki, personal preference
If FileExists($wiki_taxi) Then 
	MsgBox(16, "Error", "Wiki already created under this name." & _
		@CRLF & "Rename " & $wiki_xml & @CRLF & "or delete " & $wiki_taxi)
	Exit
EndIf

; Compress the .xml to bzip so that the importer will take it
Run('"' & @ProgramFilesDir & '\7-zip\7z.exe" -tbzip2 a "' & _
		$wiki_xml & '.bz2" "' & $wiki_xml & '"')
ProcessWaitClose("7z.exe")

; Launch Importer
Run("WikiTaxi_Importer.exe")

; Make sure WikiTaxi is focus and activate it
WinActivate("WikiTaxi Importer")
WinWaitActive("WikiTaxi Importer")

; Type in newly compressed xml
ControlSetText("WikiTaxi Importer", "", _
	"[CLASS:TTntEdit.UnicodeClass; INSTANCE:1]", $wiki_xml & ".bz2")

; Type in .taxi
ControlSetText("WikiTaxi Importer", "", _
	"[CLASS:TTntEdit.UnicodeClass; INSTANCE:2]", $wiki_taxi)

; Click Import
ControlClick("WikiTaxi Importer", "", _
	"[CLASS:TTntButton.UnicodeClass; INSTANCE:2]")

; --- If you have issues after importing, adjust or remove lines below ---

; Adjust to your needs. I use a small wiki, not the Wikipedia, 
; so the timing is right for my situation.
Sleep(1000)

; AutoIt can't see this text otherwise we'd wait for it.
; To pause script, uncomment line below for larger wikis:
;MsgBox(0,"Wait...",'Wait for "Import finished successfully!"')

; Start WikiTaxi and navigate to specified start page
Run('WikiTaxi "' & $wiki_taxi & '" "' & $startpage & '"')

; Again, adjust below for larger wiki.
Sleep(2000)

; Timing may be off and close Importer too early for larger wiki.
ProcessClose("WikiTaxi_Importer.exe")

; Remove temporary file. You could also remove .xml, 
; but I keep it since WikiTaxi strips out history.
FileDelete($wiki_xml & ".bz2")
wiki/wikitaxi/wikitaxi_import_script.txt · Last modified: 2016/01/22 15:09 by 127.0.0.1