Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PFCreatePageJob | |
0.00% |
0 / 24 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
createOrModifyPage | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * |
4 | * @file |
5 | * @ingroup PF |
6 | */ |
7 | |
8 | use MediaWiki\MediaWikiServices; |
9 | |
10 | /** |
11 | * Background job to create a new page, for use by the 'CreateClass' special |
12 | * page. |
13 | * |
14 | * @author Yaron Koren |
15 | * @ingroup PF |
16 | */ |
17 | class PFCreatePageJob extends Job { |
18 | |
19 | function __construct( Title $title, array $params ) { |
20 | parent::__construct( 'pageFormsCreatePage', $title, $params ); |
21 | $this->removeDuplicates = true; |
22 | } |
23 | |
24 | /** |
25 | * Run a pageFormsCreatePage job |
26 | * @return bool success |
27 | */ |
28 | function run() { |
29 | if ( $this->title === null ) { |
30 | $this->error = "pageFormsCreatePage: Invalid title"; |
31 | return false; |
32 | } |
33 | |
34 | try { |
35 | $wikiPage = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $this->title ); |
36 | } catch ( MWException $e ) { |
37 | $this->error = 'pageFormsCreatePage: Wiki page not found "' . $this->title->getPrefixedDBkey() . '"'; |
38 | return false; |
39 | } |
40 | |
41 | $pageText = $this->params['page_text']; |
42 | if ( array_key_exists( 'edit_summary', $this->params ) ) { |
43 | $editSummary = $this->params['edit_summary']; |
44 | } else { |
45 | $editSummary = ''; |
46 | } |
47 | $user = User::newFromId( $this->params['user_id'] ); |
48 | |
49 | self::createOrModifyPage( $wikiPage, $pageText, $editSummary, $user ); |
50 | |
51 | return true; |
52 | } |
53 | |
54 | public static function createOrModifyPage( $wikiPage, $pageText, $editSummary, $user ) { |
55 | $newContent = new WikitextContent( $pageText ); |
56 | |
57 | // It's strange that doEditContent() doesn't automatically |
58 | // attach the 'bot' flag when the user is a bot... |
59 | // @TODO - is all this code still necessary? |
60 | $flags = 0; |
61 | $permissionManager = MediaWikiServices::getInstance()->getPermissionManager(); |
62 | if ( $permissionManager->userHasRight( $user, 'bot' ) ) { |
63 | $flags = EDIT_FORCE_BOT; |
64 | } |
65 | |
66 | $updater = $wikiPage->newPageUpdater( $user ); |
67 | $updater->setContent( MediaWiki\Revision\SlotRecord::MAIN, $newContent ); |
68 | $updater->saveRevision( CommentStoreComment::newUnsavedComment( $editSummary ), $flags ); |
69 | } |
70 | |
71 | } |