Difference between revisions of "Talk:Main Page/Moderator Stuff/Text Edit Bot"
Jump to navigation
Jump to search
(Created page with "I (Wiimm) have written a text edit bot. It is very efficient and easy to handle, but it must be started as php script at severs backend. So only Tock and I are able to...") |
|||
Line 66: | Line 66: | ||
{ | { | ||
.... | .... | ||
+ | # see above | ||
} | } | ||
Line 91: | Line 92: | ||
TestIt($orig,"Test 1"); | TestIt($orig,"Test 1"); | ||
+ | |||
#-------------------------------------------------- | #-------------------------------------------------- | ||
Latest revision as of 12:17, 26 November 2016
I (Wiimm) have written a text edit bot. It is very efficient and easy to handle, but it must be started as php script at severs backend. So only Tock and I are able to start it.
How it works
It loads every current text (no history text) of every standard text and template (other namespaces are possible) and calls a function. The function returns the text, modified or not. If the text was modified, it is written back to the database.
The edit function
The edit function looks like this:
function FixText ( $old_text, &$log ) { $text = .... return $text; }
- $old_text
- The original text. It must be scanned.
- $log
- Print this before log messages and empty $log.
Example for a line based check
function FixText ( $old_text, &$log ) { #--- line collector $collect = ''; #--- split text into lines foreach ( explode("\n",$old_text) as $line ) { #--- make a fast pre test (optional) if (candiate_for_edit($line)) { #--- calculate a new line $new_line = do_something_with($line); if ( $line != $new_line ) { #--- log: can be commented out print("%s ** %s\n > %s\n",$log,$line,$new_line); $log = ''; #--- use the new line $line = $new_line; } } #--- add the current line $collect .= "\n".$line; } #--- return collected text, but remove the first unwanted line-feed. return substr($collect,1); }
Example for a test script
<?php function FixText ( $old_text, &$log ) { .... # see above } #-------------------------------------------------- function TestIt ( $orig, $info ) { $log = sprintf("\n---------- %s ---------\n",$info); $text = FixText($orig,$log); if ( $text != $orig ) printf("%s\n###ORIG###\n%s\n\n###NEW###\n%s\n\n", $log, $orig, $text ); } #-------------------------------------------------- $orig = <<< __EOT__ This is my test. == Title == __TO__ [[category:Text]] __EOT__; TestIt($orig,"Test 1"); #-------------------------------------------------- $orig = <<< __EOT__ ... __EOT__; TestIt($orig,"Test 2"); #-------------------------------------------------- ... ?>
The <<< __EOT__ part is a php here document.
Jobs
Any moderator can give me a job in form of a FixText() function. The job must be proved with example text and the edits must be explained. I accept only downloadable php-code in form of the example code.