Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SeedMapframePage | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 4 | if ( $IP === false ) { |
| 5 | $IP = __DIR__ . '/../../..'; |
| 6 | } |
| 7 | require_once "$IP/maintenance/Maintenance.php"; |
| 8 | |
| 9 | use MediaWiki\CommentStore\CommentStoreComment; |
| 10 | use MediaWiki\Content\ContentHandler; |
| 11 | use MediaWiki\Content\TextContent; |
| 12 | use MediaWiki\Maintenance\Maintenance; |
| 13 | use MediaWiki\Revision\SlotRecord; |
| 14 | use MediaWiki\Title\Title; |
| 15 | use MediaWiki\User\User; |
| 16 | |
| 17 | /** |
| 18 | * Seeds a development page with a sample <mapframe> tag for Kartographer. |
| 19 | * |
| 20 | * @license MIT |
| 21 | */ |
| 22 | class SeedMapframePage extends Maintenance { |
| 23 | private const PAGE_TITLE = 'Extension/Kartographer/Mapframe'; |
| 24 | private const PAGE_CONTENT = |
| 25 | '<mapframe text="[[wikipedia:Stockholm|Stockholm]] in Wikipedia" ' . |
| 26 | 'width=250 height=250 zoom=7 latitude="59" longitude="18" />'; |
| 27 | private const EDIT_SUMMARY = 'Seed Kartographer mapframe development content'; |
| 28 | |
| 29 | public function __construct() { |
| 30 | parent::__construct(); |
| 31 | $this->addDescription( 'Create or reset a development page containing a sample <mapframe> tag.' ); |
| 32 | $this->requireExtension( 'Kartographer' ); |
| 33 | } |
| 34 | |
| 35 | /** @inheritDoc */ |
| 36 | public function execute() { |
| 37 | $title = Title::newFromText( self::PAGE_TITLE ); |
| 38 | if ( !$title ) { |
| 39 | $this->fatalError( 'Invalid title: ' . self::PAGE_TITLE ); |
| 40 | } |
| 41 | |
| 42 | $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [ 'steal' => true ] ); |
| 43 | if ( !$user ) { |
| 44 | $this->fatalError( 'Failed to initialize maintenance script user.' ); |
| 45 | } |
| 46 | |
| 47 | $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 48 | $existingRevision = $page->getRevisionRecord(); |
| 49 | if ( $existingRevision ) { |
| 50 | $existingContent = $existingRevision->getContent( SlotRecord::MAIN ); |
| 51 | if ( $existingContent instanceof TextContent && $existingContent->getText() === self::PAGE_CONTENT ) { |
| 52 | $this->output( 'Page already has the expected content: ' . self::PAGE_TITLE . "\n" ); |
| 53 | return; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | $newContent = ContentHandler::makeContent( self::PAGE_CONTENT, $title ); |
| 58 | $updater = $page->newPageUpdater( $user ); |
| 59 | $updater->setContent( SlotRecord::MAIN, $newContent ); |
| 60 | $updater->saveRevision( CommentStoreComment::newUnsavedComment( self::EDIT_SUMMARY ) ); |
| 61 | |
| 62 | $status = $updater->getStatus(); |
| 63 | if ( !$status->isOK() ) { |
| 64 | $this->fatalError( $status ); |
| 65 | } |
| 66 | |
| 67 | if ( $existingRevision ) { |
| 68 | $this->output( 'Updated page content: ' . self::PAGE_TITLE . "\n" ); |
| 69 | } else { |
| 70 | $this->output( 'Created page: ' . self::PAGE_TITLE . "\n" ); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | $maintClass = SeedMapframePage::class; |
| 76 | require_once RUN_MAINTENANCE_IF_MAIN; |