Installer is no longer hardcoded to xhtml doctype
[mediawiki.git] / includes / RefreshLinksJob.php
blobaba18362c05e5a1768616a6e8b7e34f72abc2571
1 <?php
3 /**
4 * Background job to update links for a given title.
6 * @ingroup JobQueue
7 */
8 class RefreshLinksJob extends Job {
10 function __construct( $title, $params = '', $id = 0 ) {
11 parent::__construct( 'refreshLinks', $title, $params, $id );
14 /**
15 * Run a refreshLinks job
16 * @return boolean success
18 function run() {
19 global $wgParser;
20 wfProfileIn( __METHOD__ );
22 $linkCache = LinkCache::singleton();
23 $linkCache->clear();
25 if ( is_null( $this->title ) ) {
26 $this->error = "refreshLinks: Invalid title";
27 wfProfileOut( __METHOD__ );
28 return false;
31 $revision = Revision::newFromTitle( $this->title );
32 if ( !$revision ) {
33 $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
34 wfProfileOut( __METHOD__ );
35 return false;
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 );
44 $update->doUpdate();
45 wfProfileOut( __METHOD__.'-update' );
46 wfProfileOut( __METHOD__ );
47 return true;
51 /**
52 * Background job to update links for a given title.
53 * Newer version for high use templates.
55 * @ingroup JobQueue
57 class RefreshLinksJob2 extends Job {
59 function __construct( $title, $params, $id = 0 ) {
60 parent::__construct( 'refreshLinks2', $title, $params, $id );
63 /**
64 * Run a refreshLinks2 job
65 * @return boolean success
67 function run() {
68 global $wgParser;
70 wfProfileIn( __METHOD__ );
72 $linkCache = LinkCache::singleton();
73 $linkCache->clear();
75 if( is_null( $this->title ) ) {
76 $this->error = "refreshLinks2: Invalid title";
77 wfProfileOut( __METHOD__ );
78 return false;
80 if( !isset($this->params['start']) || !isset($this->params['end']) ) {
81 $this->error = "refreshLinks2: Invalid params";
82 wfProfileOut( __METHOD__ );
83 return false;
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' ) {
91 $jobs = array();
92 foreach ( $titles as $title ) {
93 $jobs[] = new RefreshLinksJob( $title, '' );
95 Job::batchInsert( $jobs );
96 return true;
98 # Re-parse each page that transcludes this page and update their tracking links...
99 foreach ( $titles as $title ) {
100 $revision = Revision::newFromTitle( $title );
101 if ( !$revision ) {
102 $this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
103 wfProfileOut( __METHOD__ );
104 return false;
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 );
112 $update->doUpdate();
113 wfProfileOut( __METHOD__.'-update' );
114 wfWaitForSlaves( 5 );
116 wfProfileOut( __METHOD__ );
118 return true;