Revision [4023]

This is an old revision of AutoReplace made by ChristianBarthelemy on 2005-01-05 20:49:09.


Last edited by ChristianBarthelemy:
Wed, 05 Jan 2005 20:49 UTC

Automatic Replace of strings

I like the simplicity of the automatic link creation when I type a new WikiWord. But I hate having to think about it all the time and as I naturally write "the wiki word" I would like the system to understand that for me. This is particularly enerving when typing people names: typing JohnDoe is not natural and it is also a pain for the eyes of a WikiStranger.

Those having a palm certainly like the capability to code small sequences so that they are transformed into long words as soon as typed. The same kind of thing exists in most of the word processors as well.

A solution

I picked the ExpandedWikiWords idea from Teamflux which is a commercial Wiki based on zwiki. The idea was already there.
The solution consists in adding a space before any capital letter within a word (not including the first one) when this word isn't enclosed in brackets (we may want to add similar restrictions to double quote).
This solution is easier to implement, there is nothing to be done from the WikiEditor. The decision whether to use it or not should be taken by the user so it should be a new item in the UserSettings. The anonymous users shoud be have it by default and this decision could be part of the ConfigurationOptions.

The code

1) adding field to user table:

ALTER TABLE `wikka_users` ADD `space_camelcase` ENUM( 'Y', 'N' ) DEFAULT 'N' NOT NULL;

2) adding a table row to show the status of the variable (to actions/usersettings.php):

<td align="right">Show comments by default:</td>
<td><input type="hidden" name="show_comments" value="N"><input type="checkbox" name="show_comments" value="Y" <?php echo $user["show_comments"]
"Y" ? "checked=\"checked\ : ?> /></td>
<td align="right">RecentChanges display limit:</td>
<td><input name="changescount" value="<?php echo htmlspecialchars($user["changescount"]) ?>" size="40" /></td>

<td align="right">Insert spaces in between WikiWords:</td>
<td><input type="hidden" name="space_camelcase" value="N"><input type="checkbox" name="space_camelcase" value="Y" <?php echo $user["space_camelcase"] Having a database used when saving (or editing?) the WikiPage to replace an Input Entry by the Output Entry to which it is linked.
This database would be fed by an appropriate action used in the code of the WikiPages: {{equivalent words="auto replace*automatic replace" separator ="*" casematters="no" dissociated="no"}}.
Such an action placed on this very WikiPage would then transform any string "auto replace" into [[AutoReplace auto replace]].
  • This action would allow several strings to be entered in the parameter "word" separated by the content of the optional parameter "separator".
  • This parameter "separator" must be present if there is more than one string to be replaced. It can be one single character or a chain.
  • The optional parameter "casematters" defaulted to "yes" tells to the system whether the case matters or not; in the example above "aUto REPLace" would be transformed as well.
  • The last optional parameter defaulted to "yes" tells to the system if the string to be replaced must be or not dissociated from other words; if dissociated="no" then "xxauto replacementsxx" would be transformed. In the other case, only the exact string in between spaces, commas, points, question marks... would be transformed.

Moreover the confort provided by such a functionality, it allows more consistency in the WikiPages by reformating the content to ensure that the WikiLinks are generated even when the author forgott the NoSpaceInBetweenRule.

There are 3 comments on this page. [Show comments]