Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MediaWikiのページをStructured Discussionsボードに変換するメンテナンススクリプト
<?php
require_once __DIR__ . '/maintenance/Maintenance.php';
/**
* ページを Structured Discussions ボードに変換する。
*/
class ConvertPageToSDBoard extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = "ページを Structured Discussions ボードに変換します";
$this->addArg( 'pageName', '変換するページの名前' );
$this->requireExtension( 'Flow' );
}
public function execute() {
global $wgParser;
$provided = $this->getArg( 0 );
// @todo send to prod logger?
$logger = new MaintenanceDebugLogger( $this );
$pageTitle = Title::newFromText( $provided );
if ( !$pageTitle ) {
$logger->critical( "ページ「${provided}」が見つかりません" );
exit( 1 );
}
$dbw = wfGetDB( DB_MASTER );
$talkpageManager = FlowHooks::getOccupationController()->getTalkpageManager();
$converter = new \Flow\Import\Converter(
$dbw,
Flow\Container::get( 'importer' ),
$logger,
$talkpageManager,
new Flow\Import\EnableFlow\EnableFlowWikitextConversionStrategy(
$wgParser,
new Flow\Import\SourceStore\NullImportSourceStore(),
$logger,
$talkpageManager
)
);
$logger->info( "ページ「${provided}」の変換を開始します" );
try {
$converter->convert( $pageTitle );
} catch ( \Exception $e ) {
$logger->critical( "変換失敗: " . $e->getMessage() );
exit( 1 );
}
$logger->info( "ページ「${provided}」の変換が完了しました" );
}
}
$maintClass = "ConvertPageToSDBoard";
require_once RUN_MAINTENANCE_IF_MAIN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment