Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / maintenance / updateCredits.php
blobeb717e8c66c4739908b77876bb40bb4423f230f9
1 <?php
2 /**
3 * Update the CREDITS list by merging in the list of git commit authors.
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.
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.
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.
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
25 if ( PHP_SAPI != 'cli' ) {
26 die( "This script can only be run from the command line.\n" );
29 $CREDITS = 'CREDITS';
30 $START_CONTRIBUTORS = '<!-- BEGIN CONTRIBUTOR LIST -->';
31 $END_CONTRIBUTORS = '<!-- END CONTRIBUTOR LIST -->';
33 $inHeader = true;
34 $inFooter = false;
35 $header = [];
36 $contributors = [];
37 $footer = [];
39 if ( !file_exists( $CREDITS ) ) {
40 exit( 'No CREDITS file found. Are you running this script in the right directory?' );
43 $lines = explode( "\n", file_get_contents( $CREDITS ) );
44 foreach ( $lines as $line ) {
45 if ( $inHeader ) {
46 $header[] = $line;
47 $inHeader = $line !== $START_CONTRIBUTORS;
48 } elseif ( $inFooter ) {
49 $footer[] = $line;
50 } elseif ( $line == $END_CONTRIBUTORS ) {
51 $inFooter = true;
52 $footer[] = $line;
53 } else {
54 $name = substr( $line, 2 );
55 $contributors[$name] = true;
58 unset( $lines );
60 $lines = explode( "\n", shell_exec( 'git log --format="%aN"' ) );
61 foreach ( $lines as $line ) {
62 if ( empty( $line ) ) {
63 continue;
65 if ( substr( $line, 0, 5 ) === '[BOT]' ) {
66 continue;
68 $contributors[$line] = true;
71 $contributors = array_keys( $contributors );
72 $collator = Collator::create( 'uca-default-u-kn' );
73 $collator->sort( $contributors );
74 array_walk( $contributors, function ( &$v, $k ) {
75 $v = "* {$v}";
76 } );
78 file_put_contents( $CREDITS,
79 implode( "\n", array_merge( $header, $contributors, $footer ) ) );