- /**
- * Bulk-check the pagelinks and page arrays for existence info.
- * @param Title $fromtitle
- */
- function preFill( &$fromtitle ) {
- global $wgAntiLockFlags;
- $fname = 'LinkCache::preFill';
- wfProfileIn( $fname );
-
- $this->suspend();
- $id = $fromtitle->getArticleID();
- $this->resume();
-
- if( $id == 0 ) {
- wfDebug( "$fname - got id 0 for title '" . $fromtitle->getPrefixedDBkey() . "'\n" );
- wfProfileOut( $fname );
- return;
- }
-
- if ( $this->mForUpdate ) {
- $db =& wfGetDB( DB_MASTER );
- if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) {
- $options = 'FOR UPDATE';
- } else {
- $options = '';
- }
- } else {
- $db =& wfGetDB( DB_SLAVE );
- $options = '';
- }
-
- $page = $db->tableName( 'page' );
- $pagelinks = $db->tableName( 'pagelinks' );
-
- $sql = "SELECT page_id,pl_namespace,pl_title
- FROM $pagelinks
- LEFT JOIN $page
- ON pl_namespace=page_namespace AND pl_title=page_title
- WHERE pl_from=$id $options";
- $res = $db->query( $sql, $fname );
- while( $s = $db->fetchObject( $res ) ) {
- $title = Title::makeTitle( $s->pl_namespace, $s->pl_title );
- if( $s->page_id ) {
- $this->addGoodLinkObj( $s->page_id, $title );
- } else {
- $this->addBadLinkObj( $title );
- }
- }
- $this->mPreFilled = true;
-
- wfProfileOut( $fname );
- }
-
- function getGoodAdditions() {
- return array_diff( $this->mGoodLinks, $this->mOldGoodLinks );
- }
-
- function getBadAdditions() {
- #wfDebug( "mOldBadLinks: " . implode( ', ', array_keys( $this->mOldBadLinks ) ) . "\n" );
- #wfDebug( "mBadLinks: " . implode( ', ', array_keys( $this->mBadLinks ) ) . "\n" );
- return array_values( array_diff( array_keys( $this->mBadLinks ), array_keys( $this->mOldBadLinks ) ) );
- }
-
- function getImageAdditions() {
- return array_diff_assoc( $this->mImageLinks, $this->mOldImageLinks );
- }
-
- function getGoodDeletions() {
- return array_diff( $this->mOldGoodLinks, $this->mGoodLinks );
- }
-
- function getBadDeletions() {
- return array_values( array_diff( array_keys( $this->mOldBadLinks ), array_keys( $this->mBadLinks ) ));
- }
-
- function getImageDeletions() {
- return array_diff_assoc( $this->mOldImageLinks, $this->mImageLinks );
- }
-
- function getPageAdditions() {
- $set = array_diff( array_keys( $this->mPageLinks ), array_keys( $this->mOldPageLinks ) );
- $out = array();
- foreach( $set as $key ) {
- $out[$key] = $this->mPageLinks[$key];
- }
- return $out;
- }
-
- function getPageDeletions() {
- $set = array_diff( array_keys( $this->mOldPageLinks ), array_keys( $this->mPageLinks ) );
- $out = array();
- foreach( $set as $key ) {
- $out[$key] = $this->mOldPageLinks[$key];
- }
- return $out;
- }
-
- /**
- * Parameters:
- * @param $which is one of the LINKCACHE_xxx constants
- * @param $del,$add are the incremental update arrays which will be filled.
- *
- * @return Returns whether or not it's worth doing the incremental version.
- *
- * For example, if [[List of mathematical topics]] was blanked,
- * it would take a long, long time to do incrementally.
- */
- function incrementalSetup( $which, &$del, &$add ) {
- if ( ! $this->mPreFilled ) {
- return false;
- }
-
- switch ( $which ) {
- case LINKCACHE_GOOD:
- $old =& $this->mOldGoodLinks;
- $cur =& $this->mGoodLinks;
- $del = $this->getGoodDeletions();
- $add = $this->getGoodAdditions();
- break;
- case LINKCACHE_BAD:
- $old =& $this->mOldBadLinks;
- $cur =& $this->mBadLinks;
- $del = $this->getBadDeletions();
- $add = $this->getBadAdditions();
- break;
- case LINKCACHE_PAGE:
- $old =& $this->mOldPageLinks;
- $cur =& $this->mPageLinks;
- $del = $this->getPageDeletions();
- $add = $this->getPageAdditions();
- break;
- default: # LINKCACHE_IMAGE
- return false;
- }
-
- return true;
- }
-