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
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 = new ParserOptions
;
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
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 $titles = $this->title
->getBacklinkCache()->getLinks(
92 'templatelinks', $this->params
['start'], $this->params
['end']);
94 # Not suitable for page load triggered job running!
95 # Gracefully switch to refreshLinks jobs if this happens.
96 if( php_sapi_name() != 'cli' ) {
98 foreach ( $titles as $title ) {
99 $jobs[] = new RefreshLinksJob( $title, '' );
101 Job
::batchInsert( $jobs );
103 wfProfileOut( __METHOD__
);
106 # Re-parse each page that transcludes this page and update their tracking links...
107 foreach ( $titles as $title ) {
108 $revision = Revision
::newFromTitle( $title );
110 $this->error
= 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
111 wfProfileOut( __METHOD__
);
114 wfProfileIn( __METHOD__
.'-parse' );
115 $options = new ParserOptions
;
116 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
117 wfProfileOut( __METHOD__
.'-parse' );
118 wfProfileIn( __METHOD__
.'-update' );
119 $update = new LinksUpdate( $title, $parserOutput, false );
121 wfProfileOut( __METHOD__
.'-update' );
122 wfWaitForSlaves( 5 );
124 wfProfileOut( __METHOD__
);