wfProfileOut() for new return added in c6396 (c4e407c)
[lhc/web/wiklou.git] / includes / job / RefreshLinksJob.php
1 <?php
2 /**
3 * Job to update links for a given title.
4 *
5 * @file
6 * @ingroup JobQueue
7 */
8
9 /**
10 * Background job to update links for a given title.
11 *
12 * @ingroup JobQueue
13 */
14 class RefreshLinksJob extends Job {
15
16 function __construct( $title, $params = '', $id = 0 ) {
17 parent::__construct( 'refreshLinks', $title, $params, $id );
18 }
19
20 /**
21 * Run a refreshLinks job
22 * @return boolean success
23 */
24 function run() {
25 global $wgParser, $wgContLang;
26 wfProfileIn( __METHOD__ );
27
28 $linkCache = LinkCache::singleton();
29 $linkCache->clear();
30
31 if ( is_null( $this->title ) ) {
32 $this->error = "refreshLinks: Invalid title";
33 wfProfileOut( __METHOD__ );
34 return false;
35 }
36
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;
42 }
43
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' );
49 $update = new LinksUpdate( $this->title, $parserOutput, false );
50 $update->doUpdate();
51 wfProfileOut( __METHOD__.'-update' );
52 wfProfileOut( __METHOD__ );
53 return true;
54 }
55 }
56
57 /**
58 * Background job to update links for a given title.
59 * Newer version for high use templates.
60 *
61 * @ingroup JobQueue
62 */
63 class RefreshLinksJob2 extends Job {
64
65 function __construct( $title, $params, $id = 0 ) {
66 parent::__construct( 'refreshLinks2', $title, $params, $id );
67 }
68
69 /**
70 * Run a refreshLinks2 job
71 * @return boolean success
72 */
73 function run() {
74 global $wgParser, $wgContLang;
75
76 wfProfileIn( __METHOD__ );
77
78 $linkCache = LinkCache::singleton();
79 $linkCache->clear();
80
81 if( is_null( $this->title ) ) {
82 $this->error = "refreshLinks2: Invalid title";
83 wfProfileOut( __METHOD__ );
84 return false;
85 }
86 if( !isset($this->params['start']) || !isset($this->params['end']) ) {
87 $this->error = "refreshLinks2: Invalid params";
88 wfProfileOut( __METHOD__ );
89 return false;
90 }
91 // Back compat for pre-r94435 jobs
92 $table = isset( $this->params['table'] ) ? $this->params['table'] : 'templatelinks';
93 $titles = $this->title->getBacklinkCache()->getLinks(
94 $table, $this->params['start'], $this->params['end']);
95
96 # Not suitable for page load triggered job running!
97 # Gracefully switch to refreshLinks jobs if this happens.
98 if( php_sapi_name() != 'cli' ) {
99 $jobs = array();
100 foreach ( $titles as $title ) {
101 $jobs[] = new RefreshLinksJob( $title, '' );
102 }
103 Job::batchInsert( $jobs );
104
105 wfProfileOut( __METHOD__ );
106 return true;
107 }
108 $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
109 # Re-parse each page that transcludes this page and update their tracking links...
110 foreach ( $titles as $title ) {
111 $revision = Revision::newFromTitle( $title );
112 if ( !$revision ) {
113 $this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
114 wfProfileOut( __METHOD__ );
115 return false;
116 }
117 wfProfileIn( __METHOD__.'-parse' );
118 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
119 wfProfileOut( __METHOD__.'-parse' );
120 wfProfileIn( __METHOD__.'-update' );
121 $update = new LinksUpdate( $title, $parserOutput, false );
122 $update->doUpdate();
123 wfProfileOut( __METHOD__.'-update' );
124 wfWaitForSlaves();
125 }
126 wfProfileOut( __METHOD__ );
127
128 return true;
129 }
130 }