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