Skip to content

Commit

Permalink
Merge branch 'master' into phan-MediaWikiNoEmptyIfDefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Universal-Omega authored Feb 7, 2025
2 parents 1073fc0 + c30cb8f commit fc7f942
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 55 deletions.
7 changes: 2 additions & 5 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@
"ExtensionMessagesFiles": {
"DynamicPageList3Magic": "DynamicPageList3Magic.php"
},
"AutoloadClasses": {
"MediaWiki\\Extension\\DynamicPageList3\\Maintenance\\CreateTemplate": "maintenance/createTemplate.php",
"MediaWiki\\Extension\\DynamicPageList3\\Maintenance\\CreateView": "maintenance/createView.php"
},
"AutoloadNamespaces": {
"MediaWiki\\Extension\\DynamicPageList3\\": "includes/"
"MediaWiki\\Extension\\DynamicPageList3\\": "includes/",
"MediaWiki\\Extension\\DynamicPageList3\\Maintenance\\": "maintenance/"
},
"TestAutoloadNamespaces": {
"MediaWiki\\Extension\\DynamicPageList3\\Tests\\": "tests/phpunit/"
Expand Down
27 changes: 11 additions & 16 deletions maintenance/createTemplate.php → maintenance/CreateTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@

namespace MediaWiki\Extension\DynamicPageList3\Maintenance;

use LoggedUpdateMaintenance;
$IP ??= getenv( 'MW_INSTALL_PATH' ) ?: dirname( __DIR__, 3 );
require_once "$IP/maintenance/Maintenance.php";

use MediaWiki\CommentStore\CommentStoreComment;
use MediaWiki\MediaWikiServices;
use MediaWiki\Maintenance\LoggedUpdateMaintenance;
use MediaWiki\Revision\SlotRecord;
use MediaWiki\Title\Title;
use MediaWiki\User\User;

$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}

require_once "$IP/maintenance/Maintenance.php";

class CreateTemplate extends LoggedUpdateMaintenance {

public function __construct() {
parent::__construct();

$this->addDescription( 'Handle inserting DynamicPageList3\'s necessary template for content inclusion.' );
$this->requireExtension( 'DynamicPageList3' );
}

/**
* Get the unique update key for this logged update.
*
* @return string
*/
protected function getUpdateKey() {
protected function getUpdateKey(): string {
return 'dynamic-page-list-3-create-template';
}

Expand All @@ -38,7 +33,7 @@ protected function getUpdateKey() {
*
* @return string
*/
protected function updateSkippedMessage() {
protected function updateSkippedMessage(): string {
return 'Template already created.';
}

Expand All @@ -47,13 +42,13 @@ protected function updateSkippedMessage() {
*
* @return bool
*/
protected function doDBUpdates() {
$title = Title::newFromText( 'Template:Extension DPL' );
protected function doDBUpdates(): bool {
$title = $this->getServiceContainer()->getTitleFactory()
->newFromText( 'Template:Extension DPL' );

// Make sure template does not already exist
if ( !$title->exists() ) {
$services = MediaWikiServices::getInstance();
$wikiPageFactory = $services->getWikiPageFactory();
$wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory();
$page = $wikiPageFactory->newFromTitle( $title );

$updater = $page->newPageUpdater( User::newSystemUser( 'DynamicPageList3 extension' ) );
Expand Down
15 changes: 7 additions & 8 deletions maintenance/createView.php → maintenance/CreateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace MediaWiki\Extension\DynamicPageList3\Maintenance;

use Exception;
use LoggedUpdateMaintenance;

$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
$IP = __DIR__ . '/../../..';
}

$IP ??= getenv( 'MW_INSTALL_PATH' ) ?: dirname( __DIR__, 3 );
require_once "$IP/maintenance/Maintenance.php";

use Exception;
use MediaWiki\Maintenance\LoggedUpdateMaintenance;

class CreateView extends LoggedUpdateMaintenance {

public function __construct() {
parent::__construct();

$this->addDescription( 'Handle creating DPL3\'s dpl_clview VIEW.' );
$this->addOption( 'recreate', 'Drop and recreate the view if it already exists', false, false );

$this->requireExtension( 'DynamicPageList3' );
}

/**
Expand Down
33 changes: 7 additions & 26 deletions tests/phpunit/DPLIntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ abstract class DPLIntegrationTestCase extends MediaWikiIntegrationTestCase {
/** @var Status */
private $importStreamSource;

/**
* Guard condition to ensure we only import seed data once per test suite run.
* Only used before 1.42 as it breaks on 1.42 if not running for each test
*
* @var bool
*/
private static $wasSeedDataImported = false;

protected function setUp(): void {
parent::setUp();

Expand All @@ -37,25 +29,14 @@ protected function setUp(): void {
}

private function doImport(): void {
$file = dirname( __DIR__ ) . '/seed-data.xml';
$this->seedTestUsers( $file );

$services = $this->getServiceContainer();
if ( version_compare( MW_VERSION, '1.42', '>=' ) ) {
$file = dirname( __DIR__ ) . '/seed-data.xml';
$this->seedTestUsers( $file );
$importer = $services->getWikiImporterFactory()->getWikiImporter(
$this->importStreamSource->value,
$this->getTestSysop()->getAuthority()
);
} else {
if ( self::$wasSeedDataImported ) {
return;
}
self::$wasSeedDataImported = true;
$file = dirname( __DIR__ ) . '/seed-data.xml';
$this->seedTestUsers( $file );
$importer = $services->getWikiImporterFactory()->getWikiImporter(
$this->importStreamSource->value
);
}
$importer = $services->getWikiImporterFactory()->getWikiImporter(
$this->importStreamSource->value,
$this->getTestSysop()->getAuthority()
);

$importer->disableStatisticsUpdate();

Expand Down

0 comments on commit fc7f942

Please sign in to comment.