MediaWiki
REL1_19
|
00001 <?php 00014 class RefreshLinksJob extends Job { 00015 00016 function __construct( $title, $params = '', $id = 0 ) { 00017 parent::__construct( 'refreshLinks', $title, $params, $id ); 00018 } 00019 00024 function run() { 00025 global $wgParser, $wgContLang; 00026 wfProfileIn( __METHOD__ ); 00027 00028 $linkCache = LinkCache::singleton(); 00029 $linkCache->clear(); 00030 00031 if ( is_null( $this->title ) ) { 00032 $this->error = "refreshLinks: Invalid title"; 00033 wfProfileOut( __METHOD__ ); 00034 return false; 00035 } 00036 00037 $revision = Revision::newFromTitle( $this->title ); 00038 if ( !$revision ) { 00039 $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"'; 00040 wfProfileOut( __METHOD__ ); 00041 return false; 00042 } 00043 00044 wfProfileIn( __METHOD__.'-parse' ); 00045 $options = ParserOptions::newFromUserAndLang( new User, $wgContLang ); 00046 $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() ); 00047 wfProfileOut( __METHOD__.'-parse' ); 00048 wfProfileIn( __METHOD__.'-update' ); 00049 $update = new LinksUpdate( $this->title, $parserOutput, false ); 00050 $update->doUpdate(); 00051 wfProfileOut( __METHOD__.'-update' ); 00052 wfProfileOut( __METHOD__ ); 00053 return true; 00054 } 00055 } 00056 00063 class RefreshLinksJob2 extends Job { 00064 00065 function __construct( $title, $params, $id = 0 ) { 00066 parent::__construct( 'refreshLinks2', $title, $params, $id ); 00067 } 00068 00073 function run() { 00074 global $wgParser, $wgContLang; 00075 00076 wfProfileIn( __METHOD__ ); 00077 00078 $linkCache = LinkCache::singleton(); 00079 $linkCache->clear(); 00080 00081 if( is_null( $this->title ) ) { 00082 $this->error = "refreshLinks2: Invalid title"; 00083 wfProfileOut( __METHOD__ ); 00084 return false; 00085 } 00086 if( !isset($this->params['start']) || !isset($this->params['end']) ) { 00087 $this->error = "refreshLinks2: Invalid params"; 00088 wfProfileOut( __METHOD__ ); 00089 return false; 00090 } 00091 // Back compat for pre-r94435 jobs 00092 $table = isset( $this->params['table'] ) ? $this->params['table'] : 'templatelinks'; 00093 $titles = $this->title->getBacklinkCache()->getLinks( 00094 $table, $this->params['start'], $this->params['end']); 00095 00096 # Not suitable for page load triggered job running! 00097 # Gracefully switch to refreshLinks jobs if this happens. 00098 if( php_sapi_name() != 'cli' ) { 00099 $jobs = array(); 00100 foreach ( $titles as $title ) { 00101 $jobs[] = new RefreshLinksJob( $title, '' ); 00102 } 00103 Job::batchInsert( $jobs ); 00104 00105 wfProfileOut( __METHOD__ ); 00106 return true; 00107 } 00108 $options = ParserOptions::newFromUserAndLang( new User, $wgContLang ); 00109 # Re-parse each page that transcludes this page and update their tracking links... 00110 foreach ( $titles as $title ) { 00111 $revision = Revision::newFromTitle( $title ); 00112 if ( !$revision ) { 00113 $this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"'; 00114 wfProfileOut( __METHOD__ ); 00115 return false; 00116 } 00117 wfProfileIn( __METHOD__.'-parse' ); 00118 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() ); 00119 wfProfileOut( __METHOD__.'-parse' ); 00120 wfProfileIn( __METHOD__.'-update' ); 00121 $update = new LinksUpdate( $title, $parserOutput, false ); 00122 $update->doUpdate(); 00123 wfProfileOut( __METHOD__.'-update' ); 00124 wfWaitForSlaves(); 00125 } 00126 wfProfileOut( __METHOD__ ); 00127 00128 return true; 00129 } 00130 }