Skip to content

Commit

Permalink
Transmit User and Lang to the PageParseJob instead of ParserOptions
Browse files Browse the repository at this point in the history
ParserOptions is not properly serializable, so instantiation of the PageParseJob may fail.
Solution: Recreate ParserOptions from User and Language
  • Loading branch information
s7eph4n committed Sep 22, 2016
1 parent 5693c92 commit 9cac683
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
19 changes: 12 additions & 7 deletions PageParseJob.php
Expand Up @@ -25,10 +25,11 @@
namespace PurgePage;

use Job;
use Parser;
use Language;
use ParserOptions;
use PoolWorkArticleView;
use Title;
use WikiPage;

/**
* Class PageParseJob
Expand All @@ -38,7 +39,8 @@
*/
class PageParseJob extends Job {

private $mParserOptions;
private $user;
private $language;

/**
* Callers should use DuplicateJob::newFromJob() instead
Expand All @@ -47,9 +49,10 @@ class PageParseJob extends Job {
* @param array $params Job parameters
*/
public function __construct( Title $title, array $params ) {
parent::__construct( 'pageParse', $title, $params );
parent::__construct( 'parsePage', $title, $params );

$this->mParserOptions = isset( $params[ 'parseroptions' ] ) ? $params[ 'parseroptions' ] : new ParserOptions();
$this->user = isset( $params[ 'user' ] ) ? $params[ 'user' ] : null;
$this->language = isset( $params[ 'lang' ] ) ? Language::factory( $params[ 'lang' ] ) : null;

// this does NOT protect against recursion, it only discards duplicate
// calls to {{#purge}} on the same page
Expand All @@ -64,10 +67,12 @@ public function run() {

$title = $this->getTitle();

if ( $title->isContentPage() && $title->exists() ) {
if ( $title !== null && $title->isContentPage() && $title->exists() ) {

$wikiPage = \WikiPage::factory( $title );
$pool = new PoolWorkArticleView( $wikiPage, $this->mParserOptions, $wikiPage->getLatest(), false );
$wikiPage = WikiPage::factory( $title );
$parserOptions = new ParserOptions( $this->user, $this->language );

$pool = new PoolWorkArticleView( $wikiPage, $parserOptions, $wikiPage->getLatest(), false );
$pool->execute();
}

Expand Down
15 changes: 11 additions & 4 deletions PurgePage.php
Expand Up @@ -2,7 +2,9 @@

namespace PurgePage;

use PoolWorkArticleView;
use Job;
use JobQueueGroup;
use Title;

class PurgePage {

Expand All @@ -22,10 +24,15 @@ public static function registerParserFunction( \Parser &$parser ) {
$parser = $params[ 0 ];
$pageName = $params[ 1 ];

$title = \Title::newFromText( $pageName );
$job = \Job::factory( 'parsePage', $title, [ 'parseroptions' => $parser->getOptions() ] );
$title = Title::newFromText( $pageName );

if ( $title !== null && $title->isContentPage() && $title->exists() ) {
/** @var \ParserOptions $parserOptions */
$parserOptions = $parser->getOptions();
$job = Job::factory( 'parsePage', $title, [ 'user' => $parserOptions->getUser(), 'lang' => $parserOptions->getUserLang() ] );
JobQueueGroup::singleton()->lazyPush( $job );
}

\JobQueueGroup::singleton()->lazyPush( [ $job ] );

}

Expand Down

0 comments on commit 9cac683

Please sign in to comment.