====Wikka Spellchecker====
This is code derived from a class released at [[http://www.phpclasses.org/browse/package/1992.html | Php Classes]] as a generic PHP Spell Checker and is released under GPL for non-commercial uses. ''(Version 1.1 with improved punctuation & wikicode removal)''
I don't doubt it is less "efficient" than those using packages that are "built into" the server, but it has the advantage that to set it up you don't need server root access, or the permission of your server provider. I'll also apologize that it is so "english" based, but the beauty of using this text-based file system is that non-English words can be added or other dictionaries used instead.
If anyone wants to improve this spellchecker, I think it needs a "regular expression" thing (or something) added somewhere that....
- removes anything ""{{""//in//""}}"" these brackets
- removes wiki pagenames
Other slight oddities also crop up (like two words being run together despite the space between them).
I modified the ##handlers/page/edit.php## file by adding this code close to the bottom of the file...
%%(php)
print($output);
// Spellcheck added by GMB
if ($_POST["submit"] == "Spellcheck")
{
include("spellchecker/dictionary_class.php"); // this is the main class and must be included to the main body.
$dr=new dataReader(); // creating a new instance of the class dataReader.
// this class gets the input text and uses the class LookupTable to find misspelt words.
$wrd="";
$j=0;
$i=0;
// instantiate new instance (from jsearchstring from phpclasses.org) to remove punctuation & wikiwords
$jSS=new jSearchString();
//output formatted string
$str = $jSS->parseString($body);
$str= strtolower($str);
$dr->reader($str);
}
// end of Spellcheck code}
else
{
%%
The ##handlers/page/edit.php## file was further altered by adding code for a "Spellcheck" button.....
%%(php)
//finish
// ORIGINAL LINE " href("")."';\" />\n".
// Line below this has added spellcheck button (GMB)
" href("")."';\" />\n".
$this->FormClose();
%%
The ##dictionary_class.php## file (provided at phpclasses) was modified to the following (and placed in the directory "spellchecker" in the wiki root).
%%(php)
MAX; $i++)
for($j=0; $j<$this->MAXLen; $j++)
$this->lookupTable[$i][$j]=NULL;
}
function readToTable()
{
$this->initializeArray();
$buffer=""; $n=0;
$hash=new hashing();
$index=0;
$buffer="";
$count=0; $i=0;
$fp = fopen ("spellchecker/dictionary.txt", "r");
do
{
$buffer=fgets($fp, $this->MaxWordLength);
$buffer=trim($buffer);
$index=$hash->hashFunction($buffer, $this->MAX);
//---->read process
while($this->lookupTable[$index][$i]!=NULL)
$i++;
$this->lookupTable[$index][$i]=$buffer;
$i=0;
//<--- read process
}
while($buffer);
fclose($fp);
}
function isIn($str)
{
$h=new hashing();
$i=0;
$str=trim($str);
$temp="";
$index=$h->hashFunction($str, $this->MAX);
do
{
$temp=$this->lookupTable[$index][$i++];
if($temp==$str)
return(true);
}
while($temp!=NULL);
return(false);
}
function suggestion($str)
{
$count=0;
$index=-1;
$current=97;
$strC=$str;
for($i=0; $i