title.php

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

PHP
2,308
字号
		}		if ($value=='' and $wgInterwikiScopes>=2) {			/* try globals */			$value = dba_fetch("__global:{$key}", $db);		}		if ($value=='undef')			$value='';		$s = (object)false;		$s->iw_url = '';		$s->iw_local = 0;		$s->iw_trans = 0;		if ($value!='') {			list($local,$url)=explode(' ',$value,2);			$s->iw_url=$url;			$s->iw_local=(int)$local;		}		Title::$interwikiCache[$wgDBname.':interwiki:'.$key] = $s;		return $s->iw_url;	}	/**	 * Determine whether the object refers to a page within	 * this project.	 *	 * @return bool TRUE if this is an in-project interwiki link	 *	or a wikilink, FALSE otherwise	 * @access public	 */	function isLocal() {		global $wgDBname;		if ( $this->mInterwiki != '' ) {			# Make sure key is loaded into cache			$this->getInterwikiLink( $this->mInterwiki );			$k = $wgDBname.':interwiki:' . $this->mInterwiki;			return (bool)(Title::$interwikiCache[$k]->iw_local);		} else {			return true;		}	}	/**	 * Determine whether the object refers to a page within	 * this project and is transcludable.	 *	 * @return bool TRUE if this is transcludable	 * @access public	 */	function isTrans() {		global $wgDBname;		if ($this->mInterwiki == '')			return false;		# Make sure key is loaded into cache		$this->getInterwikiLink( $this->mInterwiki );		$k = $wgDBname.':interwiki:' . $this->mInterwiki;		return (bool)(Title::$interwikiCache[$k]->iw_trans);	}	/**	 * Update the page_touched field for an array of title objects	 * @todo Inefficient unless the IDs are already loaded into the	 *	link cache	 * @param array $titles an array of Title objects to be touched	 * @param string $timestamp the timestamp to use instead of the	 *	default current time	 * @static	 * @access public	 */	function touchArray( $titles, $timestamp = '' ) {		if ( count( $titles ) == 0 ) {			return;		}		$dbw =& wfGetDB( DB_MASTER );		if ( $timestamp == '' ) {			$timestamp = $dbw->timestamp();		}		/*		$page = $dbw->tableName( 'page' );		$sql = "UPDATE $page SET page_touched='{$timestamp}' WHERE page_id IN (";		$first = true;		foreach ( $titles as $title ) {			if ( $wgUseFileCache ) {				$cm = new CacheManager($title);				@unlink($cm->fileCacheName());			}			if ( ! $first ) {				$sql .= ',';			}			$first = false;			$sql .= $title->getArticleID();		}		$sql .= ')';		if ( ! $first ) {			$dbw->query( $sql, 'Title::touchArray' );		}		*/		// hack hack hack -- brion 2005-07-11. this was unfriendly to db.		// do them in small chunks:		$fname = 'Title::touchArray';		foreach( $titles as $title ) {			$dbw->update( 'page',				array( 'page_touched' => $timestamp ),				array(					'page_namespace' => $title->getNamespace(),					'page_title'     => $title->getDBkey() ),				$fname );		}	}#----------------------------------------------------------------------------#	Other stuff#----------------------------------------------------------------------------	/** Simple accessors */	/**	 * Get the text form (spaces not underscores) of the main part	 * @return string	 * @access public	 */	function getText() { return $this->mTextform; }	/**	 * Get the URL-encoded form of the main part	 * @return string	 * @access public	 */	function getPartialURL() { return $this->mUrlform; }	/**	 * Get the main part with underscores	 * @return string	 * @access public	 */	function getDBkey() { return $this->mDbkeyform; }	/**	 * Get the namespace index, i.e. one of the NS_xxxx constants	 * @return int	 * @access public	 */	function getNamespace() { return $this->mNamespace; }	/**	 * Get the namespace text	 * @return string	 * @access public	 */	function getNsText() {		global $wgContLang;		return $wgContLang->getNsText( $this->mNamespace );	}	/**	 * Get the namespace text of the subject (rather than talk) page	 * @return string	 * @access public	 */	function getSubjectNsText() {		global $wgContLang;		return $wgContLang->getNsText( Namespace::getSubject( $this->mNamespace ) );	}	/**	 * Get the namespace text of the talk page	 * @return string	 */	function getTalkNsText() {		global $wgContLang;		return( $wgContLang->getNsText( Namespace::getTalk( $this->mNamespace ) ) );	}		/**	 * Could this title have a corresponding talk page?	 * @return bool	 */	function canTalk() {		return( Namespace::canTalk( $this->mNamespace ) );	}		/**	 * Get the interwiki prefix (or null string)	 * @return string	 * @access public	 */	function getInterwiki() { return $this->mInterwiki; }	/**	 * Get the Title fragment (i.e. the bit after the #)	 * @return string	 * @access public	 */	function getFragment() { return $this->mFragment; }	/**	 * Get the default namespace index, for when there is no namespace	 * @return int	 * @access public	 */	function getDefaultNamespace() { return $this->mDefaultNamespace; }	/**	 * Get title for search index	 * @return string a stripped-down title string ready for the	 * 	search index	 */	function getIndexTitle() {		return Title::indexTitle( $this->mNamespace, $this->mTextform );	}	/**	 * Get the prefixed database key form	 * @return string the prefixed title, with underscores and	 * 	any interwiki and namespace prefixes	 * @access public	 */	function getPrefixedDBkey() {		$s = $this->prefix( $this->mDbkeyform );		$s = str_replace( ' ', '_', $s );		return $s;	}	/**	 * Get the prefixed title with spaces.	 * This is the form usually used for display	 * @return string the prefixed title, with spaces	 * @access public	 */	function getPrefixedText() {		if ( empty( $this->mPrefixedText ) ) { // FIXME: bad usage of empty() ?			$s = $this->prefix( $this->mTextform );			$s = str_replace( '_', ' ', $s );			$this->mPrefixedText = $s;		}		return $this->mPrefixedText;	}	/**	 * Get the prefixed title with spaces, plus any fragment	 * (part beginning with '#')	 * @return string the prefixed title, with spaces and	 * 	the fragment, including '#'	 * @access public	 */	function getFullText() {		$text = $this->getPrefixedText();		if( '' != $this->mFragment ) {			$text .= '#' . $this->mFragment;		}		return $text;	}	/**	 * Get the base name, i.e. the leftmost parts before the /	 * @return string Base name	 */	function getBaseText() {		global $wgNamespacesWithSubpages;		if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) {			$parts = explode( '/', $this->getText() );			# Don't discard the real title if there's no subpage involved			if( count( $parts ) > 1 )				unset( $parts[ count( $parts ) - 1 ] );			return implode( '/', $parts );		} else {			return $this->getText();		}	}	/**	 * Get the lowest-level subpage name, i.e. the rightmost part after /	 * @return string Subpage name	 */	function getSubpageText() {		global $wgNamespacesWithSubpages;		if( isset( $wgNamespacesWithSubpages[ $this->mNamespace ] ) && $wgNamespacesWithSubpages[ $this->mNamespace ] ) {			$parts = explode( '/', $this->mTextform );			return( $parts[ count( $parts ) - 1 ] );		} else {			return( $this->mTextform );		}	}		/**	 * Get a URL-encoded form of the subpage text	 * @return string URL-encoded subpage name	 */	function getSubpageUrlForm() {		$text = $this->getSubpageText();		$text = wfUrlencode( str_replace( ' ', '_', $text ) );		$text = str_replace( '%28', '(', str_replace( '%29', ')', $text ) ); # Clean up the URL; per below, this might not be safe		return( $text );	}	/**	 * Get a URL-encoded title (not an actual URL) including interwiki	 * @return string the URL-encoded form	 * @access public	 */	function getPrefixedURL() {		$s = $this->prefix( $this->mDbkeyform );		$s = str_replace( ' ', '_', $s );		$s = wfUrlencode ( $s ) ;		# Cleaning up URL to make it look nice -- is this safe?		$s = str_replace( '%28', '(', $s );		$s = str_replace( '%29', ')', $s );		return $s;	}	/**	 * Get a real URL referring to this title, with interwiki link and	 * fragment	 *	 * @param string $query an optional query string, not used	 * 	for interwiki links	 * @return string the URL	 * @access public	 */	function getFullURL( $query = '' ) {		global $wgContLang, $wgServer, $wgRequest;		if ( '' == $this->mInterwiki ) {			$url = $this->getLocalUrl( $query );			// Ugly quick hack to avoid duplicate prefixes (bug 4571 etc)			// Correct fix would be to move the prepending elsewhere.			if ($wgRequest->getVal('action') != 'render') {				$url = $wgServer . $url;			}		} else {			$baseUrl = $this->getInterwikiLink( $this->mInterwiki );			$namespace = $wgContLang->getNsText( $this->mNamespace );			if ( '' != $namespace ) {				# Can this actually happen? Interwikis shouldn't be parsed.				$namespace .= ':';			}			$url = str_replace( '$1', $namespace . $this->mUrlform, $baseUrl );			if( $query != '' ) {				if( false === strpos( $url, '?' ) ) {					$url .= '?';				} else {					$url .= '&';				}				$url .= $query;			}		}		# Finally, add the fragment.		if ( '' != $this->mFragment ) {			$url .= '#' . $this->mFragment;		}		wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) );		return $url;	}	/**	 * Get a URL with no fragment or server name.  If this page is generated	 * with action=render, $wgServer is prepended.	 * @param string $query an optional query string; if not specified,	 * 	$wgArticlePath will be used.	 * @return string the URL	 * @access public	 */	function getLocalURL( $query = '' ) {		global $wgArticlePath, $wgScript, $wgServer, $wgRequest;		if ( $this->isExternal() ) {			$url = $this->getFullURL();			if ( $query ) {				// This is currently only used for edit section links in the				// context of interwiki transclusion. In theory we should				// append the query to the end of any existing query string,				// but interwiki transclusion is already broken in that case.				$url .= "?$query";			}		} else {			$dbkey = wfUrlencode( $this->getPrefixedDBkey() );			if ( $query == '' ) {				$url = str_replace( '$1', $dbkey, $wgArticlePath );			} else {				global $wgActionPaths;				$url = false;				if( !empty( $wgActionPaths ) &&					preg_match( '/^(.*&|)action=([^&]*)(&(.*)|)$/', $query, $matches ) )				{					$action = urldecode( $matches[2] );					if( isset( $wgActionPaths[$action] ) ) {						$query = $matches[1];						if( isset( $matches[4] ) ) $query .= $matches[4];						$url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );						if( $query != '' ) $url .= '?' . $query;					}				}				if ( $url === false ) {					if ( $query == '-' ) {						$query = '';					}					$url = "{$wgScript}?title={$dbkey}&{$query}";				}			}						// FIXME: this causes breakage in various places when we			// actually expected a local URL and end up with dupe prefixes.			if ($wgRequest->getVal('action') == 'render') {				$url = $wgServer . $url;			}		}		wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) );		return $url;	}	/**	 * Get an HTML-escaped version of the URL form, suitable for	 * using in a link, without a server name or fragment	 * @param string $query an optional query string	 * @return string the URL	 * @access public	 */	function escapeLocalURL( $query = '' ) {		return htmlspecialchars( $this->getLocalURL( $query ) );	}	/**	 * Get an HTML-escaped version of the URL form, suitable for	 * using in a link, including the server name and fragment	 *	 * @return string the URL	 * @param string $query an optional query string	 * @access public	 */	function escapeFullURL( $query = '' ) {		return htmlspecialchars( $this->getFullURL( $query ) );	}	/**	 * Get the URL form for an internal link.	 * - Used in various Squid-related code, in case we have a different	 * internal hostname for the server from the exposed one.	 *	 * @param string $query an optional query string	 * @return string the URL	 * @access public	 */	function getInternalURL( $query = '' ) {		global $wgInternalServer;		$url = $wgInternalServer . $this->getLocalURL( $query );		wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) );		return $url;	}	/**	 * Get the edit URL for this Title	 * @return string the URL, or a null string if this is an	 * 	interwiki link	 * @access public	 */	function getEditURL() {		if ( '' != $this->mInterwiki ) { return ''; }		$s = $this->getLocalURL( 'action=edit' );		return $s;	}

⌨️ 快捷键说明

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