title.php

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

PHP
2,308
字号
		return true;	}	/**	 * Move page to a title which is at present a redirect to the	 * source page	 *	 * @param Title &$nt the page to move to, which should currently	 * 	be a redirect	 * @private	 */	function moveOverExistingRedirect( &$nt, $reason = '' ) {		global $wgUseSquid;		$fname = 'Title::moveOverExistingRedirect';		$comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );		if ( $reason ) {			$comment .= ": $reason";		}		$now = wfTimestampNow();		$rand = wfRandom();		$newid = $nt->getArticleID();		$oldid = $this->getArticleID();		$dbw =& wfGetDB( DB_MASTER );		$linkCache =& LinkCache::singleton();		# Delete the old redirect. We don't save it to history since		# by definition if we've got here it's rather uninteresting.		# We have to remove it so that the next step doesn't trigger		# a conflict on the unique namespace+title index...		$dbw->delete( 'page', array( 'page_id' => $newid ), $fname );		# Save a null revision in the page's history notifying of the move		$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );		$nullRevId = $nullRevision->insertOn( $dbw );		# Change the name of the target page:		$dbw->update( 'page',			/* SET */ array(				'page_touched'   => $dbw->timestamp($now),				'page_namespace' => $nt->getNamespace(),				'page_title'     => $nt->getDBkey(),				'page_latest'    => $nullRevId,			),			/* WHERE */ array( 'page_id' => $oldid ),			$fname		);		$linkCache->clearLink( $nt->getPrefixedDBkey() );		# Recreate the redirect, this time in the other direction.		$mwRedir = MagicWord::get( MAG_REDIRECT );		$redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";		$redirectArticle = new Article( $this );		$newid = $redirectArticle->insertOn( $dbw );		$redirectRevision = new Revision( array(			'page'    => $newid,			'comment' => $comment,			'text'    => $redirectText ) );		$revid = $redirectRevision->insertOn( $dbw );		$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );		$linkCache->clearLink( $this->getPrefixedDBkey() );		# Log the move		$log = new LogPage( 'move' );		$log->addEntry( 'move_redir', $this, $reason, array( 1 => $nt->getPrefixedText() ) );		# Now, we record the link from the redirect to the new title.		# It should have no other outgoing links...		$dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), $fname );		$dbw->insert( 'pagelinks',			array(				'pl_from'      => $newid,				'pl_namespace' => $nt->getNamespace(),				'pl_title'     => $nt->getDbKey() ),			$fname );		# Purge squid		if ( $wgUseSquid ) {			$urls = array_merge( $nt->getSquidURLs(), $this->getSquidURLs() );			$u = new SquidUpdate( $urls );			$u->doUpdate();		}	}	/**	 * Move page to non-existing title.	 * @param Title &$nt the new Title	 * @private	 */	function moveToNewTitle( &$nt, $reason = '' ) {		global $wgUseSquid;		$fname = 'MovePageForm::moveToNewTitle';		$comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );		if ( $reason ) {			$comment .= ": $reason";		}		$newid = $nt->getArticleID();		$oldid = $this->getArticleID();		$dbw =& wfGetDB( DB_MASTER );		$now = $dbw->timestamp();		$rand = wfRandom();		$linkCache =& LinkCache::singleton();		# Save a null revision in the page's history notifying of the move		$nullRevision = Revision::newNullRevision( $dbw, $oldid, $comment, true );		$nullRevId = $nullRevision->insertOn( $dbw );		# Rename cur entry		$dbw->update( 'page',			/* SET */ array(				'page_touched'   => $now,				'page_namespace' => $nt->getNamespace(),				'page_title'     => $nt->getDBkey(),				'page_latest'    => $nullRevId,			),			/* WHERE */ array( 'page_id' => $oldid ),			$fname		);		$linkCache->clearLink( $nt->getPrefixedDBkey() );		# Insert redirect		$mwRedir = MagicWord::get( MAG_REDIRECT );		$redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";		$redirectArticle = new Article( $this );		$newid = $redirectArticle->insertOn( $dbw );		$redirectRevision = new Revision( array(			'page'    => $newid,			'comment' => $comment,			'text'    => $redirectText ) );		$revid = $redirectRevision->insertOn( $dbw );		$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );		$linkCache->clearLink( $this->getPrefixedDBkey() );		# Log the move		$log = new LogPage( 'move' );		$log->addEntry( 'move', $this, $reason, array( 1 => $nt->getPrefixedText()) );		# Purge caches as per article creation		Article::onArticleCreate( $nt );		# Record the just-created redirect's linking to the page		$dbw->insert( 'pagelinks',			array(				'pl_from'      => $newid,				'pl_namespace' => $nt->getNamespace(),				'pl_title'     => $nt->getDBkey() ),			$fname );		# Purge old title from squid		# The new title, and links to the new title, are purged in Article::onArticleCreate()		$this->purgeSquid();	}	/**	 * Checks if $this can be moved to a given Title	 * - Selects for update, so don't call it unless you mean business	 *	 * @param Title &$nt the new title to check	 * @access public	 */	function isValidMoveTarget( $nt ) {		$fname = 'Title::isValidMoveTarget';		$dbw =& wfGetDB( DB_MASTER );		# Is it a redirect?		$id  = $nt->getArticleID();		$obj = $dbw->selectRow( array( 'page', 'revision', 'text'),			array( 'page_is_redirect','old_text','old_flags' ),			array( 'page_id' => $id, 'page_latest=rev_id', 'rev_text_id=old_id' ),			$fname, 'FOR UPDATE' );		if ( !$obj || 0 == $obj->page_is_redirect ) {			# Not a redirect			wfDebug( __METHOD__ . ": not a redirect\n" );			return false;		}		$text = Revision::getRevisionText( $obj );		# Does the redirect point to the source?		# Or is it a broken self-redirect, usually caused by namespace collisions?		if ( preg_match( "/\\[\\[\\s*([^\\]\\|]*)]]/", $text, $m ) ) {			$redirTitle = Title::newFromText( $m[1] );			if( !is_object( $redirTitle ) ||				( $redirTitle->getPrefixedDBkey() != $this->getPrefixedDBkey() &&				$redirTitle->getPrefixedDBkey() != $nt->getPrefixedDBkey() ) ) {				wfDebug( __METHOD__ . ": redirect points to other page\n" );				return false;			}		} else {			# Fail safe			wfDebug( __METHOD__ . ": failsafe\n" );			return false;		}		# Does the article have a history?		$row = $dbw->selectRow( array( 'page', 'revision'),			array( 'rev_id' ),			array( 'page_namespace' => $nt->getNamespace(),				'page_title' => $nt->getDBkey(),				'page_id=rev_page AND page_latest != rev_id'			), $fname, 'FOR UPDATE'		);		# Return true if there was no history		return $row === false;	}	/**	 * Create a redirect; fails if the title already exists; does	 * not notify RC	 *	 * @param Title $dest the destination of the redirect	 * @param string $comment the comment string describing the move	 * @return bool true on success	 * @access public	 */	function createRedirect( $dest, $comment ) {		if ( $this->getArticleID() ) {			return false;		}		$fname = 'Title::createRedirect';		$dbw =& wfGetDB( DB_MASTER );		$article = new Article( $this );		$newid = $article->insertOn( $dbw );		$revision = new Revision( array(			'page'      => $newid,			'comment'   => $comment,			'text'      => "#REDIRECT [[" . $dest->getPrefixedText() . "]]\n",			) );		$revisionId = $revision->insertOn( $dbw );		$article->updateRevisionOn( $dbw, $revision, 0 );		# Link table		$dbw->insert( 'pagelinks',			array(				'pl_from'      => $newid,				'pl_namespace' => $dest->getNamespace(),				'pl_title'     => $dest->getDbKey()			), $fname		);		Article::onArticleCreate( $this );		return true;	}	/**	 * Get categories to which this Title belongs and return an array of	 * categories' names.	 *	 * @return array an array of parents in the form:	 *	$parent => $currentarticle	 * @access public	 */	function getParentCategories() {		global $wgContLang;		$titlekey = $this->getArticleId();		$dbr =& wfGetDB( DB_SLAVE );		$categorylinks = $dbr->tableName( 'categorylinks' );		# NEW SQL		$sql = "SELECT * FROM $categorylinks"		     ." WHERE cl_from='$titlekey'"			 ." AND cl_from <> '0'"			 ." ORDER BY cl_sortkey";		$res = $dbr->query ( $sql ) ;		if($dbr->numRows($res) > 0) {			while ( $x = $dbr->fetchObject ( $res ) )				//$data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to);				$data[$wgContLang->getNSText ( NS_CATEGORY ).':'.$x->cl_to] = $this->getFullText();			$dbr->freeResult ( $res ) ;		} else {			$data = '';		}		return $data;	}	/**	 * Get a tree of parent categories	 * @param array $children an array with the children in the keys, to check for circular refs	 * @return array	 * @access public	 */	function getParentCategoryTree( $children = array() ) {		$parents = $this->getParentCategories();		if($parents != '') {			foreach($parents as $parent => $current) {				if ( array_key_exists( $parent, $children ) ) {					# Circular reference					$stack[$parent] = array();				} else {					$nt = Title::newFromText($parent);					$stack[$parent] = $nt->getParentCategoryTree( $children + array($parent => 1) );				}			}			return $stack;		} else {			return array();		}	}	/**	 * Get an associative array for selecting this title from	 * the "page" table	 *	 * @return array	 * @access public	 */	function pageCond() {		return array( 'page_namespace' => $this->mNamespace, 'page_title' => $this->mDbkeyform );	}	/**	 * Get the revision ID of the previous revision	 *	 * @param integer $revision  Revision ID. Get the revision that was before this one.	 * @return interger $oldrevision|false	 */	function getPreviousRevisionID( $revision ) {		$dbr =& wfGetDB( DB_SLAVE );		return $dbr->selectField( 'revision', 'rev_id',			'rev_page=' . intval( $this->getArticleId() ) .			' AND rev_id<' . intval( $revision ) . ' ORDER BY rev_id DESC' );	}	/**	 * Get the revision ID of the next revision	 *	 * @param integer $revision  Revision ID. Get the revision that was after this one.	 * @return interger $oldrevision|false	 */	function getNextRevisionID( $revision ) {		$dbr =& wfGetDB( DB_SLAVE );		return $dbr->selectField( 'revision', 'rev_id',			'rev_page=' . intval( $this->getArticleId() ) .			' AND rev_id>' . intval( $revision ) . ' ORDER BY rev_id' );	}	/**	 * Compare with another title.	 *	 * @param Title $title	 * @return bool	 */	function equals( $title ) {		// Note: === is necessary for proper matching of number-like titles.		return $this->getInterwiki() === $title->getInterwiki()			&& $this->getNamespace() == $title->getNamespace()			&& $this->getDbkey() === $title->getDbkey();	}	/**	 * Check if page exists	 * @return bool	 */	function exists() {		return $this->getArticleId() != 0;	}	/**	 * Should a link should be displayed as a known link, just based on its title?	 *	 * Currently, a self-link with a fragment and special pages are in	 * this category. Special pages never exist in the database.	 */	function isAlwaysKnown() {		return  $this->isExternal() || ( 0 == $this->mNamespace && "" == $this->mDbkeyform )		  || NS_SPECIAL == $this->mNamespace;	}	/**	 * Update page_touched timestamps and send squid purge messages for	 * pages linking to this title.	May be sent to the job queue depending 	 * on the number of links. Typically called on create and delete.	 */	function touchLinks() {		$u = new HTMLCacheUpdate( $this, 'pagelinks' );		$u->doUpdate();		if ( $this->getNamespace() == NS_CATEGORY ) {			$u = new HTMLCacheUpdate( $this, 'categorylinks' );			$u->doUpdate();		}	}	function trackbackURL() {		global $wgTitle, $wgScriptPath, $wgServer;		return "$wgServer$wgScriptPath/trackback.php?article="			. htmlspecialchars(urlencode($wgTitle->getPrefixedDBkey()));	}	function trackbackRDF() {		$url = htmlspecialchars($this->getFullURL());		$title = htmlspecialchars($this->getText());		$tburl = $this->trackbackURL();		return "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"         xmlns:dc=\"http://purl.org/dc/elements/1.1/\"         xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\"><rdf:Description   rdf:about=\"$url\"   dc:identifier=\"$url\"   dc:title=\"$title\"   trackback:ping=\"$tburl\" /></rdf:RDF>";	}	/**	 * Generate strings used for xml 'id' names in monobook tabs	 * @return string	 */	function getNamespaceKey() {		switch ($this->getNamespace()) {			case NS_MAIN:			case NS_TALK:				return 'nstab-main';			case NS_USER:			case NS_USER_TALK:				return 'nstab-user';			case NS_MEDIA:				return 'nstab-media';			case NS_SPECIAL:				return 'nstab-special';			case NS_PROJECT:			case NS_PROJECT_TALK:				return 'nstab-project';			case NS_IMAGE:			case NS_IMAGE_TALK:				return 'nstab-image';			case NS_MEDIAWIKI:			case NS_MEDIAWIKI_TALK:				return 'nstab-mediawiki';			case NS_TEMPLATE:			case NS_TEMPLATE_TALK:				return 'nstab-template';			case NS_HELP:			case NS_HELP_TALK:				return 'nstab-help';			case NS_CATEGORY:			case NS_CATEGORY_TALK:				return 'nstab-category';			default:				return 'nstab-' . strtolower( $this->getSubjectNsText() );		}	}}?>

⌨️ 快捷键说明

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