2020-11-22 20:01:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* DynamicPageList3
|
|
|
|
* CreateTemplateUpdateMaintenance
|
|
|
|
*
|
2021-01-23 20:32:43 +00:00
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
* @package DynamicPageList3
|
2020-11-22 20:01:28 +00:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
namespace DPL\DB;
|
|
|
|
|
2021-01-23 20:55:26 +00:00
|
|
|
use CommentStoreComment;
|
2020-11-22 20:01:28 +00:00
|
|
|
use LoggedUpdateMaintenance;
|
2021-01-23 20:55:26 +00:00
|
|
|
use RevisionRecord;
|
|
|
|
use SlotRecord;
|
2020-11-22 20:01:28 +00:00
|
|
|
use Title;
|
2021-01-23 20:55:26 +00:00
|
|
|
use User;
|
2020-11-22 20:01:28 +00:00
|
|
|
use WikiPage;
|
2021-01-22 21:25:34 +00:00
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
|
|
|
$IP = __DIR__ . '/../../../..';
|
|
|
|
}
|
2021-01-23 20:27:50 +00:00
|
|
|
|
2021-01-22 21:25:34 +00:00
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
|
|
|
|
2020-11-22 20:01:28 +00:00
|
|
|
/*
|
|
|
|
* Creates the DPL template when updating.
|
|
|
|
*/
|
|
|
|
class CreateTemplateUpdateMaintenance extends LoggedUpdateMaintenance {
|
2021-01-23 20:27:50 +00:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->addDescription( 'Handle inserting DPL\'s necessary template for content inclusion.' );
|
|
|
|
}
|
|
|
|
|
2020-11-22 20:01:28 +00:00
|
|
|
/**
|
2021-01-23 20:27:50 +00:00
|
|
|
* Get the unique update key for this logged update.
|
2020-11-22 20:01:28 +00:00
|
|
|
*
|
2021-01-23 20:32:43 +00:00
|
|
|
* @return string
|
2021-01-23 20:27:50 +00:00
|
|
|
*/
|
|
|
|
protected function getUpdateKey() {
|
|
|
|
return 'dynamic-page-list-create-template';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Message to show that the update was done already and was just skipped
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function updateSkippedMessage() {
|
|
|
|
return 'Template already created.';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle inserting DPL's necessary template for content inclusion.
|
|
|
|
*
|
2021-01-23 20:55:26 +00:00
|
|
|
* @return bool
|
2020-11-22 20:01:28 +00:00
|
|
|
*/
|
|
|
|
protected function doDBUpdates() {
|
2021-01-23 20:55:26 +00:00
|
|
|
$title = Title::newFromText( 'Template:Extension DPL' );
|
2020-11-22 20:01:28 +00:00
|
|
|
|
2021-01-23 20:55:26 +00:00
|
|
|
// Make sure template does not already exist
|
2021-01-23 20:27:50 +00:00
|
|
|
if ( !$title->exists() ) {
|
2021-01-23 20:55:26 +00:00
|
|
|
$wikipage = WikiPage::factory( $title );
|
|
|
|
$updater = $wikipage->newPageUpdater( User::newSystemUser( 'DynamicPageList3 Extension' ) );
|
|
|
|
$content = $wikipage->getContentHandler()->makeContent( '', $title );
|
|
|
|
$updater->setContent( SlotRecord::MAIN, $content );
|
|
|
|
$comment = CommentStoreComment::newUnsavedComment( 'Autogenerated DPL\'s necessary template for content inclusion' );
|
|
|
|
$newRevision = $updater->saveRevision( $comment );
|
|
|
|
|
|
|
|
if ( $newRevision instanceof RevisionRecord ) {
|
|
|
|
$this->output( "done.\n" );
|
|
|
|
} else {
|
|
|
|
$this->output( "error.\n" );
|
|
|
|
}
|
2021-01-23 20:27:50 +00:00
|
|
|
}
|
2021-01-23 20:42:16 +00:00
|
|
|
|
|
|
|
return true;
|
2020-11-22 20:01:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-22 21:25:34 +00:00
|
|
|
|
|
|
|
$maintClass = CreateTemplateUpdateMaintenance::class;
|
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|