Page MenuHomePhabricator

maintenance/findhooks.php does not find all hooks
Closed, ResolvedPublic

Description

The regex used to find hooks is too strict, as it assumes that strings are enclosed in single quotes,
which is not always true for wfRunHooks in the Mediawiki code base.

The trivial patch:

  • a/maintenance/findhooks.php

+++ b/maintenance/findhooks.php
@@ -45,8 +45,8 @@ function getHooksFromDoc() {
function getHooksFromFile( $file ) {

$content = file_get_contents( $file );
$m = array();
  • preg_match_all( "/wfRunHooks\(\s*\'(.*?)\'/", $content, $m);
  • return $m[1];

+ preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m);
+ return $m[2];
}

/**


Version: 1.12.x
Severity: trivial

Details

Reference
bz12146

Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 9:58 PM
bzimport set Reference to bz12146.
bzimport added a subscriber: Unknown Object (MLST).

BTW: The script reports, among others:
undocumented: userCan
not found: UserCan

docs/hooks.txt should be changed as follows:

  • a/docs/hooks.txt

+++ b/docs/hooks.txt
@@ -753,13 +753,13 @@ string &$error: output: HTML error to show if upload canceled by returning false
'UploadComplete': Upon completion of a file upload
$image: Image object representing the file that was uploaded

-'UserCan': To interrupt/advise the "user can do X to Y article" check.
+'userCan': To interrupt/advise the "user can do X to Y article" check.

If you want to display an error message, try getUserPermissionsErrors.

$title: Title object being checked against
$user : Current user object
$action: Action being checked
$result: Pointer to result returned if hook returns false. If null is returned,

  • UserCan checks are continued by internal code.

+ userCan checks are continued by internal code.

'UserCreateForm': change to manipulate the login form
$template: SimpleTemplate instance for the form