User:Addshore/2018/10/DC Switch Issue/code

Generic script (only actually used for ns 0...

<?php

$file = file_get_contents(  __DIR__ .'/input.txt');
$lines = explode( "\n", $file );

$output = '';
$lastPageTitle = null;
$rawLinesForThisTitle = [];

foreach ( $lines as $line ) {
	$parts = explode( '|', $line );
	$parts = array_filter( $parts, function ($value){ return trim($value) !== ''; } );
	$parts = array_map( 'trim', $parts );

	$pageTitle = $parts[2];
	$revId = $parts[4];

	if( $lastPageTitle !== $pageTitle ) {
		// new page title...
		$output .= '<pre>' . PHP_EOL . implode( "\n", $rawLinesForThisTitle ) . PHP_EOL . '</pre>' . PHP_EOL;
		$output .= '=={{Q|' . $pageTitle . '}}==' . PHP_EOL;
		$rawLinesForThisTitle = [];
	}

	$lastPageTitle = $pageTitle;
	$rawLinesForThisTitle[] = $line;

	$output .= '* ' . '{{diff|diff=' . $revId . '}}' . PHP_EOL;
}

file_put_contents( __DIR__ . '/output.txt', $output );