37require_once __DIR__ .
'/Maintenance.php';
51 protected static $ignore = [
'testRunLegacyHooks',
'Test' ];
54 parent::__construct();
55 $this->
addDescription(
'Find hooks that are undocumented, missing, or just plain wrong' );
56 $this->
addOption(
'online',
'Check against MediaWiki.org hook documentation' );
77 "$IP/tests/phpunit/suites",
83 foreach ( $recurseDirs
as $dir ) {
85 $potentialHooks = array_merge( $potentialHooks,
$ret[
'good'] );
86 $badHooks = array_merge( $badHooks,
$ret[
'bad'] );
88 foreach ( $nonRecurseDirs
as $dir ) {
90 $potentialHooks = array_merge( $potentialHooks,
$ret[
'good'] );
91 $badHooks = array_merge( $badHooks,
$ret[
'bad'] );
94 $documented = array_keys( $documentedHooks );
95 $potential = array_keys( $potentialHooks );
96 $potential = array_unique( $potential );
97 $badHooks = array_diff( array_unique( $badHooks ), self::$ignore );
98 $todo = array_diff( $potential, $documented, self::$ignore );
99 $deprecated = array_diff( $documented, $potential, self::$ignore );
102 $badParameterCount = $badParameterReference = [];
103 foreach ( $potentialHooks
as $hook =>
$args ) {
104 if ( !isset( $documentedHooks[$hook] ) ) {
108 $argsDoc = $documentedHooks[$hook];
109 if (
$args ===
'unknown' || $argsDoc ===
'unknown' ) {
113 if ( count( $argsDoc ) !== count(
$args ) ) {
114 $badParameterCount[] = $hook .
': Doc: ' . count( $argsDoc ) .
' vs. Code: ' . count(
$args );
117 foreach ( $argsDoc
as $index => $argDoc ) {
118 $arg =
$args[$index];
119 if ( ( $arg[0] ===
'&' ) !== ( $argDoc[0] ===
'&' ) ) {
120 $badParameterReference[] = $hook .
': References different: Doc: ' . $argDoc .
121 ' vs. Code: ' . $arg;
129 $this->
printArray(
'Documented and not found', $deprecated );
130 $this->
printArray(
'Unclear hook calls', $badHooks );
131 $this->
printArray(
'Different parameter count', $badParameterCount );
132 $this->
printArray(
'Different parameter reference', $badParameterReference );
134 if ( !$todo && !$deprecated && !$badHooks
135 && !$badParameterCount && !$badParameterReference
137 $this->
output(
"Looks good!\n" );
139 $this->
error(
'The script finished with errors.', 1 );
163 $content = file_get_contents( $doc );
165 "/\n'(.*?)':.*((?:\n.+)*)/",
173 foreach ( $m
as $match ) {
175 if ( isset( $match[2] ) ) {
177 if ( preg_match_all(
"/\n(&?\\$\w+):.+/", $match[2], $n ) ) {
181 $hooks[$match[1]] =
$args;
193 return array_diff_key( $allhooks, $removed );
203 'list' =>
'categorymembers',
204 'cmtitle' =>
"Category:$title",
217 $data = FormatJson::decode( $json,
true );
218 foreach ( $data[
'query'][
'categorymembers']
as $page ) {
219 if ( preg_match(
'/Manual\:Hooks\/([a-zA-Z0-9- :]+)/',
$page[
'title'], $m ) ) {
221 $retval[str_replace(
' ',
'_', $m[1] )] =
'unknown';
224 if ( !isset( $data[
'continue'] ) ) {
237 $content = file_get_contents( $filePath );
241 '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\s*\(\s*' .
247 '(?:\s*(?:array\s*\(|\[)' .
249 '((?:[^\(\)\[\]]|\((?-1)\)|\[(?-1)\])*)' .
259 foreach ( $m
as $match ) {
261 if ( isset( $match[4] ) ) {
263 if ( preg_match_all(
'/((?:[^,\(\)]|\([^\(\)]*\))+)/', $match[4], $n ) ) {
264 $args = array_map(
'trim', $n[1] );
266 } elseif ( isset( $match[3] ) ) {
272 $hooks[$match[2]] =
$args;
284 $content = file_get_contents( $filePath );
287 preg_match_all(
'/(?<!function )wfRunHooks\(\s*[^\s\'"].*/',
$content, $m );
289 foreach ( $m[0]
as $match ) {
290 $list[] = $match .
"(" . $filePath .
")";
306 if ( $recurse === self::FIND_RECURSIVE ) {
307 $iterator =
new RecursiveIteratorIterator(
308 new RecursiveDirectoryIterator(
$dir, RecursiveDirectoryIterator::SKIP_DOTS ),
309 RecursiveIteratorIterator::SELF_FIRST
312 $iterator =
new DirectoryIterator(
$dir );
315 foreach ( $iterator
as $info ) {
317 if ( $info->isFile() && in_array( $info->getExtension(), [
'php',
'inc' ] )
319 && $info->getRealPath() !== __FILE__
321 $good = array_merge( $good, $this->
getHooksFromFile( $info->getRealPath() ) );
326 return [
'good' => $good,
'bad' => $bad ];
337 foreach ( $arr
as $v ) {
338 $this->
output(
"$msg: $v\n" );
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Maintenance script that compares documented and actually present mismatches.
printArray( $msg, $arr)
Nicely sort an print an array.
getHooksFromFile( $filePath)
Get hooks from a PHP file.
getBadHooksFromFile( $filePath)
Get bad hooks (where the hook name could not be determined) from a PHP file.
getHooksFromDoc( $doc)
Get the hook documentation, either locally or from MediaWiki.org.
getHooksFromOnlineDoc()
Get hooks from www.mediawiki.org using the API.
getHooksFromLocalDoc( $doc)
Get hooks from a local file (for example docs/hooks.txt)
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
getHooksFromDir( $dir, $recurse=0)
Get hooks from a directory of PHP files.
execute()
Do the actual work.
__construct()
Default constructor.
getHooksFromOnlineDocCategory( $title)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
const DB_NONE
Constants for DB access type.
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
if(count( $args)==0) $dir
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
require_once RUN_MAINTENANCE_IF_MAIN