pagehistory.php

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

PHP
686
字号
	/** @todo document */	function diffButtons( $rev, $firstInList, $counter ) {		if( $this->linesonpage > 1) {			$radio = array(				'type'  => 'radio',				'value' => $rev->getId(),# do we really need to flood this on every item?#				'title' => wfMsgHtml( 'selectolderversionfordiff' )			);			if( !$rev->userCan( Revision::DELETED_TEXT ) ) {				$radio['disabled'] = 'disabled';			}			/** @todo: move title texts to javascript */			if ( $firstInList ) {				$first = wfElement( 'input', array_merge(					$radio,					array(						'style' => 'visibility:hidden',						'name'  => 'oldid' ) ) );				$checkmark = array( 'checked' => 'checked' );			} else {				if( $counter == 2 ) {					$checkmark = array( 'checked' => 'checked' );				} else {					$checkmark = array();				}				$first = wfElement( 'input', array_merge(					$radio,					$checkmark,					array( 'name'  => 'oldid' ) ) );				$checkmark = array();			}			$second = wfElement( 'input', array_merge(				$radio,				$checkmark,				array( 'name'  => 'diff' ) ) );			return $first . $second;		} else {			return '';		}	}	/** @todo document */	function getLatestOffset( $id = null ) {		if ( $id === null) $id = $this->mTitle->getArticleID();		return $this->getExtremeOffset( $id, 'max' );	}	/** @todo document */	function getEarliestOffset( $id = null ) {		if ( $id === null) $id = $this->mTitle->getArticleID();		return $this->getExtremeOffset( $id, 'min' );	}	/** @todo document */	function getExtremeOffset( $id, $func ) {		$db =& wfGetDB(DB_SLAVE);		return $db->selectField( 'revision',			"$func(rev_timestamp)",			array( 'rev_page' => $id ),			'PageHistory::getExtremeOffset' );	}	/** @todo document */	function getLatestId() {		if( is_null( $this->mLatestId ) ) {			$id = $this->mTitle->getArticleID();			$db =& wfGetDB(DB_SLAVE);			$this->mLatestId = $db->selectField( 'revision',				"max(rev_id)",				array( 'rev_page' => $id ),				'PageHistory::getLatestID' );		}		return $this->mLatestId;	}	/** @todo document */	function getLastOffsetForPaging( $id, $step ) {		$fname = 'PageHistory::getLastOffsetForPaging';		$dbr =& wfGetDB(DB_SLAVE);		$res = $dbr->select(			'revision',			'rev_timestamp',			"rev_page=$id",			$fname,			array('ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => $step));		$n = $dbr->numRows( $res );		$last = null;		while( $obj = $dbr->fetchObject( $res ) ) {			$last = $obj->rev_timestamp;		}		$dbr->freeResult( $res );		return $last;	}	/**	 * @return returns the direction of browsing watchlist	 */	function getDirection() {		global $wgRequest;		if ($wgRequest->getText("dir") == "prev")			return PageHistory::DIR_PREV;		else			return PageHistory::DIR_NEXT;	}	/** @todo document */	function fetchRevisions($limit, $offset, $direction) {		$fname = 'PageHistory::fetchRevisions';		$dbr =& wfGetDB( DB_SLAVE );		if ($direction == PageHistory::DIR_PREV)			list($dirs, $oper) = array("ASC", ">=");		else /* $direction == PageHistory::DIR_NEXT */			list($dirs, $oper) = array("DESC", "<=");		if ($offset)			$offsets = array("rev_timestamp $oper '$offset'");		else			$offsets = array();		$page_id = $this->mTitle->getArticleID();		$res = $dbr->select(			'revision',			array('rev_id', 'rev_page', 'rev_text_id', 'rev_user', 'rev_comment', 'rev_user_text',				'rev_timestamp', 'rev_minor_edit', 'rev_deleted'),			array_merge(array("rev_page=$page_id"), $offsets),			$fname,			array('ORDER BY' => "rev_timestamp $dirs",				'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit)			);		$result = array();		while (($obj = $dbr->fetchObject($res)) != NULL)			$result[] = $obj;		return $result;	}	/** @todo document */	function getNotificationTimestamp() {		global $wgUser, $wgShowUpdatedMarker;		$fname = 'PageHistory::getNotficationTimestamp';		if ($this->mNotificationTimestamp !== NULL)			return $this->mNotificationTimestamp;		if ($wgUser->isAnon() || !$wgShowUpdatedMarker)			return $this->mNotificationTimestamp = false;		$dbr =& wfGetDB(DB_SLAVE);		$this->mNotificationTimestamp = $dbr->selectField(			'watchlist',			'wl_notificationtimestamp',			array(	'wl_namespace' => $this->mTitle->getNamespace(),				'wl_title' => $this->mTitle->getDBkey(),				'wl_user' => $wgUser->getID()			),			$fname);				// Don't use the special value reserved for telling whether the field is filled		if ( is_null( $this->mNotificationTimestamp ) ) {			$this->mNotificationTimestamp = false;		}		return $this->mNotificationTimestamp;	}	/** @todo document */	function makeNavbar($revisions, $offset, $limit, $direction) {		global $wgLang;		$revisions = array_slice($revisions, 0, $limit);		$latestTimestamp = wfTimestamp(TS_MW, $this->getLatestOffset());		$earliestTimestamp = wfTimestamp(TS_MW, $this->getEarliestOffset());		/*		 * When we're displaying previous revisions, we need to reverse		 * the array, because it's queried in reverse order.		 */		if ($direction == PageHistory::DIR_PREV)			$revisions = array_reverse($revisions);		/*		 * lowts is the timestamp of the first revision on this page.		 * hights is the timestamp of the last revision.		 */		$lowts = $hights = 0;		if( count( $revisions ) ) {			$latestShown = wfTimestamp(TS_MW, $revisions[0]->rev_timestamp);			$earliestShown = wfTimestamp(TS_MW, $revisions[count($revisions) - 1]->rev_timestamp);		} else {			$latestShown = null;			$earliestShown = null;		}		/* Don't announce the limit everywhere if it's the default */		$usefulLimit = $limit == $this->defaultLimit ? '' : $limit;		$urls = array();		foreach (array(20, 50, 100, 250, 500) as $num) {			$urls[] = $this->MakeLink( $wgLang->formatNum($num),				array('offset' => $offset == 0 ? '' : wfTimestamp(TS_MW, $offset), 'limit' => $num, ) );		}		$bits = implode($urls, ' | ');		wfDebug("latestShown=$latestShown latestTimestamp=$latestTimestamp\n");		if( $latestShown < $latestTimestamp ) {			$prevtext = $this->MakeLink( wfMsgHtml("prevn", $limit),				array( 'dir' => 'prev', 'offset' => $latestShown, 'limit' => $usefulLimit ) );			$lasttext = $this->MakeLink( wfMsgHtml('histlast'),				array( 'limit' => $usefulLimit ) );		} else {			$prevtext = wfMsgHtml("prevn", $limit);			$lasttext = wfMsgHtml('histlast');		}		wfDebug("earliestShown=$earliestShown earliestTimestamp=$earliestTimestamp\n");		if( $earliestShown > $earliestTimestamp ) {			$nexttext = $this->MakeLink( wfMsgHtml("nextn", $limit),				array( 'offset' => $earliestShown, 'limit' => $usefulLimit ) );			$firsttext = $this->MakeLink( wfMsgHtml('histfirst'),				array( 'go' => 'first', 'limit' => $usefulLimit ) );		} else {			$nexttext = wfMsgHtml("nextn", $limit);			$firsttext = wfMsgHtml('histfirst');		}		$firstlast = "($lasttext | $firsttext)";		return "$firstlast " . wfMsgHtml("viewprevnext", $prevtext, $nexttext, $bits);	}	function MakeLink($text, $query = NULL) {		if ( $query === null ) return $text;		return $this->mSkin->makeKnownLinkObj(				$this->mTitle, $text,				wfArrayToCGI( $query, array( 'action' => 'history' )));	}			/**	 * Output a subscription feed listing recent edits to this page.	 * @param string $type	 */	function feed( $type ) {		require_once 'SpecialRecentchanges.php';				global $wgFeedClasses;		if( !isset( $wgFeedClasses[$type] ) ) {			global $wgOut;			$wgOut->addWikiText( wfMsg( 'feed-invalid' ) );			return;		}				$feed = new $wgFeedClasses[$type](			$this->mTitle->getPrefixedText() . ' - ' .				wfMsgForContent( 'history-feed-title' ),			wfMsgForContent( 'history-feed-description' ),			$this->mTitle->getFullUrl( 'action=history' ) );		$items = $this->fetchRevisions(10, 0, PageHistory::DIR_NEXT);		$feed->outHeader();		if( $items ) {			foreach( $items as $row ) {				$feed->outItem( $this->feedItem( $row ) );			}		} else {			$feed->outItem( $this->feedEmpty() );		}		$feed->outFooter();	}		function feedEmpty() {		global $wgOut;		return new FeedItem(			wfMsgForContent( 'nohistory' ),			$wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),			$this->mTitle->getFullUrl(),			wfTimestamp( TS_MW ),			'',			$this->mTitle->getTalkPage()->getFullUrl() );	}		/**	 * Generate a FeedItem object from a given revision table row	 * Borrows Recent Changes' feed generation functions for formatting;	 * includes a diff to the previous revision (if any).	 *	 * @param $row	 * @return FeedItem	 */	function feedItem( $row ) {		$rev = new Revision( $row );		$rev->setTitle( $this->mTitle );		$text = rcFormatDiffRow( $this->mTitle,			$this->mTitle->getPreviousRevisionID( $rev->getId() ),			$rev->getId(),			$rev->getTimestamp(),			$rev->getComment() );				if( $rev->getComment() == '' ) {			global $wgContLang;			$title = wfMsgForContent( 'history-feed-item-nocomment',				$rev->getUserText(),				$wgContLang->timeanddate( $rev->getTimestamp() ) );		} else {			$title = $rev->getUserText() . ": " . $this->stripComment( $rev->getComment() );		}		return new FeedItem(			$title,			$text,			$this->mTitle->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),			$rev->getTimestamp(),			$rev->getUserText(),			$this->mTitle->getTalkPage()->getFullUrl() );	}		/**	 * Quickie hack... strip out wikilinks to more legible form from the comment.	 */	function stripComment( $text ) {		return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );	}}?>

⌨️ 快捷键说明

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