Localisation updates from http://translatewiki.net.
[mediawiki.git] / includes / job / RefreshLinksJob.php
blob7ccf00ddfc4fe44fa1e6c0de9328935819699c9b
1 <?php
2 /**
3 * Job to update links for a given title.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup JobQueue
24 /**
25 * Background job to update links for a given title.
27 * @ingroup JobQueue
29 class RefreshLinksJob extends Job {
31 function __construct( $title, $params = '', $id = 0 ) {
32 parent::__construct( 'refreshLinks', $title, $params, $id );
35 /**
36 * Run a refreshLinks job
37 * @return boolean success
39 function run() {
40 global $wgParser, $wgContLang;
41 wfProfileIn( __METHOD__ );
43 $linkCache = LinkCache::singleton();
44 $linkCache->clear();
46 if ( is_null( $this->title ) ) {
47 $this->error = "refreshLinks: Invalid title";
48 wfProfileOut( __METHOD__ );
49 return false;
52 $revision = Revision::newFromTitle( $this->title );
53 if ( !$revision ) {
54 $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
55 wfProfileOut( __METHOD__ );
56 return false;
59 wfProfileIn( __METHOD__.'-parse' );
60 $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
61 $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() );
62 wfProfileOut( __METHOD__.'-parse' );
63 wfProfileIn( __METHOD__.'-update' );
65 $updates = $parserOutput->getSecondaryDataUpdates( $this->title, false );
66 DataUpdate::runUpdates( $updates );
68 wfProfileOut( __METHOD__.'-update' );
69 wfProfileOut( __METHOD__ );
70 return true;
74 /**
75 * Background job to update links for a given title.
76 * Newer version for high use templates.
78 * @ingroup JobQueue
80 class RefreshLinksJob2 extends Job {
82 function __construct( $title, $params, $id = 0 ) {
83 parent::__construct( 'refreshLinks2', $title, $params, $id );
86 /**
87 * Run a refreshLinks2 job
88 * @return boolean success
90 function run() {
91 global $wgParser, $wgContLang;
93 wfProfileIn( __METHOD__ );
95 $linkCache = LinkCache::singleton();
96 $linkCache->clear();
98 if( is_null( $this->title ) ) {
99 $this->error = "refreshLinks2: Invalid title";
100 wfProfileOut( __METHOD__ );
101 return false;
103 if( !isset($this->params['start']) || !isset($this->params['end']) ) {
104 $this->error = "refreshLinks2: Invalid params";
105 wfProfileOut( __METHOD__ );
106 return false;
108 // Back compat for pre-r94435 jobs
109 $table = isset( $this->params['table'] ) ? $this->params['table'] : 'templatelinks';
110 $titles = $this->title->getBacklinkCache()->getLinks(
111 $table, $this->params['start'], $this->params['end']);
113 # Not suitable for page load triggered job running!
114 # Gracefully switch to refreshLinks jobs if this happens.
115 if( php_sapi_name() != 'cli' ) {
116 $jobs = array();
117 foreach ( $titles as $title ) {
118 $jobs[] = new RefreshLinksJob( $title, '' );
120 Job::batchInsert( $jobs );
122 wfProfileOut( __METHOD__ );
123 return true;
125 $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
126 # Re-parse each page that transcludes this page and update their tracking links...
127 foreach ( $titles as $title ) {
128 $revision = Revision::newFromTitle( $title );
129 if ( !$revision ) {
130 $this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
131 wfProfileOut( __METHOD__ );
132 return false;
134 wfProfileIn( __METHOD__.'-parse' );
135 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
136 wfProfileOut( __METHOD__.'-parse' );
137 wfProfileIn( __METHOD__.'-update' );
139 $updates = $parserOutput->getSecondaryDataUpdates( $title, false );
140 DataUpdate::runUpdates( $updates );
142 wfProfileOut( __METHOD__.'-update' );
143 wfWaitForSlaves();
145 wfProfileOut( __METHOD__ );
147 return true;