$licenseText = '== ' . $msg['license-header'] . " ==\n{{" . $license . "}}\n";
}
- $pageText = $comment == '' ? '' : '== ' . $msg['filedesc'] . " ==\n" . $comment . "\n";
+ $pageText = $comment . "\n";
+ $headerText = '== ' . $msg['filedesc'] . ' ==';
+ if ( $comment !== '' && strpos( $comment, $headerText ) === false ) {
+ // prepend header to page text unless it's already there (or there is no content)
+ $pageText = $headerText . "\n" . $pageText;
+ }
+
if ( $config->get( 'UseCopyrightUpload' ) ) {
$pageText .= '== ' . $msg['filestatus'] . " ==\n" . $copyStatus . "\n";
$pageText .= $licenseText;
--- /dev/null
+<?php
+
+class SpecialUploadTest extends MediaWikiTestCase {
+ /**
+ * @covers SpecialUpload::getInitialPageText
+ * @dataProvider provideGetInitialPageText
+ */
+ public function testGetInitialPageText( $expected, $inputParams ) {
+ $result = call_user_func_array( [ 'SpecialUpload', 'getInitialPageText' ], $inputParams );
+ $this->assertEquals( $expected, $result );
+ }
+
+ public function provideGetInitialPageText() {
+ return [
+ [
+ 'expect' => "== Summary ==\nthis is a test\n",
+ 'params' => [
+ 'this is a test'
+ ],
+ ],
+ [
+ 'expect' => "== Summary ==\nthis is a test\n",
+ 'params' => [
+ "== Summary ==\nthis is a test",
+ ],
+ ],
+ ];
+ }
+}