mirror of
https://github.com/Universal-Omega/DynamicPageList3
synced 2024-12-04 20:48:35 +00:00
86 lines
2.3 KiB
PHP
86 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* DynamicPageList3
|
|
* CreateTemplateUpdateMaintenance
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
* @package DynamicPageList3
|
|
*
|
|
**/
|
|
|
|
namespace DPL\DB;
|
|
|
|
use CommentStoreComment;
|
|
use LoggedUpdateMaintenance;
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
use MediaWiki\Revision\SlotRecord;
|
|
use Title;
|
|
use User;
|
|
use WikiPage;
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
if ( $IP === false ) {
|
|
$IP = __DIR__ . '/../../../..';
|
|
}
|
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
|
|
|
/*
|
|
* Creates the DPL template when updating.
|
|
*/
|
|
class CreateTemplateUpdateMaintenance extends LoggedUpdateMaintenance {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->addDescription( 'Handle inserting DPL\'s necessary template for content inclusion.' );
|
|
}
|
|
|
|
/**
|
|
* Get the unique update key for this logged update.
|
|
*
|
|
* @return string
|
|
*/
|
|
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.
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function doDBUpdates() {
|
|
$title = Title::newFromText( 'Extension DPL', NS_TEMPLATE );
|
|
|
|
// Make sure template does not already exist
|
|
if ( !$title->exists() ) {
|
|
$wikipage = WikiPage::factory( $title );
|
|
$updater = $wikipage->newPageUpdater( User::newSystemUser( 'DynamicPageList3 Extension' ) );
|
|
$content = $wikipage->getContentHandler()->makeContent( '<noinclude>This page was automatically created. It serves as an anchor page for all \'\'\'[[Special:WhatLinksHere/Template:Extension_DPL|invocations]]\'\'\' of [https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:DynamicPageList3 Extension:DynamicPageList3].</noinclude>', $title );
|
|
$this->output( "{$content}\n");
|
|
$updater->setContent( SlotRecord::MAIN, $content );
|
|
$comment = CommentStoreComment::newUnsavedComment( 'Autogenerated DPL\'s necessary template for content inclusion' );
|
|
$this->output( "{$comment}\n");
|
|
$updater->saveRevision(
|
|
$comment,
|
|
EDIT_NEW | EDIT_FORCE_BOT
|
|
);
|
|
$this->output( "{$updater}\n");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
$maintClass = CreateTemplateUpdateMaintenance::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|