0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-12 16:38:40 +00:00
htmlpurifier/maintenance/add-vimline.php
Kieran db312435cb
feat: add semantic release (#307)
* Add semantic release

* fix typo

* split from matrix

* remove only on push

* remove npm plugin

* write changelog to NEWS

* list assets to include in git commit

* fix update-for-release

* lint pr title

* split release into separate workflow that runs manually

* revert ci.yml changes

* remove references to WHATSNEW

* Fix #322 - PHP 8.1 deprecation notice in HostBlacklist URIFilter (#323)

* Replace 8.1-deprecated utf8_ funcs with mbstring (#326)

* Treat PHP version numbers as strings in GitHub Actions (#327)

YAML will try to interpret numeric values as numbers, leading to `8.0` being
interpreted as `8` instead of `'8.0'`.

This doesn't result in a functional change, but cleans up the output of the
jobs a little (e.g. in the title line).

* Update to `actions/checkout@v3` (#328)

This does not introduce any functional difference and is intended as a
future-proofing change.

see https://github.com/actions/checkout/releases/tag/v3.0.0

* Fix test selection logic in tests/test_files.php (#329)

Selecting the `fstools` tests also executed the `htmlt` tests.

* Fix some more PHP 8.2 deprecations (#330)

* Define HTMLPurifier_AttrTransform_SafeParam::$wmode

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_DefinitionCache_DecoratorHarness::$cache

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_DefinitionCache_DecoratorHarness::$mock

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_DefinitionCache_DecoratorHarness::$def

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_EntityParserTest::$_entity_lookup

This fixes a PHP 8.2 deprecation.

* Increase minimum requirement to PHP 5.6 (#331)

* Add contenteditable attribute definition (#332)

* Add contenteditable attribute definition

* gate behind html.trusted

* use enum

* Fix creation of dynamic property (#333)

* Fix creation of dynamic property (#337)

* Add PHP 8.2 to CI (#335)

* Add PHP 8.2 to CI

see ezyang/htmlpurifier#334

* Add PHP 8.2 to composer.json

* Fix contenteditable attribute definition (#336)

* Run CSSTidy tests on CI (#338)

* Run CSSTidy tests on CI

* update dirname

* use compopser instead of git clone

* use composer

* use test-settings.sample.php

* enable ext-intl

* disable Net_IDNA2

* Release 4.15.0

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
Co-authored-by: John Flatness <john@zerocrates.org>
Co-authored-by: Tim Düsterhus <duesterhus@woltlab.com>
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
Co-authored-by: Edward Z. Yang <ezyang@mit.edu>
2022-09-18 02:44:00 -04:00

130 lines
3.6 KiB
PHP

#!/usr/bin/php
<?php
chdir(dirname(__FILE__));
require_once 'common.php';
assertCli();
/**
* @file
* Adds vimline to files
*/
chdir(dirname(__FILE__) . '/..');
$FS = new FSTools();
$vimline = 'vim: et sw=4 sts=4';
$files = $FS->globr('.', '*');
foreach ($files as $file) {
if (
!is_file($file) ||
prefix_is('./docs/doxygen', $file) ||
prefix_is('./library/standalone', $file) ||
prefix_is('./docs/specimens', $file) ||
postfix_is('.ser', $file) ||
postfix_is('.tgz', $file) ||
postfix_is('.patch', $file) ||
postfix_is('.dtd', $file) ||
postfix_is('.ent', $file) ||
postfix_is('.png', $file) ||
postfix_is('.ico', $file) ||
// wontfix
postfix_is('.vtest', $file) ||
postfix_is('.svg', $file) ||
postfix_is('.phpt', $file) ||
postfix_is('VERSION', $file) ||
postfix_is('configdoc/usage.xml', $file) ||
postfix_is('library/HTMLPurifier.includes.php', $file) ||
postfix_is('library/HTMLPurifier.safe-includes.php', $file) ||
postfix_is('smoketests/xssAttacks.xml', $file) ||
// phpt files
postfix_is('.diff', $file) ||
postfix_is('.exp', $file) ||
postfix_is('.log', $file) ||
postfix_is('.out', $file) ||
$file == './library/HTMLPurifier/Lexer/PH5P.php' ||
$file == './maintenance/PH5P.php'
) continue;
$ext = strrchr($file, '.');
if (
postfix_is('README', $file) ||
postfix_is('LICENSE', $file) ||
postfix_is('CREDITS', $file) ||
postfix_is('INSTALL', $file) ||
postfix_is('NEWS', $file) ||
postfix_is('TODO', $file) ||
postfix_is('WYSIWYG', $file) ||
postfix_is('Changelog', $file)
) $ext = '.txt';
if (postfix_is('Doxyfile', $file)) $ext = 'Doxyfile';
if (postfix_is('.php.in', $file)) $ext = '.php';
$no_nl = false;
switch ($ext) {
case '.php':
case '.inc':
case '.js':
$line = '// %s';
break;
case '.html':
case '.xsl':
case '.xml':
case '.htc':
$line = "<!-- %s\n-->";
break;
case '.htmlt':
$no_nl = true;
$line = '--# %s';
break;
case '.ini':
$line = '; %s';
break;
case '.css':
$line = '/* %s */';
break;
case '.bat':
$line = 'rem %s';
break;
case '.txt':
case '.utf8':
if (
prefix_is('./library/HTMLPurifier/ConfigSchema', $file) ||
prefix_is('./smoketests/test-schema', $file) ||
prefix_is('./tests/HTMLPurifier/StringHashParser', $file)
) {
$no_nl = true;
$line = '--# %s';
} else {
$line = ' %s';
}
break;
case 'Doxyfile':
$line = '# %s';
break;
default:
throw new Exception('Unknown file: ' . $file);
}
echo "$file\n";
$contents = file_get_contents($file);
$regex = '~' . str_replace('%s', 'vim: .+', preg_quote($line, '~')) . '~m';
$contents = preg_replace($regex, '', $contents);
$contents = rtrim($contents);
if (strpos($contents, "\r\n") !== false) $nl = "\r\n";
elseif (strpos($contents, "\n") !== false) $nl = "\n";
elseif (strpos($contents, "\r") !== false) $nl = "\r";
else $nl = PHP_EOL;
if (!$no_nl) $contents .= $nl;
$contents .= $nl . str_replace('%s', $vimline, $line) . $nl;
file_put_contents($file, $contents);
}
// vim: et sw=4 sts=4