Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
PageCreation | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | namespace MediaWiki\Extension\MathSearch\Graph\Job; |
3 | |
4 | use ContentHandler; |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\Title\Title; |
7 | use Throwable; |
8 | use Wikibase\DataModel\Entity\ItemId; |
9 | use Wikibase\DataModel\SiteLink; |
10 | use Wikibase\Repo\WikibaseRepo; |
11 | |
12 | class PageCreation extends GraphJob { |
13 | public function __construct( $params ) { |
14 | parent::__construct( 'CreateProfilePages', $params ); |
15 | } |
16 | |
17 | public function run(): bool { |
18 | $user = $this->getUser(); |
19 | |
20 | $store = WikibaseRepo::getEntityStore(); |
21 | $lookup = WikibaseRepo::getEntityLookup(); |
22 | $pageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); |
23 | foreach ( $this->params['rows'] as $qid ) { |
24 | try { |
25 | self::getLog()->info( "Creating page $qid." ); |
26 | $title = Title::newFromText( $this->params['prefix'] . ':' . $qid ); |
27 | $pageContent = ContentHandler::makeContent( |
28 | '{{' . $this->params['prefix'] . '}}', $title ); |
29 | $pageFactory->newFromTitle( $title ) |
30 | ->doUserEditContent( $pageContent, $user, |
31 | 'Created automatically from ' . $this->params['jobname'] ); |
32 | $item = $lookup->getEntity( ItemId::newFromNumber( $qid ) ); |
33 | if ( $this->params['overwrite'] ) { |
34 | $item->removeSiteLink( 'mardi' ); |
35 | } |
36 | $siteLink = new SiteLink( 'mardi', $title->getPrefixedText() ); |
37 | $item->addSiteLink( $siteLink ); |
38 | self::getLog()->info( "Linking page $qid." ); |
39 | $store->saveEntity( $item, "Added link to MaRDI item.", $user, EDIT_FORCE_BOT ); |
40 | } catch ( Throwable $ex ) { |
41 | self::getLog()->error( "Skip page processing page Q$qid.", [ $ex ] ); |
42 | } |
43 | } |
44 | |
45 | return true; |
46 | } |
47 | |
48 | } |