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
Comments
Comment by BrianKoontz
2006-01-23 03:14:39
SpectreMoo--

Trying to get this to work...in the spellchecker.php hacks, can you verify the following lines are correct?

$spellercss = $wiki_path.'/speller/spellerStyle.css';
$word_win_src = spellercss = $wiki_path.'/speller/wordWindow.js';
$word_win_src = $wiki_path.'/speller/wordWindow.js';

I'm getting the spellcheck window to pop up, but aspell is failing (doesn't look like it's getting any input).

This will be a cool hack if I can get it to work!
Comment by BrianKoontz
2006-01-29 02:54:48
This is a very elegant hack! There appears to be a typo in the spellchecker.php codeblock. This:

$spellercss = $wiki_path.'/speller/spellerStyle.css';
$word_win_src = spellercss = $wiki_path.'/speller/wordWindow.js';
$word_win_src = $wiki_path.'/speller/wordWindow.js';

Should actually be this:

$spellercss = $wiki_path.'/speller/spellerStyle.css';
$word_win_src = $wiki_path.'/speller/wordWindow.js';

Also, I'm using PHP v 4.3.8, and the exec() functionality doesn't support the syntax used in spellchecker.php (exec() does not appear to return the results of the command). I had to make the following changes at about line 91:

# exec aspell command - redirect STDERR to STDOUT
$cmd = "$aspell_prog $aspell_opts < $tempfile 2>&1";
// Changes start here...
exec($cmd, $linesout, $ret);
if(!$ret) {
// ...changes end here
$index = 0;
$text_input_index = -1;
# parse each line of aspell return

Some final notes:

I had a hell of a time getting all of this to work in the chroot jail under which Apache/PHP and friends run in OpenBSD, several hours' worth of work, actually. If anyone is interested how I got it to work, leave a comment and I'll throw together a quick how-to if time permits.

If you'd like to see this hack in action, you can visit the sandbox here and try it out: http://durango.dcccd.edu/wiki/wikka.php?wakka=SandBox

Nice work, SpectreMoo!
Comment by SpectreMoo
2006-05-03 20:42:34
Good to hear you found this useful!

I've cleaned up the typo in the code above, thanks for catching that.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki