User:Csega/Install mediawiki on windows

From mediawiki.org

MédiaWiki-t TeX supporttal működésre bírni

  • Szükséges eszközök:
  • XAMPP (1.7.0)
  • MikTeX (2.7)
  • MinGW (a mingw32-make.exe telepítése szükséges!!!) (5.1.4)
  • Objective Caml (3.11.0)
  • Ghostscript (gswin32c.exe-t érdemes gs.exe néven is bemásolni a könyvtárba) (8.63)
  • ImageMagick (Q16, dynamic-ot használtam) (6.4.9)
  • Ezeket mind hozzáadni a PATH-hoz (ha nem tették meg maguktól).
  • MediaWiki telepítése (XAMPP-nál az 1.7.1-es verzióig a MySQL-nél superusert kell megadni. Felhasználónév: root, jelszó: üresen hagyva. A wikidb táblát érdemes utf8-unicode-ban létrehozni. MediaWikinél a MySQL telepítési hely localhost, és a wikiuser alá akármit be lehet írni, majd létrehozza.)-->Ezzel a MediaWiki feltelepítve, de még nincs engedélyezve a math support. (Nálam működött mind Windows Vista (és SP1) 32-bit, valamint Windows 7 RC 64 bit alatt. Természetesen ehhez a megfelelő programok 64-bites változatát kell letölteni.) Ehhez:

1. Modify math\render.ml so it looks like,

let cmd_dvips tmpprefix = "dvips -R -E -q \"" ^ tmpprefix ^ ".dvi\" -f >\"" ^tmpprefix^".ps\" "
let cmd_latex tmpprefix = "latex  -quiet \"" ^ tmpprefix ^ ".tex\" >\""^tmpprefix^".tmp\" "
let cmd_convert tmpprefix finalpath = "convert -quality 100 -density 120 \"ps:"^tmpprefix^".ps\" \""^finalpath^"\""
exception ExternalCommandFailure of string
let render tmppath finalpath outtex md5 =
  let tmpprefix0 = (string_of_int (Unix.getpid ()))^"_"^md5 in
  let tmpprefix = (tmppath^"\\"^tmpprefix0) in
  let unlink_all () =
    begin
      Sys.remove (tmpprefix ^ ".dvi"); 
      Sys.remove (tmpprefix ^ ".aux");
      Sys.remove (tmpprefix ^ ".log");
      Sys.remove (tmpprefix ^ ".tex");
      Sys.remove (tmpprefix ^ ".ps");
      Sys.remove (tmpprefix ^ ".tmp");
    end in
  let f = (Util.open_out_unless_exists (tmpprefix ^ ".tex")) in
    begin
      output_string f (Texutil.get_preface ());
      output_string f outtex;
      output_string f (Texutil.get_footer ());
      close_out f;
      if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0
      then (unlink_all (); raise (ExternalCommandFailure "latex"))
      else if (Sys.command (cmd_dvips tmpprefix) != 0)
      then (unlink_all (); raise (ExternalCommandFailure "dvips"))
      else if (Sys.command (cmd_convert tmpprefix (finalpath^"\\"^md5^".png")) != 0)
      then (unlink_all (); raise (ExternalCommandFailure "convert"))
      else unlink_all ()
end

