Add ability to override mb_strtoupper in Language::ucfirst
[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 // class Collator is provided by the intl extension.
30 // It is only suggested in composer.json, so remind here when not loaded.
31 if ( !extension_loaded( 'intl' ) ) {
32 die( "This script needs the 'intl' extension to be loaded." );
33 }
34
35 $CREDITS = 'CREDITS';
36 $START_CONTRIBUTORS = '<!-- BEGIN CONTRIBUTOR LIST -->';
37 $END_CONTRIBUTORS = '<!-- END CONTRIBUTOR LIST -->';
38
39 $inHeader = true;
40 $inFooter = false;
41 $header = [];
42 $contributors = [];
43 $footer = [];
44
45 if ( !file_exists( $CREDITS ) ) {
46 exit( 'No CREDITS file found. Are you running this script in the right directory?' );
47 }
48
49 $lines = explode( "\n", file_get_contents( $CREDITS ) );
50 foreach ( $lines as $line ) {
51 if ( $inHeader ) {
52 $header[] = $line;
53 $inHeader = $line !== $START_CONTRIBUTORS;
54 } elseif ( $inFooter ) {
55 $footer[] = $line;
56 } elseif ( $line == $END_CONTRIBUTORS ) {
57 $inFooter = true;
58 $footer[] = $line;
59 } else {
60 $name = substr( $line, 2 );
61 $contributors[$name] = true;
62 }
63 }
64 unset( $lines );
65
66 $lines = explode( "\n", shell_exec( 'git log --format="%aN"' ) );
67 foreach ( $lines as $line ) {
68 if ( empty( $line ) ) {
69 continue;
70 }
71 if ( substr( $line, 0, 5 ) === '[BOT]' ) {
72 continue;
73 }
74 $contributors[$line] = true;
75 }
76
77 $contributors = array_keys( $contributors );
78 $collator = Collator::create( 'root' );
79 $collator->setAttribute( Collator::NUMERIC_COLLATION, Collator::ON );
80 $collator->sort( $contributors );
81 array_walk( $contributors, function ( &$v, $k ) {
82 $v = "* {$v}";
83 } );
84
85 file_put_contents( $CREDITS,
86 implode( "\n", array_merge( $header, $contributors, $footer ) ) );