Enabling Media / File Uploads for MediaWiki On Windows Server

This post is part of a series of posts about MediaWiki on Windows :

  1. Installing MediaWiki on Windows Server 2012 R2 Core
  2. Installing VisualEditor for MediaWiki on IIS
  3. Enabling Media / File Uploads For MediaWiki on Windows Server

Enable PHP File Uploads
Check that “file_uploads = On” is present in your PHP.ini file. It was already enabled in my installation. If you have followed the other guides in this series, the file should be here :
C:\Program Files (x86)\PHP\v5.4\php.ini

Set the temp file upload path in PHP.ini.
On Windows, if PHP was installed by WebPI this will be set to %SystemRoot%\Temp. It needs to be set the same as the “$wgTmpDirectory” var in the MediaWiki LocalSettings.php file. If you have followed the steps in my previous posts – you will have already added the correct permissions to this folder.

Permissions on the Upload Folder
I was following the guide here which suggests you need to change the permissions on the folder :
C:\inetpub\wwwroot\wiki\images however, it looks like permissions have been set correctly on the folder above and inherited down.

Testing
If your PHP.ini file needed a change, you will need to restart IIS on the server (to cause PHP to restart and read its config again). If not, you should be able to see a new option on the left hand menu on every wiki page called ‘Upload file’ – great step 1 complete! Now does it work? Clicking the link should take you to a page where you can choose a file to upload. Try uploading a file and ensure it renders correctly – if its an image.

Converting VMware Machine to Hyper-V

As described in a previous post, I have installed MediaWiki on Server 2012 R2 Core. Now I need to convert the machine I built from ESXI to Hyper-V.

I needed to keep the original VM, with its Snapshots, and create a copy of it for a LAB environment. My setup :

  • ESXi (Free) 6.0.0 – Source
  • Server 2012 TP4 with Hyper-V – Destination

Steps I used to copy the VM :

  • Take a Snapshot of the Virtual Machine as a backup
  • We need a machine without snapshots to import into Hyper-V
  • Task Snapshot of functioning machine
  • Run “sysprep /generalize /oobe /shutdown” to generalize the machine and shut it down
  • sysprep

  • Use Vmware converter to convert machine from ESXI format to Workstation format (this will consolidate the snapshots, but leave the original VM untouched)
  • Download and install Microsoft Virtual Machine Converter (I used chocolatey to get MVMC)
  • Once conversion is finished you should have a vmdk and a vmx file in a folder.
  • Using the GUI of Microsoft Virtual Machine Converter it’s not possible to convert this ‘offline’ machine
  • We need to use powershell :
  • Import-Module 'C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1'
    ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath "C:\PathToVMDK\disk.vmdk" -DestinationLiteralPath "C:\DestinationFolder\" -VhdType DynamicHardDisk -VhdFormat Vhdx
    Disable-MvmcSourceVMTools -DestinationLiteralPath "C:\DestinationFolder\disk.vmdk"
    
  • Now, create a new VM in Hyper-V manager, I used gen 1 as my ESXI machine was using legacy / bios firmware. You may need to use Gen 2 if the original VM was running in UEFI mode.

I was pleasantly surprised by how quick and easy this was – whenever I have tried to do VM conversion in the past its never worked correctly!!

Git and Node Proxy Settings

Today i came to replicating the MediaWiki install i wrote about previously on a server in work. This mean’t dealing with proxies and i noticed some strange behavior.

Git

Using these commandlines, git was able to get out of our corporate firewall.

git config –global http.proxy http://proxy.company.com:8080

git config –global https.proxy http://proxy.company.com:8080

Node

Initially i set https-proxy to the https address for our proxy but it didnt work. I found out that for some reason changing this to http proxy address worked.

npm config set proxy http://proxy.company.com:8080

npm config set https-proxy http://proxy.company.com:8080

Installing VisualEditor for MediaWiki on IIS

This post is part of a series of posts about MediaWiki on Windows :

  1. Installing MediaWiki on Windows Server 2012 R2 Core
  2. Installing VisualEditor for MediaWiki on IIS
  3. Enabling Media / File Uploads For MediaWiki on Windows Server
  • Download and Install Git
    • Get the exe install from http://git-scm.com/download/win
    • Run install from powershell commandline
      • Git.exe /verysilent /LOG="C:\temp\gitinstall.log"
      • Wait a few minutes, then check the log to ensure successful install
      • Add Git folder to Path Environment Variable
        • SETX /M PATH "PATH%;C:\Program Files\Git\bin"
  • VisualEditor extension requires Parsoid (a component which converts wiki-text to html)
    • Download and install Node.js x86 MSI from https://nodejs.org/download/release/latest/
      • msiexec /i node-x.msi /qn /l*v C:\Temp\nodeinstall.log
    • Download and Install Python
      • Download version 2.7.x from https://www.python.org/downloads/
      • msiexec /i python-2.7.x.msi /qn /l*v C:\temp\pythoninstall.log
      • SETX /M PYTHONHOME "C:\Python27"
      • SETX /M PATH "%PATH%;C:\Python27"
    • Set Node Python Version
      • npm config set python python2.7
    • Install Parsoid
    • Copy the localsettings.js.example file to localsettings.js and edit : you will need to replace this line with url of you mediawiki
      • uri: 'http://localhost/w/api.php',
    • Start parsoid
      • node bin\server.js
      • This will start parsoid in a local session, when the machine is restarted – it won’t run again. We will sort this out at the end…
  • To ensure you get a version of VisualEditor that is compatible with the installed mediawiki visit the following site and download the appropriate version :
  • To enable VisualEditor we need to edit the mediawiki LocalSettings.php and insert the following lines at the bottom

