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 $start = intval($this->params
['start']);
86 $end = intval($this->params
['end']);
88 $dbr = wfGetDB( DB_SLAVE
);
89 $res = $dbr->select( array( 'templatelinks', 'page' ),
90 array( 'page_namespace', 'page_title' ),
93 "tl_from >= '$start'",
95 'tl_namespace' => $this->title
->getNamespace(),
96 'tl_title' => $this->title
->getDBkey()
100 # Not suitable for page load triggered job running!
101 # Gracefully switch to refreshLinks jobs if this happens.
102 if( php_sapi_name() != 'cli' ) {
104 while( $row = $dbr->fetchObject( $res ) ) {
105 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
106 $jobs[] = new RefreshLinksJob( $title, '' );
108 Job
::batchInsert( $jobs );
111 # Re-parse each page that transcludes this page and update their tracking links...
112 while( $row = $dbr->fetchObject( $res ) ) {
113 $title = Title
::makeTitle( $row->page_namespace
, $row->page_title
);
114 $revision = Revision
::newFromTitle( $title );
116 $this->error
= 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
117 wfProfileOut( __METHOD__
);
120 wfProfileIn( __METHOD__
.'-parse' );
121 $options = new ParserOptions
;
122 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
123 wfProfileOut( __METHOD__
.'-parse' );
124 wfProfileIn( __METHOD__
.'-update' );
125 $update = new LinksUpdate( $title, $parserOutput, false );
127 wfProfileOut( __METHOD__
.'-update' );
128 wfProfileOut( __METHOD__
);