title.php

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

PHP
2,308
字号
	/**	 * Get the HTML-escaped displayable text form.	 * Used for the title field in <a> tags.	 * @return string the text, including any prefixes	 * @access public	 */	function getEscapedText() {		return htmlspecialchars( $this->getPrefixedText() );	}	/**	 * Is this Title interwiki?	 * @return boolean	 * @access public	 */	function isExternal() { return ( '' != $this->mInterwiki ); }	/**	 * Is this page "semi-protected" - the *only* protection is autoconfirm?	 *	 * @param string Action to check (default: edit)	 * @return bool	 */	function isSemiProtected( $action = 'edit' ) {		$restrictions = $this->getRestrictions( $action );		# We do a full compare because this could be an array		foreach( $restrictions as $restriction ) {			if( strtolower( $restriction ) != 'autoconfirmed' ) {				return( false );			}		}		return( true );	}	/**	 * Does the title correspond to a protected article?	 * @param string $what the action the page is protected from,	 *	by default checks move and edit	 * @return boolean	 * @access public	 */	function isProtected( $action = '' ) {		global $wgRestrictionLevels;		if ( -1 == $this->mNamespace ) { return true; }						if( $action == 'edit' || $action == '' ) {			$r = $this->getRestrictions( 'edit' );			foreach( $wgRestrictionLevels as $level ) {				if( in_array( $level, $r ) && $level != '' ) {					return( true );				}			}		}				if( $action == 'move' || $action == '' ) {			$r = $this->getRestrictions( 'move' );			foreach( $wgRestrictionLevels as $level ) {				if( in_array( $level, $r ) && $level != '' ) {					return( true );				}			}		}		return false;	}	/**	 * Is $wgUser is watching this page?	 * @return boolean	 * @access public	 */	function userIsWatching() {		global $wgUser;		if ( is_null( $this->mWatched ) ) {			if ( -1 == $this->mNamespace || 0 == $wgUser->getID()) {				$this->mWatched = false;			} else {				$this->mWatched = $wgUser->isWatched( $this );			}		}		return $this->mWatched;	} 	/**	 * Can $wgUser perform $action this page?	 * @param string $action action that permission needs to be checked for	 * @return boolean	 * @private 	 */	function userCan($action) {		$fname = 'Title::userCan';		wfProfileIn( $fname );		global $wgUser;		$result = null;		wfRunHooks( 'userCan', array( &$this, &$wgUser, $action, &$result ) );		if ( $result !== null ) {			wfProfileOut( $fname );			return $result;		}		if( NS_SPECIAL == $this->mNamespace ) {			wfProfileOut( $fname );			return false;		}		// XXX: This is the code that prevents unprotecting a page in NS_MEDIAWIKI		// from taking effect -忙var		if( NS_MEDIAWIKI == $this->mNamespace &&		    !$wgUser->isAllowed('editinterface') ) {			wfProfileOut( $fname );			return false;		}		if( $this->mDbkeyform == '_' ) {			# FIXME: Is this necessary? Shouldn't be allowed anyway...			wfProfileOut( $fname );			return false;		}		# protect css/js subpages of user pages		# XXX: this might be better using restrictions		# XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working		if( NS_USER == $this->mNamespace			&& preg_match("/\\.(css|js)$/", $this->mTextform )			&& !$wgUser->isAllowed('editinterface')			&& !preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) ) {			wfProfileOut( $fname );			return false;		}		foreach( $this->getRestrictions($action) as $right ) {			// Backwards compatibility, rewrite sysop -> protect			if ( $right == 'sysop' ) {				$right = 'protect';			}			if( '' != $right && !$wgUser->isAllowed( $right ) ) {				wfProfileOut( $fname );				return false;			}		}		if( $action == 'move' &&			!( $this->isMovable() && $wgUser->isAllowed( 'move' ) ) ) {			wfProfileOut( $fname );			return false;		}		if( $action == 'create' ) {			if( (  $this->isTalkPage() && !$wgUser->isAllowed( 'createtalk' ) ) ||				( !$this->isTalkPage() && !$wgUser->isAllowed( 'createpage' ) ) ) {				return false;			}		}		wfProfileOut( $fname );		return true;	}	/**	 * Can $wgUser edit this page?	 * @return boolean	 * @access public	 */	function userCanEdit() {		return $this->userCan('edit');	}	/**	 * Can $wgUser create this page?	 * @return boolean	 * @access public	 */	function userCanCreate() {		return $this->userCan('create');	}	/**	 * Can $wgUser move this page?	 * @return boolean	 * @access public	 */	function userCanMove() {		return $this->userCan('move');	}	/**	 * Would anybody with sufficient privileges be able to move this page?	 * Some pages just aren't movable.	 *	 * @return boolean	 * @access public	 */	function isMovable() {		return Namespace::isMovable( $this->getNamespace() )			&& $this->getInterwiki() == '';	}	/**	 * Can $wgUser read this page?	 * @return boolean	 * @access public	 */	function userCanRead() {		global $wgUser;		$result = null;		wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );		if ( $result !== null ) {			return $result;		}		if( $wgUser->isAllowed('read') ) {			return true;		} else {			global $wgWhitelistRead;			/** If anon users can create an account,			    they need to reach the login page first! */			if( $wgUser->isAllowed( 'createaccount' )			    && $this->getNamespace() == NS_SPECIAL			    && $this->getText() == 'Userlogin' ) {				return true;			}			/** some pages are explicitly allowed */			$name = $this->getPrefixedText();			if( $wgWhitelistRead && in_array( $name, $wgWhitelistRead ) ) {				return true;			}			# Compatibility with old settings			if( $wgWhitelistRead && $this->getNamespace() == NS_MAIN ) {				if( in_array( ':' . $name, $wgWhitelistRead ) ) {					return true;				}			}		}		return false;	}	/**	 * Is this a talk page of some sort?	 * @return bool	 * @access public	 */	function isTalkPage() {		return Namespace::isTalk( $this->getNamespace() );	}	/**	 * Is this a .css or .js subpage of a user page?	 * @return bool	 * @access public	 */	function isCssJsSubpage() {		return ( NS_USER == $this->mNamespace and preg_match("/\\.(css|js)$/", $this->mTextform ) );	}	/**	 * Is this a *valid* .css or .js subpage of a user page?	 * Check that the corresponding skin exists	 */	function isValidCssJsSubpage() {		if ( $this->isCssJsSubpage() ) {			$skinNames = Skin::getSkinNames();			return array_key_exists( $this->getSkinFromCssJsSubpage(), $skinNames );		} else {			return false;		}	}	/**	 * Trim down a .css or .js subpage title to get the corresponding skin name	 */	function getSkinFromCssJsSubpage() {		$subpage = explode( '/', $this->mTextform );		$subpage = $subpage[ count( $subpage ) - 1 ];		return( str_replace( array( '.css', '.js' ), array( '', '' ), $subpage ) );	}	/**	 * Is this a .css subpage of a user page?	 * @return bool	 * @access public	 */	function isCssSubpage() {		return ( NS_USER == $this->mNamespace and preg_match("/\\.css$/", $this->mTextform ) );	}	/**	 * Is this a .js subpage of a user page?	 * @return bool	 * @access public	 */	function isJsSubpage() {		return ( NS_USER == $this->mNamespace and preg_match("/\\.js$/", $this->mTextform ) );	}	/**	 * Protect css/js subpages of user pages: can $wgUser edit	 * this page?	 *	 * @return boolean	 * @todo XXX: this might be better using restrictions	 * @access public	 */	function userCanEditCssJsSubpage() {		global $wgUser;		return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );	}	/**	 * Loads a string into mRestrictions array	 * @param string $res restrictions in string format	 * @access public	 */	function loadRestrictions( $res ) {		foreach( explode( ':', trim( $res ) ) as $restrict ) {			$temp = explode( '=', trim( $restrict ) );			if(count($temp) == 1) {				// old format should be treated as edit/move restriction				$this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );				$this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );			} else {				$this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );			}		}		$this->mRestrictionsLoaded = true;	}	/**	 * Accessor/initialisation for mRestrictions	 * @param string $action action that permission needs to be checked for	 * @return array the array of groups allowed to edit this article	 * @access public	 */	function getRestrictions($action) {		$id = $this->getArticleID();		if ( 0 == $id ) { return array(); }		if ( ! $this->mRestrictionsLoaded ) {			$dbr =& wfGetDB( DB_SLAVE );			$res = $dbr->selectField( 'page', 'page_restrictions', 'page_id='.$id );			$this->loadRestrictions( $res );		}		if( isset( $this->mRestrictions[$action] ) ) {			return $this->mRestrictions[$action];		}		return array();	}	/**	 * Is there a version of this page in the deletion archive?	 * @return int the number of archived revisions	 * @access public	 */	function isDeleted() {		$fname = 'Title::isDeleted';		if ( $this->getNamespace() < 0 ) {			$n = 0;		} else {			$dbr =& wfGetDB( DB_SLAVE );			$n = $dbr->selectField( 'archive', 'COUNT(*)', array( 'ar_namespace' => $this->getNamespace(),				'ar_title' => $this->getDBkey() ), $fname );			if( $this->getNamespace() == NS_IMAGE ) {				$n += $dbr->selectField( 'filearchive', 'COUNT(*)',					array( 'fa_name' => $this->getDBkey() ), $fname );			}		}		return (int)$n;	}	/**	 * Get the article ID for this Title from the link cache,	 * adding it if necessary	 * @param int $flags a bit field; may be GAID_FOR_UPDATE to select	 * 	for update	 * @return int the ID	 * @access public	 */	function getArticleID( $flags = 0 ) {		$linkCache =& LinkCache::singleton();		if ( $flags & GAID_FOR_UPDATE ) {			$oldUpdate = $linkCache->forUpdate( true );			$this->mArticleID = $linkCache->addLinkObj( $this );			$linkCache->forUpdate( $oldUpdate );		} else {			if ( -1 == $this->mArticleID ) {				$this->mArticleID = $linkCache->addLinkObj( $this );			}		}		return $this->mArticleID;	}	function getLatestRevID() {		if ($this->mLatestID !== false)			return $this->mLatestID;		$db =& wfGetDB(DB_SLAVE);		return $this->mLatestID = $db->selectField( 'revision',			"max(rev_id)",			array('rev_page' => $this->getArticleID()),			'Title::getLatestRevID' );	}	/**	 * This clears some fields in this object, and clears any associated	 * keys in the "bad links" section of the link cache.	 *	 * - This is called from Article::insertNewArticle() to allow	 * loading of the new page_id. It's also called from	 * Article::doDeleteArticle()	 *	 * @param int $newid the new Article ID	 * @access public	 */	function resetArticleID( $newid ) {		$linkCache =& LinkCache::singleton();		$linkCache->clearBadLink( $this->getPrefixedDBkey() );		if ( 0 == $newid ) { $this->mArticleID = -1; }		else { $this->mArticleID = $newid; }		$this->mRestrictionsLoaded = false;		$this->mRestrictions = array();	}	/**	 * Updates page_touched for this page; called from LinksUpdate.php	 * @return bool true if the update succeded	 * @access public	 */	function invalidateCache() {		global $wgUseFileCache;		if ( wfReadOnly() ) {			return;		}		$dbw =& wfGetDB( DB_MASTER );		$success = $dbw->update( 'page',			array( /* SET */				'page_touched' => $dbw->timestamp()			), array( /* WHERE */				'page_namespace' => $this->getNamespace() ,				'page_title' => $this->getDBkey()			), 'Title::invalidateCache'		);		if ($wgUseFileCache) {			$cache = new CacheManager($this);			@unlink($cache->fileCacheName());		}		return $success;	}	/**	 * Prefix some arbitrary text with the namespace or interwiki prefix	 * of this object	 *	 * @param string $name the text	 * @return string the prefixed text	 * @private	 */

⌨️ 快捷键说明

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