2020-11-22 20:01:28 +00:00
< ? php
2022-03-13 19:57:34 +00:00
namespace MediaWiki\Extension\DynamicPageList3\Maintenance ;
2020-11-22 20:01:28 +00:00
2021-01-23 20:55:26 +00:00
use CommentStoreComment ;
2020-11-22 20:01:28 +00:00
use LoggedUpdateMaintenance ;
2021-10-01 22:52:30 +00:00
use MediaWiki\MediaWikiServices ;
2021-01-23 21:31:13 +00:00
use MediaWiki\Revision\SlotRecord ;
2020-11-22 20:01:28 +00:00
use Title ;
2021-01-23 20:55:26 +00:00
use User ;
2021-01-22 21:25:34 +00:00
$IP = getenv ( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
2022-01-28 17:07:16 +00:00
$IP = __DIR__ . '/../../..' ;
2021-01-22 21:25:34 +00:00
}
2021-01-23 20:27:50 +00:00
2021-01-22 21:25:34 +00:00
require_once " $IP /maintenance/Maintenance.php " ;
2021-03-16 22:39:18 +00:00
class CreateTemplate extends LoggedUpdateMaintenance {
2021-01-23 20:27:50 +00:00
public function __construct () {
parent :: __construct ();
2021-10-01 22:52:30 +00:00
2022-04-14 17:50:05 +00:00
$this -> addDescription ( 'Handle inserting DynamicPageList3\'s necessary template for content inclusion.' );
2021-01-23 20:27:50 +00:00
}
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 () {
2022-04-14 17:50:05 +00:00
return 'dynamic-page-list-3-create-template' ;
2021-01-23 20:27:50 +00:00
}
/**
* Message to show that the update was done already and was just skipped
*
* @ return string
*/
protected function updateSkippedMessage () {
return 'Template already created.' ;
}
/**
2022-04-14 17:50:05 +00:00
* Handle inserting DynamicPageList3 ' s necessary template for content inclusion .
2021-01-23 20:27:50 +00:00
*
2021-01-23 20:55:26 +00:00
* @ return bool
2020-11-22 20:01:28 +00:00
*/
protected function doDBUpdates () {
2021-01-23 23:48:02 +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 22:50:14 +00:00
if ( ! $title -> exists () ) {
2022-01-28 17:06:58 +00:00
$services = MediaWikiServices :: getInstance ();
2022-12-07 00:10:46 +00:00
$wikiPageFactory = $services -> getWikiPageFactory ();
$page = $wikiPageFactory -> newFromTitle ( $title );
2021-10-01 22:52:30 +00:00
$updater = $page -> newPageUpdater ( User :: newSystemUser ( 'DynamicPageList3 extension' ) );
$content = $page -> 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 );
2021-01-23 20:55:26 +00:00
$updater -> setContent ( SlotRecord :: MAIN , $content );
2022-04-14 17:50:05 +00:00
$comment = CommentStoreComment :: newUnsavedComment ( 'Autogenerated DynamicPageList3\'s necessary template for content inclusion.' );
2021-10-01 22:52:30 +00:00
2021-01-23 21:57:22 +00:00
$updater -> saveRevision (
2021-01-23 23:48:02 +00:00
$comment ,
EDIT_NEW | EDIT_FORCE_BOT
2021-01-23 21:07:02 +00:00
);
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
2021-03-16 22:39:18 +00:00
$maintClass = CreateTemplate :: class ;
2021-01-22 21:25:34 +00:00
require_once RUN_MAINTENANCE_IF_MAIN ;