diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 2096e9c858..721f4f18e3 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -18,6 +18,7 @@ if (php_sapi_name() != 'cli') $phpEx = substr(strrchr(__FILE__, '.'), 1); $phpbb_root_path = __DIR__ . '/../'; +define('IN_PHPBB', true); function usage() { @@ -54,9 +55,11 @@ function validate_argument_count($arguments, $count) validate_argument_count($argc, 1); $action = $argv[1]; -$extension = isset($argv[2]) ? $argv[2] : null; +$extension = isset($argv[2]) && $argv[2] !== 'null' ? $argv[2] : null; +$min_version = isset($argv[3]) ? $argv[3] : null; require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx; require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; +require __DIR__ . '/../includes/functions.' . $phpEx; require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx; require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; @@ -66,7 +69,7 @@ switch ($action) echo '__FORCETOC__' . "\n"; case 'php': - $exporter = new \phpbb\event\php_exporter($phpbb_root_path, $extension); + $exporter = new \phpbb\event\php_exporter($phpbb_root_path, $extension, $min_version); $exporter->crawl_phpbb_directory_php(); echo $exporter->export_events_for_wiki(); diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 35144eeeec..0857298c07 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -25,6 +25,12 @@ class php_exporter /** @var string phpBB Root Path */ protected $root_path; + /** @var string The minimum version for the events to return */ + protected $min_version; + + /** @var string The maximum version for the events to return */ + protected $max_version; + /** @var string */ protected $current_file; @@ -43,14 +49,18 @@ class php_exporter /** * @param string $phpbb_root_path * @param mixed $extension String 'vendor/ext' to filter, null for phpBB core + * @param string $min_version + * @param string $max_version */ - public function __construct($phpbb_root_path, $extension = null) + public function __construct($phpbb_root_path, $extension = null, $min_version = null, $max_version = null) { $this->root_path = $phpbb_root_path; $this->path = $phpbb_root_path; $this->events = $this->file_lines = array(); $this->current_file = $this->current_event = ''; $this->current_event_line = 0; + $this->min_version = $min_version; + $this->max_version = $max_version; $this->path = $this->root_path; if ($extension) @@ -215,6 +225,33 @@ class php_exporter $since_line_num = $this->find_since(); $since = $this->validate_since($this->file_lines[$since_line_num]); + $changed_line_nums = $this->find_changed('changed'); + if (empty($changed_line_nums)) + { + $changed_line_nums = $this->find_changed('change'); + } + $changed_versions = array(); + if (!empty($changed_line_nums)) + { + foreach ($changed_line_nums as $changed_line_num) { + $changed_versions[] = $this->validate_changed($this->file_lines[$changed_line_num]); + } + } + + if (!$this->version_is_filtered($since)) + { + $valid_version = false; + foreach ($changed_versions as $changed) + { + $valid_version = $valid_version || $this->version_is_filtered($changed); + } + + if (!$valid_version) + { + continue; + } + } + // Find event description line $description_line_num = $this->find_description(); $description = substr(trim($this->file_lines[$description_line_num]), strlen('* ')); @@ -242,6 +279,17 @@ class php_exporter return $num_events_found; } + /** + * The version to check + * + * @param string $version + */ + protected function version_is_filtered($version) + { + return (!$this->min_version || phpbb_version_compare($this->min_version, $version, '<=')) + && (!$this->max_version || phpbb_version_compare($this->max_version, $version, '>=')); + } + /** * Find the name of the event inside the dispatch() line * @@ -448,6 +496,33 @@ class php_exporter return $this->find_tag('since', array('event', 'var')); } + /** + * Find the "@changed" Information lines + * + * @param string $tag_name Should be 'changed' or 'change' + * @return array Absolute line numbers + * @throws \LogicException + */ + public function find_changed($tag_name) + { + $lines = array(); + $last_line = 0; + try + { + while ($line = $this->find_tag($tag_name, array('since'), $last_line)) + { + $lines[] = $line; + $last_line = $line; + } + } + catch (\LogicException $e) + { + // Not changed? No problem! + } + + return $lines; + } + /** * Find the "@event" Information line * @@ -464,13 +539,14 @@ class php_exporter * @param string $find_tag Name of the tag we are trying to find * @param array $disallowed_tags List of tags that must not appear between * the tag and the actual event + * @param int $skip_to_line Skip lines until this one * @return int Absolute line number * @throws \LogicException */ - public function find_tag($find_tag, $disallowed_tags) + public function find_tag($find_tag, $disallowed_tags, $skip_to_line = 0) { - $find_tag_line = 0; - $found_comment_end = false; + $find_tag_line = $skip_to_line ? $this->current_event_line - $skip_to_line + 1 : 0; + $found_comment_end = ($skip_to_line) ? true : false; while (strpos(ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t "), '* @' . $find_tag . ' ') !== 0) { if ($found_comment_end && ltrim($this->file_lines[$this->current_event_line - $find_tag_line], "\t") === '/**') @@ -560,6 +636,27 @@ class php_exporter return $match[1]; } + /** + * Validate "@changed" Information + * + * @param string $line + * @return string + * @throws \LogicException + */ + public function validate_changed($line) + { + $match = array(); + $line = str_replace("\t", ' ', ltrim($line, "\t ")); + preg_match('#^\* @change(d)? (\d+\.\d+\.\d+(?:-(?:a|b|RC|pl)\d+)?)( (?:.*))?$#', ltrim($line, "\t "), $match); + if (!isset($match[2])) + { + throw new \LogicException("Invalid '@changed' information for event " + . "'{$this->current_event}' in file '{$this->current_file}:{$this->current_event_line}'"); + } + + return $match[2]; + } + /** * Validate "@event" Information *