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' );
50 $updates = $parserOutput->getLinksUpdateAndOtherUpdates( $this->title
, false );
51 SecondaryDataUpdate
::runUpdates( $updates );
53 wfProfileOut( __METHOD__
.'-update' );
54 wfProfileOut( __METHOD__
);
60 * Background job to update links for a given title.
61 * Newer version for high use templates.
65 class RefreshLinksJob2
extends Job
{
67 function __construct( $title, $params, $id = 0 ) {
68 parent
::__construct( 'refreshLinks2', $title, $params, $id );
72 * Run a refreshLinks2 job
73 * @return boolean success
76 global $wgParser, $wgContLang;
78 wfProfileIn( __METHOD__
);
80 $linkCache = LinkCache
::singleton();
83 if( is_null( $this->title
) ) {
84 $this->error
= "refreshLinks2: Invalid title";
85 wfProfileOut( __METHOD__
);
88 if( !isset($this->params
['start']) ||
!isset($this->params
['end']) ) {
89 $this->error
= "refreshLinks2: Invalid params";
90 wfProfileOut( __METHOD__
);
93 // Back compat for pre-r94435 jobs
94 $table = isset( $this->params
['table'] ) ?
$this->params
['table'] : 'templatelinks';
95 $titles = $this->title
->getBacklinkCache()->getLinks(
96 $table, $this->params
['start'], $this->params
['end']);
98 # Not suitable for page load triggered job running!
99 # Gracefully switch to refreshLinks jobs if this happens.
100 if( php_sapi_name() != 'cli' ) {
102 foreach ( $titles as $title ) {
103 $jobs[] = new RefreshLinksJob( $title, '' );
105 Job
::batchInsert( $jobs );
107 wfProfileOut( __METHOD__
);
110 $options = ParserOptions
::newFromUserAndLang( new User
, $wgContLang );
111 # Re-parse each page that transcludes this page and update their tracking links...
112 foreach ( $titles as $title ) {
113 $revision = Revision
::newFromTitle( $title );
115 $this->error
= 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
116 wfProfileOut( __METHOD__
);
119 wfProfileIn( __METHOD__
.'-parse' );
120 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
121 wfProfileOut( __METHOD__
.'-parse' );
122 wfProfileIn( __METHOD__
.'-update' );
124 $updates = $parserOutput->getLinksUpdateAndOtherUpdates( $title, false );
125 SecondaryDataUpdate
::runUpdates( $updates );
127 wfProfileOut( __METHOD__
.'-update' );
130 wfProfileOut( __METHOD__
);