article.php

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

PHP
2,311
字号
		}		$wgOut->redirect( $this->mTitle->getFullURL( $query ) . $sectionAnchor );	}			/**	 * Mark this particular edit as patrolled	 */	function markpatrolled() {		global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;		$wgOut->setRobotpolicy( 'noindex,nofollow' );		# Check RC patrol config. option		if( !$wgUseRCPatrol ) {			$wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );			return;		}				# Check permissions		if( !$wgUser->isAllowed( 'patrol' ) ) {			$wgOut->permissionRequired( 'patrol' );			return;		}				$rcid = $wgRequest->getVal( 'rcid' );		if ( !is_null ( $rcid ) ) {			if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {				RecentChange::markPatrolled( $rcid );				wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );				$wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );				$wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );			}			$rcTitle = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );			$wgOut->returnToMain( false, $rcTitle->getPrefixedText() );		}		else {			$wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );		}	}	/**	 * User-interface handler for the "watch" action	 */	function watch() {		global $wgUser, $wgOut;		if ( $wgUser->isAnon() ) {			$wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );			return;		}		if ( wfReadOnly() ) {			$wgOut->readOnlyPage();			return;		}				if( $this->doWatch() ) {			$wgOut->setPagetitle( wfMsg( 'addedwatch' ) );			$wgOut->setRobotpolicy( 'noindex,nofollow' );			$link = $this->mTitle->getPrefixedText();			$text = wfMsg( 'addedwatchtext', $link );			$wgOut->addWikiText( $text );		}		$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );	}		/**	 * Add this page to $wgUser's watchlist	 * @return bool true on successful watch operation	 */	function doWatch() {		global $wgUser;		if( $wgUser->isAnon() ) {			return false;		}				if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {			$wgUser->addWatch( $this->mTitle );			$wgUser->saveSettings();			return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));		}				return false;	}	/**	 * User interface handler for the "unwatch" action.	 */	function unwatch() {		global $wgUser, $wgOut;		if ( $wgUser->isAnon() ) {			$wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );			return;		}		if ( wfReadOnly() ) {			$wgOut->readOnlyPage();			return;		}				if( $this->doUnwatch() ) {			$wgOut->setPagetitle( wfMsg( 'removedwatch' ) );			$wgOut->setRobotpolicy( 'noindex,nofollow' );			$link = $this->mTitle->getPrefixedText();			$text = wfMsg( 'removedwatchtext', $link );			$wgOut->addWikiText( $text );		}		$wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );	}		/**	 * Stop watching a page	 * @return bool true on successful unwatch	 */	function doUnwatch() {		global $wgUser;		if( $wgUser->isAnon() ) {			return false;		}		if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {			$wgUser->removeWatch( $this->mTitle );			$wgUser->saveSettings();			return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));		}				return false;	}	/**	 * action=protect handler	 */	function protect() {		require_once 'ProtectionForm.php';		$form = new ProtectionForm( $this );		$form->show();	}	/**	 * action=unprotect handler (alias)	 */	function unprotect() {		$this->protect();	}	/**	 * Update the article's restriction field, and leave a log entry.	 *	 * @param array $limit set of restriction keys	 * @param string $reason	 * @return bool true on success	 */	function updateRestrictions( $limit = array(), $reason = '' ) {		global $wgUser, $wgRestrictionTypes, $wgContLang;				$id = $this->mTitle->getArticleID();		if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {			return false;		}		# FIXME: Same limitations as described in ProtectionForm.php (line 37);		# we expect a single selection, but the schema allows otherwise.		$current = array();		foreach( $wgRestrictionTypes as $action )			$current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );		$current = Article::flattenRestrictions( $current );		$updated = Article::flattenRestrictions( $limit );				$changed = ( $current != $updated );		$protect = ( $updated != '' );				# If nothing's changed, do nothing		if( $changed ) {			if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {				$dbw =& wfGetDB( DB_MASTER );								# Prepare a null revision to be added to the history				$comment = $wgContLang->ucfirst( wfMsgForContent( $protect ? 'protectedarticle' : 'unprotectedarticle', $this->mTitle->getPrefixedText() ) );				if( $reason )					$comment .= ": $reason";				if( $protect )					$comment .= " [$updated]";				$nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );				$nullRevId = $nullRevision->insertOn( $dbw );							# Update page record				$dbw->update( 'page',					array( /* SET */						'page_touched' => $dbw->timestamp(),						'page_restrictions' => $updated,						'page_latest' => $nullRevId					), array( /* WHERE */						'page_id' => $id					), 'Article::protect'				);				wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );					# Update the protection log				$log = new LogPage( 'protect' );				if( $protect ) {					$log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]" ) );				} else {					$log->addEntry( 'unprotect', $this->mTitle, $reason );				}							} # End hook		} # End "changed" check				return true;	}	/**	 * Take an array of page restrictions and flatten it to a string	 * suitable for insertion into the page_restrictions field.	 * @param array $limit	 * @return string	 * @private	 */	function flattenRestrictions( $limit ) {		if( !is_array( $limit ) ) {			throw new MWException( 'Article::flattenRestrictions given non-array restriction set' );		}		$bits = array();		ksort( $limit );		foreach( $limit as $action => $restrictions ) {			if( $restrictions != '' ) {				$bits[] = "$action=$restrictions";			}		}		return implode( ':', $bits );	}	/*	 * UI entry point for page deletion	 */	function delete() {		global $wgUser, $wgOut, $wgRequest;		$confirm = $wgRequest->wasPosted() &&			$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );		$reason = $wgRequest->getText( 'wpReason' );		# This code desperately needs to be totally rewritten		# Check permissions		if( $wgUser->isAllowed( 'delete' ) ) {			if( $wgUser->isBlocked() ) {				$wgOut->blockedPage();				return;			}		} else {			$wgOut->permissionRequired( 'delete' );			return;		}		if( wfReadOnly() ) {			$wgOut->readOnlyPage();			return;		}		$wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );				# Better double-check that it hasn't been deleted yet!		$dbw =& wfGetDB( DB_MASTER );		$conds = $this->mTitle->pageCond();		$latest = $dbw->selectField( 'page', 'page_latest', $conds, __METHOD__ );		if ( $latest === false ) {			$wgOut->showFatalError( wfMsg( 'cannotdelete' ) );			return;		}		if( $confirm ) {			$this->doDelete( $reason );			return;		}		# determine whether this page has earlier revisions		# and insert a warning if it does		$maxRevisions = 20;		$authors = $this->getLastNAuthors( $maxRevisions, $latest );				if( count( $authors ) > 1 && !$confirm ) {			$skin=$wgUser->getSkin();			$wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );		}		# If a single user is responsible for all revisions, find out who they are		if ( count( $authors ) == $maxRevisions ) {			// Query bailed out, too many revisions to find out if they're all the same			$authorOfAll = false;		} else {			$authorOfAll = reset( $authors );			foreach ( $authors as $author ) {				if ( $authorOfAll != $author ) {					$authorOfAll = false;					break;				}			}		}		# Fetch article text		$rev = Revision::newFromTitle( $this->mTitle );		if( !is_null( $rev ) ) {			# if this is a mini-text, we can paste part of it into the deletion reason			$text = $rev->getText();			#if this is empty, an earlier revision may contain "useful" text			$blanked = false;			if( $text == '' ) {				$prev = $rev->getPrevious();				if( $prev ) {					$text = $prev->getText();					$blanked = true;				}			}			$length = strlen( $text );			# this should not happen, since it is not possible to store an empty, new			# page. Let's insert a standard text in case it does, though			if( $length == 0 && $reason === '' ) {				$reason = wfMsgForContent( 'exblank' );			}			if( $length < 500 && $reason === '' ) {				# comment field=255, let's grep the first 150 to have some user				# space left				global $wgContLang;				$text = $wgContLang->truncate( $text, 150, '...' );				# let's strip out newlines				$text = preg_replace( "/[\n\r]/", '', $text );				if( !$blanked ) {					if( $authorOfAll === false ) {						$reason = wfMsgForContent( 'excontent', $text );					} else {						$reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );					}				} else {					$reason = wfMsgForContent( 'exbeforeblank', $text );				}			}		}		return $this->confirmDelete( '', $reason );	}	/**	 * Get the last N authors	 * @param int $num Number of revisions to get	 * @param string $revLatest The latest rev_id, selected from the master (optional)	 * @return array Array of authors, duplicates not removed	 */	function getLastNAuthors( $num, $revLatest = 0 ) {		wfProfileIn( __METHOD__ );		// First try the slave		// If that doesn't have the latest revision, try the master		$continue = 2;		$db =& wfGetDB( DB_SLAVE );		do {			$res = $db->select( array( 'page', 'revision' ),				array( 'rev_id', 'rev_user_text' ),				array(					'page_namespace' => $this->mTitle->getNamespace(),					'page_title' => $this->mTitle->getDBkey(),					'rev_page = page_id'				), __METHOD__, $this->getSelectOptions( array(					'ORDER BY' => 'rev_timestamp DESC',					'LIMIT' => $num				) )			);			if ( !$res ) {				wfProfileOut( __METHOD__ );				return array();			}			$row = $db->fetchObject( $res );			if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) {				$db =& wfGetDB( DB_MASTER );				$continue--;			} else {				$continue = 0;			}		} while ( $continue );		$authors = array( $row->rev_user_text );		while ( $row = $db->fetchObject( $res ) ) {			$authors[] = $row->rev_user_text;		}		wfProfileOut( __METHOD__ );		return $authors;	}		/**	 * Output deletion confirmation dialog	 */	function confirmDelete( $par, $reason ) {		global $wgOut, $wgUser;		wfDebug( "Article::confirmDelete\n" );		$sub = htmlspecialchars( $this->mTitle->getPrefixedText() );		$wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );		$wgOut->setRobotpolicy( 'noindex,nofollow' );		$wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );		$formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );		$confirm = htmlspecialchars( wfMsg( 'deletepage' ) );		$delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );		$token = htmlspecialchars( $wgUser->editToken() );		$wgOut->addHTML( "<form id='deleteconfirm' method='post' action=\"{$formaction}\">	<table border='0'>		<tr>			<td align='right'>				<label for='wpReason'>{$delcom}:</label>			</td>			<td align='left'>				<input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />			</td>		</tr>		<tr>			<td>&nbsp;</td>			<td>				<input type='submit' name='wpConfirmB' value=\"{$confirm}\" />			</td>		</tr>	</table>	<input type='hidden' name='wpEditToken' value=\"{$token}\" /></form>\n" );		$wgOut->returnToMain( false );	}	/**	 * Perform a deletion and output success or failure messages	 */	function doDelete( $reason ) {		global $wgOut, $wgUser;		wfDebug( __METHOD__."\n" );		if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {			if ( $this->doDeleteArticle( $reason ) ) {				$deleted = $this->mTitle->getPrefixedText();				$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );				$wgOut->setRobotpolicy( 'noindex,nofollow' );				$loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';				$text = wfMsg( 'deletedtext', $deleted, $loglink );

⌨️ 快捷键说明

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