[pmwiki-users] How good (and usefull) is AI at writing basic (or not so basic) PmWiki code ?
Petko Yotov
5ko at 5ko.fr
Tue May 13 08:11:14 PDT 2025
On 13/05/2025 14:56, ABClf wrote:
> Markup('ExtractLine', 'directives',
> '/\\(:ExtractLine\\s+(\\S+)\\s+([\'"])(.+?)\\2\\s*:\\)/',
> 'ExtractLineMarkup');
>
> function ExtractLineMarkup($m) {
> $targetPage = $m[1];
> $pattern = $m[3]; // Motif brut sans délimiteurs
> return ExtractAllMatchingLines($targetPage, $pattern);
> }
>
> function ExtractAllMatchingLines($pagename, $pattern) {
> $page = ReadPage($pagename, READPAGE_CURRENT);
> if (!$page) return "Page non trouvée";
>
> $text = $page['text'];
> $lines = explode("\n", $text);
> $matches = [];
>
> foreach ($lines as $line) {
> if (@preg_match("/$pattern/", $line)) {
> $matches[] = Keep($line); // Empêche le parsing wiki
> }
> }
>
> if (count($matches) > 0) {
> return implode("<br />\n", $matches);
> } else {
> return "Aucune ligne ne correspond au motif.";
> }
> }
>
> Might be easy for smart people, but I'm still so admirative. For the
> result I get so quickly, and for the easy way to get it, fluently, in
> 3, 4 "conversational" steps. That's not something I would have
> expected 1 year ago. One more second and I believe you get the
> extracted line cleaned up from PmWiki markup if you need it.
>
> My question is two open questions :
>
> 1. is the Ai generated code well done ? Ok, it works, but is it well
> written ? secure enough ? doesn't it forget something important ?
> efficient enough for speed ? (I believe it is, because here it is
> something very basic).
This is indeed impressive. The only major problem I see is that it
doesn't check for permissions on the page, it should use
RetrieveAuthPage($pagename, 'read', false, READPAGE_CURRENT);
instead of ReadPage().
Currently if different people have different permissions, someone typing
in a sandbox and pressing Preview could retrieve all text from SiteAdmin
like emails of the other users in Notify, possibly sensible AuthUser
information, or any text from any other protected page. And you'll never
know.
Less dangerous but may be annoying, you need to type the full Group.Page
in the markup, not relative names like Page (in the same group).
The speed is not really a problem, but using PmWiki helper functions
would make the code shorter, more readable, and easier to maintain and
update.
A minor improvement for easier maintenance and evolution might be to use
ParseArgs() to parse the arguments. You don't need to quote arguments
that do not contain spaces, "=" or ":".
Also there is $MarkupDirectiveFunctions that makes it even
easier/simpler to add a directive, receive its parsed arguments, and
update it in the future with new arguments.
Also for convenience, it may be useful to allow simpler "glob" patterns
like ? and *. The MatchNames() function will match all lines at once
against a regular expression if the pattern starts and ends with "/" or
"!" (inverted match), otherwise a glob pattern will be assumed:
"/^(Hello|Bonjour)/" -> find lines starting with Hello or Bonjour
"Hello*,Bonjour*" -> find lines starting with Hello or Bonjour
"Hello*,-*Bye*" -> starting with Hello that do not contain Bye
BTW there is Cookbook:Grep.
> 2. do you play with AI tools like ChapGPT, Deepseek, Mistral for
> improving your PmWiki ? What do you do (can we do something else than
> markups and recipes ?) Does it work fine for you ? Which AI do you
> find is the best for this kind of work ?
I have tried ChatGPT but found that for code it takes me more time to
explain, review and correct its output, than if I wrote it myself. Never
for writing PmWiki code, I'm surprised it was able to assemble something
that actually works.
ChatGPT works for my linguistic questions, like explain to me an English
language expression I don't understand or a cultural reference I don't
get.
Petko
More information about the pmwiki-users
mailing list