2. make the bytecode version texvc.bc (in the dos window, first go the the folder with math files, run command mingw32-make texvc.bc then rename texvc.bc to texvc.exe.

3. move the file texvc.exe to the main folder with localsetting.php

4. In /includes/Math.php replace the following:

wfDebug( "TeX: $cmd\n" );

with the following:

$cmd=str_replace("'","\"",$cmd); wfDebug( "TeX: $cmd\n" );

and comment out the following:

I also had to comment out the following in Math.php so that things don't run in a cygwin shell.
#     if ( wfIsWindows() ) {
#		# Invoke it within cygwin sh, because texvc expects sh features in its default shell
#		$cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
#	}

5. In LocalSettings.php, change

$wgUseTeX= false;

to

$wgUseTeX= true;

and add this line

$wgTexvc = "texvc.exe";

You are done now. Good luck.

Ez még nem teljesen elég, mert néha nyafogni fog, hogy nem tud átnevezni/áthelyezni fájlokat. Ennek kiküszöbölésére hajtsuk végre a következő változtatásokat (néhányat már megcsináltunk korábban, azokat békén lehet hagyni):

I have experienced several problems with this method in connection with math.php as of MediaWiki version 1.10.0 (I have no experience with earlier versions) and the above texvc executable (1.4.7) by Fernando. I chose the latter one because it required neither cygwin nor ocaml runtimes. Here's what I figured out:

  1. only the directory "$wgTmpDirectory" is passed to both the temp and the math directory that texvc expects on its command line. This somehow seems to cause unwanted deletion of the generated image.
  2. the math.php relies on the cygwin shell "sh" to be installed on the system, which is not the case on my system.
  3. "$wgTmpDirectory" and "$wgMathDirectory" contain some slashes instead of backslashes as is common for windows. This seems to mess something up for the texvc executable so the image file does not get generated. Surprisingly, if I copy the very same commandline from the MediaWiki debug logfile to a shell window, the file gets generated.
  4. after execution of texvc, the math.php looks for the image file in "$wgTmpDirectory" which is consistent with the call of texvc

The following steps to change math.php were necessary for me to get it working.

The constuctor:

function __construct( $tex, $params=array() ) {
    if ( wfIsWindows() ) {
        $tex = str_replace( "\n", ' ', $tex );
    }
    $this->tex = $tex;
    $this->params = $params;
}

In "function render()";

Make "$wgMathDirectory" accessible by changing

function render() {
    global $wgTmpDirectory, $wgInputEncoding;

into

function render() {
    global $wgTmpDirectory,$wgMathDirectory, $wgInputEncoding;

Then change the target directory for the texvc call into wgMathDirectory by replacing

$cmd = $wgTexvc . ' ' .
    escapeshellarg( $wgTmpDirectory ).' '.
    escapeshellarg( $wgTmpDirectory ).' '.
    escapeshellarg( $this->tex ).' '.
    escapeshellarg( $wgInputEncoding );

with

$cmd = $wgTexvc . ' ' .
    escapeshellarg( $wgTmpDirectory ).' '.
    escapeshellarg( $wgMathDirectory ).' '.
    escapeshellarg( $this->tex ).' '.
    escapeshellarg( $wgInputEncoding );

Now comment out the lines that try to use cygwin shell, if your system happens to be devoid of cygwin. Cmd.exe seems to be perfect for this anyway.

/*if ( wfIsWindows() ) {
    # Invoke it within cygwin sh, because texvc expects sh features in its default shell
    $cmd = 'sh -c ' . wfEscapeShellArg( $cmd );
}*/

In order to solve the slash problem replace the line

wfDebug( "TeX: $cmd\n" );

with the lines

 $cmd=str_replace("/","\\",$cmd); # replace slash by backslash for windows so texvc can work with it
 wfDebug( "TeX: $cmd\n" );

Finally replace

if( !file_exists( "$wgTmpDirectory/{$this->hash}.png" ) ) {

by

if( !file_exists( "$wgMathDirectory/{$this->hash}.png" ) ) {

and

if( !rename( "$wgTmpDirectory/{$this->hash}.png", "$hashpath/{$this->hash}.png" ) ) {
    return $this->_error( 'math_output_error' );
}

by

if (!file_exists("$hashpath/{$this->hash}.png")) {
    if( !rename( "$wgMathDirectory/{$this->hash}.png", "$hashpath/{$this->hash}.png" ) ) {
        return $this->_error( 'math_output_error' );
    }
}

so the generated file will be found where it has been saved. And if the image already exists at the final destination don't error when calling rename().

The suggested solution is obviously a workaround for problems located in the specific texvc executable (with the exception of the probably missing cygwin shell). Perhaps it would be a cleaner solution to compile a texvc that does not have these problems, but personally I did not want to delve into the rather involved procedure of fixing and building texvc.

Így már elvileg tényleg működni fog. Ha elakadunk, hasznos segítségek találhatóak itt: MediaWiki futtatása Windows-on