r90064 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90063‎ | r90064 | r90065 >
Date:18:02, 14 June 2011
Author:ankitgarg833
Status:deferred (Comments)
Tags:
Comment:
Adding the Create page Job class.
Modified paths:
  • /trunk/extensions/PageSchemas/PS_CreatePageJob.php (added) (history)

Diff [purge]

Index: trunk/extensions/PageSchemas/PS_CreatePageJob.php
@@ -0,0 +1,47 @@
 2+<?php
 3+
 4+/**
 5+ * Background job to create a new property page,
 6+ *
 7+ * @author ankit garg
 8+ */
 9+class PSCreatePageJob 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+

Comments

#Comment by Nikerabbit (talk | contribs)   18:49, 14 June 2011

Article constructor needs zero as second parameter.

+                $article = new Article( $this->title );

doEdit nowdays takes user as parameter - use it instead of the global

+		global $wgUser;

Status & tagging log