Index: trunk/extensions/SemanticForms/includes/SF_CreatePageJob.php |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Background job to create a new page, for use by the 'CreateClass' special page |
| 6 | + * |
| 7 | + * @author Yaron Koren |
| 8 | + */ |
| 9 | +class SFCreatePageJob extends Job { |
| 10 | + |
| 11 | + function __construct( $title, $params = '', $id = 0 ) { |
| 12 | + parent::__construct( 'createPage', $title, $params, $id ); |
| 13 | + } |
| 14 | + |
| 15 | + /** |
| 16 | + * Run a createPage job |
| 17 | + * @return boolean success |
| 18 | + */ |
| 19 | + function run() { |
| 20 | + wfProfileIn( __METHOD__ ); |
| 21 | + |
| 22 | + if ( is_null( $this->title ) ) { |
| 23 | + $this->error = "createPage: Invalid title"; |
| 24 | + wfProfileOut( __METHOD__ ); |
| 25 | + return false; |
| 26 | + } |
| 27 | + $article = new Article($this->title); |
| 28 | + if ( !$article ) { |
| 29 | + $this->error = 'createPage: Article not found "' . $this->title->getPrefixedDBkey() . '"'; |
| 30 | + wfProfileOut( __METHOD__ ); |
| 31 | + return false; |
| 32 | + } |
| 33 | + |
| 34 | + $page_text = $this->params['page_text']; |
| 35 | + // change global $wgUser variable to the one |
| 36 | + // specified by the job only for the extent of this |
| 37 | + // replacement |
| 38 | + global $wgUser; |
| 39 | + $actual_user = $wgUser; |
| 40 | + $wgUser = User::newFromId($this->params['user_id']); |
| 41 | + $edit_summary = ''; //$this->params['edit_summary']; |
| 42 | + $article->doEdit($page_text, $edit_summary); |
| 43 | + $wgUser = $actual_user; |
| 44 | + wfProfileOut( __METHOD__ ); |
| 45 | + return true; |
| 46 | + } |
| 47 | +} |
| 48 | + |