linksupdate.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 602 行 · 第 1/2 页

PHP
602
字号
				$where[] = "$toField IN (" . $this->mDb->makeList( array_keys( $deletions ) ) . ')';			} else {				$where = false;			}		}		if ( $where ) {			$this->mDb->delete( $table, $where, $fname );		}		if ( count( $insertions ) ) {			$this->mDb->insert( $table, $insertions, $fname, 'IGNORE' );		}	}	/**	 * Get an array of pagelinks insertions for passing to the DB	 * Skips the titles specified by the 2-D array $existing	 * @private	 */	function getLinkInsertions( $existing = array() ) {		$arr = array();		foreach( $this->mLinks as $ns => $dbkeys ) {			# array_diff_key() was introduced in PHP 5.1, there is a compatibility function			# in GlobalFunctions.php			$diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;			foreach ( $diffs as $dbk => $id ) {				$arr[] = array(					'pl_from'      => $this->mId,					'pl_namespace' => $ns,					'pl_title'     => $dbk				);			}		}		return $arr;	}	/**	 * Get an array of template insertions. Like getLinkInsertions()	 * @private	 */	function getTemplateInsertions( $existing = array() ) {		$arr = array();		foreach( $this->mTemplates as $ns => $dbkeys ) {			$diffs = isset( $existing[$ns] ) ? array_diff_key( $dbkeys, $existing[$ns] ) : $dbkeys;			foreach ( $diffs as $dbk => $id ) {				$arr[] = array(					'tl_from'      => $this->mId,					'tl_namespace' => $ns,					'tl_title'     => $dbk				);			}		}		return $arr;	}	/**	 * Get an array of image insertions	 * Skips the names specified in $existing	 * @private	 */	function getImageInsertions( $existing = array() ) {		$arr = array();		$diffs = array_diff_key( $this->mImages, $existing );		foreach( $diffs as $iname => $dummy ) {			$arr[] = array(				'il_from' => $this->mId,				'il_to'   => $iname			);		}		return $arr;	}	/**	 * Get an array of externallinks insertions. Skips the names specified in $existing	 * @private	 */	function getExternalInsertions( $existing = array() ) {		$arr = array();		$diffs = array_diff_key( $this->mExternals, $existing );		foreach( $diffs as $url => $dummy ) {			$arr[] = array(				'el_from'   => $this->mId,				'el_to'     => $url,				'el_index'  => wfMakeUrlIndex( $url ),			);		}		return $arr;	}	/**	 * Get an array of category insertions	 * @param array $existing Array mapping existing category names to sort keys. If both	 * match a link in $this, the link will be omitted from the output	 * @private	 */	function getCategoryInsertions( $existing = array() ) {		$diffs = array_diff_assoc( $this->mCategories, $existing );		$arr = array();		foreach ( $diffs as $name => $sortkey ) {			$arr[] = array(				'cl_from'    => $this->mId,				'cl_to'      => $name,				'cl_sortkey' => $sortkey,				'cl_timestamp' => $this->mDb->timestamp()			);		}		return $arr;	}	/**	 * Get an array of interlanguage link insertions	 * @param array $existing Array mapping existing language codes to titles	 	 * @private	 */	function getInterlangInsertions( $existing = array() ) {	    $diffs = array_diff_assoc( $this->mInterlangs, $existing );	    $arr = array();	    foreach( $diffs as $lang => $title ) {	        $arr[] = array(	            'll_from'  => $this->mId,	            'll_lang'  => $lang,	            'll_title' => $title	        );	    }	    return $arr;	}	/**	 * Given an array of existing links, returns those links which are not in $this	 * and thus should be deleted.	 * @private	 */	function getLinkDeletions( $existing ) {		$del = array();		foreach ( $existing as $ns => $dbkeys ) {			if ( isset( $this->mLinks[$ns] ) ) {				$del[$ns] = array_diff_key( $existing[$ns], $this->mLinks[$ns] );			} else {				$del[$ns] = $existing[$ns];			}		}		return $del;	}	/**	 * Given an array of existing templates, returns those templates which are not in $this	 * and thus should be deleted.	 * @private	 */	function getTemplateDeletions( $existing ) {		$del = array();		foreach ( $existing as $ns => $dbkeys ) {			if ( isset( $this->mTemplates[$ns] ) ) {				$del[$ns] = array_diff_key( $existing[$ns], $this->mTemplates[$ns] );			} else {				$del[$ns] = $existing[$ns];			}		}		return $del;	}	/**	 * Given an array of existing images, returns those images which are not in $this	 * and thus should be deleted.	 * @private	 */	function getImageDeletions( $existing ) {		return array_diff_key( $existing, $this->mImages );	}	/** 	 * Given an array of existing external links, returns those links which are not	 * in $this and thus should be deleted.	 * @private	 */	function getExternalDeletions( $existing ) {		return array_diff_key( $existing, $this->mExternals );	}	/**	 * Given an array of existing categories, returns those categories which are not in $this	 * and thus should be deleted.	 * @private	 */	function getCategoryDeletions( $existing ) {		return array_diff_assoc( $existing, $this->mCategories );	}	/** 	 * Given an array of existing interlanguage links, returns those links which are not	 * in $this and thus should be deleted.	 * @private	 */	function getInterlangDeletions( $existing ) {	    return array_diff_assoc( $existing, $this->mInterlangs );	}	/**	 * Get an array of existing links, as a 2-D array	 * @private	 */	function getExistingLinks() {		$fname = 'LinksUpdate::getExistingLinks';		$res = $this->mDb->select( 'pagelinks', array( 'pl_namespace', 'pl_title' ),			array( 'pl_from' => $this->mId ), $fname, $this->mOptions );		$arr = array();		while ( $row = $this->mDb->fetchObject( $res ) ) {			if ( !isset( $arr[$row->pl_namespace] ) ) {				$arr[$row->pl_namespace] = array();			}			$arr[$row->pl_namespace][$row->pl_title] = 1;		}		$this->mDb->freeResult( $res );		return $arr;	}	/**	 * Get an array of existing templates, as a 2-D array	 * @private	 */	function getExistingTemplates() {		$fname = 'LinksUpdate::getExistingTemplates';		$res = $this->mDb->select( 'templatelinks', array( 'tl_namespace', 'tl_title' ),			array( 'tl_from' => $this->mId ), $fname, $this->mOptions );		$arr = array();		while ( $row = $this->mDb->fetchObject( $res ) ) {			if ( !isset( $arr[$row->tl_namespace] ) ) {				$arr[$row->tl_namespace] = array();			}			$arr[$row->tl_namespace][$row->tl_title] = 1;		}		$this->mDb->freeResult( $res );		return $arr;	}	/**	 * Get an array of existing images, image names in the keys	 * @private	 */	function getExistingImages() {		$fname = 'LinksUpdate::getExistingImages';		$res = $this->mDb->select( 'imagelinks', array( 'il_to' ),			array( 'il_from' => $this->mId ), $fname, $this->mOptions );		$arr = array();		while ( $row = $this->mDb->fetchObject( $res ) ) {			$arr[$row->il_to] = 1;		}		$this->mDb->freeResult( $res );		return $arr;	}	/**	 * Get an array of existing external links, URLs in the keys	 * @private	 */	function getExistingExternals() {		$fname = 'LinksUpdate::getExistingExternals';		$res = $this->mDb->select( 'externallinks', array( 'el_to' ),			array( 'el_from' => $this->mId ), $fname, $this->mOptions );		$arr = array();		while ( $row = $this->mDb->fetchObject( $res ) ) {			$arr[$row->el_to] = 1;		}		$this->mDb->freeResult( $res );		return $arr;	}	/**	 * Get an array of existing categories, with the name in the key and sort key in the value.	 * @private	 */	function getExistingCategories() {		$fname = 'LinksUpdate::getExistingCategories';		$res = $this->mDb->select( 'categorylinks', array( 'cl_to', 'cl_sortkey' ),			array( 'cl_from' => $this->mId ), $fname, $this->mOptions );		$arr = array();		while ( $row = $this->mDb->fetchObject( $res ) ) {			$arr[$row->cl_to] = $row->cl_sortkey;		}		$this->mDb->freeResult( $res );		return $arr;	}	/**	 * Get an array of existing interlanguage links, with the language code in the key and the 	 * title in the value.	 * @private	 */	function getExistingInterlangs() {		$fname = 'LinksUpdate::getExistingInterlangs';		$res = $this->mDb->select( 'langlinks', array( 'll_lang', 'll_title' ), 			array( 'll_from' => $this->mId ), $fname, $this->mOptions );		$arr = array();		while ( $row = $this->mDb->fetchObject( $res ) ) {			$arr[$row->ll_lang] = $row->ll_title;		}		return $arr;	}}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?