require_once "$IP/extensions/VisualEditor/VisualEditor.php";
// Enable by default for everybody
$wgDefaultUserOptions['visualeditor-enable'] = 1;
// Don't allow users to disable it
$wgHiddenPrefs[] = 'visualeditor-enable';
// OPTIONAL: Enable VisualEditor's experimental code features
#$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1;

  • Go to your wiki in a browser and you should now have an extra ‘Edit Source’ option in the top right – this will take you to the old editor.

visualeditor_1

  • Click the edit button and you should see a loading bar and shortly after that the VisualEditor!

visualeditor_2

(UPDATE – i have noticed that the below will only work after a user logs in, I will edit this post with a fix once I have one…)

  • parsoid is running in a local session and we need to run it automatically.
    • I added a string registry key using regedit
    • HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
    • "C:\Program Files (x86)\nodejs\node.exe" C:\parsoid_install_dir\bin\server.js
  • Reboot the machine and check parsoid is still working by loading your wiki and trying to edit a page. If it doesnt work you the loading bar will pause about 3/4 of the way along

visualeditor_3

 

 

Installing MediaWiki on Windows Server 2012 R2 Core

Guide on how to install Media Wiki on Windows Server, using Web PI.

This post is part of a series of posts about MediaWiki on Windows :

  1. Installing MediaWiki on Windows Server 2012 R2 Core
  2. Installing VisualEditor for MediaWiki on IIS
  3. Enabling Media / File Uploads For MediaWiki on Windows Server
  • Install Server 2012 R2 Core on a machine or VM
  • Install IIS using powershell
    • Install-WindowsFeature -Name Web-Server
    • iis_install_serv_core
  • Install Microsoft Web Platform Installer (WebPI)
  • Install Media Wiki using webpicmd
    • Change the directory to : C:\Program Files\Microsoft\Web Platform Installer
    • Run the following command to install the MediaWiki application
      • .\webpicmd /Install /Application:MediaWiki
    • Web Pi will ask you several questions (config options, usernames and password etc…) at the end you should see :
    • media_wiki_core_install
  • Test the installation
  • At the next page i encountered a problem, the css didnt load
    • media_wiki_missing_css
  • I opened up the source and clicked the link which should load the css, this returned :
    • Exception encountered, of type "Less_Exception_Parser" [ec4dcf50] /mediawiki/mw-config/index.php?css=1 Less_Exception_Parser from line 447 of C:\inetpub\wwwroot\mediawiki\vendor\oyejorge\less.php\lib\Less\Parser.php: Less.php cache directory isn't writable: C:\Windows\TEMP Backtrace: #0 C:\inetpub\wwwroot\mediawiki\includes\resourceloader\ResourceLoader.php(1620): Less_Parser->SetCacheDir(string) ...
  • MediaWiki is trying to write to “C:\Window\TEMP” but the user context that PHP is running in (via IIS) doesn’t have permission.
    • !!! This is what I did to resolve the issue, its highly not recommended – it would be better to isolate the MediaWiki temp folder somewhere else !!!
      • Get an object representing the permissions of “C:\inetpub\wwwroot\mediawiki” folder
        • $acl_web = get-acl "C:\inetpub\wwwroot\mediawiki"
      • Get an array of just the access rules for *IUSR*
        • $perms = $acl_web.access|?{$_.identityreference -like "*IUSR*"}
      • Get an object representing just the access permissions for the TEMP folder
        • $acl_temp = (get-item "C:\Windows\TEMP").GetAccessControl("Access")
      • Add the access rules from the mediawiki folder to the temp folder acl
        • $perms | %{$acl_temp.AddAccessRule($_)}
      • Set the TEMP folder permissions to the newly created acl object
        • Set-Acl -path "C:\Windows\TEMP" -aclobject $acl_temp
    • I reloaded the wiki page in my browser and the CSS loaded properly
  • “Installing” MediaWiki
    • Choose language options and continue
    • The next page told me that i was ready to install mediawiki.
    • At the next page, i added the same MySQL options as during the WebPI command line install of MediaWiki
    • I left the database settings as default
    • Next add a title and create yourself a user account
    • This page allows you to change the reply address on the emails sent by mediawiki and also select some extensions. I choose just WikiEditor
    • Download your “LocalSettings.php”
    • Now we need to get this LocalSettings.php file to the server and store it in the mediawiki root folder.
      • I am using a virtual machine, so I opened the file and copied the text – then on the vm i opened notepad, pasted the text and saved the file as “C:\inetpub\wwwroot\mediawiki\LocalSettings.php”
  • I went back to the main page and this time it took a little longer to load – but loaded the Wiki correctly (it didn’t try to take me through install again, meaning it had picked up the settings)
  • To fully enable the WikiEditor extension, I had to add some more lines to the LocalSettings.php file more information : https://www.mediawiki.org/wiki/Extension:WikiEditor

Page loading initially was very slow at about 10s per page! This was happening because the database was being access using the hostname – localhost. This brings the ipv6 stack into play, which for some reason slows everything down.

To fix this, change the $wgDBserver variable in LocalSettings.php to 127.0.0.1 to force the use of ipv4