Merge "Remove last remnants of pre-1.16 live preview"
[lhc/web/wiklou.git] / maintenance / updateCredits.php
1 <?php
2 /**
3 * Update the CREDITS list by merging in the list of git commit authors.
4 *
5 * The contents of the existing contributors list will be preserved. If a name
6 * needs to be removed for some reason that must be done manually before or
7 * after running this script.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
23 */
24
25 if ( PHP_SAPI != 'cli' ) {
26 die( "This script can only be run from the command line.\n" );
27 }
28
29 chdir( dirname( __DIR__ ) );
30
31 $CREDITS = 'CREDITS';
32 $START_CONTRIBUTORS = '<!-- BEGIN CONTRIBUTOR LIST -->';
33 $END_CONTRIBUTORS = '<!-- END CONTRIBUTOR LIST -->';
34
35 $inHeader = true;
36 $inFooter = false;
37 $header = [];
38 $contributors = [];
39 $footer = [];
40
41 $lines = explode( "\n", file_get_contents( $CREDITS ) );
42 foreach ( $lines as $line ) {
43 if ( $inHeader ) {
44 $header[] = $line;
45 $inHeader = $line !== $START_CONTRIBUTORS;
46 } elseif ( $inFooter ) {
47 $footer[] = $line;
48 } elseif ( $line == $END_CONTRIBUTORS ) {
49 $inFooter = true;
50 $footer[] = $line;
51 } else {
52 $name = substr( $line, 2 );
53 $contributors[$name] = true;
54 }
55 }
56 unset( $lines );
57
58 $lines = explode( "\n", shell_exec( 'git log --format="%aN"' ) );
59 foreach ( $lines as $line ) {
60 if ( empty( $line ) ) {
61 continue;
62 }
63 if ( substr( $line, 0, 5 ) === '[BOT]' ) {
64 continue;
65 }
66 $contributors[$line] = true;
67 }
68
69 $contributors = array_keys( $contributors );
70 $collator = Collator::create( 'uca-default-u-kn' );
71 $collator->sort( $contributors );
72 array_walk( $contributors, function ( &$v, $k ) {
73 $v = "* {$v}";
74 } );
75
76 file_put_contents( $CREDITS,
77 implode( "\n", array_merge( $header, $contributors, $footer ) ) );