From e0180991bfb2d1b3fe6c01065f1741ff77948aa2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 May 2015 10:18:19 +0200 Subject: [PATCH 1/7] [ticket/13807] Allow filtering events by phpBB version PHPBB3-13807 --- phpBB/develop/export_events_for_wiki.php | 7 +- phpBB/phpbb/event/php_exporter.php | 105 ++++++++++++++++++++++- 2 files changed, 106 insertions(+), 6 deletions(-) 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 * From bdad879508d7d3d36119d0d106682c213ff61f35 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 May 2015 14:32:14 +0200 Subject: [PATCH 2/7] [ticket/13807] Allow filtering template events PHPBB3-13807 --- phpBB/phpbb/event/md_exporter.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index f7021875f3..d5de56525a 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -24,6 +24,12 @@ class md_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 $filter; @@ -36,8 +42,10 @@ class md_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 = $this->root_path; @@ -49,6 +57,8 @@ class md_exporter $this->events = array(); $this->events_by_file = array(); $this->filter = $this->current_event = ''; + $this->min_version = $min_version; + $this->max_version = $max_version; } /** @@ -152,6 +162,11 @@ class md_exporter $files = $this->validate_file_list($file_details); $since = $this->validate_since($since); + if (!$this->version_is_filtered($since)) + { + continue; + } + $this->events[$event_name] = array( 'event' => $this->current_event, 'files' => $files, @@ -163,6 +178,17 @@ class md_exporter return sizeof($this->events); } + /** + * 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, '>=')); + } + /** * Format the php events as a wiki table * @return string Number of events found From 96d97ae2d2afc3574d7ba28a40c40c1e772398fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 May 2015 14:33:31 +0200 Subject: [PATCH 3/7] [ticket/13807] Add an option to generate a diff for the release highlights PHPBB3-13807 --- phpBB/develop/export_events_for_wiki.php | 47 +++++++++++++++++++----- phpBB/phpbb/event/md_exporter.php | 22 +++++++++-- phpBB/phpbb/event/php_exporter.php | 13 ++++++- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 721f4f18e3..029affcbe9 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -28,6 +28,9 @@ function usage() echo " all:\n"; echo " Generate the complete wikipage for https://wiki.phpbb.com/Event_List\n"; echo "\n"; + echo " diff:\n"; + echo " Generate the Event Diff for the release highlights\n"; + echo "\n"; echo " php:\n"; echo " Generate the PHP event section of Event_List\n"; echo "\n"; @@ -37,6 +40,9 @@ function usage() echo " styles:\n"; echo " Generate the Styles Template event section of Event_List\n"; echo "\n"; + echo "VERSION (diff only):\n"; + echo " Filter events (minimum version)\n"; + echo "\n"; echo "EXTENSION (Optional):\n"; echo " If not given, only core events will be exported.\n"; echo " Otherwise only events from the extension will be exported.\n"; @@ -55,8 +61,8 @@ function validate_argument_count($arguments, $count) validate_argument_count($argc, 1); $action = $argv[1]; -$extension = isset($argv[2]) && $argv[2] !== 'null' ? $argv[2] : null; -$min_version = isset($argv[3]) ? $argv[3] : null; +$extension = isset($argv[2]) ? $argv[2] : null; +$min_version = null; require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx; require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; require __DIR__ . '/../includes/functions.' . $phpEx; @@ -68,10 +74,19 @@ switch ($action) case 'all': echo '__FORCETOC__' . "\n"; + case 'diff': + if ($action === 'diff') + { + echo '== Event changes ==' . "\n"; + } + $min_version = $extension; + $extension = isset($argv[3]) ? $argv[3] : null; + + case 'php': $exporter = new \phpbb\event\php_exporter($phpbb_root_path, $extension, $min_version); $exporter->crawl_phpbb_directory_php(); - echo $exporter->export_events_for_wiki(); + echo $exporter->export_events_for_wiki($action); if ($action === 'php') { @@ -81,9 +96,16 @@ switch ($action) // no break; case 'styles': - $exporter = new \phpbb\event\md_exporter($phpbb_root_path, $extension); - $exporter->crawl_phpbb_directory_styles('docs/events.md'); - echo $exporter->export_events_for_wiki(); + $exporter = new \phpbb\event\md_exporter($phpbb_root_path, $extension, $min_version); + if ($min_version && $action === 'diff') + { + $exporter->crawl_eventsmd('docs/events.md', 'styles'); + } + else + { + $exporter->crawl_phpbb_directory_styles('docs/events.md'); + } + echo $exporter->export_events_for_wiki($action); if ($action === 'styles') { @@ -93,9 +115,16 @@ switch ($action) // no break; case 'adm': - $exporter = new \phpbb\event\md_exporter($phpbb_root_path, $extension); - $exporter->crawl_phpbb_directory_adm('docs/events.md'); - echo $exporter->export_events_for_wiki(); + $exporter = new \phpbb\event\md_exporter($phpbb_root_path, $extension, $min_version); + if ($min_version && $action === 'diff') + { + $exporter->crawl_eventsmd('docs/events.md', 'adm'); + } + else + { + $exporter->crawl_phpbb_directory_adm('docs/events.md'); + } + echo $exporter->export_events_for_wiki($action); if ($action === 'all') { diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php index d5de56525a..7f94ca9299 100644 --- a/phpBB/phpbb/event/md_exporter.php +++ b/phpBB/phpbb/event/md_exporter.php @@ -191,19 +191,35 @@ class md_exporter /** * Format the php events as a wiki table + * + * @param string $action * @return string Number of events found */ - public function export_events_for_wiki() + public function export_events_for_wiki($action = '') { if ($this->filter === 'adm') { - $wiki_page = '= ACP Template Events =' . "\n"; + if ($action === 'diff') + { + $wiki_page = '=== ACP Template Events ===' . "\n"; + } + else + { + $wiki_page = '= ACP Template Events =' . "\n"; + } $wiki_page .= '{| class="zebra sortable" cellspacing="0" cellpadding="5"' . "\n"; $wiki_page .= '! Identifier !! Placement !! Added in Release !! Explanation' . "\n"; } else { - $wiki_page = '= Template Events =' . "\n"; + if ($action === 'diff') + { + $wiki_page = '=== Template Events ===' . "\n"; + } + else + { + $wiki_page = '= Template Events =' . "\n"; + } $wiki_page .= '{| class="zebra sortable" cellspacing="0" cellpadding="5"' . "\n"; $wiki_page .= '! Identifier !! Prosilver Placement (If applicable) !! Subsilver Placement (If applicable) !! Added in Release !! Explanation' . "\n"; } diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 0857298c07..1e0bd4ac67 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -158,11 +158,20 @@ class php_exporter /** * Format the php events as a wiki table + * + * @param string $action * @return string */ - public function export_events_for_wiki() + public function export_events_for_wiki($action = '') { - $wiki_page = '= PHP Events (Hook Locations) =' . "\n"; + if ($action === 'diff') + { + $wiki_page = '=== PHP Events (Hook Locations) ===' . "\n"; + } + else + { + $wiki_page = '= PHP Events (Hook Locations) =' . "\n"; + } $wiki_page .= '{| class="sortable zebra" cellspacing="0" cellpadding="5"' . "\n"; $wiki_page .= '! Identifier !! Placement !! Arguments !! Added in Release !! Explanation' . "\n"; foreach ($this->events as $event) From 222604332539a811907bb18ab89833038f7746b6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 May 2015 14:34:00 +0200 Subject: [PATCH 4/7] [ticket/13807] Fix "changed version" to match our version numbering PHPBB3-13807 --- phpBB/includes/ucp/ucp_prefs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 1d3fb19f67..3c274b53c7 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -69,7 +69,7 @@ class ucp_prefs * @var array data Array with current ucp options data * @var array error Array with list of errors * @since 3.1.0-a1 - * @changed 3.1.4-rc1 Added error variable to the event + * @changed 3.1.4-RC1 Added error variable to the event */ $vars = array('submit', 'data', 'error'); extract($phpbb_dispatcher->trigger_event('core.ucp_prefs_personal_data', compact($vars))); From 34141b576e141050f2a898f93cd1e29295985225 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 May 2015 16:55:35 +0200 Subject: [PATCH 5/7] [ticket/13807] Fix minor coding flaws PHPBB3-13807 --- phpBB/phpbb/event/php_exporter.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/event/php_exporter.php b/phpBB/phpbb/event/php_exporter.php index 1e0bd4ac67..8cffa4620f 100644 --- a/phpBB/phpbb/event/php_exporter.php +++ b/phpBB/phpbb/event/php_exporter.php @@ -242,7 +242,8 @@ class php_exporter $changed_versions = array(); if (!empty($changed_line_nums)) { - foreach ($changed_line_nums as $changed_line_num) { + foreach ($changed_line_nums as $changed_line_num) + { $changed_versions[] = $this->validate_changed($this->file_lines[$changed_line_num]); } } @@ -656,7 +657,7 @@ class php_exporter { $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); + preg_match('#^\* @change(d)? (\d+\.\d+\.\d+(?:-(?:a|b|RC|pl)\d+)?)( (?:.*))?$#', $line, $match); if (!isset($match[2])) { throw new \LogicException("Invalid '@changed' information for event " From 45baaf602289f3d148739999d5972852b45dd882 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 May 2015 17:29:55 +0200 Subject: [PATCH 6/7] [ticket/13807] Only output the header for diff PHPBB3-13807 --- phpBB/develop/export_events_for_wiki.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 029affcbe9..004a200f1d 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -71,17 +71,18 @@ require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; switch ($action) { - case 'all': - echo '__FORCETOC__' . "\n"; case 'diff': - if ($action === 'diff') - { - echo '== Event changes ==' . "\n"; - } + echo '== Event changes ==' . "\n"; $min_version = $extension; $extension = isset($argv[3]) ? $argv[3] : null; + case 'all': + if ($action === 'all') + { + echo '__FORCETOC__' . "\n"; + } + case 'php': $exporter = new \phpbb\event\php_exporter($phpbb_root_path, $extension, $min_version); From 740be0507e209afda5eb954ab674e557c2d8f8f6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 5 May 2015 18:35:57 +0200 Subject: [PATCH 7/7] [ticket/13807] Add version to the usage output PHPBB3-13807 --- phpBB/develop/export_events_for_wiki.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index 004a200f1d..be16e5e7cd 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -22,7 +22,7 @@ define('IN_PHPBB', true); function usage() { - echo "Usage: export_events_for_wiki.php COMMAND [EXTENSION]\n"; + echo "Usage: export_events_for_wiki.php COMMAND [VERSION] [EXTENSION]\n"; echo "\n"; echo "COMMAND:\n"; echo " all:\n";