Event Timeline
Some nitpicks:
- there should be some instructions in a comment at the beginning of the file ("place this script in the doc/ directory of MediaWiki and run it" or something like that).
- there should be basic error handling (output a message if the file could not be opened, and more importantly, warn the user if a hook could not be converted, ie. if you could not convert something that's not at the beginning or the end of the file)
- instead of changing hook.txt in-place, it should write the output to hook.yaml.
- IMO the preamble would be more readable if even empty lines were commented out.
Other than that, looks solid. Nice regexp-fu :)
there should be some instructions in a comment at the beginning of the file ("place this script in the doc/ directory of MediaWiki and run it" or something like that).
So, are we planning to place the script in core?
IMO the preamble would be more readable if even empty lines were commented out.
I have edited the script to comment out the empty lines. But as discussed here tabs need to be converted to spaces in hooks.txt. Hence, I will upload the hooks.yaml after I get updated hooks.txt.
Should I submit a patch for updated hooks.txt or wait for one?
So, are we planning to place the script in core?
We aren't. But the patch might not get merged for a while, and hook.txt changes all the time, so the script will need to be re-run a few times. Someone else might get involved in that; in general it is a good practice to always include usage documentation with code.
Should I submit a patch for updated hooks.txt or wait for one?
You should, or you can just handle tab -> space conversion in the script.
Now, script handles the tabs too. It searches for the tabs and replaces with four spaces.
In hooks.txt :
'SpecialResetTokensTokens': Called when building token list for SpecialResetTokens. &$tokens: array of token information arrays in the format of array( 'preference' => '<preference-name>', 'label-message' => '<message-key>', )
In hooks.yaml :
- Before:
SpecialResetTokensTokens:
Description: |
Called when building token list for
SpecialResetTokens.
arguments:
- "&$tokens": |
array of token information arrays in the format of
array(
'preference' => '<preference-name>',
'label-message' => '<message-key>',
)- After:
SpecialResetTokensTokens:
Description: |
Called when building token list for
SpecialResetTokens.
arguments:
- "&$tokens": |
array of token information arrays in the format of
array(
'preference' => '<preference-name>',
'label-message' => '<message-key>',
)The script works for me, a few minor comments:
$data = preg_replace( "@\t@", " ", $hooksData );
$explanatoryText = preg_replace( '~^(.*)$~m', '# $0', $text[0] );
why @ and '~'? Any delimiter works, but '/' is the standard.
$explanatoryText = preg_replace( '~^(.*)$~m', '# $0', $text[0] );
You're just changing the beginning of each line, so no need to capture the rest of it.
$explanatoryText = preg_replace( '/^/m', '# ', $text[0] );
function wfHooksInYaml( $handle, $string, $hookFile ) {
Why is this prefixed wf? That's a convention for global PHP functions in MediaWiki.