4 * Background job to update links for a given title.
8 class RefreshLinksJob
extends Job
{
10 function __construct( $title, $params = '', $id = 0 ) {
11 parent
::__construct( 'refreshLinks', $title, $params, $id );
15 * Run a refreshLinks job
16 * @return boolean success
20 wfProfileIn( __METHOD__
);
22 $linkCache = LinkCache
::singleton();
25 if ( is_null( $this->title
) ) {
26 $this->error
= "refreshLinks: Invalid title";
27 wfProfileOut( __METHOD__
);
31 $revision = Revision
::newFromTitle( $this->title
);
33 $this->error
= 'refreshLinks: Article not found "' . $this->title
->getPrefixedDBkey() . '"';
34 wfProfileOut( __METHOD__
);
38 wfProfileIn( __METHOD__
.'-parse' );
39 $options = new ParserOptions
;
40 $parserOutput = $wgParser->parse( $revision->getText(), $this->title
, $options, true, true, $revision->getId() );
41 wfProfileOut( __METHOD__
.'-parse' );
42 wfProfileIn( __METHOD__
.'-update' );
43 $update = new LinksUpdate( $this->title
, $parserOutput, false );
45 wfProfileOut( __METHOD__
.'-update' );
46 wfProfileOut( __METHOD__
);
52 * Background job to update links for a given title.
53 * Newer version for high use templates.
57 class RefreshLinksJob2
extends Job
{
59 function __construct( $title, $params, $id = 0 ) {
60 parent
::__construct( 'refreshLinks2', $title, $params, $id );
64 * Run a refreshLinks2 job
65 * @return boolean success
70 wfProfileIn( __METHOD__
);
72 $linkCache = LinkCache
::singleton();
75 if( is_null( $this->title
) ) {
76 $this->error
= "refreshLinks2: Invalid title";
77 wfProfileOut( __METHOD__
);
80 if( !isset($this->params
['start']) ||
!isset($this->params
['end']) ) {
81 $this->error
= "refreshLinks2: Invalid params";
82 wfProfileOut( __METHOD__
);
85 $titles = $this->title
->getBacklinkCache()->getLinks(
86 'templatelinks', $this->params
['start'], $this->params
['end']);
88 # Not suitable for page load triggered job running!
89 # Gracefully switch to refreshLinks jobs if this happens.
90 if( php_sapi_name() != 'cli' ) {
92 foreach ( $titles as $title ) {
93 $jobs[] = new RefreshLinksJob( $title, '' );
95 Job
::batchInsert( $jobs );
98 # Re-parse each page that transcludes this page and update their tracking links...
99 foreach ( $titles as $title ) {
100 $revision = Revision
::newFromTitle( $title );
102 $this->error
= 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
103 wfProfileOut( __METHOD__
);
106 wfProfileIn( __METHOD__
.'-parse' );
107 $options = new ParserOptions
;
108 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
109 wfProfileOut( __METHOD__
.'-parse' );
110 wfProfileIn( __METHOD__
.'-update' );
111 $update = new LinksUpdate( $title, $parserOutput, false );
113 wfProfileOut( __METHOD__
.'-update' );
114 wfWaitForSlaves( 5 );
116 wfProfileOut( __METHOD__
);