Spellcheck Hack for Wiki Pages

Using ASpell and Spellerpages


Adding spell checking to your wiki pages isn't very difficult, here's how I did it:


Steps




	this.popUpUrl = '/speller/spellchecker.html';
	this.spellCheckScript = '/speller/server-scripts/spellchecker.php';


...to...

	this.popUpUrl = [YOUR HARD-CODED PATH TO SPELLCHECKER.HTML]";
	// 	For Example:  this.popUpUrl = "http://www.notadomain.net/wiki/3rdparty/plugins/speller/spellchecker.html";

	this.spellCheckScript = './server-scripts/spellchecker.php';	// note the '.'


and:

		if( evalText ) {
			this.controlWin.evaluatedText.value = evalText;
			ww.setFocus( this.currentTextIndex, this.currentWordIndex );
			this._getSuggestions( this.currentTextIndex, this.currentWordIndex );
		}


...becomes...

	if( evalText ) {
		// changes to prevent WikiWords from being checked:
		if (evalText.match(/[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*/) == null)
		{
			this.controlWin.evaluatedText.value = evalText;
			ww.setFocus( this.currentTextIndex, this.currentWordIndex );
			this._getSuggestions( this.currentTextIndex, this.currentWordIndex );
		}
		else
		{
			this.currentWordIndex++;
			this._spellcheck();
		}
	}		


Depending on the editor and character set you're using, a cut-and-paste on the code above may not work due to the extended character set. If you cannot get the spellchecker to display, check to see if the evalText.match(...) line copied correctly. If you do not anticipate the need for extended characters in your wiki names, you can replace this line:

if (evalText.match(/[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*/) == null)


with

if (evalText.match(/[A-Z]+[a-z]+[A-Z0-9][A-Za-z0-9]*/) == null)

 




$spellercss = '/speller/spellerStyle.css';
$word_win_src = '/speller/wordWindow.js';
$textinputs = $_POST['textinputs']; # array
$aspell_prog = 'aspell';

...becomes...
$wiki_path = "/wiki/3rdparty/plugins";
$spellercss = $wiki_path.'/speller/spellerStyle.css';
$word_win_src = $wiki_path.'/speller/wordWindow.js';
$textinputs = $_POST['textinputs']; # array
$aspell_prog = 'aspell';   // fine for *nix systems?
# $aspell_prog = '"[PATCH TO ASPELL EXECUTABLE]"';   // required for Windows, replaces previous line




this.addButton(" ");
this.addButton("spell","Check Spelling","","document.getElementById('" + this.id + "')._owner.spellcheck");


...and this at the end of the file, after the closing brace: (line 645 or so):

WikiEdit.prototype.spellcheck = function ()
{
	var speller = new spellChecker();
	speller.checkTextAreas(); 
}



line 142:
	'<script language="JavaScript" src="3rdparty/plugins/speller/spellChecker.js"></script>'."\n".


PHP4 does not support return values from exec(); invocation of the spellchecker will fail on these systems. You must modify 3rdparty/plugins/speller/server-scripts/spellchecker.php. Locate this code at about line 92 in the file:

	# exec aspell command - redirect STDERR to STDOUT
	$cmd = "$aspell_prog $aspell_opts < $tempfile 2>&1";
	if($aspellret = exec($cmd)) {
		$linesout = explode( "\n", $aspellret );
		$index = 0;


and replace with

		# exec aspell command - redirect STDERR to STDOUT
		$cmd = "$aspell_prog $aspell_opts < $tempfile 2>&1";
		exec($cmd, $linesout, $ret);
		if(!$ret) {
		//if($aspellret = exec($cmd)) {
			// $linesout = explode( "\n", $aspellret );
			$index = 0;

 


You need to provide your own "spell" icon to put in 3rdparty/plugins/wikiedit/images -- I used someone's copy of a standard MS application spellcheck action. For testing, you can use any of the included icons, for instance "createtable".

There's probably a way to clean up the wiki paths to use the Wikka config variables, but for me the hard coded paths worked fine.


CategoryUserContributions
There are 3 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki