editpage.php

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

PHP
1,865
字号
			}				$this->autoSumm = $request->getText( 'wpAutoSummary' );					} else {			# Not a posted form? Start with nothing.			wfDebug( "$fname: Not a posted form.\n" );			$this->textbox1  = '';			$this->textbox2  = '';			$this->mMetaData = '';			$this->summary   = '';			$this->edittime  = '';			$this->starttime = wfTimestampNow();			$this->preview   = false;			$this->save      = false;			$this->diff	 = false;			$this->minoredit = false;			$this->watchthis = false;			$this->recreate  = false;		}		$this->oldid = $request->getInt( 'oldid' );		# Section edit can come from either the form or a link		$this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );		$this->live = $request->getCheck( 'live' );		$this->editintro = $request->getText( 'editintro' );		wfProfileOut( $fname );	}	/**	 * Make sure the form isn't faking a user's credentials.	 *	 * @param $request WebRequest	 * @return bool	 * @private	 */	function tokenOk( &$request ) {		global $wgUser;		if( $wgUser->isAnon() ) {			# Anonymous users may not have a session			# open. Don't tokenize.			$this->mTokenOk = true;		} else {			$this->mTokenOk = $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );		}		return $this->mTokenOk;	}	/** */	function showIntro() {		global $wgOut, $wgUser;		$addstandardintro=true;		if($this->editintro) {			$introtitle=Title::newFromText($this->editintro);			if(isset($introtitle) && $introtitle->userCanRead()) {				$rev=Revision::newFromTitle($introtitle);				if($rev) {					$wgOut->addSecondaryWikiText($rev->getText());					$addstandardintro=false;				}			}		}		if($addstandardintro) {			if ( $wgUser->isLoggedIn() )				$wgOut->addWikiText( wfMsg( 'newarticletext' ) );			else				$wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );		}	}	/**	 * Attempt submission	 * @return bool false if output is done, true if the rest of the form should be displayed	 */	function attemptSave() {		global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;		global $wgMaxArticleSize;		$fname = 'EditPage::attemptSave';		wfProfileIn( $fname );		wfProfileIn( "$fname-checks" );		# Reintegrate metadata		if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;		$this->mMetaData = '' ;		# Check for spam		if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) {			$this->spamPage ( $matches[0] );			wfProfileOut( "$fname-checks" );			wfProfileOut( $fname );			return false;		}		if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section ) ) {			# Error messages or other handling should be performed by the filter function			wfProfileOut( $fname );			wfProfileOut( "$fname-checks" );			return false;		}		if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError ) ) ) {			# Error messages etc. could be handled within the hook...			wfProfileOut( $fname );			wfProfileOut( "$fname-checks" );			return false;		} elseif( $this->hookError != '' ) {			# ...or the hook could be expecting us to produce an error			wfProfileOut( "$fname-checks " );			wfProfileOut( $fname );			return true;		}		if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {			# Check block state against master, thus 'false'.			$this->blockedPage();			wfProfileOut( "$fname-checks" );			wfProfileOut( $fname );			return false;		}		$this->kblength = (int)(strlen( $this->textbox1 ) / 1024);		if ( $this->kblength > $wgMaxArticleSize ) {			// Error will be displayed by showEditForm()			$this->tooBig = true;			wfProfileOut( "$fname-checks" );			wfProfileOut( $fname );			return true;		}				if ( !$wgUser->isAllowed('edit') ) {			if ( $wgUser->isAnon() ) {				$this->userNotLoggedInPage();				wfProfileOut( "$fname-checks" );				wfProfileOut( $fname );				return false;			}			else {				$wgOut->readOnlyPage();				wfProfileOut( "$fname-checks" );				wfProfileOut( $fname );				return false;			}		}		if ( wfReadOnly() ) {			$wgOut->readOnlyPage();			wfProfileOut( "$fname-checks" );			wfProfileOut( $fname );			return false;		}		if ( $wgUser->pingLimiter() ) {			$wgOut->rateLimited();			wfProfileOut( "$fname-checks" );			wfProfileOut( $fname );			return false;		}		# If the article has been deleted while editing, don't save it without		# confirmation		if ( $this->deletedSinceEdit && !$this->recreate ) {			wfProfileOut( "$fname-checks" );			wfProfileOut( $fname );			return true;		}		wfProfileOut( "$fname-checks" );		# If article is new, insert it.		$aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );		if ( 0 == $aid ) {			// Late check for create permission, just in case *PARANOIA*			if ( !$this->mTitle->userCanCreate() ) {				wfDebug( "$fname: no create permission\n" );				$this->noCreatePermission();				wfProfileOut( $fname );				return;			}			# Don't save a new article if it's blank.			if ( ( '' == $this->textbox1 ) ) {					$wgOut->redirect( $this->mTitle->getFullURL() );					wfProfileOut( $fname );					return false;			}			# If no edit comment was given when creating a new page, and what's being			# created is a redirect, be smart and fill in a neat auto-comment			if( $this->summary == '' ) {				$rt = Title::newFromRedirect( $this->textbox1 );				if( is_object( $rt ) )					$this->summary = wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );			}			$isComment=($this->section=='new');			$this->mArticle->insertNewArticle( $this->textbox1, $this->summary,				$this->minoredit, $this->watchthis, false, $isComment);			wfProfileOut( $fname );			return false;		}		# Article exists. Check for edit conflict.		$this->mArticle->clear(); # Force reload of dates, etc.		$this->mArticle->forUpdate( true ); # Lock the article		if( $this->mArticle->getTimestamp() != $this->edittime ) {			$this->isConflict = true;			if( $this->section == 'new' ) {				if( $this->mArticle->getUserText() == $wgUser->getName() &&					$this->mArticle->getComment() == $this->summary ) {					// Probably a duplicate submission of a new comment.					// This can happen when squid resends a request after					// a timeout but the first one actually went through.					wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );				} else {					// New comment; suppress conflict.					$this->isConflict = false;					wfDebug( "EditPage::editForm conflict suppressed; new section\n" );				}			}		}		$userid = $wgUser->getID();		if ( $this->isConflict) {			wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .				$this->mArticle->getTimestamp() . "'\n" );			$text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime);		}		else {			wfDebug( "EditPage::editForm getting section '$this->section'\n" );			$text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary);		}		if( is_null( $text ) ) {			wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );			$this->isConflict = true;			$text = $this->textbox1;		}		# Suppress edit conflict with self, except for section edits where merging is required.		if ( ( $this->section == '' ) && ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {			wfDebug( "Suppressing edit conflict, same user.\n" );			$this->isConflict = false;		} else {			# switch from section editing to normal editing in edit conflict			if($this->isConflict) {				# Attempt merge				if( $this->mergeChangesInto( $text ) ){					// Successful merge! Maybe we should tell the user the good news?					$this->isConflict = false;					wfDebug( "Suppressing edit conflict, successful merge.\n" );				} else {					$this->section = '';					$this->textbox1 = $text;					wfDebug( "Keeping edit conflict, failed merge.\n" );				}			}		}		if ( $this->isConflict ) {			wfProfileOut( $fname );			return true;		}		# If no edit comment was given when turning a page into a redirect, be smart		# and fill in a neat auto-comment		if( $this->summary == '' ) {			$rt = Title::newFromRedirect( $this->textbox1 );			if( is_object( $rt ) )				$this->summary = wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );		}		# Handle the user preference to force summaries here		if( $this->section != 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary' ) ) {			if( md5( $this->summary ) == $this->autoSumm ) {				$this->missingSummary = true;				wfProfileOut( $fname );				return( true );			}		}		# All's well		wfProfileIn( "$fname-sectionanchor" );		$sectionanchor = '';		if( $this->section == 'new' ) {			if ( $this->textbox1 == '' ) {				$this->missingComment = true;				return true;			}			if( $this->summary != '' ) {				$sectionanchor = $this->sectionAnchor( $this->summary );			}		} elseif( $this->section != '' ) {			# Try to get a section anchor from the section source, redirect to edited section if header found			# XXX: might be better to integrate this into Article::replaceSection			# for duplicate heading checking and maybe parsing			$hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );			# we can't deal with anchors, includes, html etc in the header for now,			# headline would need to be parsed to improve this			if($hasmatch and strlen($matches[2]) > 0) {				$sectionanchor = $this->sectionAnchor( $matches[2] );			}		}		wfProfileOut( "$fname-sectionanchor" );		// Save errors may fall down to the edit form, but we've now		// merged the section into full text. Clear the section field		// so that later submission of conflict forms won't try to		// replace that into a duplicated mess.		$this->textbox1 = $text;		$this->section = '';		// Check for length errors again now that the section is merged in		$this->kblength = (int)(strlen( $text ) / 1024);		if ( $this->kblength > $wgMaxArticleSize ) {			$this->tooBig = true;			wfProfileOut( $fname );			return true;		}		# update the article here		if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,			$this->watchthis, '', $sectionanchor ) ) {			wfProfileOut( $fname );			return false;		} else {			$this->isConflict = true;		}		wfProfileOut( $fname );		return true;	}	/**	 * Initialise form fields in the object	 * Called on the first invocation, e.g. when a user clicks an edit link	 */	function initialiseForm() {		$this->edittime = $this->mArticle->getTimestamp();		$this->textbox1 = $this->getContent();		$this->summary = '';		if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI )			$this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ) ;		wfProxyCheck();	}	/**	 * Send the edit form and related headers to $wgOut	 * @param $formCallback Optional callable that takes an OutputPage	 *                      parameter; will be called during form output	 *                      near the top, for captchas and the like.	 */	function showEditForm( $formCallback=null ) {		global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize;		$fname = 'EditPage::showEditForm';		wfProfileIn( $fname );		$sk =& $wgUser->getSkin();		wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;		$wgOut->setRobotpolicy( 'noindex,nofollow' );		# Enabled article-related sidebar, toplinks, etc.		$wgOut->setArticleRelated( true );		if ( $this->isConflict ) {			$s = wfMsg( 'editconflict', $this->mTitle->getPrefixedText() );			$wgOut->setPageTitle( $s );			$wgOut->addWikiText( wfMsg( 'explainconflict' ) );			$this->textbox2 = $this->textbox1;			$this->textbox1 = $this->getContent();			$this->edittime = $this->mArticle->getTimestamp();		} else {			if( $this->section != '' ) {				if( $this->section == 'new' ) {					$s = wfMsg('editingcomment', $this->mTitle->getPrefixedText() );				} else {					$s = wfMsg('editingsection', $this->mTitle->getPrefixedText() );					if( !$this->preview && !$this->diff ) {						preg_match( "/^(=+)(.+)\\1/mi",							$this->textbox1,							$matches );						if( !empty( $matches[2] ) ) {							$this->summary = "/* ". trim($matches[2])." */ ";						}					}				}			} else {				$s = wfMsg( 'editing', $this->mTitle->getPrefixedText() );			}			$wgOut->setPageTitle( $s );			if ( $this->missingComment ) {				$wgOut->addWikiText( wfMsg( 'missingcommenttext' ) );			}						if( $this->missingSummary ) {				$wgOut->addWikiText( wfMsg( 'missingsummary' ) );			}						if( !$this->hookError == '' ) {				$wgOut->addWikiText( $this->hookError );			}			if ( !$this->checkUnicodeCompliantBrowser() ) {				$wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );			}			if ( isset( $this->mArticle )			     && isset( $this->mArticle->mRevision )			     && !$this->mArticle->mRevision->isCurrent() ) {				$this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );				$wgOut->addWikiText( wfMsg( 'editingold' ) );			}		}		if( wfReadOnly() ) {			$wgOut->addWikiText( wfMsg( 'readonlywarning' ) );		} elseif( $wgUser->isAnon() && $this->formtype != 'preview' ) {			$wgOut->addWikiText( wfMsg( 'anoneditwarning' ) );		} else {			if( $this->isCssJsSubpage && $this->formtype != 'preview' ) {				# Check the skin exists				if( $this->isValidCssJsSubpage ) {					$wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) );				} else {					$wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ) );				}			}		}					if( $this->mTitle->isProtected( 'edit' ) ) {			# Is the protection due to the namespace, e.g. interface text?			if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {				# Yes; remind the user				$notice = wfMsg( 'editinginterface' );			} elseif( $this->mTitle->isSemiProtected() ) {				# No; semi protected				$notice = wfMsg( 'semiprotectedpagewarning' );				if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' ) {					$notice = '';				}			} else {				# No; regular protection				$notice = wfMsg( 'protectedpagewarning' );			}			$wgOut->addWikiText( $notice );		}		if ( $this->kblength === false ) {			$this->kblength = (int)(strlen( $this->textbox1 ) / 1024);		}		if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {			$wgOut->addWikiText( wfMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgMaxArticleSize ) );		} elseif( $this->kblength > 29 ) {			$wgOut->addWikiText( wfMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) ) );		}		$rows = $wgUser->getIntOption( 'rows' );		$cols = $wgUser->getIntOption( 'cols' );		$ew = $wgUser->getOption( 'editwidth' );		if ( $ew ) $ew = " style=\"width:100%\"";		else $ew = '';		$q = 'action=submit';

⌨️ 快捷键说明

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