3 * Job to update links for a given title.
10 * Background job to update links for a given title.
14 class RefreshLinksJob
extends Job
{
16 function __construct( $title, $params = '', $id = 0 ) {
17 parent
::__construct( 'refreshLinks', $title, $params, $id );
21 * Run a refreshLinks job
22 * @return boolean success
25 global $wgParser, $wgContLang;
26 wfProfileIn( __METHOD__
);
28 $linkCache = LinkCache
::singleton();
31 if ( is_null( $this->title
) ) {
32 $this->error
= "refreshLinks: Invalid title";
33 wfProfileOut( __METHOD__
);
37 $revision = Revision
::newFromTitle( $this->title
);
39 $this->error
= 'refreshLinks: Article not found "' . $this->title
->getPrefixedDBkey() . '"';
40 wfProfileOut( __METHOD__
);
44 wfProfileIn( __METHOD__
.'-parse' );
45 $options = ParserOptions
::newFromUserAndLang( new User
, $wgContLang );
46 $parserOutput = $wgParser->parse( $revision->getText(), $this->title
, $options, true, true, $revision->getId() );
47 wfProfileOut( __METHOD__
.'-parse' );
48 wfProfileIn( __METHOD__
.'-update' );
49 $update = new LinksUpdate( $this->title
, $parserOutput, false );
51 wfProfileOut( __METHOD__
.'-update' );
52 wfProfileOut( __METHOD__
);
58 * Background job to update links for a given title.
59 * Newer version for high use templates.
63 class RefreshLinksJob2
extends Job
{
65 function __construct( $title, $params, $id = 0 ) {
66 parent
::__construct( 'refreshLinks2', $title, $params, $id );
70 * Run a refreshLinks2 job
71 * @return boolean success
74 global $wgParser, $wgContLang;
76 wfProfileIn( __METHOD__
);
78 $linkCache = LinkCache
::singleton();
81 if( is_null( $this->title
) ) {
82 $this->error
= "refreshLinks2: Invalid title";
83 wfProfileOut( __METHOD__
);
86 if( !isset($this->params
['start']) ||
!isset($this->params
['end']) ) {
87 $this->error
= "refreshLinks2: Invalid params";
88 wfProfileOut( __METHOD__
);
91 // Back compat for pre-r94435 jobs
92 $table = isset( $this->params
['table'] ) ?
$this->params
['table'] : 'templatelinks';
93 $titles = $this->title
->getBacklinkCache()->getLinks(
94 $table, $this->params
['start'], $this->params
['end']);
96 # Not suitable for page load triggered job running!
97 # Gracefully switch to refreshLinks jobs if this happens.
98 if( php_sapi_name() != 'cli' ) {
100 foreach ( $titles as $title ) {
101 $jobs[] = new RefreshLinksJob( $title, '' );
103 Job
::batchInsert( $jobs );
105 wfProfileOut( __METHOD__
);
108 $options = ParserOptions
::newFromUserAndLang( new User
, $wgContLang );
109 # Re-parse each page that transcludes this page and update their tracking links...
110 foreach ( $titles as $title ) {
111 $revision = Revision
::newFromTitle( $title );
113 $this->error
= 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
114 wfProfileOut( __METHOD__
);
117 wfProfileIn( __METHOD__
.'-parse' );
118 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
119 wfProfileOut( __METHOD__
.'-parse' );
120 wfProfileIn( __METHOD__
.'-update' );
121 $update = new LinksUpdate( $title, $parserOutput, false );
123 wfProfileOut( __METHOD__
.'-update' );
126 wfProfileOut( __METHOD__
);