00001 <?php
00002
00008 class RefreshLinksJob extends Job {
00009
00010 function __construct( $title, $params = '', $id = 0 ) {
00011 parent::__construct( 'refreshLinks', $title, $params, $id );
00012 }
00013
00018 function run() {
00019 global $wgParser;
00020 wfProfileIn( __METHOD__ );
00021
00022 $linkCache = LinkCache::singleton();
00023 $linkCache->clear();
00024
00025 if ( is_null( $this->title ) ) {
00026 $this->error = "refreshLinks: Invalid title";
00027 wfProfileOut( __METHOD__ );
00028 return false;
00029 }
00030
00031 $revision = Revision::newFromTitle( $this->title );
00032 if ( !$revision ) {
00033 $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"';
00034 wfProfileOut( __METHOD__ );
00035 return false;
00036 }
00037
00038 wfProfileIn( __METHOD__.'-parse' );
00039 $options = new ParserOptions;
00040 $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() );
00041 wfProfileOut( __METHOD__.'-parse' );
00042 wfProfileIn( __METHOD__.'-update' );
00043 $update = new LinksUpdate( $this->title, $parserOutput, false );
00044 $update->doUpdate();
00045 wfProfileOut( __METHOD__.'-update' );
00046 wfProfileOut( __METHOD__ );
00047 return true;
00048 }
00049 }
00050
00057 class RefreshLinksJob2 extends Job {
00058
00059 function __construct( $title, $params, $id = 0 ) {
00060 parent::__construct( 'refreshLinks2', $title, $params, $id );
00061 }
00062
00067 function run() {
00068 global $wgParser;
00069
00070 wfProfileIn( __METHOD__ );
00071
00072 $linkCache = LinkCache::singleton();
00073 $linkCache->clear();
00074
00075 if( is_null( $this->title ) ) {
00076 $this->error = "refreshLinks2: Invalid title";
00077 wfProfileOut( __METHOD__ );
00078 return false;
00079 }
00080 if( !isset($this->params['start']) || !isset($this->params['end']) ) {
00081 $this->error = "refreshLinks2: Invalid params";
00082 wfProfileOut( __METHOD__ );
00083 return false;
00084 }
00085 $titles = $this->title->getBacklinkCache()->getLinks(
00086 'templatelinks', $this->params['start'], $this->params['end']);
00087
00088 # Not suitable for page load triggered job running!
00089 # Gracefully switch to refreshLinks jobs if this happens.
00090 if( php_sapi_name() != 'cli' ) {
00091 $jobs = array();
00092 foreach ( $titles as $title ) {
00093 $jobs[] = new RefreshLinksJob( $title, '' );
00094 }
00095 Job::batchInsert( $jobs );
00096 return true;
00097 }
00098 # Re-parse each page that transcludes this page and update their tracking links...
00099 foreach ( $titles as $title ) {
00100 $revision = Revision::newFromTitle( $title );
00101 if ( !$revision ) {
00102 $this->error = 'refreshLinks: Article not found "' . $title->getPrefixedDBkey() . '"';
00103 wfProfileOut( __METHOD__ );
00104 return false;
00105 }
00106 wfProfileIn( __METHOD__.'-parse' );
00107 $options = new ParserOptions;
00108 $parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
00109 wfProfileOut( __METHOD__.'-parse' );
00110 wfProfileIn( __METHOD__.'-update' );
00111 $update = new LinksUpdate( $title, $parserOutput, false );
00112 $update->doUpdate();
00113 wfProfileOut( __METHOD__.'-update' );
00114 wfProfileOut( __METHOD__ );
00115 }
00116
00117 return true;
00118 }
00119 }