tag:blogger.com,1999:blog-45166932849094148632024-03-14T05:05:48.389+01:00Life & Work ImprovementTools, tips and tricks to do what you do - only better, faster, more efficiently. Or at least more fun.Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-4516693284909414863.post-85606038212003545072015-09-19T23:25:00.001+02:002015-09-19T23:27:57.529+02:00Installing Laravel 5 on Ubuntu 15.04On a fresh install of Ubuntu 15.04, and after doing a<br />
<i>sudo apt-get update && sudo apt-get upgrade</i><br />
<br />
Install VirtualBox and Vagrant:<br />
<i>sudo apt-get install virtualbox</i><br />
<i>sudo apt-get install vagrant</i><br />
<br />
Install the homestead box:<br />
<i>vagrant box add laravel/homestead</i><br />
(option 1, virtualbox)<br />
<br />
Install git:<br />
<i>sudo apt-get install git</i><br />
<br />
Get Homestead:<br />
<i>git clone https://github.com/laravel/homestead.git Homestead</i><br />
<br />
Go into the Homestead directory and create the Homestead configuration file:<br />
<i>cd Homestead</i><br />
<i>bash init.sh</i><br />
<br />
Go to this directory<br />
<i>cd ~/.homestead</i><br />
Where you find the homestead.yaml configuration file.<br />
<br />
Create a key<br />
<i>ssh-keygen -t rsa -C "you@homestead"</i><br />
enter 3 times (keep default location)<br />
<br />
Change the key location in the homestead.yaml file in the authorize section (/home/xxx/.ssh/id_rsa.pub) + the keys section (/home/xxx/.ssh/id_rsa)<br />
<br />
Create Code folder in your home folder /home/xxx:<br />
<i>cd ~</i><br />
<i>mkdir Code</i><br />
<br />
Go into the Homestead directory in your home folder:<br />
<i>cd ~/Homestead</i><br />
<br />
Run<br />
<i>vagrant up</i><br />
<br />
Change hosts so you can surf to your Homestead box:<br />
<i>sudo nano /etc/hosts</i><br />
<br />
Add the line<br />
<i>192.168.10.10 homestead.app</i><br />
<br />
Go into the vagrant box<br />
<i>vagrant ssh</i><br />
cd into the Code directory<br />
<i>cd Code</i><br />
<br />
And download laravel in the default folder:<br />
<i>composer create-project laravel/laravel Laravel --prefer-dist</i><br />
<br />
Now you can surf to http://homestead.app and it should show you 'Laravel 5'.Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-82903899599410635622015-09-10T15:10:00.000+02:002015-09-10T15:10:04.606+02:00Moving from MediaWiki to SharePoint O365 - part 6Now that we <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">have our scripts in place to emulate MediaWiki functionalities</a>, <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-part-4.html">copied over the images and files</a>, and <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-part-5.html">prepared html-pages for all our relevant articles</a>, we can send the pages to SharePoint.<br />
<br />
<!-- HTML generated using hilite.me -->With this script, you prepare the articles one by one, create files for it, and call a PowerShell script which does the actual uploading (see below). Don't forget to update the rootPath to whatever you're using.<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0px;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54</pre>
</td><td><pre style="line-height: 125%; margin: 0px;"><span style="color: #557799;"><?php</span>
<span style="color: #007020;">ini_set</span>(<span style="background-color: #fff0f0;">'display_errors'</span>, <span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #996633;">$rootPath</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"C:/workspace/PortableSoft/UniServerZ/www/wikimigration/articles/"</span>;
<span style="color: #888888;">//get files from </span>
<span style="color: #996633;">$files</span> <span style="color: #333333;">=</span> <span style="color: #007020;">scandir</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'articlesToSend'</span>);
<span style="color: #996633;">$i</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">""</span>;
<span style="color: #888888;">//check if there are files to process</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">sizeof</span>(<span style="color: #996633;">$files</span>)<span style="color: #333333;">></span><span style="color: #0000dd; font-weight: bold;">2</span>){
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$files</span>[<span style="color: #996633;">$i</span>];
<span style="color: #888888;">//skip the "this" and "one up" files</span>
<span style="color: #008800; font-weight: bold;">while</span>((<span style="color: #996633;">$filename</span> <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">"."</span> <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #996633;">$filename</span> <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">".."</span>) <span style="color: #008800; font-weight: bold;">and</span> <span style="color: #996633;">$i</span> <span style="color: #333333;"><</span> <span style="color: #007020;">sizeof</span>(<span style="color: #996633;">$files</span>)){
<span style="color: #996633;">$i</span><span style="color: #333333;">++</span>;
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$files</span>[<span style="color: #996633;">$i</span>];
}
<span style="color: #888888;">//get the contents of the file, split out title and content</span>
<span style="color: #996633;">$page</span> <span style="color: #333333;">=</span> <span style="color: #007020;">file_get_contents</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesToSend/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>);
<span style="color: #888888;">//$title = substr($page,strlen("<h1>"),strpos($page,"</h1>")-strlen("<h1>"));</span>
<span style="color: #888888;">//$content = substr($page, strlen($title)+strlen("<h1></h1>"));</span>
<span style="color: #996633;">$title</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$filename</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #007020;">strlen</span>(<span style="color: #996633;">$filename</span>)<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">5</span>);
<span style="color: #996633;">$content</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$page</span>;
<span style="color: #888888;">//write data to files</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"powershell/pageName.txt"</span>, <span style="color: #996633;">$title</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"issue writing title to file<br>"</span>;
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"powershell/pageContent.txt"</span>, <span style="color: #996633;">$content</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"issue writing contents to file<br>"</span>;
<span style="color: #888888;">//call the powershell script to upload the article to SharePoint</span>
<span style="color: #996633;">$command</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">'powershell "'</span><span style="color: #333333;">.</span><span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'powershell/JV.ps1"'</span>;
<span style="color: #996633;">$output</span> <span style="color: #333333;">=</span> <span style="color: #007020;">shell_exec</span>(<span style="color: #996633;">$command</span>);
<span style="color: #888888;">//show the output produced by powershell</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"<div><pre></span><span style="background-color: #eeeeee;">$output</span><span style="background-color: #fff0f0;"></pre></div>"</span>;
<span style="color: #888888;">//move the file from articlesToSend to articlesSent</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesToSend/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>,<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSent/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//if unsuccessfull: give feedback</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"<div>issue moving </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;"> to articlesSent</div>"</span>;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #888888;">//if successfull: continue with next file</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">'<meta http-equiv="refresh" content="3;URL=http://localhost:8080/wikimigration/articles/uploadToSharepoint.php" />'</span>;
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"<div>file </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;"> sent and moved to 'articlesSent'</div>"</span>;
}
}
<span style="color: #008800; font-weight: bold;">else</span> {
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">'<meta http-equiv="refresh" content="3;URL=http://localhost:8080/wikimigration/articles/uploadToSharepoint.php" />'</span>;
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"no files present"</span>;
}
<span style="color: #557799;">?></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Now for the PowerShell script. Put it in a subdirectory <em>powershell</em> in the <em>articles</em> directory. Don't forget to change the siteURL, your username and your password on line 78. And of course the script directory on line 4. <br />
You'll notice the script is calling a dll. You actually need a bunch of them. Create a subdirectory <em>dll</em> in your <em>powershell</em> folder, and put these dlls there: client.dll, microsoft.office.client.policy.dll, microsoft.office.sharepoint.tools.dll, microsoft.sharepoint.client.dll, microsoft.sharepoint.client.publishing.dll, microsoft.sharepoint.client.publishing.silverlight.dll, microsoft.sharepoint.client.runtime.dll, microsoft.sharepoint.client.silverlight.dll, microsoft.sharepoint.client.silverlight.runtime.dll, microsoft.sharepoint.client.taxonomy.dll, microsoft.sharepoint.client.taxonomy.silverlight.dll, microsoft.sharepoint.client.userprofiles.dll, microsoft.sharepoint.client.userprofiles.phone.dll, microsoft.sharepoint.client.userprofiles.silverlight.dll, microsoft.sharepoint.dll. I'm not sure if they're all needed, but hey, this bunch made it work for me. I'll upload a zip of them somewhere later, if somebody needs them and can't find them anywhere else.<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0px;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87</pre>
</td><td><pre style="line-height: 125%; margin: 0px;"><span style="color: #888888;"># global vars</span>
<span style="color: #996633;">$clientContext</span>
<span style="color: #996633;">$rootSiteUrl</span>
<span style="color: #996633;">$scriptdir</span> = <span style="background-color: #fff0f0;">"C:\workspace\PortableSoft\UniServerZ\www\wikimigration\articles\powershell"</span>
<span style="color: #008800; font-weight: bold;">function</span> Initialize-SPPS
{
[<span style="color: #008800; font-weight: bold;">CmdletBinding</span>()]
<span style="color: #008800; font-weight: bold;">param</span>
(
[<span style="color: #008800; font-weight: bold;">Parameter</span>(<span style="color: #008800; font-weight: bold;">Mandatory</span>=<span style="color: #996633;">$true</span>, <span style="color: #008800; font-weight: bold;">Position</span>=1)]
<span style="color: #003366; font-weight: bold;">[string]</span><span style="color: #996633;">$siteURL</span>,
[<span style="color: #008800; font-weight: bold;">Parameter</span>(<span style="color: #008800; font-weight: bold;">Mandatory</span>=<span style="color: #996633;">$false</span>, <span style="color: #008800; font-weight: bold;">Position</span>=2)]
<span style="color: #003366; font-weight: bold;">[bool]</span><span style="color: #996633;">$online</span>,
[<span style="color: #008800; font-weight: bold;">Parameter</span>(<span style="color: #008800; font-weight: bold;">Mandatory</span>=<span style="color: #996633;">$false</span>, <span style="color: #008800; font-weight: bold;">Position</span>=3)]
<span style="color: #003366; font-weight: bold;">[string]</span><span style="color: #996633;">$username</span>,
[<span style="color: #008800; font-weight: bold;">Parameter</span>(<span style="color: #008800; font-weight: bold;">Mandatory</span>=<span style="color: #996633;">$false</span>, <span style="color: #008800; font-weight: bold;">Position</span>=4)]
<span style="color: #003366; font-weight: bold;">[string]</span><span style="color: #996633;">$password</span>
)
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Loading the CSOM library"</span> -foregroundcolor black -backgroundcolor yellow
<span style="color: #003366; font-weight: bold;">[Reflection.Assembly]</span><span style="background-color: #ffaaaa; color: red;">::</span>LoadFrom(<span style="background-color: #fff0f0;">"$scriptdir\dll\Microsoft.SharePoint.Client.dll"</span>)
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Succesfully loaded the CSOM library"</span> -foregroundcolor black -backgroundcolor green
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Create client context for site $siteUrl"</span> -foregroundcolor black -backgroundcolor yellow
<span style="color: #996633;">$context</span> = <span style="color: #007020;">New-Object</span> Microsoft.SharePoint.Client.ClientContext(<span style="color: #996633;">$siteURL</span>)
<span style="color: #996633;">$context</span>.RequestTimeOut = 1000 * 60 * 10<span style="background-color: #ffaaaa; color: red;">;</span>
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #996633;">$online</span>)
{
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Setting SharePoint Online credentials"</span> -foregroundcolor black -backgroundcolor yellow
<span style="color: #996633;">$context</span>.AuthenticationMode = <span style="color: #003366; font-weight: bold;">[Microsoft.SharePoint.Client.ClientAuthenticationMode]</span><span style="background-color: #ffaaaa; color: red;">::</span><span style="color: #008800; font-weight: bold;">Default</span>
<span style="color: #996633;">$securePassword</span> = <span style="color: #007020;">ConvertTo-SecureString</span> <span style="color: #996633;">$password</span> -AsPlainText -Force
<span style="color: #996633;">$credentials</span> = <span style="color: #007020;">New-Object</span> Microsoft.SharePoint.Client.SharePointOnlineCredentials(<span style="color: #996633;">$username</span>, <span style="color: #996633;">$securePassword</span>)
<span style="color: #996633;">$context</span>.Credentials = <span style="color: #996633;">$credentials</span>
}
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Check connection"</span> -foregroundcolor black -backgroundcolor yellow
<span style="color: #996633;">$web</span> = <span style="color: #996633;">$context</span>.Web
<span style="color: #996633;">$site</span> = <span style="color: #996633;">$context</span>.Site
<span style="color: #996633;">$context</span>.Load(<span style="color: #996633;">$web</span>)
<span style="color: #996633;">$context</span>.Load(<span style="color: #996633;">$site</span>)
<span style="color: #996633;">$context</span>.ExecuteQuery()
<span style="color: #007020;">Set-Variable</span> -Name <span style="background-color: #fff0f0;">"clientContext"</span> -Value <span style="color: #996633;">$context</span> -Scope Global
<span style="color: #007020;">Set-Variable</span> -Name <span style="background-color: #fff0f0;">"rootSiteUrl"</span> -Value <span style="color: #996633;">$siteURL</span> -Scope Global
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Succesfully connected"</span> -foregroundcolor black -backgroundcolor green
}
<span style="color: #008800; font-weight: bold;">Function</span> Create-WikiPage(<span style="color: #003366; font-weight: bold;">[Microsoft.SharePoint.Client.ClientContext]</span><span style="color: #996633;">$Context</span>,<span style="color: #003366; font-weight: bold;">[string]</span><span style="color: #996633;">$WikiLibraryTitle</span>,<span style="color: #003366; font-weight: bold;">[string]</span><span style="color: #996633;">$PageName</span>,<span style="color: #003366; font-weight: bold;">[string]</span><span style="color: #996633;">$PageContent</span>)
{
<span style="color: #996633;">$wikiLibrary</span> = <span style="color: #996633;">$Context</span>.Web.Lists.GetByTitle(<span style="color: #996633;">$wikiLibraryTitle</span>)
<span style="color: #996633;">$Context</span>.Load(<span style="color: #996633;">$wikiLibrary</span>.RootFolder)
<span style="color: #996633;">$Context</span>.ExecuteQuery()
<span style="color: #996633;">$wikiPageInfo</span> = <span style="color: #007020;">New-Object</span> Microsoft.SharePoint.Client.Utilities.WikiPageCreationInformation
<span style="color: #996633;">$wikiPageInfo</span>.WikiHtmlContent = <span style="color: #996633;">$PageContent</span>
<span style="color: #996633;">$wikiPageInfo</span>.ServerRelativeUrl = <span style="color: #003366; font-weight: bold;">[String]</span><span style="background-color: #ffaaaa; color: red;">::</span>Format(<span style="background-color: #fff0f0;">"{0}/{1}"</span>, <span style="color: #996633;">$wikiLibrary</span>.RootFolder.ServerRelativeUrl, <span style="color: #996633;">$PageName</span>)
<span style="color: #996633;">$wikiFile</span> = <span style="color: #003366; font-weight: bold;">[Microsoft.SharePoint.Client.Utilities.Utility]</span><span style="background-color: #ffaaaa; color: red;">::</span>CreateWikiPageInContextWeb(<span style="color: #996633;">$Context</span>, <span style="color: #996633;">$wikiPageInfo</span>)
<span style="color: #996633;">$context</span>.ExecuteQuery()
}
<span style="color: #888888;"># get files for variables</span>
<span style="color: #888888;"># get file for pagename</span>
<span style="color: #996633;">$pageName</span> = <span style="color: #003366; font-weight: bold;">[IO.File]</span><span style="background-color: #ffaaaa; color: red;">::</span>ReadAllText(<span style="background-color: #fff0f0;">"$scriptdir\pageName.txt"</span>)
<span style="color: #888888;"># get file for page contents</span>
<span style="color: #996633;">$pageContent</span> = <span style="color: #003366; font-weight: bold;">[IO.File]</span><span style="background-color: #ffaaaa; color: red;">::</span>ReadAllText(<span style="background-color: #fff0f0;">"$scriptdir\pageContent.txt"</span>)
<span style="color: #888888;"># connect</span>
Initialize-SPPS -siteURL <span style="background-color: #fff0f0;">"https://xxxxx.sharepoint.com/sites/yyyyy/"</span> -online <span style="color: #996633;">$true</span> -username <span style="background-color: #fff0f0;">"user@domain.com"</span> -password <span style="background-color: #fff0f0;">"yourPass"</span>
<span style="color: #888888;"># put page</span>
<span style="color: #996633;">$fullPageName</span> = <span style="background-color: #fff0f0;">"$pageName.aspx"</span>
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"Adding page"</span> -foregroundcolor black -backgroundcolor yellow
Create-WikiPage -Context <span style="color: #996633;">$clientContext</span> -WikiLibraryTitle <span style="background-color: #fff0f0;">"Site Pages"</span> -PageName <span style="color: #996633;">$fullPageName</span> -PageContent <span style="color: #996633;">$pageContent</span>
<span style="color: #007020;">Write-Host</span> <span style="background-color: #fff0f0;">"New page added"</span> -foregroundcolor black -backgroundcolor green
<span style="color: #996633;">$clientContext</span>.Dispose()
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-80116258760880092052015-01-21T14:00:00.001+01:002015-01-21T14:00:25.733+01:00Moving from MediaWiki to SharePoint O365 - doRegularPages.phpThis script will process the individual html files created from a MediaWiki xml dump by <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-extractPages.html" target="_blank">this script</a> to final output files to be uploaded to SharePoint (except for templates, which remains a manual work).<br />
<br />
Make sure you've created the folders as explained <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-part-5.html">here</a>, update the URL of your MediaWiki installation on line 5, the URL of your SharePoint site on line 7 and the path of your project directory on line 8.<br />
<br />
<a name='more'></a><br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?php</span>
<span style="color: #007020;">ini_set</span>(<span style="background-color: #fff0f0;">'display_errors'</span>, <span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$wikiURL</span>;
<span style="color: #996633;">$wikiURL</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"http://yourWikiURL/wiki/"</span>;
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$spSiteRelativeURL</span>;
<span style="color: #996633;">$spSiteRelativeURL</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/"</span>;
<span style="color: #996633;">$localPath</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"C:/something/UniServerZ/www/wikimigration/articles/"</span>;
<span style="color: #888888;">//get article files</span>
<span style="color: #996633;">$files</span> <span style="color: #333333;">=</span> <span style="color: #007020;">scandir</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'articlesSplit'</span>);
<span style="color: #008800; font-weight: bold;">foreach</span>(<span style="color: #996633;">$files</span> <span style="color: #008800; font-weight: bold;">as</span> <span style="color: #996633;">$filename</span>){
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #888888;">//skip the "this" and "one up" files</span>
<span style="color: #008800; font-weight: bold;">while</span>((<span style="color: #996633;">$filename</span> <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">"."</span> <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #996633;">$filename</span> <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">".."</span>)){
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #008800; font-weight: bold;">continue</span> <span style="color: #0000dd; font-weight: bold;">2</span>;
}
<span style="color: #888888;">//get the contents of the file, split out title and content</span>
<span style="color: #996633;">$page</span> <span style="color: #333333;">=</span> <span style="color: #007020;">file_get_contents</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>);
<span style="color: #996633;">$title</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$page</span>,<span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">"<h1>"</span>),<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$page</span>,<span style="background-color: #fff0f0;">"</h1>"</span>)<span style="color: #333333;">-</span><span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">"<h1>"</span>));
<span style="color: #996633;">$offlineContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$page</span>, <span style="color: #007020;">strlen</span>(<span style="color: #996633;">$title</span>)<span style="color: #333333;">+</span><span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">"<h1></h1>"</span>));
<span style="color: #888888;">//strip out categories: they are lost to us</span>
<span style="color: #996633;">$offlineContent</span> <span style="color: #333333;">=</span> stripCategories(<span style="color: #996633;">$offlineContent</span>);
<span style="color: #888888;">//scan the content for templates and redirects</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$offlineContent</span>), <span style="background-color: #fff0f0;">"#redirect"</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">" contains redirect, formatting and sending... "</span>;
<span style="color: #888888;">//get the link</span>
<span style="color: #996633;">$link</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$offlineContent</span>,<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>,<span style="background-color: #fff0f0;">'[['</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span>, <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>,<span style="background-color: #fff0f0;">']]'</span>) <span style="color: #333333;">-</span> (<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>,<span style="background-color: #fff0f0;">'[['</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span>));
<span style="color: #888888;">//if the redirect uses an anchor for positioning, take it out</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$link</span>, <span style="background-color: #fff0f0;">'#'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #996633;">$link</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$link</span>, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$link</span>, <span style="background-color: #fff0f0;">'#'</span>));
<span style="color: #888888;">//make sure the redirect link is uppercase and without unneccessary spaces</span>
<span style="color: #996633;">$offlineContent</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"#REDIRECT[[</span><span style="background-color: #eeeeee;">$link</span><span style="background-color: #fff0f0;">]]"</span>;
<span style="color: #888888;">//send prepared article to folder for uploading</span>
<span style="color: #996633;">$data</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"<h1></span><span style="background-color: #eeeeee;">$title</span><span style="background-color: #fff0f0;"></h1></span><span style="background-color: #eeeeee;">$offlineContent</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesToSend/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>, <span style="color: #996633;">$data</span>) <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>);
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"done</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #888888;">//move file to handled folder</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>,<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit-handled/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>);
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #888888;">//no difficult wiki syntax we need to save, so copy html instead</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">" will be fetched from online... "</span>;
<span style="color: #888888;">//get the online html</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> getContent(<span style="color: #996633;">$wikiURL</span>,<span style="color: #996633;">$title</span>);
<span style="color: #888888;">//extract the article content from the page</span>
<span style="color: #996633;">$articleStartPosition</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div id="mw-content-text"'</span>);
<span style="color: #996633;">$articleStartPosition</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'>'</span>, <span style="color: #996633;">$articleStartPosition</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #996633;">$articleEndPosition</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>,<span style="background-color: #fff0f0;">'<div class="printfooter"'</span>,<span style="color: #996633;">$articleStartPosition</span>);
<span style="color: #996633;">$articleEndPosition</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strrpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</div>'</span>,<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span><span style="color: #333333;">*</span>(<span style="color: #007020;">strlen</span>(<span style="color: #996633;">$onlineContent</span>) <span style="color: #333333;">-</span> <span style="color: #996633;">$articleEndPosition</span>));
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$articleStartPosition</span>, <span style="color: #996633;">$articleEndPosition</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$articleStartPosition</span>);
<span style="color: #888888;">//clean caching and other non-visible info</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> cleanCaching(<span style="color: #996633;">$onlineContent</span>);
<span style="color: #888888;">//strip out edit links</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> stripEditLinks(<span style="color: #996633;">$onlineContent</span>);
<span style="color: #888888;">//strip out TOC</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> stripTOC(<span style="color: #996633;">$onlineContent</span>);
<span style="color: #888888;">//replace image and file links</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> replaceImageAndFileLinks(<span style="color: #996633;">$onlineContent</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> replaceIntraWikiLinks(<span style="color: #996633;">$onlineContent</span>);
<span style="color: #888888;">//replace math</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> replaceMath(<span style="color: #996633;">$onlineContent</span>);
<span style="color: #888888;">//replace source code</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> replaceSourceCode(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$offlineContent</span>);
<span style="color: #888888;">//beautify tables</span>
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'class="wikitable"'</span>, <span style="background-color: #fff0f0;">'style="margin: 1em 1em 1em 0;background-color: #f9f9f9;border: 1px #aaa solid;border-collapse: collapse;color: black;"'</span>, <span style="color: #996633;">$onlineContent</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'<tr>'</span>,<span style="background-color: #fff0f0;">'<tr style="border: 1px #aaa solid;">'</span>,<span style="color: #996633;">$onlineContent</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'<td>'</span>,<span style="background-color: #fff0f0;">'<td style="border: 1px #aaa solid;">'</span>,<span style="color: #996633;">$onlineContent</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'<th>'</span>,<span style="background-color: #fff0f0;">'<th style="border: 1px #aaa solid;">'</span>,<span style="color: #996633;">$onlineContent</span>);
<span style="color: #888888;">//make the title sharepoint-legal - change the "special characters" to double underscores</span>
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">":"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"?"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"/"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>,<span style="background-color: #fff0f0;">'Template__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//templates moved to special folder for revision</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"but is template</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"templates/template/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>, <span style="color: #996633;">$onlineContent</span>);
<span style="color: #996633;">$origFilename</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$filename</span>;
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">".html"</span>, <span style="background-color: #fff0f0;">"_source.html"</span>, <span style="color: #996633;">$filename</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit/</span><span style="background-color: #eeeeee;">$origFilename</span><span style="background-color: #fff0f0;">"</span>,<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"templates/template/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>);
}
<span style="color: #008800; font-weight: bold;">elseif</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>, <span style="background-color: #fff0f0;">'{{'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//templatecallers moved to special folder for revision</span>
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"but has template</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"templates/caller/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>, <span style="color: #996633;">$onlineContent</span>);
<span style="color: #996633;">$origFilename</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$filename</span>;
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">".html"</span>, <span style="background-color: #fff0f0;">"_source.html"</span>, <span style="color: #996633;">$filename</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit/</span><span style="background-color: #eeeeee;">$origFilename</span><span style="background-color: #fff0f0;">"</span>,<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"templates/caller/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>);
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #888888;">//send prepared article to folder for uploading</span>
<span style="color: #996633;">$data</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"<h1></span><span style="background-color: #eeeeee;">$title</span><span style="background-color: #fff0f0;"></h1></span><span style="background-color: #eeeeee;">$onlineContent</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesToSend/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>, <span style="color: #996633;">$data</span>) <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>);
<span style="color: #888888;">//move file to handled folder</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>,<span style="color: #996633;">$localPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit-handled/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>);
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"done</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
}
}
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Some functions</span>
<span style="color: #888888;"> * */</span>
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">stripCategories</span>(<span style="color: #996633;">$content</span>){
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$content</span>;
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$content</span>),<span style="background-color: #fff0f0;">"[[category:"</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$catStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$content</span>),<span style="background-color: #fff0f0;">"[[category:"</span>);
<span style="color: #996633;">$catEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$content</span>,<span style="background-color: #fff0f0;">"]]"</span>,<span style="color: #996633;">$catStart</span>);
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$content</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$catStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$content</span>,<span style="color: #996633;">$catEnd</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span>);
<span style="color: #996633;">$content</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$content</span>),<span style="background-color: #fff0f0;">"[[category :"</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$catStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$content</span>),<span style="background-color: #fff0f0;">"[[category :"</span>);
<span style="color: #996633;">$catEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$content</span>,<span style="background-color: #fff0f0;">"]]"</span>,<span style="color: #996633;">$catStart</span>);
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$content</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$catStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$content</span>,<span style="color: #996633;">$catEnd</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span>);
<span style="color: #996633;">$content</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">getContent</span>(<span style="color: #996633;">$wikiURL</span>,<span style="color: #996633;">$title</span>){
<span style="color: #996633;">$articleURL</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$wikiURL</span><span style="color: #333333;">.</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">" "</span>,<span style="background-color: #fff0f0;">"%20"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #996633;">$ch</span> <span style="color: #333333;">=</span> <span style="color: #007020;">curl_init</span>();
<span style="color: #007020;">curl_setopt</span>(<span style="color: #996633;">$ch</span>, CURLOPT_URL, <span style="color: #996633;">$articleURL</span>);
<span style="color: #007020;">curl_setopt</span>(<span style="color: #996633;">$ch</span>, CURLOPT_HEADER, <span style="color: #0000dd; font-weight: bold;">0</span>);
<span style="color: #007020;">curl_setopt</span>(<span style="color: #996633;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color: #008800; font-weight: bold;">true</span>);
<span style="color: #007020;">curl_setopt</span>(<span style="color: #996633;">$ch</span>, CURLOPT_AUTOREFERER, <span style="color: #008800; font-weight: bold;">true</span>);
<span style="color: #007020;">curl_setopt</span>(<span style="color: #996633;">$ch</span>, CURLOPT_FOLLOWLOCATION, <span style="color: #008800; font-weight: bold;">true</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #007020;">curl_exec</span>(<span style="color: #996633;">$ch</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">die</span>(<span style="background-color: #fff0f0;">'Curl error: '</span> <span style="color: #333333;">.</span> <span style="color: #007020;">curl_error</span>(<span style="color: #996633;">$ch</span>));
<span style="color: #007020;">curl_close</span>(<span style="color: #996633;">$ch</span>);
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">cleanCaching</span>(<span style="color: #996633;">$onlineContent</span>){
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">"<!--"</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$commentStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">"<!--"</span>);
<span style="color: #996633;">$commentEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">"-->"</span>,<span style="color: #996633;">$commentStart</span>);
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #996633;">$commentStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$commentEnd</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">3</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">stripEditLinks</span>(<span style="color: #996633;">$onlineContent</span>){
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<span class="mw-editsection">'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$editStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<span class="mw-editsection">'</span>);
<span style="color: #996633;">$lastSpan</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$editStart</span> <span style="color: #333333;">+</span> <span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">'<span class="mw-editsection">'</span>);
<span style="color: #996633;">$openSpan</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #996633;">$openSpan</span> <span style="color: #333333;">></span> <span style="color: #0000dd; font-weight: bold;">0</span>){
<span style="color: #996633;">$nextOpenSpan</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<span'</span>,<span style="color: #996633;">$lastSpan</span>);
<span style="color: #996633;">$nextCloseSpan</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</span>'</span>, <span style="color: #996633;">$lastSpan</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$nextOpenSpan</span> <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span> <span style="color: #008800; font-weight: bold;">and</span> <span style="color: #996633;">$nextOpenSpan</span> <span style="color: #333333;"><</span> <span style="color: #996633;">$nextCloseSpan</span>){
<span style="color: #996633;">$openSpan</span><span style="color: #333333;">++</span>;
<span style="color: #996633;">$lastSpan</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextOpenSpan</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">5</span>;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #996633;">$openSpan</span><span style="color: #333333;">--</span>;
<span style="color: #996633;">$lastSpan</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextCloseSpan</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span>;
}
}
<span style="color: #996633;">$editEnd</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$lastSpan</span>;
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #996633;">$editStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$editEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">stripTOC</span>(<span style="color: #996633;">$onlineContent</span>){
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div id="toc"'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$editStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div id="toc"'</span>);
<span style="color: #996633;">$lastSpan</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$editStart</span> <span style="color: #333333;">+</span> <span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">'<div id="toc"'</span>);
<span style="color: #996633;">$openSpan</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #996633;">$openSpan</span> <span style="color: #333333;">></span> <span style="color: #0000dd; font-weight: bold;">0</span>){
<span style="color: #996633;">$nextOpenSpan</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div'</span>,<span style="color: #996633;">$lastSpan</span>);
<span style="color: #996633;">$nextCloseSpan</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</div>'</span>, <span style="color: #996633;">$lastSpan</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$nextOpenSpan</span> <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span> <span style="color: #008800; font-weight: bold;">and</span> <span style="color: #996633;">$nextOpenSpan</span> <span style="color: #333333;"><</span> <span style="color: #996633;">$nextCloseSpan</span>){
<span style="color: #996633;">$openSpan</span><span style="color: #333333;">++</span>;
<span style="color: #996633;">$lastSpan</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextOpenSpan</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">5</span>;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #996633;">$openSpan</span><span style="color: #333333;">--</span>;
<span style="color: #996633;">$lastSpan</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextCloseSpan</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span>;
}
}
<span style="color: #996633;">$editEnd</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$lastSpan</span>;
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #996633;">$editStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$editEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">replaceImageAndFileLinks</span>(<span style="color: #996633;">$onlineContent</span>){
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$spSiteRelativeURL</span>;
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<a href="/wiki/File:'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$linkStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<a href="/wiki/File:'</span>);
<span style="color: #996633;">$urlStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>,<span style="background-color: #fff0f0;">'"'</span>,<span style="color: #996633;">$linkStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #996633;">$urlEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'"'</span>, <span style="color: #996633;">$urlStart</span>);
<span style="color: #996633;">$url</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$urlStart</span>, <span style="color: #996633;">$urlEnd</span><span style="color: #333333;">-</span><span style="color: #996633;">$urlStart</span>);
<span style="color: #996633;">$linkEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</a>'</span>, <span style="color: #996633;">$urlEnd</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">4</span>;
<span style="color: #996633;">$imgStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<img'</span>,<span style="color: #996633;">$urlEnd</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$imgStart</span> <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span> <span style="color: #008800; font-weight: bold;">and</span> <span style="color: #996633;">$imgStart</span> <span style="color: #333333;"><</span> <span style="color: #996633;">$linkEnd</span>){
<span style="color: #888888;">//link to image</span>
<span style="color: #996633;">$imgSourceStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'src="'</span>,<span style="color: #996633;">$imgStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">5</span>;
<span style="color: #996633;">$imgSourceEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'"'</span>, <span style="color: #996633;">$imgSourceStart</span>);
<span style="color: #996633;">$imgSource</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #996633;">$imgSourceStart</span>, <span style="color: #996633;">$imgSourceEnd</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$imgSourceStart</span>);
<span style="color: #996633;">$imgFile</span> <span style="color: #333333;">=</span> extractFileName(<span style="color: #996633;">$imgSource</span>);
<span style="color: #996633;">$widthStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'width="'</span>, <span style="color: #996633;">$imgStart</span>) <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">7</span>;
<span style="color: #996633;">$widthEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'"'</span>, <span style="color: #996633;">$widthStart</span>);
<span style="color: #996633;">$width</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$widthStart</span>, <span style="color: #996633;">$widthEnd</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$widthStart</span>);
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$linkStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> <span style="background-color: #fff0f0;">'<img src="'</span><span style="color: #333333;">.</span><span style="color: #996633;">$spSiteRelativeURL</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'SiteAssets/mw/'</span><span style="color: #333333;">.</span><span style="color: #996633;">$imgFile</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'" width="'</span><span style="color: #333333;">.</span><span style="color: #996633;">$width</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'">'</span>;
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$linkEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #888888;">//link to file</span>
<span style="color: #996633;">$link</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$linkStart</span>, <span style="color: #996633;">$linkEnd</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$linkStart</span>);
<span style="color: #996633;">$link</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'/wiki/File:'</span>, <span style="color: #996633;">$spSiteRelativeURL</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">'Shared Documents/'</span>, <span style="color: #996633;">$link</span>);
<span style="color: #996633;">$link</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'File:'</span>,<span style="background-color: #fff0f0;">''</span>,<span style="color: #996633;">$link</span>);
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$linkStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> <span style="color: #996633;">$link</span>;
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$linkEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">extractFileName</span>(<span style="color: #996633;">$imgSource</span>){
<span style="color: #996633;">$nextSlash</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$imgSource</span>, <span style="background-color: #fff0f0;">'/'</span>);
<span style="color: #996633;">$pathPiece</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$imgSource</span>, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #996633;">$nextSlash</span>);
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$pathPiece</span>, <span style="background-color: #fff0f0;">'.'</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #996633;">$prevSlash</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextSlash</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #996633;">$nextSlash</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$imgSource</span>,<span style="background-color: #fff0f0;">'/'</span>,<span style="color: #996633;">$prevSlash</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$nextSlash</span> <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #996633;">$nextSlash</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strlen</span>(<span style="color: #996633;">$imgSource</span>);
<span style="color: #996633;">$pathPiece</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$imgSource</span>, <span style="color: #996633;">$prevSlash</span>, <span style="color: #996633;">$nextSlash</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$prevSlash</span>);
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$pathPiece</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">replaceIntraWikiLinks</span>(<span style="color: #996633;">$onlineContent</span>){
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<a href="/wiki/'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//existing article</span>
<span style="color: #996633;">$linkStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<a href="/wiki/'</span>);
<span style="color: #996633;">$linkEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</a>'</span>, <span style="color: #996633;">$linkStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">4</span>;
<span style="color: #996633;">$nameStart</span><span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'>'</span>,<span style="color: #996633;">$linkStart</span>);
<span style="color: #996633;">$nameEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<'</span>, <span style="color: #996633;">$linkStart</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #996633;">$name</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #996633;">$nameStart</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>, <span style="color: #996633;">$nameEnd</span> <span style="color: #333333;">-</span> (<span style="color: #996633;">$nameStart</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>));
<span style="color: #996633;">$titleStart</span><span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'title="'</span>,<span style="color: #996633;">$linkStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span>;
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$titleStart</span> <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #996633;">$title</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$name</span>;
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #996633;">$titleEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'"'</span>, <span style="color: #996633;">$titleStart</span>);
<span style="color: #996633;">$title</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$titleStart</span>, <span style="color: #996633;">$titleEnd</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$titleStart</span>);
}
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$linkStart</span>);
<span style="color: #888888;">//change the underscores back to spaces, but keep the double underscores</span>
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"__"</span>, <span style="background-color: #fff0f0;">"%%"</span>, <span style="color: #996633;">$title</span>);
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"_"</span>, <span style="background-color: #fff0f0;">" "</span>, <span style="color: #996633;">$title</span>);
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"%%"</span>, <span style="background-color: #fff0f0;">"__"</span>, <span style="color: #996633;">$title</span>);
<span style="color: #888888;">//change the "special characters" to double underscores</span>
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">":"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"?"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #996633;">$title</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"/"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #888888;">//write out link</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$title</span><span style="color: #333333;">==</span><span style="color: #996633;">$name</span>)
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> <span style="background-color: #fff0f0;">"[[</span><span style="background-color: #eeeeee;">$title</span><span style="background-color: #fff0f0;">]]"</span>;
<span style="color: #008800; font-weight: bold;">else</span>
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> <span style="background-color: #fff0f0;">"[[</span><span style="background-color: #eeeeee;">$title</span><span style="background-color: #fff0f0;">|</span><span style="background-color: #eeeeee;">$name</span><span style="background-color: #fff0f0;">]]"</span>;
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$linkEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<a href="/w/'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//non-existing article</span>
<span style="color: #996633;">$linkStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<a href="/w/'</span>);
<span style="color: #996633;">$linkEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</a>'</span>, <span style="color: #996633;">$linkStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">4</span>;
<span style="color: #996633;">$nameStart</span><span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'>'</span>,<span style="color: #996633;">$linkStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #996633;">$nameEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<'</span>, <span style="color: #996633;">$nameStart</span>);
<span style="color: #996633;">$name</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #996633;">$nameStart</span>, <span style="color: #996633;">$nameEnd</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$nameStart</span>);
<span style="color: #888888;">//change the underscores back to spaces, but keep the double underscores</span>
<span style="color: #996633;">$name</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"__"</span>, <span style="background-color: #fff0f0;">"%%"</span>, <span style="color: #996633;">$name</span>);
<span style="color: #996633;">$name</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"_"</span>, <span style="background-color: #fff0f0;">" "</span>, <span style="color: #996633;">$name</span>);
<span style="color: #996633;">$name</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"%%"</span>, <span style="background-color: #fff0f0;">"__"</span>, <span style="color: #996633;">$name</span>);
<span style="color: #888888;">//change the "special characters" to double underscores</span>
<span style="color: #996633;">$name</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">":"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$name</span>);
<span style="color: #996633;">$name</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"?"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$name</span>);
<span style="color: #996633;">$name</span><span style="color: #333333;">=</span><span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"/"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$name</span>);
<span style="color: #888888;">//write out link</span>
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$linkStart</span>);
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> <span style="background-color: #fff0f0;">"[[</span><span style="background-color: #eeeeee;">$name</span><span style="background-color: #fff0f0;">]]"</span>;
<span style="color: #996633;">$newContent</span><span style="color: #333333;">.=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$linkEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$newContent</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">replaceMath</span>(<span style="color: #996633;">$onlineContent</span>){
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>,<span style="background-color: #fff0f0;">'<img class="tex" alt="'</span>)){
<span style="color: #996633;">$mathImgStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>,<span style="background-color: #fff0f0;">'<img class="tex" alt="'</span>);
<span style="color: #996633;">$mathImgEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>,<span style="background-color: #fff0f0;">'>'</span>,<span style="color: #996633;">$mathImgStart</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #996633;">$mathImg</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$mathImgStart</span>, <span style="color: #996633;">$mathImgEnd</span><span style="color: #333333;">-</span><span style="color: #996633;">$mathImgStart</span>);
<span style="color: #996633;">$mathFormulaStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$mathImg</span>, <span style="background-color: #fff0f0;">'alt="'</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">5</span>;
<span style="color: #996633;">$mathFormulaEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$mathImg</span>, <span style="background-color: #fff0f0;">'"'</span>,<span style="color: #996633;">$mathFormulaStart</span>);
<span style="color: #996633;">$mathFormula</span> <span style="color: #333333;">=</span> trim(substr(<span style="color: #996633;">$mathImg</span>, <span style="color: #996633;">$mathFormulaStart</span>, <span style="color: #996633;">$mathFormulaEnd</span><span style="color: #333333;">-</span><span style="color: #996633;">$mathFormulaStart</span>));
<span style="color: #996633;">$mathFormula</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"&#10;"</span>, <span style="background-color: #fff0f0;">""</span>, <span style="color: #996633;">$mathFormula</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="color: #996633;">$mathImg</span>, <span style="background-color: #fff0f0;">"$$$mathFormula$$"</span>, <span style="color: #996633;">$onlineContent</span>);
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">replaceSourceCode</span>(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$offlineContent</span>){
<span style="color: #888888;">//look for <div dir="ltr" class="mw-geshi mw-code mw-content-ltr"> - these are the online code elements</span>
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//determine source element in online content</span>
<span style="color: #996633;">$sourceStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">'</span>);
<span style="color: #996633;">$lastDiv</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$sourceStart</span> <span style="color: #333333;">+</span> <span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">'<div dir="ltr" class="mw-geshi mw-code mw-content-ltr">'</span>);
<span style="color: #996633;">$openDiv</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #996633;">$openDiv</span> <span style="color: #333333;">></span> <span style="color: #0000dd; font-weight: bold;">0</span>){
<span style="color: #996633;">$nextOpenDiv</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'<div'</span>,<span style="color: #996633;">$lastDiv</span>);
<span style="color: #996633;">$nextCloseDiv</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$onlineContent</span>, <span style="background-color: #fff0f0;">'</div>'</span>, <span style="color: #996633;">$lastDiv</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$nextOpenDiv</span> <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span> <span style="color: #008800; font-weight: bold;">and</span> <span style="color: #996633;">$nextOpenDiv</span> <span style="color: #333333;"><</span> <span style="color: #996633;">$nextCloseDiv</span>){
<span style="color: #996633;">$openDiv</span><span style="color: #333333;">++</span>;
<span style="color: #996633;">$lastDiv</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextOpenDiv</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">4</span>;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #996633;">$openDiv</span><span style="color: #333333;">--</span>;
<span style="color: #996633;">$lastDiv</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$nextCloseDiv</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">6</span>;
}
}
<span style="color: #996633;">$sourceEnd</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$lastDiv</span>;
<span style="color: #888888;">//determine raw code from offlinecontent - first code element is right one because they're cut out after use</span>
<span style="color: #996633;">$rawStart</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>, <span style="background-color: #fff0f0;">'&lt;syntaxhighlight lang=&quot;'</span>);
<span style="color: #996633;">$sourceLangStart</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$rawStart</span> <span style="color: #333333;">+</span> <span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">'&lt;syntaxhighlight lang=&quot;'</span>);
<span style="color: #996633;">$sourceLangEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>, <span style="background-color: #fff0f0;">'&quot;&gt;'</span>, <span style="color: #996633;">$sourceLangStart</span>);
<span style="color: #996633;">$sourceLanguage</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$offlineContent</span>, <span style="color: #996633;">$sourceLangStart</span>, <span style="color: #996633;">$sourceLangEnd</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$sourceLangStart</span>);
<span style="color: #996633;">$codeStart</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$sourceLangEnd</span> <span style="color: #333333;">+</span> <span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">'&quot;&gt;'</span>);
<span style="color: #996633;">$codeEnd</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$offlineContent</span>,<span style="background-color: #fff0f0;">'&lt;/syntaxhighlight&gt;'</span>,<span style="color: #996633;">$rawStart</span>);
<span style="color: #996633;">$code</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$offlineContent</span>, <span style="color: #996633;">$codeStart</span>, <span style="color: #996633;">$codeEnd</span><span style="color: #333333;">-</span><span style="color: #996633;">$codeStart</span>);
<span style="color: #996633;">$rawEnd</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$codeEnd</span> <span style="color: #333333;">+</span> <span style="color: #007020;">strlen</span>(<span style="background-color: #fff0f0;">'&lt;/syntaxhighlight&gt;'</span>);
<span style="color: #888888;">//create sharepoint source code element</span>
<span style="color: #996633;">$codeElement</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">'<pre class="brush: '</span><span style="color: #333333;">.</span><span style="color: #996633;">$sourceLanguage</span> <span style="color: #333333;">.</span> <span style="background-color: #fff0f0;">'">'</span><span style="color: #333333;">.</span> <span style="color: #996633;">$code</span> <span style="color: #333333;">.</span> <span style="background-color: #fff0f0;">'</pre>'</span>;
<span style="color: #888888;">//replace in onlinecontent and cut out of offline content</span>
<span style="color: #996633;">$offlineContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$offlineContent</span>,<span style="color: #0000dd; font-weight: bold;">0</span>,<span style="color: #996633;">$rawStart</span>) <span style="color: #333333;">.</span> substr(<span style="color: #996633;">$offlineContent</span>,<span style="color: #996633;">$rawEnd</span>);
<span style="color: #996633;">$onlineContent</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #0000dd; font-weight: bold;">0</span>, <span style="color: #996633;">$sourceStart</span>) <span style="color: #333333;">.</span> <span style="color: #996633;">$codeElement</span> <span style="color: #333333;">.</span> substr(<span style="color: #996633;">$onlineContent</span>, <span style="color: #996633;">$sourceEnd</span>);
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #996633;">$onlineContent</span>;
}
<span style="color: #557799;">?></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-28962136965436360112015-01-21T13:58:00.000+01:002015-01-21T13:58:14.958+01:00Moving from MediaWiki to SharePoint O365 - extractPages.phpThis is the source code of the extractPages-script, which will create individual html files for all the articles contained in an XML dump from MediaWiki.<br />
<br />
Don't forget to update the <i>rootPath</i> on line 2 and the <i>yourSite</i> MediaWiki namespaces on lines 49 - 51.<br />
<br />
<br />
<a name='more'></a><br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?php</span>
<span style="color: #996633;">$rootPath</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"C:/something/UniServerZ/www/wikimigration/articles/"</span>;
<span style="color: #996633;">$xmlDumpFilename</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"backup-dump.xml"</span>;
<span style="color: #996633;">$file</span> <span style="color: #333333;">=</span> <span style="color: #007020;">file_get_contents</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="color: #996633;">$xmlDumpFilename</span>);
<span style="color: #996633;">$pagecount</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>; <span style="color: #996633;">$skipped</span> <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">while</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$file</span>, <span style="background-color: #fff0f0;">"<page>"</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">FALSE</span>){
<span style="color: #996633;">$pagecount</span><span style="color: #333333;">++</span>;
<span style="color: #888888;">//extract one page = one article</span>
<span style="color: #996633;">$pageStartPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$file</span>, <span style="background-color: #fff0f0;">"<page>"</span>);
<span style="color: #996633;">$pageEndPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$file</span>, <span style="background-color: #fff0f0;">"</page>"</span>);
<span style="color: #996633;">$page</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$file</span>, <span style="color: #996633;">$pageStartPos</span>, <span style="color: #996633;">$pageEndPos</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span> <span style="color: #333333;">-</span> <span style="color: #996633;">$pageStartPos</span>);
<span style="color: #888888;">//the title of the article</span>
<span style="color: #996633;">$titleStartPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$page</span>, <span style="background-color: #fff0f0;">"<title>"</span>);
<span style="color: #996633;">$titleEndPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$page</span>, <span style="background-color: #fff0f0;">"</title>"</span>);
<span style="color: #996633;">$title</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$page</span>, <span style="color: #996633;">$titleStartPos</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span>, <span style="color: #996633;">$titleEndPos</span> <span style="color: #333333;">-</span> (<span style="color: #996633;">$titleStartPos</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span>));
<span style="color: #888888;">//overwrite illegal filename characters to get a legal filename</span>
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"<"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$title</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">">"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">":"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">'"'</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"/"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\\</span><span style="background-color: #fff0f0;">"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"|"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"?"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"*"</span>,<span style="background-color: #fff0f0;">"__"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #888888;">//the actual textual content of the article</span>
<span style="color: #996633;">$textStartPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$page</span>, <span style="background-color: #fff0f0;">"<text"</span>);
<span style="color: #996633;">$textStartPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$page</span>, <span style="background-color: #fff0f0;">">"</span>, <span style="color: #996633;">$textStartPos</span>) <span style="color: #333333;">+</span> <span style="color: #0000dd; font-weight: bold;">1</span>;
<span style="color: #996633;">$textEndPos</span> <span style="color: #333333;">=</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$page</span>, <span style="background-color: #fff0f0;">"</text>"</span>);
<span style="color: #996633;">$text</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$page</span>, <span style="color: #996633;">$textStartPos</span>, <span style="color: #996633;">$textEndPos</span><span style="color: #333333;">-</span><span style="color: #996633;">$textStartPos</span>);
<span style="color: #888888;">//new content = (original) title + content</span>
<span style="color: #996633;">$newContent</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"<h1></span><span style="background-color: #eeeeee;">$title</span><span style="background-color: #fff0f0;"></h1></span>
<span style="background-color: #eeeeee;">$text</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #996633;">$filename</span> <span style="color: #333333;">=</span> <span style="color: #007020;">str_replace</span>(<span style="background-color: #fff0f0;">"&amp;"</span>,<span style="background-color: #fff0f0;">"&"</span>,<span style="color: #996633;">$filename</span>);
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'User__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'Category__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'Talk__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'Module__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'MediaWiki__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'yourSite_talk__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'<span style="line-height: 125%;">yourSite</span><span style="line-height: 125%;"> talk__'</span><span style="background-color: transparent; line-height: 125%;">) </span><span style="background-color: transparent; color: #333333; line-height: 125%;">!==</span><span style="background-color: transparent; line-height: 125%;"> </span><span style="background-color: transparent; color: #008800; font-weight: bold; line-height: 125%;">false</span></span> <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'<span style="line-height: 125%;">yourSite</span><span style="line-height: 125%;">__'</span><span style="background-color: transparent; line-height: 125%;">) </span><span style="background-color: transparent; color: #333333; line-height: 125%;">!==</span><span style="background-color: transparent; line-height: 125%;"> </span><span style="background-color: transparent; color: #008800; font-weight: bold; line-height: 125%;">false</span></span> <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'User_talk__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'File_talk__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">or</span> <span style="color: #007020;">strpos</span>(<span style="color: #996633;">$filename</span>, <span style="background-color: #fff0f0;">'File__'</span>) <span style="color: #333333;">!==</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"skipping file </span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #996633;">$skipped</span><span style="color: #333333;">++</span>;
}
<span style="color: #888888;">//write page to file</span>
<span style="color: #008800; font-weight: bold;">elseif</span>(<span style="color: #007020;">file_put_contents</span>(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"articlesSplit/</span><span style="background-color: #eeeeee;">$filename</span><span style="background-color: #fff0f0;">.html"</span>, <span style="color: #996633;">$newContent</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"issue with article </span><span style="background-color: #eeeeee;">$title</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #888888;">//continue with the dump-file</span>
<span style="color: #996633;">$file</span> <span style="color: #333333;">=</span> substr(<span style="color: #996633;">$file</span>, <span style="color: #996633;">$pageEndPos</span><span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">7</span>);
}
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"</span><span style="background-color: #eeeeee;">$pagecount</span><span style="background-color: #fff0f0;"> pages processed, </span><span style="background-color: #eeeeee;">$skipped</span><span style="background-color: #fff0f0;"> skipped (in unrequired namespaces)"</span>;
<span style="color: #557799;">?></span>
</pre>
</td></tr>
</tbody></table>
</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-15819992501712165222015-01-21T13:57:00.000+01:002015-01-21T13:57:55.008+01:00Moving from MediaWiki to SharePoint O365 - part 5So <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">we've pimped SharePoint O365 with some javascripts</a> and <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-part-4.html">copied all files and images from our MediaWiki to certain libraries in SharePoint</a>. What remains is getting the textual content there. To do this, we're going to combine the formatted (HTML) content, which we rip from our local MediaWiki website using PHP with cURL, and the unformatted wiki-syntax content which we get from an xml-dump.<br />
<br />
<a name='more'></a><h3>
The xml-dump</h3>
<div>
In your MediaWiki installation, go to the <i>maintenance</i> folder. There you will find a script called <i>dumpbackup.php</i>. Let this script run with parameter <i>--current</i> (we're only interested in the most recent version of each article, not its revision history) and send its contents to an xml file. I'm working in ubuntu, so after <a href="https://help.ubuntu.com/community/UsingTheTerminal" target="_blank">cd-ing</a> myself into /var/www/w/maintenance, I can just do:</div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">php dumpBackup.php --current > backup-dump.xml</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<div>
Then move the file to a newly created folder <i>articles</i> in your <i>wikimigration</i> directory. Create a folder <i>articlesSplit</i>, which is where we're going to store the articles in separate html-files. In the <i>articles</i> folder, create a new file called <i>extractPages.php</i> and <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-extractPages.html" target="_blank">paste this script</a> into it. After updating the root path (on line 2) and the namespace of your MediaWiki installation on lines 49 - 51, save it and let it run:<br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 16.25px;">1</pre>
</td><td><pre style="line-height: 16.25px;">C:\something\UniServerZ\core\php<span style="color: #6600ee; font-weight: bold;">54</span>\php.exe <span style="background-color: #fff0f0;">"C:\something\UniServerZ\www\wikimigration\articles\extractPages.php"</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<div>
</div>
When the script is done, it will tell you how many pages it has processed. This number should be (more or less) the same as the number of pages on your MediaWiki, which you can check by creating an article and putting {{NUMBEROFPAGES}} in it (well, there'll be one more page on you MediaWiki now, i.e. the one you just created).</div>
<div>
<br />
For a number of these pages, it doesn't make sense to copy them to SharePoint. E.g. category pages, since categories don't exist there. Or file pages, another thing SharePoint doesn't have. User pages. Talk pages. User talk pages. Pages in the namespace MediaWiki or <i>yourInstallation</i>. These pages are automatically skipped by <i>extractPages.php</i>, i.e. they will not be put in the <i>articlesSplit</i> directory.<br />
<br />
<h3>
Processing the content</h3>
</div>
<div>
All non-skipped articles are now in the <i>articlesSplit</i> directory in the form of separate html files. You may want to scroll through it to check that no unrelevant articles have made it through.<br />
What is in these files again? The wiki-syntax content we extracted from the xml dump. <a href="http://lifeworkimprovement.blogspot.be/2015/01/moving-from-mediawiki-to-sharepoint_17.html">Remember</a>: we're going to use this in combination with the online-content. So now we need to process each individual page, compare it to the online content, update links, reformat math code, swap out source code, and finally write out the final version we want sent to SharePoint.<br />
<br />
I've made a script that does all that. Create the following folders in the <i>articles</i> directory for this script to put its processed pages in:<br />
<br />
<ul>
<li><i>articlesSplit-handled</i>, which is where the original files from <i>articlesSplit</i> will be moved after the script is through with them. </li>
<li><i>articlesToSend</i>, which is where the processed output will be put for later uploading to SharePoint.</li>
<li><i>templates</i> with subfolders <i>caller</i> and <i>template</i>. </li>
</ul>
In the <i>articles</i> directory, create a file <i>doRegularPages.php</i> and copy <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-doRegularPages.html" target="_blank">this script</a> into it. Update the URL of your MediaWiki installation on line 5, the URL of your SharePoint site on line 7 and the path of your project directory on line 8. Then run the script and wait for it to finish (this can take some time):</div>
<div>
<br /></div>
<div>
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 16.25px;">1</pre>
</td><td><pre style="line-height: 16.25px;">C:\something\UniServerZ\core\php<span style="color: #6600ee; font-weight: bold;">54</span>\php.exe <span style="background-color: #fff0f0;">"C:\something\UniServerZ\www\wikimigration\articles\doRegularPages.php"</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<div>
</div>
<br />
<h3>
Templates</h3>
</div>
<div>
The script will not send processed output for everything to do with templates to the <i>articlesToSend</i> folder, but to the <i>caller </i>and <i>template</i> folders instead. That is because template-code is not easy to swap out between the online content and the wiki-syntax content, and because template chaining and special code in templates (e.g. <i>ParserFunctions</i>) is not supported anyway.<br />So for templates and pages making use of templates, you will have to go through these folders manually to create the content to be sent to SharePoint. The script will, however, provide you with both the online content and the wikisyntax content per page, so you can easily compare the two and combine as necessary.</div>
<div>
Once you're satisfied, copy the resulting files over to the <i>articlesToSend</i> folder, so they can be picked up there together with the other files, and be automatically sent to SharePoint. This last part is easy, and <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-part-6.html">explained in the following post</a>.</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-50385851565329220702015-01-21T11:39:00.001+01:002015-01-21T11:39:54.473+01:00Moving from MediaWiki to SharePoint O365 - filePathFlattener.phpThis is the source code of the filePathFlattener-script, which will move all files from the <i>images</i> folder-structure of a MediaWiki installation to two folders: one for all the images, and one for all the other files.<br />
<br />
It requires there to be an <i>images</i> folder, a <i>filesFlat</i> folder and an <i>imagesFlat</i> folder. You of course also need to update the rootPath on line 4.<br />
<br />
<a name='more'></a><br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #557799;"><?php</span>
<span style="color: #888888;">//set the path where the images are, relative to the path of this script</span>
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$rootPath</span>; <span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$imagesPath</span>;
<span style="color: #996633;">$rootPath</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"C:/something/UniServerZ/www/wikimigration/fileProcessing/"</span>;
<span style="color: #996633;">$imagesPath</span> <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"images/"</span>;
<span style="color: #888888;">//keep a tab on how many files were moved</span>
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$moveCounter</span>;
<span style="color: #996633;">$moveCounter</span><span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #888888;">//move files, starting from the root 'images' path</span>
moveFiles(<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="color: #996633;">$imagesPath</span>);
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"</span><span style="background-color: #eeeeee;">$moveCounter</span><span style="background-color: #fff0f0;"> files copied"</span>;
<span style="color: #888888;">//recursive function 'moveFiles' starting from a path relative to the script path</span>
<span style="color: #008800; font-weight: bold;">function</span> <span style="color: #0066bb; font-weight: bold;">moveFiles</span>(<span style="color: #996633;">$fullPath</span>){
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$moveCounter</span>;
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$rootPath</span>;
<span style="color: #008800; font-weight: bold;">global</span> <span style="color: #996633;">$imagesPath</span>;
<span style="color: #888888;">//see what's in the path and iterate over all entries</span>
<span style="color: #996633;">$filesAndFolders</span> <span style="color: #333333;">=</span> <span style="color: #007020;">scandir</span>(<span style="color: #996633;">$fullPath</span>);
<span style="color: #008800; font-weight: bold;">foreach</span>(<span style="color: #996633;">$filesAndFolders</span> <span style="color: #008800; font-weight: bold;">as</span> <span style="color: #996633;">$fileOrFolder</span>){
<span style="color: #888888;">//skip the special entries '.' (this path) and '..' (one up)</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #996633;">$fileOrFolder</span> <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">'.'</span> <span style="color: #008800; font-weight: bold;">or</span> <span style="color: #996633;">$fileOrFolder</span> <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">'..'</span>)
<span style="color: #008800; font-weight: bold;">continue</span>;
<span style="color: #888888;">//check whether the entry is a file or again a folder</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">is_dir</span>(<span style="color: #996633;">$fullPath</span><span style="color: #333333;">.</span><span style="color: #996633;">$fileOrFolder</span>)){
<span style="color: #888888;">//if it's a folder, move all files from inside it (recursive)</span>
<span style="color: #996633;">$folder</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$fileOrFolder</span>;
moveFiles(<span style="background-color: #fff0f0;">"</span><span style="background-color: #eeeeee;">$fullPath</span><span style="background-color: #fff0f0;">/</span><span style="background-color: #eeeeee;">$folder</span><span style="background-color: #fff0f0;">/"</span>);
}
<span style="color: #008800; font-weight: bold;">else</span> {
<span style="color: #996633;">$file</span> <span style="color: #333333;">=</span> <span style="color: #996633;">$fileOrFolder</span>;
<span style="color: #888888;">//if it's a file, check whether it's an image file or not</span>
<span style="color: #008800; font-weight: bold;">if</span>( <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".png"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">and</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".jpg"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">and</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".jpeg"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">and</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".bmp"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">and</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".gif"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">and</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".exif"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>
<span style="color: #008800; font-weight: bold;">and</span> <span style="color: #007020;">strpos</span>(strtolower(<span style="color: #996633;">$file</span>), <span style="background-color: #fff0f0;">".tiff"</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>){
<span style="color: #888888;">//try to move the file - if something goes wrong, give output</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$fullPath</span><span style="color: #333333;">.</span><span style="color: #996633;">$file</span>,<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"filesFlat/"</span><span style="color: #333333;">.</span><span style="color: #996633;">$file</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$path</span><span style="background-color: #fff0f0;">/</span><span style="background-color: #eeeeee;">$file</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #008800; font-weight: bold;">else</span>
<span style="color: #996633;">$moveCounter</span><span style="color: #333333;">++</span>;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #888888;">//try to move the image - if something goes wrong, give output</span>
<span style="color: #008800; font-weight: bold;">if</span>(<span style="color: #007020;">rename</span>(<span style="color: #996633;">$fullPath</span><span style="color: #333333;">.</span><span style="color: #996633;">$file</span>,<span style="color: #996633;">$rootPath</span><span style="color: #333333;">.</span><span style="background-color: #fff0f0;">"imagesFlat/"</span><span style="color: #333333;">.</span><span style="color: #996633;">$file</span>) <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">false</span>)
<span style="color: #008800; font-weight: bold;">echo</span> <span style="background-color: #fff0f0;">"issue with </span><span style="background-color: #eeeeee;">$fullPath</span><span style="background-color: #fff0f0;">/</span><span style="background-color: #eeeeee;">$file</span><span style="background-color: #fff0f0; color: #666666; font-weight: bold;">\r\n</span><span style="background-color: #fff0f0;">"</span>;
<span style="color: #008800; font-weight: bold;">else</span>
<span style="color: #996633;">$moveCounter</span><span style="color: #333333;">++</span>;
}
}
}
}
<span style="color: #557799;">?></span>
</pre>
</td></tr>
</tbody></table>
</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-15836833312532956252015-01-21T11:39:00.000+01:002015-01-21T11:39:41.644+01:00Moving from MediaWiki to SharePoint O365 - part 4<a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">Having our scripts in place</a> to emulate some of the MediaWiki functionality and <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_27.html">knowing how to use it</a>, we can now <i>finally</i> turn our attention to the actual migration of content. Content comes in two forms: text, as inputted in MediaWiki, and attachments. The attachments can be documents (docx, xslx, pdf, ...) which are available for download, or they can be images (png, jpg, gif, ...) which are displayed in the articles themselves.<br />
<br />
<br />
In this post, let's focus our attention on the attachments.<br />
<br />
<a name='more'></a><h3>
Migrating files from MediaWiki to SharePoint O365</h3>
<div>
In your MediaWiki installation, you need to go to your <i>images</i> folder and copy it. In the www directory of your UniServerZ folder, create a new folder called <i>wikimigration</i>. This will be our project work folder (for an Eclipse PHP project, if you're using Eclipse). Inside that folder, we create a folder <i>fileProcessing</i>. Paste the <i>images</i> folder from the MediaWiki installation in here so we can work with this copy.</div>
<div>
<br /></div>
<div>
In the <i>images</i> folder, there are a number of directories: they go from 0-9 and a-z and some others besides. If you had the Math extension working on your wiki, there's probably a <i>math</i> folder. Since we have the MathJax scripts in place to re-render all math, you can safely delete this folder. That's a whole bunch of images we don't have to worry about any more.</div>
<div>
There's also a <i>thumb</i> folder in there: this contains pre-rendered thumbnails. If you set a certain image with for an image in a MediaWiki article, the system pre-renders the image at that size so as to limit the amount of data that needs to be sent to the browser. That's clever! But a bit too clever for SharePoint. So you can go ahead and delete this folder as well - the originals are all in the other folders, and the originals is what we are going to be working with.</div>
<div>
Some more folders you can delete if they appear in you installation: <i>tmp</i>, <i>temp</i>, <i>archive</i>, <i>deleted</i>, <i>lockdir</i>, <i>timeline</i>.</div>
<div>
<br /></div>
<div>
The remaining stuff is the stuff we need. We're now going to get all the files out of the hierarchical folder structure (it goes many folders deep) into a flat structure (i.e. we're going to move all the files into a single directory without subdirectories). Well, two directories really: one for non-image files, and one for image files.</div>
<div>
<br /></div>
<h3>
The script</h3>
<div>
In the <i>fileProcessing</i> directory you made earlier, create two additional folders: <i>imagesFlat</i> and <i>filesFlat</i>. Now, using a text editor (Eclipse or whatever IDE, in worst case use Notepad), create a file called <i>filePathFlattener.php</i> in the <i>fileProcessing</i> directory. <a href="http://0.0.7.223/01/moving-from-mediawiki-to-sharepoint-filepathflattener.html" target="_blank">Copy this code</a> and paste it in this file, update the rootpath on line 4, then save it.</div>
<div>
<br /></div>
<div>
Before we run the script, right-click the <i>images</i> folder and ask for its <i>properties</i>. Note down the number of files - as a check, for later.</div>
<div>
Now we're going to run the script to move all the files into either the <i>imagesFlat</i> or the <i>filesFlat </i>directory. To do this, open a command line console and type the full path to the php.exe in your UniServerZ folders, followed by a space and the path to the php-script, best put between quotes:</div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1</pre>
</td><td><pre style="line-height: 125%; margin: 0;">C:\something\UniServerZ\core\php<span style="color: #6600ee; font-weight: bold;">54</span>\php.exe <span style="background-color: #fff0f0;">"C:\something\UniServerZ\www\wikimigration\fileProcessing\filePathFlattener.php"</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<div>
<br /></div>
<div>
Have some patience while the script is moving stuff. When it's ready, it should tell you how many files it copied - the number should of course be identical to the number of files you had originally.</div>
<div>
<br /></div>
<div>
<h3>
On to SharePoint</h3>
</div>
<div>
<a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">In an earlier article</a>, I explained how to open a SharePoint library with Explorer. Now open the <i>Documents</i> library (through <i>Site Contents</i>) in Explorer (where it's called <i>Shared Documents</i> after you open it - go figure). Now simply copy all files from <i>filesFlat</i> to this directory. Depending on the number of files you have, this may take some time.</div>
<div>
<br /></div>
<div>
We're going to do the same thing for the images: open the <i>Site Assets</i> library (through <i>Site Contents</i>) in Explorer. Create a folder <i>mw</i> (for <i>MediaWiki</i>) and copy all images from <i>imagesFlat</i> into this directory.</div>
<div>
<br /></div>
<h3>
And now we wait?</h3>
<div>
While you're waiting for everything to copy - for me at least, this is going hideously slow: 10 KB/s is not of this age... what am I working with here, a 56K modem? - let's <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint-part-5.html">turn our attention to the textual content of the articles</a>.</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-14745709969941548572015-01-17T16:40:00.002+01:002015-01-21T10:37:09.167+01:00Moving from MediaWiki to SharePoint O365 - part 3<a href="http://lifeworkimprovement.blogspot.be/2015/01/moving-from-mediawiki-to-sharepoint_17.html">Now that you have the scripts in place</a>, how do you make use of them?<br />
<h3>
Redirect</h3>
<div>
This one is simple. Write #REDIRECT[[pagename]] like you're used to doing it in MediaWiki. Just take care that you write it exactly as I did: in uppercase, without a space between # and REDIRECT or between REDIRECT and [[. My script is not dummy-proofed like MediaWiki is.</div>
<div>
<br /></div>
<h3>
Math and source code</h3>
<div>
As we're making use of third party scripts (MathJax and SyntaxHighlighter), you should refer to the corresponding websites for documentation. In short, you can do the following:</div>
<div>
<a name='more'></a>For inline math, use the delimiters \( to start and \) to end your math, eg \(a \ne 0\). For display equations you can use either a double dollar sign to start and end your math ($$) or use \[ to start and \] to end, eg</div>
<div>
<div>
<br /></div>
<div>
$$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$$</div>
</div>
<div>
<br />
If you're wondering about the syntax being used, then you haven't used math on your MediaWiki website either. In that case, <a href="http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference" target="_blank">here's a basic tutorial</a> and <a href="http://www.suluclac.com/Wiki+MathJax+Syntax" target="_blank">here's a bunch of additional samples</a> to get you started.<br />
<br />
<br /></div>
<div>
For source code, put your code in a pre-block and give it the appropriate class to call the corresponding brush for the language of your code, e.g. js for JavaScript. If you have something with < or > (like HTML or XML), you need to use the <script> tag and a ![CDATA[ escape. More information <a href="http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html" target="_blank">on the SyntaxHighlighter website</a>.</div>
<div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4
5
6</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><pre</span> <span style="color: #0000cc;">class=</span><span style="background-color: #fff0f0;">"brush: js;"</span><span style="color: #007700;">></span>
function helloSyntaxHighlighter()
{
return 'hi!';
}
<span style="color: #007700;"></pre></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
<h3>
Templates</h3>
</div>
<div>
Templates are <i>not</i> as powerful as they are on MediaWiki. Most important to understand is that my script <u style="font-style: italic;">does not handle chaining of templates</u> (i.e. calling a template from within a template). No doubt that's perfectly possible, but for now I can make do without it, and so I haven't put it in. If anybody out there improves on the code to make it possible, please share it back to me!</div>
<div>
<br /></div>
<div>
Calling a template works the same way as on MediaWiki: use double curly brackets.</div>
<div>
{{templateName}} will include the page with name template_templateName.aspx </div>
<div>
{{templateName</div>
<div>
|var1 = variable 1</div>
<div>
|var2 = some other variable</div>
<div>
}}</div>
<div>
will include the page with name template_templateName.aspx and pass it the variables mentioned. The template page can display them with {{{var1}}} and {{{var2}}} as named variables, or {{{1}}} and {{{2}}} in the order as they are mentioned on the calling page.</div>
<div>
On the template page you can include a default value like {{{var1|default value}}}. An empty default value is rendered correctly, just do {{{var1|}}}. If you do not specify a default value, the name of the variable will be used as default.</div>
<div>
<br /></div>
<div>
I'm using the <i>template_templateName</i> as filename as naming convention, seeing there's no namespaces in SharePoint wikis (that I'm aware of). That doesn't mean you can only include pages prefixed with <i>template_</i>! You can include any page (eg {{<i>pageName</i>}}), but the script will always first look for <i>template_pageName.aspx</i> and only if it can't find that as a page will it try <i>pageName.aspx</i> itself.</div>
<div>
<br /></div>
<div>
Because there's no decent way to put functionality in a template like with the ParserFunctions on MediaWiki, and you might want your template to be more powerful, I've added some hooks. For a template called <i>aaa</i> and stored on a page with name <i>template_aaa.aspx</i>, you can create a script like shown below, call it <i>template_aaa.js</i> and upload it to the <i>Documents</i> library. </div>
<div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">function</span> template_aaa_preprocessor(templateContent, variables){
<span style="color: #888888;">/* Do your template specific logic here by updating the string 'templateContent'.</span>
<span style="color: #888888;"> * The variables given by the template caller are available in 'variables' as variables['variableName']</span>
<span style="color: #888888;"> * At this point, the string templateContent holds the raw code of your template. </span>
<span style="color: #888888;"> * Variables like {{{variableName}}} have not yet been replaced.</span>
<span style="color: #888888;"> */</span>
<span style="color: #888888;">//...</span>
<span style="color: #888888;">//ALWAYS return the result, even if you didn't use this function or do anything with it</span>
<span style="color: #008800; font-weight: bold;">return</span> templateContent;
}
<span style="color: #008800; font-weight: bold;">function</span> template_aaa_postprocessor(templateContent, variables){
<span style="color: #888888;">/* Do your template specific logic here by updating the string 'templateContent'.</span>
<span style="color: #888888;"> * The variables given by the template caller are available in 'variables' as variables['variableName']</span>
<span style="color: #888888;"> * At this point, the string templateContent holds the updated code of your template, with variables </span>
<span style="color: #888888;"> * like {{{variableName}}} replaced by their given value or default value and any other changes made by </span>
<span style="color: #888888;"> * your preprocessor.</span>
<span style="color: #888888;"> */</span>
<span style="color: #888888;">//...</span>
<span style="color: #888888;">//ALWAYS return the result, even if you didn't use this function or do anything with it</span>
<span style="color: #008800; font-weight: bold;">return</span> templateContent;
}
<span style="color: #888888;">//include the below line for better debugging in Google Chrome</span>
<span style="color: #888888;">//@ sourceURL=https://yourInstallation.sharepoint.com/sites/yourSitenumber/Shared%20Documents/template_aaa.js</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
<div>
In these functions, you have all the power of JavaScript and jQuery at your fingertips. There is little you and your users will not be able to do. Assuming they know their way around JavaScript.<br />
<b><u>Important:</u></b> if you make a template-specific script, always have both functions present, even if you're only using one of them.<br />
<br />
<br />
One more extra thrown in for good measure: you remember the <noinclude></noinlude> tags from MediaWiki, right? They allow you to put content on a page which will not be included when the page is called as a template. Very handy place to put your template documentation: if you look at the template page itself, you'll see it, if you call the template from another page, it won't be included.<br />
Of course, SharePoint does not allow you to put a <noinlude> tag in your content. It will helpfully strip that out for you. The bastard.<br />
So my script allows you to use {noinclude} and {\noinclude} instead.<br />
<br />
<br />
<h3>
Next up</h3>
So, now that we've gotten some functionality upgrades in SharePoint O365, we can (finally) get started on <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_19.html">moving our MediaWiki content over</a>. That will be happening with a number of PHP scripts and some PowerShell. </div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-80844226138920906852015-01-17T12:59:00.001+01:002015-01-21T10:20:41.733+01:00Moving from MediaWiki to SharePoint O365 - part 2After <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint.html">getting our tools set up and acquainting ourselves with SharePoint O365</a>, lets take a step back and think for a moment. The objective is to migrate all wiki content from MediaWiki to SharePoint O365. We can get to our content in MediaWiki, i.e. the raw content as the user types it in, or if need be the HTML-content produced by MediaWiki (using PHP with cURL). And I've got a way to upload HTML-content into pages in SharePoint. So this doesn't sound like such a challenge after all?<br />
<br />
Wrong.<br />
<br />
MediaWiki has a lot of user friendly formatting syntax. Like * for bulleted and # for numbered lists. Like ==heading==. Like [[some other article]]. Or how about [some external link]. And don't forget the [[Image:something|thumb|right]]. And then there's categories. And templates. And wikitables. And if you've had a bit of fun with the extensions, there's code highlighting. And math. And lots of other stuff.<br />
SharePoint has HTML and an editor.<br />
<br />
<a name='more'></a><br />
There's basically two ways to go about this. You could choose to grab the online (HTML) content, which doesn't present any MediaWiki syntax, and work with that. Just swap out the links pointing to a location on the wiki (like other articles, files, or images) to the location on SharePoint, and you're done. True and probably works fine for articles that use basic MediaWiki syntax and nothing more. If, however, you've had people using templates... Then you'll end up destroying the write-once-use-plenty they've set up. Or code highlighting - sure it will still look nice on your SharePoint. Trouble starts when somebody needs to make changes to the code - oops, that formatting and those colors are hard-coded? Or math... You'd end up copying pictures, and try and edit that later on.<br />
The alternative is to use the original content, i.e. the one with the wiki-syntax. This will show template-calls, variables in templates, math source, code highlighted source, etc. But it will also show wiki-syntax for tables, headings, ordered and unordered lists, image positioning, etc, which would force us to translate all this 'common' wiki-syntax to HTML, while we get this for free in the online content.<br />
<br />
<br />
Which is why I've chosen to use a combination of the two. It sounds complicated, but it actually makes things a lot easier.<br />
<br />
<ul>
<li>All articles having no math, code highlighting or templates - which can be verified by scanning the wiki-syntax content - are copied over using their online content. Not a 1:1 copy of course, we still need to swap out image-, file- and intrawiki-links for links pointing to the new locations. </li>
<li>On studying articles with math, it turns out the online content also has the original math source syntax (as alternate content to the image of the formula that it shows), so some processing can reformat the math-parts to work in SharePoint: take out the image-code, add a prefix and suffix to the math source syntax, and we're done.</li>
<li>For articles containing highlighted code, the online content of the highlighted code is not usable. But because every code block can still be recognized as such, we can combine the online content with the wiki-syntax content: we swap out all code blocks from the online content with the corresponding code blocks from the wiki-syntax content, and then update the code block prefix and suffix from wiki-syntax to SharePoint-syntax. <span style="font-size: x-small;">(Actually: SyntaxHighlighter syntax. But we'll get to that later.)</span></li>
</ul>
<br />
<br />
<i>What about categories?</i><br />
I'm sorry my friend, but they've been lost to us. They are no more. You must let them go, and not let your mourning keep you from continuing to read (and work).<br />
Seriously though, I haven't found a feasible way to get categories to work in SharePoint. There's a button for tags (but it's disabled in our installation) and in the settings there seems to be something like taxonomy, but I couldn't find anything which could emulate the Category tagging from MediaWiki.<br />
<br />
<i>But, so, templates and code highlighting and math, that works on SharePoint? We just need to throw it into a new format?</i><br />
Sorry if I gave you that impression. SharePoint allows you to write HTML in their content editor. And if any of your HTML looks decidedly script-y, they'll automatically throw it into a <i>Web part</i> for you, just to be nice. Not that you're given a choice.<br />
So, no, SharePoint doesn't have that stuff. The only thing still formatted like in MediaWiki is [[internal links]], <i>everything else</i> is done directly in HTML. And if you see the HTML the content editor produces... Oh boy... You'll think it's 1998 again.<br />
<br />
<br />
<h3>
Introducing... javascript</h3>
<div>
You being the <i>Site owner</i> and all, you'll be able to make changes to the master page, which includes adding scripts to it. So what I've done is made (a basic form of) templates, code highlighting, math and redirects by interpreting the page content through JavaScript. It is not super fast (as compared to code being executed on the server - although the server response times aren't great all by themselves either), and the user will see certain stuff loading/changing after the page has been loaded instead of it all being already parsed like in MediaWiki. But it does work, and it's more than you're getting from SharePoint out of the box. </div>
<div>
<br /></div>
<h3>
Step 1: jQuery</h3>
<div>
This one is easy. <a href="http://jquery.com/download/" target="_blank">Download jQuery.</a></div>
<div>
I suppose you could use a CDN, but then again do you really want (more) outsider scripts running on your confidential company information? I didn't think so.</div>
<div>
Once you have it, you'll need to upload it. Go to your site in SharePoint, click the cog-wheel, go to <i>Site contents</i>, and open the <i>Site assets</i> library. Then click the <i>Library </i>button (top left somewhere), and in the toolbar that appears then, you'll see the <i>Open with Explorer</i> in the <i>Connect & Export</i> part.</div>
<div>
If you find this button to be disabled, then you're probably not using Internet Explorer. Try again with the Microsoft browser, and the button should be available. Click it, and the library opens as a folder in Explorer. I've made a new folder 'JayVee' (call me vain) and copied the <i>jquery.min.js</i> to it.</div>
<div>
<br /></div>
<div>
Of course you've seen the upload button on the SharePoint library page itself, and seeing as it's only one file, wouldn't this have been faster? Maybe, but there's a whole lot more files that need to be sent there (thousands), and at that point you'll be very happy to know how to do this using Explorer, as the online upload only allows 99 files to be uploaded at once.</div>
<div>
<br /></div>
<div>
Also, consider <a href="https://jquery.org/donate/" target="_blank">donating</a> to the people who bring you jQuery for free.<br />
<br />
<br /></div>
<h3>
Step 2: templateCaller.js</h3>
<div>
This is my own script. I'm not a javascript master and never had the time to truly study the possibilities of jQuery, so I basically hacked this together from Google and StackOverflow. A lot of improvements to this script are probably possible. If you have some, please leave a comment on that page and enlighten me, so I can update it for myself and for other readers. </div>
<div>
The important thing for now is: it works.</div>
<div>
<br /></div>
<div>
You can <a href="http://lifeworkimprovement.blogspot.be/2015/01/moving-from-mediawiki-to-sharepoint_25.html" target="_blank">find the code here</a>. Copy it into a text file, rename it 'templateCaller.js' (it does more than that by now, but it started life as a script to work with templates, hence the name), and upload it to the same location as the jQuery script.<br />
<br />
<br />
<h3>
Step 3: MathJax</h3>
</div>
<div>
I work in an organisation where there's the occasional need to document some statistics and other math. We can use MathJax to have any existing math formulas be formatted nicely. <a href="http://docs.mathjax.org/en/latest/installation.html" target="_blank">Download an archive</a>, because we don't want to use the CDN and risk letting scripts not under our control get a look at our confidential information.</div>
<div>
Unpack the archive, and upload everything to <i>SiteAssets/JayVee/MathJax</i>. Consider <a href="http://www.mathjax.org/sponsors/" target="_blank">donating</a> to the people who bring you this for free.</div>
<div>
<br /></div>
<div>
<br /></div>
<h3>
Step 4: SyntaxHighlighter</h3>
<div>
There's a number of syntax-highlighting JavaScripts out there, and I had time only for a quick compare. So this may or may not be the script that suits your needs best. For me, it's a 90% match to my requirements: it can do JavaScript, SQL, PHP, batch, powershell, java and matlab (and many others, but these are the ones I care about most). It does not do SAS, which is a pity, but you can extend the script with <i>brushes</i> (there's one for every language it can highlight), so if need be I can eventually create a brush for SAS myself.</div>
<div>
And very important (for me): it can automatically add line numbers. </div>
<div>
<br /></div>
<div>
<a href="http://alexgorbatchev.com/SyntaxHighlighter/download/" target="_blank">Download it from here</a>, unpack, and put it in <i>SiteAssets/JayVee/SyntaxHighlighter.</i> <a href="http://alexgorbatchev.com/SyntaxHighlighter/donate.html" target="_blank">Consider donating to Alex Gorbatchev</a>, who made, maintains and improves this script and lets you use it for free.</div>
<div>
<br /></div>
<div>
<br /></div>
<h3>
Step 5: run the scripts on all pages</h3>
<div>
You really want to have the scripts available on all wiki pages, without having to add a block of code to each (<i>Web parts</i>, <u>bleh</u>). To do that, we're going to change the master page for wiki pages. What exactly happens to that master between the file as it is and a generated wiki page as you see it, I do not know, but the changes I've made to it work just fine. </div>
<div>
<br /></div>
<div>
Using Internet Explorer, go to your <i>Site settings</i> (behind the cog-wheel). Under <i>Web designer galleries</i> you should find an entry <i>Master pages</i>. Click it, and you'll be brought to the library. Click the library link (top left somewhere) and then use the button to open the library in Explorer. From the explorer window, you can download the <i>seattle.master</i> file. I'm sure there's a story behind that filename, but I don't know what it is.</div>
<div>
Using Eclipse (or your IDE of choice, or WordPad if need be), open the file. At a certain point you'll find this:</div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><SharePoint:CustomJSUrl</span> <span style="color: #0000cc;">runat=</span><span style="background-color: #fff0f0;">"server"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><SharePoint:SoapDiscoveryLink</span> <span style="color: #0000cc;">runat=</span><span style="background-color: #fff0f0;">"server"</span> <span style="color: #007700;">/></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
Between these two lines, you need to add the references to the other scripts we're loading, making it:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #007700;"><SharePoint:CustomJSUrl</span> <span style="color: #0000cc;">runat=</span><span style="background-color: #fff0f0;">"server"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shCore.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushAS3.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushAppleScript.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushBash.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushBat.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushCSharp.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushColdFusion.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushCpp.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushCss.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushDelphi.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushDiff.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushErlang.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushGroovy.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushJScript.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushJava.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushJavaFX.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushMathematica.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushMatlabSimple.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushPerl.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushPhp.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushPlain.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushPowerShell.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushPython.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushRuby.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushSass.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushScala.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushSql.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushVb.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shBrushXml.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/jquery.min.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><script </span><span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/javascript"</span> <span style="color: #0000cc;">src=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/templateCaller.js"</span><span style="color: #007700;">></script></span>
<span style="color: #007700;"><SharePoint:SoapDiscoveryLink</span> <span style="color: #0000cc;">runat=</span><span style="background-color: #fff0f0;">"server"</span> <span style="color: #007700;">/></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
You'll notice syntaxHighlighter has a lot of scripts being loaded: that's actually just the core script (<i>shCore.js</i>) with a lot of brushes for specific languages. If you don't need all these languages, omit the corresponding lines. If you need more/other languages, make sure to upload the <a href="http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/" target="_blank">corresponding brush script from here</a> (or <a href="http://www.undermyhat.org/blog/2009/09/list-of-brushes-syntaxhighligher/" target="_blank">here for a full list</a>) and add a line in <i>seattle.master</i> for it.<br />
At the end, we call <i>jQuery</i> and my own <i>templateCaller</i>.<br />
<br />
A second change we need to do concerns <i>css</i>, we need to add a stylesheet for <i>SyntaxHighlighter</i>.<br />
Find these lines:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2</pre>
</td><td><pre style="line-height: 125%; margin: 0;"> <span style="color: #007700;"><SharePoint:CssRegistration</span> <span style="color: #0000cc;">Name=</span><span style="background-color: #fff0f0;">"Themable/corev15.css"</span> <span style="color: #0000cc;">runat=</span><span style="background-color: #fff0f0;">"server"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"></head></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
And add a link to the stylesheet:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"> <span style="color: #007700;"><SharePoint:CssRegistration</span> <span style="color: #0000cc;">Name=</span><span style="background-color: #fff0f0;">"Themable/corev15.css"</span> <span style="color: #0000cc;">runat=</span><span style="background-color: #fff0f0;">"server"</span> <span style="color: #007700;">/></span>
<span style="color: #007700;"><link</span> <span style="color: #0000cc;">type=</span><span style="background-color: #fff0f0;">"text/css"</span> <span style="color: #0000cc;">rel=</span><span style="background-color: #fff0f0;">"stylesheet"</span> <span style="color: #0000cc;">href=</span><span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber/SiteAssets/JayVee/syntaxHighlighter/shCoreDefault.css"</span><span style="color: #007700;">></span>
<span style="color: #007700;"></head></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
<h3>
Step 6: what can you now do?</h3>
<div>
Now that everything is in place, how do you call the functionality offered by the scripts from within your page content? After all, migrating our MediaWiki content is one thing, but your users also have to know how to make new content on SharePoint.</div>
<div>
<a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_78.html">We'll go over that in the next article.</a></div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-90190628920533987092015-01-17T12:12:00.004+01:002015-01-29T20:02:18.350+01:00Moving from MediaWiki to SharePoint O365 - templateCaller.jsThis is the source code of the templateCaller script, which, <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">as mentioned</a>, does more than replacing templates by now.<br />
<br />
To work, it requires to be placed in your SiteAssets/JayVee folder (create the JayVee folder), where there should also be <a href="http://jquery.com/download/" target="_blank">jquery.min.js</a> and the folders <a href="http://docs.mathjax.org/en/latest/installation.html" target="_blank">MathJax</a> and <a href="https://www.google.be/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0CC4QjBAwAg&url=http%3A%2F%2Falexgorbatchev.com%2FSyntaxHighlighter%2Fdownload%2F&ei=nEG6VPCzOImqywOJ-4KgCQ&usg=AFQjCNH7BLZfOPGSIL9FPmkchOSSNuoMPA&sig2=GzCYYbjw58eWP4in4LZ8Cg&bvm=bv.83829542,d.bGQ" target="_blank">SyntaxHighlighter</a> with the corresponding scripts inside. Your <i>seattle.master</i> should be updated to load the jquery script (first) and this script (second) as <a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">explained here</a>.<br />
You of course need to change the vars <i>sharePointRootURL </i>(line 15) and <i>sharePointSiteRootURL </i>(line 16) to match the URLs of your site.<br />
<br />
If there are errors in it, or things that can be done better, please let me know in the comments so I can improve it! I am not at all fluent in javascript / jQuery, nor will I pretend to be.<br />
<br />
<a name='more'></a><br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">/* </span>
<span style="color: #888888;"> * The below script is uploaded as templateCaller.js. It scans the article content for template code </span>
<span style="color: #888888;"> * and calls the template accordingly.</span>
<span style="color: #888888;"> * The script, and the jQuery script upon which it depends, are loaded by every page (they've been added </span>
<span style="color: #888888;"> * to the seattle.master masterpage). </span>
<span style="color: #888888;">*/</span>
<span style="color: #888888;">/******</span>
<span style="color: #888888;"> * This code starts as soon as it is loaded</span>
<span style="color: #888888;"> */</span>
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Global variables</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">var</span> sharePointRootURL <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com"</span>;
<span style="color: #008800; font-weight: bold;">var</span> sharePointSiteRootURL <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"https://yourInstallation.sharepoint.com/sites/yourSiteNumber"</span>;
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Additional jQuery function to check if element is available</span>
<span style="color: #888888;"> */</span>
(<span style="color: #008800; font-weight: bold;">function</span> ($) {
$.fn.waitUntilExists <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">function</span> (handler, shouldRunHandlerOnce, isChild) {
<span style="color: #008800; font-weight: bold;">var</span> found <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">'found'</span>;
<span style="color: #008800; font-weight: bold;">var</span> $this <span style="color: #333333;">=</span> $(<span style="color: #008800; font-weight: bold;">this</span>.selector);
<span style="color: #008800; font-weight: bold;">var</span> $elements <span style="color: #333333;">=</span> $this.not(<span style="color: #008800; font-weight: bold;">function</span> () { <span style="color: #008800; font-weight: bold;">return</span> $(<span style="color: #008800; font-weight: bold;">this</span>).data(found); }).each(handler).data(found, <span style="color: #008800; font-weight: bold;">true</span>);
<span style="color: #008800; font-weight: bold;">if</span> (<span style="color: #333333;">!</span>isChild)
{
(<span style="color: #007020;">window</span>.waitUntilExists_Intervals <span style="color: #333333;">=</span> <span style="color: #007020;">window</span>.waitUntilExists_Intervals <span style="color: #333333;">||</span> {})[<span style="color: #008800; font-weight: bold;">this</span>.selector] <span style="color: #333333;">=</span>
<span style="color: #007020;">window</span>.setInterval(<span style="color: #008800; font-weight: bold;">function</span> () { $this.waitUntilExists(handler, shouldRunHandlerOnce, <span style="color: #008800; font-weight: bold;">true</span>); }, <span style="color: #0000dd; font-weight: bold;">500</span>)
;
}
<span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span> (shouldRunHandlerOnce <span style="color: #333333;">&&</span> $elements.length)
{
<span style="color: #007020;">window</span>.clearInterval(<span style="color: #007020;">window</span>.waitUntilExists_Intervals[<span style="color: #008800; font-weight: bold;">this</span>.selector]);
}
<span style="color: #008800; font-weight: bold;">return</span> $this;
};
}(jQuery));
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * We wait until the element which holds the actual article content has become available.</span>
<span style="color: #888888;"> * We check that we're not in edit mode, because any changes made to the content while in edit mode</span>
<span style="color: #888888;"> * would be in danger of being stored, so making the change hardcoded, which we don't want.</span>
<span style="color: #888888;"> */</span>
$(<span style="background-color: #fff0f0;">'#ctl00_PlaceHolderMain_WikiField'</span>).waitUntilExists(<span style="color: #008800; font-weight: bold;">function</span>(){
<span style="color: #008800; font-weight: bold;">if</span>(notEditMode()){
redirect();
replaceTemplates();
replaceMath();
highlightCode();
}
});
<span style="color: #888888;">/******</span>
<span style="color: #888888;"> * These are the supporting functions called upon</span>
<span style="color: #888888;"> */</span>
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Checks whether a certain element exists to determine if we're in edit mode.</span>
<span style="color: #888888;"> * There is rumored to be a way to check this using SP.Ribbon, but none of the examples worked for me,</span>
<span style="color: #888888;"> * hence this "ugly" hack.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> notEditMode(){
<span style="color: #008800; font-weight: bold;">return</span> (<span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">'ctl00_PlaceHolderMain_WikiField_ctl00_ctl00_TextField_inplacerte_layoutsTable'</span>)<span style="color: #333333;">==</span><span style="color: #008800; font-weight: bold;">null</span>);
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Checks for #REDIRECT[[pagename]] and redirects accordingly. </span>
<span style="color: #888888;"> * It does this by replacing the #REDIRECT[[pagename]] with a notification and a javascript which</span>
<span style="color: #888888;"> * redirects the user after 2.5 seconds. The delay is necessary to be able to go into edit mode</span>
<span style="color: #888888;"> * to change the redirect if desired.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> redirect(){
<span style="color: #888888;">//get actual wiki content out of the page</span>
<span style="color: #008800; font-weight: bold;">var</span> articleContent <span style="color: #333333;">=</span> <span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">'ctl00_PlaceHolderMain_WikiField'</span>).innerHTML;
<span style="color: #888888;">//detect redirect call in the content</span>
<span style="color: #008800; font-weight: bold;">if</span>(articleContent.indexOf(<span style="background-color: #fff0f0;">'#REDIRECT'</span>)<span style="color: #333333;">>-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #008800; font-weight: bold;">var</span> redirectStart <span style="color: #333333;">=</span> articleContent.indexOf(<span style="background-color: #fff0f0;">'#REDIRECT'</span>);
<span style="color: #008800; font-weight: bold;">var</span> redirectLinkStart <span style="color: #333333;">=</span> articleContent.indexOf(<span style="background-color: #fff0f0;">'href="'</span>,redirectStart) <span style="color: #333333;">+</span> <span style="background-color: #fff0f0;">'href="'</span>.length;
<span style="color: #008800; font-weight: bold;">var</span> redirectLinkEnd <span style="color: #333333;">=</span> articleContent.indexOf(<span style="background-color: #fff0f0;">'"'</span>,redirectLinkStart);
<span style="color: #008800; font-weight: bold;">var</span> redirectEnd <span style="color: #333333;">=</span> articleContent.indexOf(<span style="background-color: #fff0f0;">'</a>'</span>,redirectLinkEnd);
<span style="color: #008800; font-weight: bold;">var</span> redirectLink <span style="color: #333333;">=</span> articleContent.substr(redirectLinkStart,redirectLinkEnd<span style="color: #333333;">-</span>redirectLinkStart);
<span style="color: #008800; font-weight: bold;">var</span> fullLink <span style="color: #333333;">=</span> sharePointRootURL<span style="color: #333333;">+</span>redirectLink;
<span style="color: #008800; font-weight: bold;">var</span> lastSlashPosition <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">while</span>(fullLink.indexOf(<span style="background-color: #fff0f0;">'/'</span>,lastSlashPosition)<span style="color: #333333;">>-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
lastSlashPosition <span style="color: #333333;">=</span> fullLink.indexOf(<span style="background-color: #fff0f0;">'/'</span>,lastSlashPosition)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>;
}
<span style="color: #008800; font-weight: bold;">var</span> articleTitle <span style="color: #333333;">=</span> fullLink.substr(lastSlashPosition,fullLink.length<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">5</span><span style="color: #333333;">-</span>(lastSlashPosition));
<span style="color: #008800; font-weight: bold;">var</span> newArticleContent <span style="color: #333333;">=</span> articleContent.substr(<span style="color: #0000dd; font-weight: bold;">0</span>,redirectStart);
newArticleContent<span style="color: #333333;">+=</span><span style="background-color: #fff0f0;">'This page redirects to <a href="'</span><span style="color: #333333;">+</span>fullLink<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'">'</span><span style="color: #333333;">+</span>articleTitle<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'</a>.<script type="text/javascript">setTimeout(function(){window.location="'</span>;
newArticleContent<span style="color: #333333;">+=</span> fullLink;
newArticleContent<span style="color: #333333;">+=</span> <span style="background-color: #fff0f0;">'";},2500);</script>'</span>;
newArticleContent<span style="color: #333333;">+=</span> articleContent.substr(redirectEnd<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">4</span>);
$(<span style="background-color: #fff0f0;">"#ctl00_PlaceHolderMain_WikiField"</span>).html(newArticleContent);
}
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * This function does the actual template replacement.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> replaceTemplates(){
<span style="color: #888888;">//define variables</span>
<span style="color: #008800; font-weight: bold;">var</span> variablesArray <span style="color: #333333;">=</span> [];
<span style="color: #008800; font-weight: bold;">var</span> templateCounter<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #888888;">//get actual wiki content out of the page</span>
<span style="color: #008800; font-weight: bold;">var</span> articleContent <span style="color: #333333;">=</span> <span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">'ctl00_PlaceHolderMain_WikiField'</span>).innerHTML;
<span style="color: #888888;">//strip out {noinclude} tags as these should not be visible</span>
<span style="color: #008800; font-weight: bold;">while</span>(articleContent.indexOf(<span style="background-color: #fff0f0;">'{noinclude}'</span>)<span style="color: #333333;">>-</span><span style="color: #0000dd; font-weight: bold;">1</span>)
articleContent <span style="color: #333333;">=</span> articleContent.replace(<span style="background-color: #fff0f0;">'{noinclude}'</span>,<span style="background-color: #fff0f0;">''</span>);
<span style="color: #008800; font-weight: bold;">while</span>(articleContent.indexOf(<span style="background-color: #fff0f0;">'{/noinclude'</span>)<span style="color: #333333;">>-</span><span style="color: #0000dd; font-weight: bold;">1</span>)
articleContent <span style="color: #333333;">=</span> articleContent.substr(<span style="color: #0000dd; font-weight: bold;">0</span>,articleContent.indexOf(<span style="background-color: #fff0f0;">'{/noinclude'</span>)) <span style="color: #333333;">+</span> articleContent.substr(articleContent.indexOf(<span style="background-color: #fff0f0;">'}'</span>,articleContent.indexOf(<span style="background-color: #fff0f0;">'{/noinclude'</span>))<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #888888;">//detect template calls in the content</span>
<span style="color: #008800; font-weight: bold;">var</span> articlePosition<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">while</span>(articleContent.indexOf(<span style="background-color: #fff0f0;">'{{'</span>,articlePosition)<span style="color: #333333;">>-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #888888;">//get template content</span>
<span style="color: #008800; font-weight: bold;">var</span> templateStartPosition <span style="color: #333333;">=</span> articleContent.indexOf(<span style="background-color: #fff0f0;">'{{'</span>);
<span style="color: #008800; font-weight: bold;">var</span> templateEndPosition <span style="color: #333333;">=</span> articleContent.indexOf(<span style="background-color: #fff0f0;">'}}'</span>,templateStartPosition)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">2</span>;
<span style="color: #008800; font-weight: bold;">var</span> templateContent <span style="color: #333333;">=</span> articleContent.substr(templateStartPosition, templateEndPosition <span style="color: #333333;">-</span> templateStartPosition);
<span style="color: #888888;">//if on a template page, don't interpret variable placeholders as template calls</span>
<span style="color: #008800; font-weight: bold;">var</span> tripleBraces <span style="color: #333333;">=</span> articleContent.substr(templateStartPosition,<span style="color: #0000dd; font-weight: bold;">3</span>);
<span style="color: #008800; font-weight: bold;">if</span>(tripleBraces <span style="color: #333333;">==</span> <span style="background-color: #fff0f0;">"{{{"</span>){
articlePosition <span style="color: #333333;">+=</span> <span style="color: #0000dd; font-weight: bold;">3</span>;
<span style="color: #008800; font-weight: bold;">continue</span>;
}
templateCounter<span style="color: #333333;">++</span>;
<span style="color: #888888;">//clean up, get relevant content</span>
templateContent <span style="color: #333333;">=</span> cleanUpTemplate(templateContent);
<span style="color: #888888;">//split into name and variables (=parameters)</span>
<span style="color: #008800; font-weight: bold;">var</span> variables <span style="color: #333333;">=</span> getUrlAndVarsFromTemplateContent(templateContent,templateCounter);
<span style="color: #888888;">//put placeholder in html, the specific div-id will be used later on to fill the correct content</span>
<span style="color: #008800; font-weight: bold;">var</span> newArticleContent <span style="color: #333333;">=</span> articleContent.substr(<span style="color: #0000dd; font-weight: bold;">0</span>,templateStartPosition);
newArticleContent <span style="color: #333333;">+=</span> <span style="background-color: #fff0f0;">'<div id="template-'</span><span style="color: #333333;">+</span>templateCounter<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'" style="display:inline;"><img src="'</span><span style="color: #333333;">+</span>sharePointRootURL<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'/_layouts/15/images/loadingcirclests16.gif"></div>'</span>;
articlePosition <span style="color: #333333;">=</span> newArticleContent.length;
newArticleContent <span style="color: #333333;">+=</span> articleContent.substr(templateEndPosition);
articleContent <span style="color: #333333;">=</span> newArticleContent;
<span style="color: #888888;">//store information for later loading</span>
variablesArray[templateCounter] <span style="color: #333333;">=</span> variables;
}
<span style="color: #888888;">//replace current contents with updated contents (= all templates)</span>
$(<span style="background-color: #fff0f0;">"#ctl00_PlaceHolderMain_WikiField"</span>).html(articleContent);
<span style="color: #888888;">//replace contents of placeholder-<div>s with fetched content</span>
<span style="color: #008800; font-weight: bold;">for</span> (<span style="color: #008800; font-weight: bold;">var</span> index <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">1</span>; index <span style="color: #333333;"><=</span> templateCounter; index<span style="color: #333333;">++</span>)
getTemplate(variablesArray[index]);
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Removes all xml tags from the template calling code (given as a string input).</span>
<span style="color: #888888;"> * What remains is {{templateName|var1=some value|var2=some other value...}} without </span>
<span style="color: #888888;"> * breaks (<br>), divs (<div>) or other xml elements.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Returns the cleaned content as a string.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> cleanUpTemplate(templateContent){
<span style="color: #008800; font-weight: bold;">while</span>(templateContent.indexOf(<span style="background-color: #fff0f0;">'<'</span>)<span style="color: #333333;">>-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #008800; font-weight: bold;">var</span> ltPosition <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'<'</span>);
<span style="color: #008800; font-weight: bold;">var</span> gtPosition <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'>'</span>);
<span style="color: #008800; font-weight: bold;">var</span> newTemplateContent <span style="color: #333333;">=</span> templateContent.substring(<span style="color: #0000dd; font-weight: bold;">0</span>,ltPosition);
newTemplateContent <span style="color: #333333;">+=</span> templateContent.substring(gtPosition<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
templateContent <span style="color: #333333;">=</span> newTemplateContent;
}
<span style="color: #008800; font-weight: bold;">return</span> templateContent;
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Extracts the string containing the template into its useful elements: </span>
<span style="color: #888888;"> * - the template name</span>
<span style="color: #888888;"> * - the template variables (names & values)</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Input:</span>
<span style="color: #888888;"> * [String] templateContent, a string containing one template call (i.e. starts with {{ and ends with }})</span>
<span style="color: #888888;"> * [int] templateCounter, a number indicating the rank of the template on the wiki page</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Output:</span>
<span style="color: #888888;"> * [Array] variables as variables['variableName'] = variableValue</span>
<span style="color: #888888;"> * In addition to the template variables, the following variables are always defined:</span>
<span style="color: #888888;"> * - templateNumber (=templateCounter from the input)</span>
<span style="color: #888888;"> * - templateName</span>
<span style="color: #888888;"> * - templatePageName (= templateName prefixed with 'template_')</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> getUrlAndVarsFromTemplateContent(templateContent,templateCounter){
<span style="color: #008800; font-weight: bold;">var</span> templatePageName;
<span style="color: #008800; font-weight: bold;">var</span> variables <span style="color: #333333;">=</span> [];
<span style="color: #008800; font-weight: bold;">var</span> pipePosition <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'|'</span>);
<span style="color: #008800; font-weight: bold;">var</span> lastPipePosition <span style="color: #333333;">=</span> templateContent.lastIndexOf(<span style="background-color: #fff0f0;">'|'</span>);
<span style="color: #008800; font-weight: bold;">var</span> templateEndPosition <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'}}'</span>);
<span style="color: #008800; font-weight: bold;">var</span> templateName;
<span style="color: #008800; font-weight: bold;">if</span>(pipePosition <span style="color: #333333;">==</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #888888;">//contains no variables, just the template name</span>
templateName <span style="color: #333333;">=</span> templateContent.substr(<span style="color: #0000dd; font-weight: bold;">2</span>,templateEndPosition<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span>).trim();
templatePageName <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"template_"</span><span style="color: #333333;">+</span>templateName;
}
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #888888;">//get name</span>
templateName <span style="color: #333333;">=</span> templateContent.substr(<span style="color: #0000dd; font-weight: bold;">2</span>,pipePosition<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">2</span>).trim();
templatePageName <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"template_"</span><span style="color: #333333;">+</span>templateName;
<span style="color: #888888;">//get all variables</span>
<span style="color: #008800; font-weight: bold;">var</span> variableCounter<span style="color: #333333;">=</span><span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">while</span>(pipePosition <span style="color: #333333;"><=</span> lastPipePosition){
variableCounter<span style="color: #333333;">++</span>;
<span style="color: #888888;">//extract variable string</span>
<span style="color: #008800; font-weight: bold;">var</span> nextPipePosition;
<span style="color: #008800; font-weight: bold;">if</span>(pipePosition <span style="color: #333333;">==</span> lastPipePosition)
nextPipePosition <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'}}'</span>,pipePosition<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #008800; font-weight: bold;">else</span>
nextPipePosition <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'|'</span>,pipePosition<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #008800; font-weight: bold;">var</span> variableContent <span style="color: #333333;">=</span> templateContent.substr(pipePosition<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>,nextPipePosition<span style="color: #333333;">-</span>(pipePosition<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>));
<span style="color: #888888;">//split variable string into variable name and value</span>
<span style="color: #008800; font-weight: bold;">var</span> eqPosition <span style="color: #333333;">=</span> variableContent.indexOf(<span style="background-color: #fff0f0;">'='</span>);
<span style="color: #008800; font-weight: bold;">if</span>(eqPosition <span style="color: #333333;">==</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>)
variables[variableCounter.toString()] <span style="color: #333333;">=</span> variableContent;
<span style="color: #008800; font-weight: bold;">else</span>{
<span style="color: #008800; font-weight: bold;">var</span> variableName <span style="color: #333333;">=</span> variableContent.substr(<span style="color: #0000dd; font-weight: bold;">0</span>,eqPosition).trim();
<span style="color: #008800; font-weight: bold;">var</span> variableValue <span style="color: #333333;">=</span> variableContent.substr(eqPosition<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>).trim();
<span style="color: #888888;">//store variables - note that each variable is stored once under its name and once under its rank</span>
variables[variableName] <span style="color: #333333;">=</span> variableValue;
variables[variableCounter.toString()] <span style="color: #333333;">=</span> variableValue;
}
pipePosition <span style="color: #333333;">=</span> nextPipePosition;
}
}
<span style="color: #888888;">//these variables are defined for every template</span>
variables[<span style="background-color: #fff0f0;">'templateNumber'</span>] <span style="color: #333333;">=</span> templateCounter;
variables[<span style="background-color: #fff0f0;">'templateName'</span>] <span style="color: #333333;">=</span> templateName;
variables[<span style="background-color: #fff0f0;">'templatePageName'</span>] <span style="color: #333333;">=</span> templatePageName;
<span style="color: #008800; font-weight: bold;">return</span> variables;
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Replaces the placeholder content for a template with the actual template content.</span>
<span style="color: #888888;"> * Warning: the code in this function is asynchronous! </span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Input:</span>
<span style="color: #888888;"> * [Array] variables: an array of the form: variables['variableName'] = variableValue</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Output:</span>
<span style="color: #888888;"> * None</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> getTemplate(variables){
<span style="color: #888888;">//get the template page (assuming its template_name.aspx)</span>
$.ajax({
url<span style="color: #333333;">:</span> sharePointSiteRootURL<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'/SitePages/'</span><span style="color: #333333;">+</span>variables[<span style="background-color: #fff0f0;">'templatePageName'</span>]<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'.aspx'</span>,
dataType<span style="color: #333333;">:</span> <span style="background-color: #fff0f0;">"html"</span>,
success<span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">function</span> (data) {
<span style="color: #888888;">//when the content has come in (asynchronously!), it is available in the variable 'data'</span>
processReceivedTemplateData(data, variables);
},
<span style="color: #888888;">//if that didn't work, assume you're calling a page by name (name.aspx)</span>
error<span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">function</span> () {
$.ajax({
url<span style="color: #333333;">:</span> sharePointSiteRootURL<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'/SitePages/'</span><span style="color: #333333;">+</span>variables[<span style="background-color: #fff0f0;">'templateName'</span>]<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">'.aspx'</span>,
dataType<span style="color: #333333;">:</span> <span style="background-color: #fff0f0;">"html"</span>,
success<span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">function</span> (data) {
<span style="color: #888888;">//when the content has come in (asynchronously!), it is available in the variable 'data'</span>
processReceivedTemplateData(data, variables);
},
error<span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">function</span>(){
<span style="color: #888888;">//set error message</span>
newTemplateContent <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">'Template '</span><span style="color: #333333;">+</span>variables[<span style="background-color: #fff0f0;">'templateName'</span>]<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">' not found. Does this template exist yet?<br>'</span>;
<span style="color: #888888;">//do processing on this content</span>
runTemplateScript(variables, newTemplateContent);
}
});
}
});
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Finds the actual article content from the fetched data, strips out the {noinclude} content, and</span>
<span style="color: #888888;"> * inserts the parameters with which the template was called.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Input:</span>
<span style="color: #888888;"> * [String] data, being the full html of the template page (as fetched through an ajax call)</span>
<span style="color: #888888;"> * [Array] variables, an array of the form: variables['variableName'] = variableValue</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Output:</span>
<span style="color: #888888;"> * None, but the call to runTemplateScript will cause the content currently on the calling page to be </span>
<span style="color: #888888;"> * replaced by the template content.</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> processReceivedTemplateData(data, variables){
<span style="color: #888888;">//extract the content-part of the page</span>
<span style="color: #008800; font-weight: bold;">var</span> templateContentStart <span style="color: #333333;">=</span> data.indexOf(<span style="background-color: #fff0f0;">'<div id="ctl00_PlaceHolderMain_WikiField">'</span>);
templateContentStart <span style="color: #333333;">=</span> data.indexOf(<span style="background-color: #fff0f0;">'ms-rte-layoutszone-inner'</span>,templateContentStart);
templateContentStart <span style="color: #333333;">=</span> data.indexOf(<span style="background-color: #fff0f0;">'>'</span>,templateContentStart);
<span style="color: #008800; font-weight: bold;">var</span> openDivs <span style="color: #333333;">=</span> <span style="color: #0000dd; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">var</span> lastDiv <span style="color: #333333;">=</span> templateContentStart;
<span style="color: #008800; font-weight: bold;">while</span>(openDivs <span style="color: #333333;">></span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #008800; font-weight: bold;">var</span> nextOpenDiv <span style="color: #333333;">=</span> data.indexOf(<span style="background-color: #fff0f0;">'<div'</span>,lastDiv<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #008800; font-weight: bold;">var</span> nextCloseDiv <span style="color: #333333;">=</span> data.indexOf(<span style="background-color: #fff0f0;">'</div'</span>,lastDiv<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>);
<span style="color: #008800; font-weight: bold;">if</span>((nextOpenDiv <span style="color: #333333;"><</span> nextCloseDiv <span style="color: #333333;">&&</span> nextOpenDiv <span style="color: #333333;">></span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>) <span style="color: #333333;">||</span> nextCloseDiv <span style="color: #333333;">==</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
openDivs<span style="color: #333333;">++</span>;
lastDiv <span style="color: #333333;">=</span> nextOpenDiv;
}
<span style="color: #008800; font-weight: bold;">else</span> <span style="color: #008800; font-weight: bold;">if</span>((nextCloseDiv <span style="color: #333333;"><</span> nextOpenDiv <span style="color: #333333;">&&</span> nextCloseDiv <span style="color: #333333;">></span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>) <span style="color: #333333;">||</span> nextOpenDiv <span style="color: #333333;">==</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
openDivs<span style="color: #333333;">--</span>;
lastDiv <span style="color: #333333;">=</span> nextCloseDiv;
}
}
<span style="color: #008800; font-weight: bold;">var</span> newTemplateContent <span style="color: #333333;">=</span> data.substr(templateContentStart<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>, lastDiv<span style="color: #333333;">-</span>(templateContentStart<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>));
<span style="color: #888888;">//decode html escaped characters</span>
newTemplateContent <span style="color: #333333;">=</span> $(<span style="background-color: #fff0f0;">'<textarea/>'</span>).html(newTemplateContent).text();
<span style="color: #888888;">//strip out all content between <noinclude>...</noinclude> tag pairs</span>
<span style="color: #008800; font-weight: bold;">while</span>(newTemplateContent.indexOf(<span style="background-color: #fff0f0;">'{noinclude}'</span>) <span style="color: #333333;">></span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #008800; font-weight: bold;">var</span> noIncludeStart <span style="color: #333333;">=</span> newTemplateContent.indexOf(<span style="background-color: #fff0f0;">'{noinclude}'</span>);
<span style="color: #008800; font-weight: bold;">var</span> noIncludeEnd <span style="color: #333333;">=</span> newTemplateContent.indexOf(<span style="background-color: #fff0f0;">'{/noinclude}'</span>,noIncludeStart);
<span style="color: #008800; font-weight: bold;">var</span> strippedContent <span style="color: #333333;">=</span> newTemplateContent.substr(<span style="color: #0000dd; font-weight: bold;">0</span>,noIncludeStart);
<span style="color: #008800; font-weight: bold;">if</span>(noIncludeEnd <span style="color: #333333;">==</span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
newTemplateContent <span style="color: #333333;">=</span> strippedContent;
}
<span style="color: #008800; font-weight: bold;">else</span>{
noIncludeEnd<span style="color: #333333;">+=</span><span style="background-color: #fff0f0;">'{/noinclude}'</span>.length;
newTemplateContent <span style="color: #333333;">=</span> strippedContent <span style="color: #333333;">+</span> newTemplateContent.substr(noIncludeEnd);
}
}
<span style="color: #888888;">//do processing on the remaining content</span>
runTemplateScript(variables, newTemplateContent);
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Includes the template-specific script and calls the template-specific methods as well as the generic processing.</span>
<span style="color: #888888;"> *</span>
<span style="color: #888888;"> * Input: </span>
<span style="color: #888888;"> * [String] templateName: the name of the template, e.g. 'aaa' when the template page is 'template_aaa'</span>
<span style="color: #888888;"> * [Array] variables: an array of the form: variables['variableName'] = variableValue</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Output:</span>
<span style="color: #888888;"> * none</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> runTemplateScript(variables, newTemplateContent) {
$.ajax({
url<span style="color: #333333;">:</span> sharePointSiteRootURL<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">"/Shared%20Documents/"</span><span style="color: #333333;">+</span>variables[<span style="background-color: #fff0f0;">'templatePageName'</span>]<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">".js"</span>,
dataType<span style="color: #333333;">:</span> <span style="background-color: #fff0f0;">"script"</span>,
success<span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">function</span> () {
<span style="color: #888888;">// call template-specific preprocessing method in loaded script</span>
newTemplateContent <span style="color: #333333;">=</span> <span style="color: #007020;">eval</span>(variables[<span style="background-color: #fff0f0;">'templatePageName'</span>]<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">"_preprocessor"</span>)(newTemplateContent, variables);
<span style="color: #888888;">// replace the variables into the template content (= standard processing)</span>
newTemplateContent <span style="color: #333333;">=</span> replace_variables(newTemplateContent, variables);
<span style="color: #888888;">// call template-specific postprocessing method in loaded script</span>
newTemplateContent <span style="color: #333333;">=</span> <span style="color: #007020;">eval</span>(variables[<span style="background-color: #fff0f0;">'templatePageName'</span>]<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">"_postprocessor"</span>)(newTemplateContent, variables);
<span style="color: #888888;">//replace the template content into the placeholder</span>
<span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">'template-'</span><span style="color: #333333;">+</span>variables[<span style="background-color: #fff0f0;">'templateNumber'</span>]).innerHTML <span style="color: #333333;">=</span> newTemplateContent;
},
error<span style="color: #333333;">:</span> <span style="color: #008800; font-weight: bold;">function</span> () {
<span style="color: #888888;">// replace the variables into the template content (= standard processing)</span>
newTemplateContent <span style="color: #333333;">=</span> replace_variables(newTemplateContent, variables);
<span style="color: #888888;">//replace the template content into the placeholder</span>
<span style="color: #007020;">document</span>.getElementById(<span style="background-color: #fff0f0;">'template-'</span><span style="color: #333333;">+</span>variables[<span style="background-color: #fff0f0;">'templateNumber'</span>]).innerHTML <span style="color: #333333;">=</span> newTemplateContent;
}
});
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Replaces the variables in templateContent, assuming they're written as {{{variableName}}} or</span>
<span style="color: #888888;"> * {{{variableName|defaultValue}}}, with the variables given.</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Input: </span>
<span style="color: #888888;"> * [String] templateContent: containing the {{{variablesToBeFilledIn}}}</span>
<span style="color: #888888;"> * [Array] variables: an array of the form variables['variableName'] = variableValue</span>
<span style="color: #888888;"> * </span>
<span style="color: #888888;"> * Output:</span>
<span style="color: #888888;"> * [String] being templateContent with the variables inserted</span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> replace_variables(templateContent, variables){
<span style="color: #888888;">//for all variables found (ie {{{...}}})</span>
<span style="color: #008800; font-weight: bold;">while</span>(templateContent.indexOf(<span style="background-color: #fff0f0;">'{{{'</span>) <span style="color: #333333;">></span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
<span style="color: #888888;">//cut out the variable</span>
<span style="color: #008800; font-weight: bold;">var</span> variableStartPos <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'{{{'</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">3</span>;
<span style="color: #008800; font-weight: bold;">var</span> variableEndPos <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'}}}'</span>,variableStartPos);
<span style="color: #008800; font-weight: bold;">var</span> variablePipePos <span style="color: #333333;">=</span> templateContent.indexOf(<span style="background-color: #fff0f0;">'|'</span>,variableStartPos);
<span style="color: #008800; font-weight: bold;">var</span> variableName;
<span style="color: #008800; font-weight: bold;">var</span> variableValue;
<span style="color: #008800; font-weight: bold;">var</span> variableDefaultValue;
<span style="color: #888888;">//check if there is a default value, if not, assign the name as default value</span>
<span style="color: #008800; font-weight: bold;">if</span>(variablePipePos <span style="color: #333333;"><</span> variableEndPos <span style="color: #333333;">&&</span> variablePipePos <span style="color: #333333;">></span> <span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">1</span>){
variableName <span style="color: #333333;">=</span> templateContent.substr(variableStartPos, variablePipePos<span style="color: #333333;">-</span>variableStartPos);
variableDefaultValue <span style="color: #333333;">=</span> templateContent.substr(variablePipePos<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>, variableEndPos<span style="color: #333333;">-</span>(variablePipePos<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">1</span>));
}
<span style="color: #008800; font-weight: bold;">else</span>{
variableName <span style="color: #333333;">=</span> templateContent.substr(variableStartPos, variableEndPos<span style="color: #333333;">-</span>variableStartPos);
variableDefaultValue <span style="color: #333333;">=</span> variableName;
}
<span style="color: #888888;">//if the value is not given, use the default value</span>
<span style="color: #008800; font-weight: bold;">if</span>(variables[variableName] <span style="color: #333333;">===</span> <span style="color: #008800; font-weight: bold;">undefined</span>)
variableValue <span style="color: #333333;">=</span> variableDefaultValue;
<span style="color: #008800; font-weight: bold;">else</span>
variableValue <span style="color: #333333;">=</span> variables[variableName];
<span style="color: #888888;">//replace the variable with its value</span>
<span style="color: #008800; font-weight: bold;">var</span> newTemplateContent <span style="color: #333333;">=</span> templateContent.substr(<span style="color: #0000dd; font-weight: bold;">0</span>,variableStartPos<span style="color: #333333;">-</span><span style="color: #0000dd; font-weight: bold;">3</span>);
newTemplateContent <span style="color: #333333;">+=</span> variableValue;
newTemplateContent <span style="color: #333333;">+=</span> templateContent.substr(templateContent.indexOf(<span style="background-color: #fff0f0;">'}}}'</span>)<span style="color: #333333;">+</span><span style="color: #0000dd; font-weight: bold;">3</span>);
templateContent <span style="color: #333333;">=</span> newTemplateContent;
}
<span style="color: #008800; font-weight: bold;">return</span> templateContent;
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Adds the MathJax script to the page. It will replace math code. </span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> replaceMath(){
(<span style="color: #008800; font-weight: bold;">function</span> () {
<span style="color: #008800; font-weight: bold;">var</span> script <span style="color: #333333;">=</span> <span style="color: #007020;">document</span>.createElement(<span style="background-color: #fff0f0;">"script"</span>);
script.type <span style="color: #333333;">=</span> <span style="background-color: #fff0f0;">"text/javascript"</span>;
script.src <span style="color: #333333;">=</span> sharePointSiteRootURL<span style="color: #333333;">+</span><span style="background-color: #fff0f0;">"/SiteAssets/JayVee/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"</span>;
<span style="color: #007020;">document</span>.getElementsByTagName(<span style="background-color: #fff0f0;">"head"</span>)[<span style="color: #0000dd; font-weight: bold;">0</span>].appendChild(script);
})();
}
<span style="color: #888888;">/*</span>
<span style="color: #888888;"> * Activates the SyntaxHighlighter script. It will replace source code. </span>
<span style="color: #888888;"> */</span>
<span style="color: #008800; font-weight: bold;">function</span> highlightCode(){
SyntaxHighlighter.highlight();
}
</pre>
</td></tr>
</tbody></table>
</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-48359195029132214602015-01-17T09:00:00.000+01:002015-01-21T09:40:54.694+01:00Moving from MediaWiki to SharePoint O365 - part 1Some clever person at Microsoft understood the <i>wiki</i> hype and decided to call some component of their SharePoint platform 'wiki', never mind if it really is one or has some of the much-used functionalities of such things. They knew management would fall for it. And in my case (and yours apparently), they did. <i>It's just another wiki right?</i><br />
<br />
From the articles I've written before, you know I'm a fan of good software being used for what it's meant to do. Like MediaWiki for wikis. So if you've ended up on this page because you're being forced to move <i>away</i> from MediaWiki instead of <i>towards</i> it, let me tell you: I feel your pain. I understand your frustration. If you've never worked with SharePoint before, I understand the frustration you're about to have.<br />
But let's not mix these feelings with the work that needs to be done. So here's some empty space where you're allowed to feel sorry for yourself:<br />
<br />
<br />
<br />
<br />
<br />
... and done.<br />
<br />
Now we get to work.<br />
<br />
<a name='more'></a><br />
<br />
<h3>
Understanding the setting</h3>
<div>
I'm working within the limitations of not being a SharePoint admin, not having administration rights on my computer (= I can't install anything), and having no monetary budget to buy software anyway. Add to that a very strict firewall/scanner thing that blocks you from most websites offering code (usually the code you need to get something done), and then you're about in my situation. </div>
<div>
It seems funny to have to do work in software with those types of limitations, but let me assure you, there's nothing funny about it. The only upside is that you're forced to learn new things faster than the IT admins so you can stay a step ahead of them and rescue the tools you need to still get some work done :-)</div>
<div>
<br /></div>
<div>
So what do I have at my disposal? </div>
<div>
<ul>
<li>I can read from USB and so copy stuff to my computer. </li>
<li>I'm the guy who got the MediaWiki in, so I have direct access to that system.</li>
<li>I have a Windows 7 laptop (with not enough RAM). It includes PowerShell (how could it not?).</li>
<li>SharePoint O365 has something called "sites". I have one of those for which I'm the <i>owner</i>. As the IT staff can create as many of these "sites" as they want, I'm going to assume its not a problem for you to get one either. <i>SharePoint designer</i>, I do not have. <i>OneDrive for Business</i>, I do not have.</li>
</ul>
<div>
<br /></div>
<h3>
Let's set up some software</h3>
<div>
To create the scripts, I've needed a code editor. If you plan on tinkering with my scripts to make them better suited to your unique situation (or to just plain make them better), then you'll be needing a code editor. I have a personal preference for Eclipse, mainly because it's the one that was heavily used at university and also because until now I haven't found another tool that offers enough interesting <i>extra</i> functionality to seduce me into switching.</div>
<div>
So head <a href="https://eclipse.org/pdt/" target="_blank">over here and download the Eclipse for PHP</a> that suits your system. It doesn't require installing, you can just unzip it and run the executable. If the download itself is being blocked by your firewall, I'm sure there's a way you can get it onto your computer anyway. Cough*<i>USB</i>*cough.<br />
If you plan to use the scripts mostly as-is, you don't necessarily need a code-editor: you can always use <i>WordPad</i> or <i>Notepad</i>.</div>
<div>
<br /></div>
<div>
So we'll be using PHP then? Yes, and also a bit of JavaScript and jQuery. The JavaScript and jQuery is going into scripts that we're going to install in our SharePoint site to give it at least a basic version of some of MediaWiki's standard/extension functionalities. The PHP is for scripts to do the actual migration: exporting and manipulating your MediaWiki content. The actual upload into SharePoint will be handled by PowerShell. And we'll also need to make some updates to the master page for wiki pages in your SharePoint site, which is some meta version of ASP (don't ask, I don't know either: my knowledge of computer languages invented by Microsoft is limited). </div>
</div>
<div>
Anyway, back to the PHP scripts: we'll need something to run them on. Chances are you can simply use the server MediaWiki is using for this, because it has all necessary components anyway (Apache, PHP). Me, I don't like to have to continually upload stuff, so I've got a webserver running on my laptop. </div>
<div>
<i>What? I thought you couldn't install anything??</i></div>
<div>
That's right. I've got a portable, non-install version of a webserver which allows me to do data manipulations in my own MySQL (or MariaDB, which also comes in a portable version) and using PHP scripts (or Java programs for the heavier stuff).</div>
<div>
<i>How?</i></div>
<div>
Right here my friend: <a href="http://www.uniformserver.com/" target="_blank">Uniform Server</a>. I had a small issue with it at the start: I got an error saying my port 80 was already in use (due to IIS, which I couldn't kill, not having admin rights and all...), and I couldn't get into the control panel to change it. Since it's portable, just start it up on a computer on which port 80 is not yet in use (like a personal computer), go into the control panel, change the port to 8080 or something, and copy the result back to your work pc. </div>
<div>
<br /></div>
<div>
<br /></div>
<h3>
Getting to know your SharePoint site</h3>
<div>
SharePoint offers you a site. The site has apps/libraries (they're rather loose with the term). There's one called <i>Site Pages</i>, which is where your wiki pages go. You're thinking you can just upload pages in there and you're good? Sorry, no go.</div>
<div>
We'll be using three libraries (ok four) - you can find these by clicking the cog-wheel icon at the top right of your SharePoint site and then clicking <i>Site Contents</i>:</div>
<div>
<ul>
<li><i>Site Pages</i>: your wiki content will go here.</li>
<li><i>Site Assets: </i>this is where we'll be putting our javascript. It is also the default location for SharePoint to put the images used in the Site Pages when you're uploading them from inside the page content editor. Unfortunately, SharePoint creates a folder per wiki page and puts the content in that folder, as if the same image couldn't be reused on multiple pages. We'll put the images uploaded in MediaWiki there as well, but in one common folder. </li>
<li><i>Documents:</i> your users can upload stuff here to share it with others. This is where we'll put the files that were uploaded to your wiki which weren't images.</li>
</ul>
<div>
There's also a fourth library, but you can't find it in <i>Site Contents</i>. You need to go to <i>Site Settings</i> (it's also one of the links behind the cogwheel) and then find the link <i>Master pages</i>. It's under the heading <i>Web designer galleries</i>. That library contains the master page, i.e. the template behind all our wiki pages. By making changes to this page, we can change all pages, which is handy when we want to run some javascript on all our pages without having to add <i>web parts</i> to all of them. You don't know what <i>web parts</i> are? Count your blessings.</div>
</div>
<div>
<br /></div>
<div>
<br />
<a href="http://lifeworkimprovement.blogspot.com/2015/01/moving-from-mediawiki-to-sharepoint_17.html">Next up: javascript, jQuery, and messing with the master (page).</a></div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-76712983990027108652013-05-19T00:50:00.000+02:002015-01-17T13:04:07.488+01:00CoolTools - SphinxSearchIn the previous posts, we've <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-virtual-machine.html">set up a virtual machine</a>, <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-ubuntu-operating-system.html">installed ubuntu</a>, <a href="http://lifeworkimprovement.blogspot.be/2013/05/setting-up-web-server.html">got the prerequisite server software ready</a> and a <a href="http://lifeworkimprovement.blogspot.com/2013/05/cooltools-mediawiki.html">basic install of MediaWiki running and reachable</a> as your intranet wiki.<br />
But we're not quite ready to go live. In this and the next post, we'll be installing Sphinx as your back-end search engine and doing some additional configuration work.<br />
<br />
People will be continuously searching through your wiki for that exact bit of information they need, so it follows you'll be needing a good search functionality. The basic search included in your wiki installation is <i>not</i> a good search functionality. <br />
SphinxSearch is a (stand-alone) lightning-fast indexing and searching engine. We'll install it, then give it access to the MediaWiki MySQL-database . Finally, we'll install the sphinxsearch-mediawiki-extension to feed search queries from wiki users to Sphinx and results from Sphinx to your wiki. <br />
<br />
I realize this post is a bit extensive, but rest assured, it's worth it.<br />
<br />
<br />
<a name='more'></a><br /><br />
<h3>
SphinxSearch installation</h3>
Using FireFox, download your preferred version from <a href="http://sphinxsearch.com/downloads/">http://sphinxsearch.com/downloads/</a>. For myself, I've chosen the most recent beta. Pick the Ubuntu “.deb” package (12.04 LTS at time of writing, i386 for Intel, x86_64 for AMD processor).<br />
<div>
After clicking it, select not to just to download it but to let it open with <i>Ubuntu software center</i>. After the file is downloaded, the <i>Ubuntu software center</i> will analyze the file and give you the option to install it. Click the <i>install</i> button and let Ubuntu do the work.</div>
<div>
You might wonder if there isn't a <i>sudo apt-get install something</i> instead; after all, it’s been going great that way. Well, there is. But we're not using it this time because the <i>apt-get</i> version is terribly outdated and not being updated with a good frequency.<br />
<br />
Alright, so the install is done. Now, we'll need to provide a configuration file for Sphinx to work nicely with MediaWiki. A preconfigured one (for MediaWiki-use) is provided by the SphinxSearch extension (we'll get to that in the next section). There is also a configuration file provided by Sphinx itself - this is a general one which you can use as a starting point when you’re configuring Sphinx for other purposes. This configuration file is automatically loaded and will mess things up for us as we will have a preconfigured one in a different location. So first thing you need to do is delete this configuration file.<br />
<div>
<br /></div>
<div>
Open the terminal and type:</div>
<blockquote class="tr_bq">
gksu nautilus</blockquote>
<div>
which will start the GUI file manager with super-user permission. Use it to navigate to <i>File system</i>, <i>etc</i>, <i>sphinxsearch</i>. There you will find a file <i>sphinx.conf</i>. You need to delete this file, we'll be setting up a different configuration file in a minute.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<h3>
Configuration - MediaWiki extension</h3>
Using FireFox inside your virtual machine, download the extension from:<br />
<a href="http://www.mediawiki.org/wiki/Special:ExtensionDistributor/SphinxSearch">http://www.mediawiki.org/wiki/Special:ExtensionDistributor/SphinxSearch</a><br />
<br />
When the download is complete, open the terminal and enter the following commands:<br />
<blockquote class="tr_bq">
cd Downloads<br />
tar xvzf wikimedia-mediawiki-extensions-SphinxSearch*.tar.gz </blockquote>
Move the extracted file - check the output given during extraction for the exact name of the folder for your version (the underlined part may be different):<br />
<blockquote class="tr_bq">
sudo mv wikimedia-mediawiki-extensions-SphinxSearch<u>-f6f56dd</u> /etc/w/extensions/SphinxSearch</blockquote>
(note that this is one long line)<br />
<br />
<br />
Now to move the <i>sphinx.conf</i> file and prepare a folder structure for Sphinx. At the terminal which you still have open, type the following series of commands:<br />
<blockquote class="tr_bq">
cd ../../../etc/w/extensions/SphinxSearch<br />
sudo mkdir /usr/local/var/<br />
sudo mkdir /usr/local/var/data<br />
sudo mkdir /usr/local/var/data/sphinx<br />
sudo mkdir /usr/local/var/data/sphinx/wiki_main<br />
sudo mkdir /usr/local/var/data/sphinx/wiki_incremental<br />
sudo mkdir /usr/local/var/log<br />
sudo mkdir /usr/local/var/log/sphinx<br />
sudo mv sphinx.conf usr/local/var/data/sphinx<br />
cd ../../../../usr/local/var/data/sphinx</blockquote>
Update the default configuration using nano:<br />
<blockquote class="tr_bq">
nano sphinx.conf</blockquote>
Enter your database name (<i>mediawiki</i>), username (<i>mediawiki</i>) and password (<a href="http://lifeworkimprovement.blogspot.com/2013/05/cooltools-mediawiki.html">you've set this previously</a>). </div>
<div>
You also need to change all the paths to the folder structure we've created above. This means you need to</div>
<div>
<ul>
<li>replace all occurrences of the <i>/var/data/...</i> paths to <i>/usr/local/var/data/...</i> </li>
<li>replace all occurrences of <i>/var/log/...</i> to <i>/usr/local/var/log/...</i></li>
</ul>
Don't forget the paths always start with a forward slash (/). Forget the slash, and it won't work. When you're done, press CTRL+o, enter, and close with CTRL+x.<br />
<br />
<br />
<h3>
Indexer & Folder Access</h3>
</div>
<div>
The indexer is a process which will read the articles in your wiki (by means of the queries in the <i>sphinx.conf</i>-file), and create an index on this textual data. The index will allow very quick searching.<br />
A little in-between theory on indexers: indexing all your articles (when you have tens of thousands) will take some time. On the other hand, you want to include new articles to your index very quickly, because they can't be found as long as they haven't been indexed. To address this dual requirement, there are two indexes being used:<br />
<br />
<ul>
<li>The main index, which will index <i>all</i> your articles but will only run once a day.</li>
<li>The incremental index, which will only index the articles added/updated since the last run of the main index and so doesn't take much time to complete. We'll configure it to run every few minutes.</li>
</ul>
<br />
Enough theory. Let's run the indexer to check if it’s working (and at the same time create the initial index):</div>
<div>
<blockquote class="tr_bq">
cd ../../../../bin/<br />
sudo indexer --config /usr/local/var/data/sphinx/sphinx.conf --all</blockquote>
If it doesn't give you any errors, then you're good. Otherwise, read the error and try to fix whatever went wrong.<br />
<br />
<br />
We've let Sphinx read and write to <i>/usr/local/var/data/sphinx</i> and <i>/usr/local/var/log/sphinx</i>, but only our “sudo” lets Sphinx access those folders. When Sphinx is being queried by MediaWiki, it won’t have access. So we need to change this. At the terminal, type:<br />
<blockquote class="tr_bq">
gksu nautilus</blockquote>
This will start up the GUI file manager in <i>superuser</i> mode again. Use it to navigate to the above mentioned folders: first click <i>File System</i> in the left window of the file manager, then you'll find the <i>/usr</i> folder in the right window. Navigate further through <i>local</i>, <i>var </i>to find the <i>data</i> and <i>log</i> folders. </div>
<div>
Now right-click the <i>sphinx</i> folder (do this both in the <i>data</i> and <i>log</i> folder) and go to the permissions tab. Search for the user group <i>your username</i> (as set <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-ubuntu-operating-system.html">when installing Ubuntu</a>). Then set the access to let this user group create and delete files, and read and write in existing files. Don't forget to apply the permissions to enclosed files.</div>
<div>
<br />
<br />
<h3>
SearchDaemon & Cron</h3>
The SearchDaemon is a process that listens continuously on a certain port and accepts queries from other processes (in our case: the MediaWiki-SphinxSearch-extension). It then performs the search on the indexes prepared by the indexing process (which we executed once in the previous section).<br />
To make the search daemon start up automatically when your server starts up, you need to add it to the startup script (rc.local):<br />
<blockquote class="tr_bq">
cd ../../etc<br />
sudo nano rc.local</blockquote>
Before the line with “exit 0”, add:<br />
<br />
<blockquote class="tr_bq">
/usr/bin/searchd --config /usr/local/var/data/sphinx/sphinx.conf >> /usr/local/var/log/sphinx/sphinx-startup.log 2>&1</blockquote>
(one long line, space before and after the <i>>></i>)<br />
<br />
End with CTRL+o, enter, CTRL+x.<br />
<br />
Now, to set up an automated task for the indexers:<br />
<blockquote class="tr_bq">
crontab -e</blockquote>
Which will open your crontab in nano. Add the following below the comments:<br />
<blockquote class="tr_bq">
0 7 * * * /usr/bin/indexer --quiet --config /usr/local/var/data/sphinx/sphinx.conf wiki_main --rotate >/dev/null 2>&1; /usr/bin/indexer --quiet --config /usr/local/var/data/sphinx/sphinx.conf wiki_incremental --rotate >/dev/null 2>&1</blockquote>
(one long line)<br />
<br />
That will let the main and incremental index run at 7 AM every day. To let the incremental indexer run with a higher frequency during the day, add another line below the previous one:<br />
<blockquote class="tr_bq">
*/5 * * * * /usr/bin/indexer --quiet --config /usr/local/var/data/sphinx/sphinx.conf wiki_incremental --rotate >/dev/null 2>&1</blockquote>
(again, one long line)<br />
<br />
This will make the incremental indexer work every 5 minutes. You may want to lower the frequency if you’re having performance problems (e.g. */10 = every 10 minutes, */30 = every 30 minutes).<br />
<br />
Again CTRL+o, enter, CTRL+x.<br />
<br />
<br />
<h3>
MediaWiki extension</h3>
We need to make the Sphinx PHP API available to the extension. We do this by copying <i>sphinxapi.php</i> from <i>/usr/share/sphinxsearch/api</i> to <i>/etc/w/extensions/sphinxsearch</i>. Do this using the file manager.<br />
<br />
Then we need to tell our wiki to use Sphinx for searching. Using the file manager, go to <i>/etc/w</i> and open the <i>LocalSettings.php</i> file. At the bottom of the file, add<br />
<blockquote class="tr_bq">
$wgSearchType = 'SphinxMWSearch';<br />
require_once( "$IP/extensions/SphinxSearch/SphinxSearch.php" );<br />
$wgEnableMWSuggest = true;<br />
$wgEnableSphinxPrefixSearch = true;</blockquote>
Save and close.<br />
<br />
<br />
<h3>
Done!</h3>
Reboot the server to let the search-daemon start up (as configured in <i>rc.local</i>). After reboot, Sphinx will be serving your wiki-users their search results.<br />
<br />
In the following article, we'll be installing and configuring some other nice extra's - we're not done pimping your workplace yet! But what you have so far is good to go, so at this point you can start adding information in your wiki and letting your colleagues/employees know about it.<br />
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com2tag:blogger.com,1999:blog-4516693284909414863.post-35408975852801521432013-05-11T09:00:00.000+02:002015-01-17T13:04:22.231+01:00CoolTools - MediaWiki<div>
After the <a href="http://lifeworkimprovement.blogspot.be/2013/05/setting-up-web-server.html">installation of the free web server and other required software</a> on the free operating system <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-ubuntu-operating-system.html">Ubuntu, which we've set up in a Virtual Machine</a> run by the <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-virtual-machine.html">previously installed - and again, free - VirtualBox</a>, we're now ready to install our own wiki.</div>
<div>
<a href="http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://upload.wikimedia.org/wikipedia/mediawiki/b/bc/Wiki.png" /></a></div>
<div>
<br /></div>
<div>
The software we'll be using for that is MediaWiki:</div>
<blockquote class="tr_bq">
<span style="font-size: x-small;">MediaWiki is a free software open source wiki package written in PHP, originally for use on <a href="http://www.wikipedia.org/">Wikipedia</a>. It is now also used by several other projects of the non-profit Wikimedia Foundation and by many other wikis.</span></blockquote>
<br />
<a name='more'></a><br /><br />
<br />
<h3>
Get the software</h3>
<div>
Check the <a href="http://www.mediawiki.org/wiki/Download" target="_blank">MediaWiki website</a> for the current version. At the time of writing, that would be 1.20.5.</div>
<div>
We're going to install curl to download the package without opening Firefox. Just to be nerdy. At the terminal, which you open via Dash (the button on the upper left corner of your screen), type:</div>
<blockquote class="tr_bq">
sudo apt-get install curl</blockquote>
Now download the selected version of mediawiki:<br />
<blockquote class="tr_bq">
curl -O http://dumps.wikimedia.org/mediawiki/1.20/mediawiki-1.20.5.tar.gz</blockquote>
Extract this file. There is an archive manager with a GUI available, but... :<br />
<blockquote class="tr_bq">
tar xvzf mediawiki-*.tar.gz</blockquote>
Move it to /etc/w:<br />
<blockquote class="tr_bq">
sudo mv mediawiki-1.20.5 /etc/w</blockquote>
Now link this directory to /var/www (= the directory which will be public to your intranet):<br />
<blockquote class="tr_bq">
sudo ln -s /etc/w /var/www</blockquote>
<br />
And for good measure, restart Apache:<br />
<blockquote class="tr_bq">
sudo service apache2 restart</blockquote>
<br />
<br />
<h3>
Set up the database</h3>
<div>
Using FireFox (third button on the column on the left of your screen), navigate to <i>localhost/phpmyadmin</i>. Log in with your root user account <a href="http://lifeworkimprovement.blogspot.be/2013/05/setting-up-web-server.html">as set during MySQL installation</a>, click <i>Privileges</i> and <i>Add a new user</i>:<br />
<ul>
<li>User name: mediawiki</li>
<li>Host: localhost</li>
<li>Password: pick something or let it generate a password. You need to keep it handy for the installation of MediaWiki in the next section.</li>
</ul>
<br />
Under <i>Database for user</i>, tick <i>Create database with same name and grant all privileges</i>.<br />
<br />
<br />
<h3>
Installation</h3>
Using FireFox, go to <i>localhost/w/index.php</i><br />
MediaWiki will automatically start the setup process.<br />
<ol>
<li>Enter the credentials for the MySQL user and database for MediaWiki (which you just configured in PHPMyAdmin). There is no need for a table prefix as we created a dedicated database specifically for this wiki.</li>
<li>Pick credentials for the MediaWiki admin and make sure to remember them.</li>
<li>The user rights profile is well explained on the setup page itself. Pick whichever is right for you.</li>
<li>You might want to enable email (user-to-user, talk page notification, watchlist notification, e-mail authentication). You might want to set the return e-mail address to your email address.</li>
<li>When asked, enable the following extensions:<br />The <u>ParserFunctions</u> extension enhances the wikitext parser with helpful functions, mostly related to logic and string-handling. <br />The <u>Renameuser</u> extension provides a special page which allows authorized users to rename user accounts. This will cause page histories, etc. to be updated.<br />The <u>Vector</u> extension adds a few enhancements to the Vector skin. Note that these features are only available in Vector, not in other skins.<br /><u>WikiEditor</u> is an extendable framework with a set of feature-based modules that improve the user experience of editing. It is also the editing interface that Wikipedia currently uses.</li>
<li>You might want to enable file uploads, so your users can upload images, pdf, documents, etc.</li>
<li> Caching is not required unless you’re having performance problems - you shouldn’t have performance problems with the limited audience of an intranet wiki, even if you’re not working for a tiny company.</li>
</ol>
<br />
<br />
After installation is complete, MediaWiki will give you a settings file to download. After downloading, open the file manager (second button in the column on the left of your screen), go to the <i>Downloads</i> folder, right-click the <i>LocalSettings.php</i>-file, <i>Cut</i>. Go to <i>File System</i>, <i>etc</i>, <i>w</i>. Right-click in the folder and <i>Paste</i>. Overwrite the existing file. </div>
<div>
Also, delete the mw-config folder.</div>
<div>
<br />
Congratulations, you’ve got your basic wiki up and running! In the last page of the configuration (in FireFox), there's a link you can click to go to your actual wiki and see it live for the first time.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<h3>
Network</h3>
<div>
So now your wiki is up, but you can only access it from within your Virtual Machine. What you want is a wiki you can use from your regular operating system, and from everywhere in the network. To do that, we need to go to the Virtual Machine settings.</div>
<div>
In the VirtualBox menu, pick <i>Machine</i> and then <i>Settings</i>. Under <i>Network</i>, you will find the virtual machine is coupled through NAT (Network Address Translation). You need to do a port forwarding (or port mapping). Click the appropriate button.</div>
<div>
In the popup, click the little button in the top right corner to add a port forward. It will appear as a new line in the popup: <i>Rule 1</i>. Change both the <i>Host port</i> and <i>Guest port</i> to 80, the regular http-traffic port. Click OK to confirm.</div>
<div>
<br /></div>
<div>
Now try navigating to <i>localhost/w</i> with the browser on your regular operating system (not inside the virtual machine), and you will see you also get to the wiki!</div>
<div>
<br /></div>
<div>
To access the wiki from a different machine in the network, you need to know the IP address of the machine that is running the Virtual Machine. If the operating system you're using is Windows, you can do this by:</div>
<div>
<ol>
<li>Click Start.</li>
<li>Type <i>cmd</i> + enter to open the command line.</li>
<li>Type <i>ipconfig</i></li>
</ol>
</div>
<div>
Depending on your configuration, you might get a number of entries. Typically there will only be 2 with an IP (IPv4) address assigned: </div>
<div>
<ul>
<li>your (<i>Ethernet adapter</i>) <i>Local Area Connection</i> or (<i>Wireless LAN adapter</i>) <i>Wireless Network Connection</i> with your actual network IP, </li>
<li>and the (<i>Ethernet adapter</i>) <i>VirtualBox Host-Only Network</i> which was added by the installation of VirtualBox.</li>
</ul>
It's the first IP address that we need. For an intranet, it is typically of the form 192.168.x.y or 10.0.x.y. Use this number as the website URL; a machine in your network can then get to the wiki by entering the URL</div>
<blockquote class="tr_bq">
192.168.x.y/w or 10.0.x.y/w</blockquote>
in the address bar of a browser.<br />
(You can close the command line window now ;-) )<br />
<br />
<br />
<h3>
Are we done?</h3>
</div>
<div>
No, we are not done. Although you do have a basic wiki up and running, there are a number of additional settings and extensions a decent wiki just can't do without. So don't start advertising your wiki to your colleagues or employees just yet...</div>
<div>
In the <a href="http://lifeworkimprovement.blogspot.com/2013/05/cooltools-sphinxsearch.html">next installment of the series of CoolTool articles, we'll set you up with Sphinx</a> as your search engine back-end. This is a must-have: a wiki without a powerful search engine is not much use. And trust me, Sphinx is a powerful search engine. Ever heard of Craigslist? That's right. It's running Sphinx.</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com4tag:blogger.com,1999:blog-4516693284909414863.post-56898304733610245782013-05-05T23:37:00.001+02:002015-01-17T13:04:42.134+01:00CoolTools - Setting up the web serverIn the previous articles, we've <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-virtual-machine.html">installed our virtual machine player</a> and <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-ubuntu-operating-system.html">set up a virtual machine with Ubuntu</a>.<br />
Now it's time to make our machine a real web server. The actual “web server” software is Apache HTTP server, but we’ll also be needing PHP for dynamic websites like the wiki, MySQL as the database of choice, and PHPMyAdmin as a GUI on MySQL. These are typical tools for web servers.<br />
<br />
<br />
Start up your virtual machine, and start up a terminal window. You can do this via Dash, the uppermost button in the shortcut bar on the left of the screen of your virtual machine. In the search box, enter “terminal”. This will open a console within the GUI, like cmd would on a Windows machine. We’ll be using this terminal a lot. <br />
<br />
<a name='more'></a><br /><br />
<h3>
Apache</h3>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.apache.org/images/feather-small.gif" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="Logo of the Apache Software Foundation" border="0" src="http://www.apache.org/images/feather-small.gif" height="60" title="" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Apache Software Foundation</td></tr>
</tbody></table>
<div>
The most used web server software is the Apache HTTP server. It's powerful, robust, and completely free. </div>
To install, type this into the terminal:<br />
<blockquote class="tr_bq">
sudo apt-get install apache2</blockquote>
It will ask you for your password (you set this up when installing Ubuntu). Then it will ask you to confirm the installation. Enter Y to confirm. That's it! You've just made your machine a web server.<br />
<br />
The entering Y to confirm installation is a rather standard thing. I won't be repeating it for all the following installs, I'm sure you'll remember.<br />
<br />
<br />
<h3>
MySQL</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.mysql.com/common/logos/logo-mysql-110x57.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img alt="Logo of MySQL" border="0" src="http://www.mysql.com/common/logos/logo-mysql-110x57.png" title="" /></a></div>
<div>
MySQL is a free and open source database from Oracle. It is often used for storing data for dynamic websites such as a wiki, forum (phpBB), bugtracker, etc</div>
<div>
<br /></div>
In the terminal, type:<br />
<blockquote class="tr_bq">
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql</blockquote>
During install, it will ask you for a password for the “root” user for MySQL. Enter one and remember it, you'll be needing this later.<br />
<br />
Now, to activate mysql, type:<br />
<blockquote class="tr_bq">
sudo mysql_install_db</blockquote>
And do the security setup by typing:<br />
<blockquote class="tr_bq">
sudo /usr/bin/mysql_secure_installation</blockquote>
<div>
You’ll have to give the MySQL root password again. No need to change it, we’ve already changed from default. To make the thing secure, you will want to remove the anonymous users, disallow root login remotely, and remove the test database. Let it reload the privilege tables to complete the security setup.</div>
<div>
<br /></div>
<div>
<br /></div>
<h3>
PHP</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://be.php.net/images/php.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="PHP logo" border="0" src="http://be.php.net/images/php.gif" title="" /></a></div>
<div>
PHP is a programming language. It's fast and easy, and is widely used to create websites which require programming logic, such as (ao) Wikipedia. Since we'll be using the same software to create our own wiki, we have need of PHP.</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
In the terminal, type:</div>
<blockquote class="tr_bq">
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt</blockquote>
And voilà, you've installed PHP. Admit it, you're beginning to love how fast this is going. If you wouldn't have taken the time to read all the text in between commands, you could have done all this installing work in 30 seconds flat :-)<br />
Don't stop reading the text in between commands though. You'd be done with the article too fast. Bad for my ratings.<br />
<br />
Anyway, you may have installed PHP, but Apache doesn't know this yet. We need to let Apache know that a file like <i>index.php</i> is now also a valid index file to show to your website users. To do this, we need to change an Apache configuration file. In the terminal, type:<br />
<blockquote class="tr_bq">
sudo nano /etc/apache2/mods-enabled/dir.conf</blockquote>
You need to add <i>index.php</i> as shown here:<b id="docs-internal-guid-244d26f7-7690-f7df-0fc7-1985b1b67c3a"><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span></b><br />
<div dir="ltr" style="font-weight: normal;">
<table style="border-collapse: collapse; border: none; width: 650px;"><colgroup><col width="*"></col></colgroup><tbody>
<tr style="height: 0px;"><td style="border: 1px solid rgb(0, 0, 0); padding: 7px; vertical-align: top;"><div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><IfModule mod_dir.c></span></div>
<br />
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> DirectoryIndex </span><span style="font-family: Arial; font-size: 15px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">index.php</span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"> index.html index.cgi index.pl index.php index.xhtml index.htm</span></div>
<br />
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br />
<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></IfModule></span></div>
</td></tr>
</tbody></table>
</div>
<b id="docs-internal-guid-244d26f7-7690-f7df-0fc7-1985b1b67c3a"><br /><span style="vertical-align: baseline;"></span></b>After you've done that, press CTRL+o to save the file (and ENTER to confirm the filename), CTRL+x to exit the editor. As always after changing Apache settings, you need to restart Apache for the changes to take effect. In the terminal, type:<br />
<blockquote class="tr_bq">
sudo service apache2 restart</blockquote>
<span id="docs-internal-guid-244d26f7-7690-f7df-0fc7-1985b1b67c3a"></span><br />
<div style="font-weight: normal;">
<span id="docs-internal-guid-244d26f7-7690-f7df-0fc7-1985b1b67c3a"><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><br /></span></span></div>
<span id="docs-internal-guid-244d26f7-7690-f7df-0fc7-1985b1b67c3a">
</span>
<br />
<h3>
PHPMyAdmin</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://blog.mrwebmaster.it/files/2013/01/PhpMyAdmin.gif" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img alt="phpMyAdmin logo" border="0" src="http://blog.mrwebmaster.it/files/2013/01/PhpMyAdmin.gif" height="137" title="" width="200" /></a></div>
<span style="font-weight: normal;">Actually, you're done installing the basic web server software. PHPMyAdmin is a website which will already be making use of it! But I still count is as a basic requirement, because we'll be needing it to administer our MySQL database. You can do everything we need to do just from command-line, but hey, if people build you a nice GUI, you're not going to say no.</span><br />
<br />
Install PHPMyAdmin by typing:<br />
<blockquote class="tr_bq">
sudo apt-get install phpmyadmin</blockquote>
When asked, select Apache as web server. When asked, select Yes.<br />
It will ask for the MySQL root password. Then PHPMyAdmin will ask for a password for itself (its own user). Leave this blank to let it generate its own password, we don’t need to know this per se.<br />
<br />
Now some more magic. Enter:<br />
<blockquote class="tr_bq">
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf<br />
sudo /etc/init.d/apache2 reload</blockquote>
When it’s done, open FireFox (there's a button on the bar on the left) and go to <br />
<blockquote class="tr_bq">
localhost/phpmyadmin</blockquote>
You can login with the (root) MySQL username and password and have a first look. This is your first installed website, and it works. Well done.<br />
<br />
<br />
<h3>
Next</h3>
<div>
In the <a href="http://lifeworkimprovement.blogspot.com/2013/05/cooltools-mediawiki.html">next article, we'll be installing the MediaWiki software</a> which will empower your own wiki. It's the same software that is used for Wikipedia. How cool is that!</div>
<br />Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-25584365849376084602013-05-05T22:36:00.001+02:002015-01-17T13:04:49.493+01:00CoolTools - Ubuntu Operating SystemOpen source tools and websites tend to get better support on free operating systems. For this series, I've chosen to go with Ubuntu. No particular reason.<br />
<div>
<a href="http://assets.ubuntu.com/sites/ubuntu/latest/u/img/desktop/desktop-accessible.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://assets.ubuntu.com/sites/ubuntu/latest/u/img/desktop/desktop-accessible.jpg" height="121" width="200" /></a>There are specific editions of Ubuntu for desktop, server, mobile, tablet, TV... You'd think I'd go for the server edition, but I won't. I'm not enough of a guru to do without some GUI backup :-)</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
Head over to the <a href="http://www.ubuntu.com/download/desktop" target="_blank">Ubuntu website</a> and download the Desktop version. I've gone with 12.04 because that is an LTS, or Long-Time-Support release. Remember where you stored it, we'll need it in a minute.</div>
<div>
<br />
<br />
<a name='more'></a><br /><br />
<h2>
Preparing your Virtual Machine</h2>
</div>
<div>
Start up VirtualBox, which we installed in the <a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-virtual-machine.html">previous article</a>. Create a new Virtual Machine<i> </i>(I've called mine <i>UbuntuServer</i>). Set the type to <i>Linux</i> and the version to <i>Ubuntu</i>. </div>
In the following screens, I’ve chosen 1024 MB ram, and a new virtual hard drive with standard settings (8GB HD dynamic). <br />
Some more settings to change: <br />
<ul>
<li>video memory -> 128 MB</li>
<li>3D-acceleration & 2D video-acceleration (for what it’s worth - I'm not sure this does much)</li>
</ul>
<div>
<br /></div>
<h2>
Install Ubuntu</h2>
<div>
In VirtualBox, select your <i>UbuntuServer</i> and press start. It will ask for a start-up disk. Navigate to the location where you downloaded the Ubuntu image and select it. Then let it start.</div>
After first start-up, Ubuntu will ask you to “Try Ubuntu” or “Install Ubuntu”. Install it. Check to allow downloading updates while installing. Let it Erase disk and install Ubuntu: it’s an empty virtual disk created specifically for this server, so no danger here.<br />
<br />
During install, it will ask for some other settings. These should be rather obvious. I’ve also let it “Log in automatically”. Not sure if this is needed but I would rather not have to walk to the machine if there was an unexpected reset.<br />
After install, let it reboot as it asks. If it blocks on asking you to <i>press enter and close tray</i> (I sure can’t press ENTER), just reset the machine (using the VirtualBox menu: Machine -> Reset).<br />
<br />
<br />
After restart, you may get a warning: “The system is running in low-graphics mode”.<br />
We get around that by pressing:<br />
<blockquote class="tr_bq">
ctrl+alt+F1 </blockquote>
Which will allow you to switch to console. Just once, I promise, the rest is GUI. Ok, terminal, but still, from GUI ;-)<br />
In console, enter your username (you picked it during install) and your password. Then you type:<br />
<blockquote class="tr_bq">
sudo apt-get update</blockquote>
It will ask you for password again. Then type:<br />
<blockquote class="tr_bq">
sudo apt-get upgrade</blockquote>
When it asks, confirm with Y. When it’s done, we reboot the machine, after which the screen should be OK:<br />
<blockquote class="tr_bq">
sudo reboot</blockquote>
<div>
After reboot, you're done installing Ubuntu!</div>
<div>
<br /></div>
<h3>
</h3>
<h3>
Mouse integration</h3>
An overall tip at this point: in the VirtualBox menu, do Machine -> disable mouse integration. This will capture the mouse fully when you’re using it within the Virtual Machine, with two results:<br />
<ul>
<li>You won’t be able to move your mouse outside the Virtual Machine window. To release the mouse, tap your right CTRL key. </li>
<li>Your mouse will be fully functional when inside the Virtual Machine window, including scrolling. Otherwise, no scrolling. You’ll want to be able to scroll. I sure do.</li>
</ul>
<div>
<br /></div>
<div>
<br /></div>
<div>
In the <a href="http://lifeworkimprovement.blogspot.be/2013/05/setting-up-web-server.html">next article, we'll install our webserver</a> and some other necessary software.</div>
<div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com1tag:blogger.com,1999:blog-4516693284909414863.post-8388904050661580122013-05-04T14:58:00.000+02:002013-05-05T22:59:16.933+02:00CoolTools - Virtual MachineWhen you're experimenting with new software, you don't want to endanger your existing set-up. The ideal way to go is using a Virtual Machine: you create a virtual computer inside of your existing computer and install everything there.<br />
The advantages are many:<br />
<br />
<ul>
<li>Only 1 thing to install on your existing set-up: the Virtual Machine player.</li>
<li>If you mess something up: just throw away your Virutal Machine and start again.</li>
<li>If you end up with a smoothly running Virtual Machine, and you want to experiment some more without endangering what you've already done, you can easily clone your existing VM and experiment on the clone. If you're happy with it, start using the clone. If not, stick to the original.</li>
<li>If you work in a big company, you'll probably be trying this out in your team/department. If you & your management get convinced of the added value, you can turn over the Virtual Machine to your IT-guys: there's a good chance your company is already using virtualized servers, which means they can most likely just drop the VM in their cloud and be up and running in 5 minutes. </li>
<li>You can use a different operating system than the one your computer is equipped with. I.e. if you have an MS Windows computer, you can install the Ubuntu operating system in the Virtual Machine <i>inside</i> of MS Windows. Why not use Windows? To use the built-in features of Windows as a web server, you'd need extra licences as soon as the number of connections gets to be too high (or just buy their server software: Windows Server). We want this to be free. Also: the software we'll be using tends to get better support on non-Windows operating systems. </li>
</ul>
There's actually only one disadvantage I can think of, and that is that your computer needs to run 2 operating systems instead of one, which means a lower performance. However, this disadvantage is a rather theoretical one: you don't need much power for running the tools I'll be describing, and as long as your public is limited to no more than a few hundred users, you'll be fine. And if you find you're serving more than a few hundred users (at which time you can definitely call your experiment a success!), you can throw the VM in a cloud to give it more power.<br />
<br />
To work!<br />
<br />
<h2>
Installing the VM-player</h2>
<div>
The Virtual Machine player of choice is called VirtualBox. It's an Oracle product (the company known for their Oracle database). Although Oracle is a commercial enterprise, VirtualBox is free. In a following article, we'll be installing MySQL, a free database system also available from these guys.</div>
<div>
<br /></div>
<div>
Ok, to get started. Head over to <a href="http://www.virtualbox.org/" target="_blank">http://www.virtualbox.org</a> and download the appropriate software from their <i>Downloads</i> page. You only need the VirtualBox platform package, the extension pack is not free for commercial use. If you have a Windows computer, download the one described as <i>VirtualBox ... for Windows hosts</i>.</div>
<div>
Once downloaded, install it. The installer makes this a pretty straight-forward process, you shouldn't have any issues here.</div>
<div>
<br /></div>
<h2>
Next</h2>
<div>
Now that we've got the VM player in place, it's time to install ourselves an operating system. I've chosen Ubuntu, and will describe the installation <a href="http://lifeworkimprovement.blogspot.com/2013/05/cooltools-ubuntu-operating-system.html">in the following article</a>.</div>
Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0tag:blogger.com,1999:blog-4516693284909414863.post-1053899463054818922013-05-04T14:24:00.000+02:002013-05-05T18:44:47.234+02:00CoolTools seriesIn this series of articles, I will provide a walk-through on how to enrich your work environment with some shiny 21st century software. Whether you're a small or even a bigger enterprise, stuff like this will enable your employees/coworkers to perform better, smarter, more efficiently.<br />
<br />
And, because CoolTools is aimed at companies, all the software mentioned is free for commercial use. That's right: it literally won't cost you a penny in licenses. All you need is a computer plugged into your network: an old spare one if you have it, or if you don't have one to spare, a computer in use will work as well (provided it's not too old).<br />
Apprehensive? Not wanting to mess up settings and doing a lot of installation work on one of your existing, working computers? No worries. We'll install everything we need inside of a virtual machine, so there's only one thing you need to install on your existing computer: the virtual machine player. Everything else is inside of the virtual machine, and if something gets messed up, you just delete it and start over. Hassle free!<br />
<br />
Ready to get started? Check the rest of the series!<br />
<br />
<a href="http://lifeworkimprovement.blogspot.be/2013/05/cooltools-virtual-machine.html">Getting started with the Virtual Machine --></a>Anonymoushttp://www.blogger.com/profile/17171233649471806268noreply@blogger.com0