* @copyright Copyright © Ashar voultoiz * @license http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later */ /** This is a command line script*/ require('commandLine.inc'); # GLOBALS $doc = $IP . '/docs/hooks.txt'; $pathinc = array( $IP.'/', $IP.'/includes/', $IP.'/includes/api/', $IP.'/includes/db/', $IP.'/includes/diff/', $IP.'/includes/filerepo/', $IP.'/includes/parser/', $IP.'/includes/search/', $IP.'/includes/specials/', $IP.'/includes/upload/', $IP.'/languages/', $IP.'/maintenance/', $IP.'/skins/', ); # FUNCTIONS /** * @return array of documented hooks */ function getHooksFromDoc() { global $doc, $options; if( isset( $options['online'] ) ){ // All hooks $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' ); $allhookdata = unserialize( $allhookdata ); $allhooks = array(); foreach( $allhookdata['query']['categorymembers'] as $page ) { $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); if( $found ) { $hook = str_replace( ' ', '_', $matches[1] ); $allhooks[] = $hook; } } // Removed hooks $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' ); $oldhookdata = unserialize( $oldhookdata ); $removed = array(); foreach( $oldhookdata['query']['categorymembers'] as $page ) { $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); if( $found ) { $hook = str_replace( ' ', '_', $matches[1] ); $removed[] = $hook; } } return array_diff( $allhooks, $removed ); } else { $m = array(); $content = file_get_contents( $doc ); preg_match_all( "/\n'(.*?)'/", $content, $m ); return array_unique( $m[1] ); } } /** * Get hooks from a PHP file * @param $file Full filename to the PHP file. * @return array of hooks found. */ function getHooksFromFile( $file ) { $content = file_get_contents( $file ); $m = array(); preg_match_all( '/wfRunHooks\(\s*([\'"])(.*?)\1/', $content, $m); return $m[2]; } /** * Get hooks from the source code. * @param $path Directory where the include files can be found * @return array of hooks found. */ function getHooksFromPath( $path ) { $hooks = array(); if( $dh = opendir($path) ) { while(($file = readdir($dh)) !== false) { if( filetype($path.$file) == 'file' ) { $hooks = array_merge( $hooks, getHooksFromFile($path.$file) ); } } closedir($dh); } return $hooks; } /** * Get bad hooks (where the hook name could not be determined) from a PHP file * @param $file Full filename to the PHP file. * @return array of bad wfRunHooks() lines */ function getBadHooksFromFile( $file ) { $content = file_get_contents( $file ); $m = array(); # We want to skip the "function wfRunHooks()" one. :) preg_match_all( '/(?