Localisation updates for core and extension messages from translatewiki.net (2011...
[mediawiki.git] / includes / job / RefreshLinksJob.php
blob910f0c58101d706561b728876cf323c2746bba2f
1 <?php
2 /**
3 * Job to update links for a given title.
5 * @file
6 * @ingroup JobQueue
7 */
9 /**
10 * Background job to update links for a given title.
12 * @ingroup JobQueue
14 class RefreshLinksJob extends Job {
16 function __construct( $title, $params = '', $id = 0 ) {
17 parent::__construct( 'refreshLinks', $title, $params, $id );
20 /**
21 * Run a refreshLinks job
22 * @return boolean success
24 function run() {
25 global $wgParser;
26 wfProfileIn( __METHOD__ );
28 $linkCache = LinkCache::singleton();
29 $linkCache->clear();
31 if ( is_null( $this->title ) ) {
32 $this->error = "refreshLinks: Invalid title";
33 wfProfileOut( __METHOD__ );
34 return false;
37 $revision = Revision::newFromTitle( $this->title );
38 if ( !$revision ) {
39 $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
40 wfProfileOut( __METHOD__ );
41 return false;
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 );
50 $update->doUpdate();
51 wfProfileOut( __METHOD__.'-update' );
52 wfProfileOut( __METHOD__ );
53 return true;
57 /**
58 * Background job to update links for a given title.
59 * Newer version for high use templates.
61 * @ingroup JobQueue
63 class RefreshLinksJob2 extends Job {
65 function __construct( $title, $params, $id = 0 ) {
66 parent::__construct( 'refreshLinks2', $title, $params, $id );
69 /**
70 * Run a refreshLinks2 job
71 * @return boolean success
73 function run() {
74 global $wgParser;
76 wfProfileIn( __METHOD__ );
78 $linkCache = LinkCache::singleton();
79 $linkCache->clear();
81 if( is_null( $this->title ) ) {
82 $this->error = "refreshLinks2: Invalid title";
83 wfProfileOut( __METHOD__ );
84 return false;
86 if( !isset($this->params['start']) || !isset($this->params['end']) ) {
87 $this->error = "refreshLinks2: Invalid params";
88 wfProfileOut( __METHOD__ );
89 return false;
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' ) {
97 $jobs = array();
98 foreach ( $titles as $title ) {
99 $jobs[] = new RefreshLinksJob( $title, '' );
101 Job::batchInsert( $jobs );
103 wfProfileOut( __METHOD__ );
104 return true;
106 # Re-parse each page that transcludes this page and update their tracking links...
107 foreach ( $titles as $title ) {
108 $revision = Revision::newFromTitle( $title );
109 if ( !$revision ) {
110 $this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
111 wfProfileOut( __METHOD__ );
112 return false;
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 );
120 $update->doUpdate();
121 wfProfileOut( __METHOD__.'-update' );
122 wfWaitForSlaves();
124 wfProfileOut( __METHOD__ );
126 return true;