3 if ( !defined( 'MEDIAWIKI' ) ) {
4 die( "This file is part of MediaWiki, it is not a valid entry point\n" );
14 /*-------------------------------------------------------------------------
16 *------------------------------------------------------------------------*/
18 * Add an array of refreshLinks jobs to the queue
19 * @param array $titles Array of title objects.
22 function queueLinksJobs( $titles ) {
23 $fname = 'Job::queueLinksJobs';
24 wfProfileIn( $fname );
25 foreach ( $titles as $title ) {
26 $job = new Job( 'refreshLinks', $title );
29 wfProfileOut( $fname );
33 * Pop a job off the front of the queue
35 * @return Job or false if there's no jobs
39 wfProfileIn( $fname );
41 // First check to see if there are any jobs in the slave DB
42 $dbr =& wfGetDB( DB_SLAVE
);
43 $id = $dbr->selectField( 'job', 'job_id', '', $fname, array( 'LIMIT' => 1 ) );
44 if ( $id === false ) {
45 wfProfileOut( $fname );
49 // Pop an item off the front of the queue
50 // Method due to Domas, may not work on all DBMSes
51 $dbw =& wfGetDB( DB_MASTER
);
52 $jobTable = $dbw->tableName( 'job' );
53 $dbw->query( "DELETE FROM $jobTable WHERE " .
54 '(job_cmd = @job_cmd := job_cmd) AND ' .
55 '(job_namespace = @job_namespace := job_namespace) AND ' .
56 '(job_title = @job_title := job_title) AND ' .
57 '(job_params = @job_params := job_params) ' .
58 'ORDER BY job_id LIMIT 1', $fname );
59 $affected = $dbw->affectedRows();
60 // Commit now before 100 other threads pile up behind us
61 $dbw->immediateCommit();
63 wfProfileOut( $fname );
67 $res = $dbw->query( "SELECT @job_cmd, @job_namespace, @job_title, @job_params", $fname );
68 $row = $dbw->fetchRow( $res );
70 wfProfileOut( $fname );
74 $command = $row['@job_cmd'];
75 $namespace = $row['@job_namespace'];
76 $dbkey = $row['@job_title'];
77 $title = Title
::makeTitleSafe( $namespace, $dbkey );
78 $params = $row['@job_params'];
79 $job = new Job( $command, $title, $params );
80 wfProfileOut( $fname );
84 /*-------------------------------------------------------------------------
85 * Non-static functions
86 *------------------------------------------------------------------------*/
88 function Job( $command, $title, $params = '' ) {
89 $this->command
= $command;
90 $this->title
= $title;
91 $this->params
= $params;
93 // A bit of premature generalisation
94 // Oh well, the whole class is premature generalisation really
95 $this->removeDuplicates
= true;
99 $fname = 'Job::insert';
102 'job_cmd' => $this->command
,
103 'job_namespace' => $this->title
->getNamespace(),
104 'job_title' => $this->title
->getDBkey(),
105 'job_params' => $this->params
108 $dbw =& wfGetDB( DB_MASTER
);
110 if ( $this->removeDuplicates
) {
111 $dbw->delete( 'job', $fields, $fname );
113 $fields['job_id'] = $dbw->nextSequenceValue( 'job_job_id_seq' );
114 $dbw->insert( 'job', $fields, $fname );
119 * @return boolean success
123 wfProfileIn( $fname );
124 switch ( $this->command
) {
126 $retval = $this->refreshLinks();
129 $this->error
= "Invalid job type {$this->command}, ignoring";
130 wfDebug( $this->error
. "\n" );
133 wfProfileOut( $fname );
138 * Run a refreshLinks job
139 * @return boolean success
141 function refreshLinks() {
144 $dbw =& wfGetDB( DB_MASTER
);
146 $linkCache =& LinkCache
::singleton();
149 if ( is_null( $this->title
) ) {
150 $this->error
= "refreshLinks: Invalid title";
154 $revision = Revision
::newFromTitle( $this->title
);
156 $this->error
= 'refreshLinks: Article not found "' . $this->title
->getPrefixedDBkey() . '"';
160 $options = new ParserOptions
;
161 $parserOutput = $wgParser->parse( $revision->getText(), $this->title
, $options, true, true, $revision->getId() );
162 $update = new LinksUpdate( $this->title
, $parserOutput );
167 function toString() {
168 if ( is_object( $this->title
) ) {
169 $s = "{$this->command} " . $this->title
->getPrefixedDBkey();
170 if ( $this->params
!== '' ) {
171 $s .= ', ' . $this->params
;
175 return "{$this->command} {$this->params}";
179 function getLastError() {