Last active
June 6, 2019 14:15
-
-
Save ochaochaocha3/6d40d0f7666d85431450c51375b939e4 to your computer and use it in GitHub Desktop.
MediaWikiのページをStructured Discussionsボードに変換するメンテナンススクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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