Index: trunk/phase3/includes/RefreshLinksJob.php |
— | — | @@ -0,0 +1,49 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Background job to update links for a given title. |
| 6 | + */ |
| 7 | +class RefreshLinksJob extends Job { |
| 8 | + |
| 9 | + function __construct( $title, $params = '', $id = 0 ) { |
| 10 | + parent::__construct( 'refreshLinks', $title, $params, $id ); |
| 11 | + } |
| 12 | + |
| 13 | + /** |
| 14 | + * Run a refreshLinks job |
| 15 | + * @return boolean success |
| 16 | + */ |
| 17 | + function run() { |
| 18 | + global $wgParser; |
| 19 | + wfProfileIn( __METHOD__ ); |
| 20 | + |
| 21 | + $linkCache =& LinkCache::singleton(); |
| 22 | + $linkCache->clear(); |
| 23 | + |
| 24 | + if ( is_null( $this->title ) ) { |
| 25 | + $this->error = "refreshLinks: Invalid title"; |
| 26 | + wfProfileOut( __METHOD__ ); |
| 27 | + return false; |
| 28 | + } |
| 29 | + |
| 30 | + $revision = Revision::newFromTitle( $this->title ); |
| 31 | + if ( !$revision ) { |
| 32 | + $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"'; |
| 33 | + wfProfileOut( __METHOD__ ); |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + wfProfileIn( __METHOD__.'-parse' ); |
| 38 | + $options = new ParserOptions; |
| 39 | + $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() ); |
| 40 | + wfProfileOut( __METHOD__.'-parse' ); |
| 41 | + wfProfileIn( __METHOD__.'-update' ); |
| 42 | + $update = new LinksUpdate( $this->title, $parserOutput, false ); |
| 43 | + $update->doUpdate(); |
| 44 | + wfProfileOut( __METHOD__.'-update' ); |
| 45 | + wfProfileOut( __METHOD__ ); |
| 46 | + return true; |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +?> |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/RefreshLinksJob.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 51 | + native |
Index: trunk/phase3/includes/EnotifNotifyJob.php |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Job for email notification mails |
| 6 | + */ |
| 7 | +class EnotifNotifyJob extends Job { |
| 8 | + |
| 9 | + function __construct( $title, $params, $id = 0 ) { |
| 10 | + parent::__construct( 'enotifNotify', $title, $params, $id ); |
| 11 | + } |
| 12 | + |
| 13 | + function run() { |
| 14 | + $enotif = new EmailNotification(); |
| 15 | + $enotif->actuallyNotifyOnPageChange( |
| 16 | + User::newFromName( $this->params['editor'], false ), |
| 17 | + $this->title, |
| 18 | + $this->params['timestamp'], |
| 19 | + $this->params['summary'], |
| 20 | + $this->params['minorEdit'], |
| 21 | + $this->params['oldid'] |
| 22 | + ); |
| 23 | + return true; |
| 24 | + } |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | +?> |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/EnotifNotifyJob.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 29 | + native |
Index: trunk/phase3/includes/EmaillingJob.php |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Old job used for sending single notification emails; |
| 6 | + * kept for backwards-compatibility |
| 7 | + */ |
| 8 | +class EmaillingJob extends Job { |
| 9 | + |
| 10 | + function __construct( $title, $params, $id = 0 ) { |
| 11 | + parent::__construct( 'sendMail', Title::newMainPage(), $params, $id ); |
| 12 | + } |
| 13 | + |
| 14 | + function run() { |
| 15 | + userMailer( |
| 16 | + $this->params['to'], |
| 17 | + $this->params['from'], |
| 18 | + $this->params['subj'], |
| 19 | + $this->params['body'], |
| 20 | + $this->params['replyto'] |
| 21 | + ); |
| 22 | + return true; |
| 23 | + } |
| 24 | + |
| 25 | +} |
| 26 | + |
| 27 | +?> |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/EmaillingJob.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 28 | + native |
Index: trunk/phase3/includes/UserMailer.php |
— | — | @@ -247,7 +247,7 @@ |
248 | 248 | "summary" => $summary, |
249 | 249 | "minorEdit" => $minorEdit, |
250 | 250 | "oldid" => $oldid); |
251 | | - $job = new EnotifNotifyJob($title, $params); |
| 251 | + $job = new EnotifNotifyJob( $title, $params ); |
252 | 252 | $job->insert(); |
253 | 253 | } else { |
254 | 254 | $this->actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid); |
Index: trunk/phase3/includes/JobQueue.php |
— | — | @@ -167,32 +167,23 @@ |
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | | - * Create an object of a subclass |
| 171 | + * Create the appropriate object to handle a specific job |
| 172 | + * |
| 173 | + * @param string $command Job command |
| 174 | + * @param Title $title Associated title |
| 175 | + * @param array $params Job parameters |
| 176 | + * @param int $id Job identifier |
| 177 | + * @return Job |
172 | 178 | */ |
173 | 179 | static function factory( $command, $title, $params = false, $id = 0 ) { |
174 | | - switch ( $command ) { |
175 | | - case 'refreshLinks': |
176 | | - return new RefreshLinksJob( $title, $params, $id ); |
177 | | - case 'htmlCacheUpdate': |
178 | | - case 'html_cache_update': # BC |
179 | | - return new HTMLCacheUpdateJob( $title, $params['table'], $params['start'], $params['end'], $id ); |
180 | | - case 'sendMail': |
181 | | - return new EmaillingJob( $params ); |
182 | | - case 'enotifNotify': |
183 | | - return new EnotifNotifyJob( $title, $params ); |
| 180 | + global $wgJobClasses; |
| 181 | + if( isset( $wgJobClasses[$command] ) ) { |
| 182 | + $class = $wgJobClasses[$command]; |
| 183 | + return new $class( $title, $params, $id ); |
184 | 184 | } |
185 | | - // OK, check if this is a custom job |
186 | | - global $wgCustomJobs; |
187 | | - wfLoadAllExtensions(); // This may be for an extension |
188 | | - |
189 | | - if( isset($wgCustomJobs[$command]) ) { |
190 | | - $class = $wgCustomJobs[$command]; |
191 | | - return new $class($title, $params, $id); |
192 | | - } else { |
193 | | - throw new MWException( "Invalid job command \"$command\"" ); |
194 | | - } |
| 185 | + throw new MWException( "Invalid job command `{$command}`" ); |
195 | 186 | } |
196 | | - |
| 187 | + |
197 | 188 | static function makeBlob( $params ) { |
198 | 189 | if ( $params !== false ) { |
199 | 190 | return serialize( $params ); |
— | — | @@ -299,76 +290,4 @@ |
300 | 291 | } |
301 | 292 | } |
302 | 293 | |
303 | | - |
304 | | -/** |
305 | | - * Background job to update links for a given title. |
306 | | - */ |
307 | | -class RefreshLinksJob extends Job { |
308 | | - function __construct( $title, $params = '', $id = 0 ) { |
309 | | - parent::__construct( 'refreshLinks', $title, $params, $id ); |
310 | | - } |
311 | | - |
312 | | - /** |
313 | | - * Run a refreshLinks job |
314 | | - * @return boolean success |
315 | | - */ |
316 | | - function run() { |
317 | | - global $wgParser; |
318 | | - wfProfileIn( __METHOD__ ); |
319 | | - |
320 | | - $linkCache =& LinkCache::singleton(); |
321 | | - $linkCache->clear(); |
322 | | - |
323 | | - if ( is_null( $this->title ) ) { |
324 | | - $this->error = "refreshLinks: Invalid title"; |
325 | | - wfProfileOut( __METHOD__ ); |
326 | | - return false; |
327 | | - } |
328 | | - |
329 | | - $revision = Revision::newFromTitle( $this->title ); |
330 | | - if ( !$revision ) { |
331 | | - $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"'; |
332 | | - wfProfileOut( __METHOD__ ); |
333 | | - return false; |
334 | | - } |
335 | | - |
336 | | - wfProfileIn( __METHOD__.'-parse' ); |
337 | | - $options = new ParserOptions; |
338 | | - $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() ); |
339 | | - wfProfileOut( __METHOD__.'-parse' ); |
340 | | - wfProfileIn( __METHOD__.'-update' ); |
341 | | - $update = new LinksUpdate( $this->title, $parserOutput, false ); |
342 | | - $update->doUpdate(); |
343 | | - wfProfileOut( __METHOD__.'-update' ); |
344 | | - wfProfileOut( __METHOD__ ); |
345 | | - return true; |
346 | | - } |
347 | | -} |
348 | | - |
349 | | -class EmaillingJob extends Job { |
350 | | - function __construct($params) { |
351 | | - parent::__construct('sendMail', Title::newMainPage(), $params); |
352 | | - } |
353 | | - |
354 | | - function run() { |
355 | | - userMailer($this->params['to'], $this->params['from'], $this->params['subj'], |
356 | | - $this->params['body'], $this->params['replyto']); |
357 | | - } |
358 | | -} |
359 | | - |
360 | | -class EnotifNotifyJob extends Job { |
361 | | - function __construct($title, $params) { |
362 | | - parent::__construct('enotifNotify', $title, $params); |
363 | | - } |
364 | | - |
365 | | - function run() { |
366 | | - $enotif = new EmailNotification(); |
367 | | - $enotif->actuallyNotifyOnPageChange( User::newFromName($this->params['editor'], false), |
368 | | - $this->title, $this->params['timestamp'], |
369 | | - $this->params['summary'], $this->params['minorEdit'], |
370 | | - $this->params['oldid']); |
371 | | - } |
372 | | -} |
373 | | - |
374 | | - |
375 | | -?> |
| 294 | +?> |
\ No newline at end of file |
Index: trunk/phase3/includes/LinksUpdate.php |
— | — | @@ -189,7 +189,7 @@ |
190 | 190 | break; |
191 | 191 | } |
192 | 192 | $title = Title::makeTitle( $row->page_namespace, $row->page_title ); |
193 | | - $jobs[] = Job::factory( 'refreshLinks', $title ); |
| 193 | + $jobs[] = new RefreshLinksJob( $title, '' ); |
194 | 194 | } |
195 | 195 | Job::batchInsert( $jobs ); |
196 | 196 | } |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -94,8 +94,6 @@ |
95 | 95 | 'HistoryBlobStub' => 'includes/HistoryBlob.php', |
96 | 96 | 'HistoryBlobCurStub' => 'includes/HistoryBlob.php', |
97 | 97 | 'HTMLCacheUpdate' => 'includes/HTMLCacheUpdate.php', |
98 | | - 'HTMLCacheUpdateJob' => 'includes/HTMLCacheUpdate.php', |
99 | | - 'EnotifNotifyJob' => 'includes/JobQueue.php', |
100 | 98 | 'Http' => 'includes/HttpFunctions.php', |
101 | 99 | 'IP' => 'includes/IP.php', |
102 | 100 | 'ThumbnailImage' => 'includes/Image.php', |
— | — | @@ -104,6 +102,10 @@ |
105 | 103 | 'ImageHistoryList' => 'includes/ImagePage.php', |
106 | 104 | 'ImageRemote' => 'includes/ImageRemote.php', |
107 | 105 | 'Job' => 'includes/JobQueue.php', |
| 106 | + 'EmaillingJob' => 'includes/EmaillingJob.php', |
| 107 | + 'EnotifNotifyJob' => 'includes/EnotifNotifyJob.php', |
| 108 | + 'HTMLCacheUpdateJob' => 'includes/HTMLCacheUpdate.php', |
| 109 | + 'RefreshLinksJob' => 'includes/RefreshLinksJob.php', |
108 | 110 | 'Licenses' => 'includes/Licenses.php', |
109 | 111 | 'License' => 'includes/Licenses.php', |
110 | 112 | 'LinkBatch' => 'includes/LinkBatch.php', |
Index: trunk/phase3/includes/HTMLCacheUpdate.php |
— | — | @@ -67,13 +67,13 @@ |
68 | 68 | break; |
69 | 69 | } |
70 | 70 | } |
71 | | - if ( $id !== false ) { |
72 | | - // One less on the end to avoid duplicating the boundary |
73 | | - $job = new HTMLCacheUpdateJob( $this->mTitle, $this->mTable, $start, $id - 1 ); |
74 | | - } else { |
75 | | - $job = new HTMLCacheUpdateJob( $this->mTitle, $this->mTable, $start, false ); |
76 | | - } |
77 | | - $jobs[] = $job; |
| 71 | + |
| 72 | + $params = array( |
| 73 | + 'table' => $this->mTable, |
| 74 | + 'start' => $start, |
| 75 | + 'end' => ( $id !== false ? $id - 1 : false ), |
| 76 | + ); |
| 77 | + $jobs[] = new HTMLCacheUpdateJob( $this->mTitle, $params ); |
78 | 78 | |
79 | 79 | $start = $id; |
80 | 80 | } while ( $start ); |
— | — | @@ -193,20 +193,14 @@ |
194 | 194 | /** |
195 | 195 | * Construct a job |
196 | 196 | * @param Title $title The title linked to |
197 | | - * @param string $table The name of the link table. |
198 | | - * @param integer $start Beginning page_id or false for open interval |
199 | | - * @param integer $end End page_id or false for open interval |
| 197 | + * @param array $params Job parameters (table, start and end page_ids) |
200 | 198 | * @param integer $id job_id |
201 | 199 | */ |
202 | | - function __construct( $title, $table, $start, $end, $id = 0 ) { |
203 | | - $params = array( |
204 | | - 'table' => $table, |
205 | | - 'start' => $start, |
206 | | - 'end' => $end ); |
| 200 | + function __construct( $title, $params, $id = 0 ) { |
207 | 201 | parent::__construct( 'htmlCacheUpdate', $title, $params, $id ); |
208 | | - $this->table = $table; |
209 | | - $this->start = intval( $start ); |
210 | | - $this->end = intval( $end ); |
| 202 | + $this->table = $params['table']; |
| 203 | + $this->start = $params['start']; |
| 204 | + $this->end = $params['end']; |
211 | 205 | } |
212 | 206 | |
213 | 207 | function run() { |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -1361,10 +1361,16 @@ |
1362 | 1362 | $wgAllowSlowParserFunctions = false; |
1363 | 1363 | |
1364 | 1364 | /** |
1365 | | - * Extra custom jobs can be added to the Job Queue system. |
1366 | | - * This array should consist of job name => job queue subclass pairs |
| 1365 | + * Maps jobs to their handling classes; extensions |
| 1366 | + * can add to this to provide custom jobs |
1367 | 1367 | */ |
1368 | | -$wgCustomJobs = array(); |
| 1368 | +$wgJobClasses = array( |
| 1369 | + 'refreshLinks' => 'RefreshLinksJob', |
| 1370 | + 'htmlCacheUpdate' => 'HTMLCacheUpdateJob', |
| 1371 | + 'html_cache_update' => 'HTMLCacheUpdateJob', // backwards-compatible |
| 1372 | + 'sendMail' => 'EmaillingJob', |
| 1373 | + 'enotifNotify' => 'EnotifNotifyJob', |
| 1374 | +); |
1369 | 1375 | |
1370 | 1376 | /** |
1371 | 1377 | * To use inline TeX, you need to compile 'texvc' (in the 'math' subdirectory of |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -97,6 +97,8 @@ |
98 | 98 | to cause hard-to-track-down interactions between extensions. |
99 | 99 | * (bug 9415) Added options to Special:Protect to allow setting of per-page robot |
100 | 100 | policies. This can be done only by users with the 'editrobots' permission |
| 101 | +* Use $wgJobClasses to determine the correct Job to instantiate for a particular |
| 102 | + queued task; allows extensions to introduce custom jobs |
101 | 103 | |
102 | 104 | == Bugfixes since 1.10 == |
103 | 105 | |