var $deletedSinceEdit = false;
var $formtype;
var $firsttime;
+ var $lastDelete;
# Form values
var $save = false, $preview = false, $diff = false;
*/
function edit() {
global $wgOut, $wgUser, $wgRequest, $wgTitle;
+
+ $fname = 'EditPage::edit';
+ wfProfileIn( $fname );
+
// this is not an article
$wgOut->setArticleFlag(false);
if( $this->live ) {
$this->livePreview();
+ wfProfileOut( $fname );
return;
}
if ( ! $this->mTitle->userCanEdit() ) {
$wgOut->readOnlyPage( $this->mArticle->getContent( true ), true );
+ wfProfileOut( $fname );
return;
}
if ( !$this->preview && !$this->diff && $wgUser->isBlockedFrom( $this->mTitle, !$this->save ) ) {
# When previewing, don't check blocked state - will get caught at save time.
# Also, check when starting edition is done against slave to improve performance.
$this->blockedIPpage();
+ wfProfileOut( $fname );
return;
}
if ( !$wgUser->isAllowed('edit') ) {
if ( $wgUser->isAnon() ) {
$this->userNotLoggedInPage();
+ wfProfileOut( $fname );
return;
} else {
$wgOut->readOnlyPage( $this->mArticle->getContent( true ), true );
+ wfProfileOut( $fname );
return;
}
}
$this->formtype = 'diff';
} else {
$wgOut->readOnlyPage( $this->mArticle->getContent( true ) );
+ wfProfileOut( $fname );
return;
}
} else {
}
}
}
+
+ wfProfileIn( "$fname-business-end" );
$this->isConflict = false;
// css / js subpages of user pages get a special treatment
* to only perform it on saves
*/
if ( $this->mTitle->isDeleted() ) {
- $query = $this->getLastDelete();
- if ( !is_null($query) ) {
- $deletetime = $query->log_timestamp;
+ $this->lastDelete = $this->getLastDelete();
+ if ( !is_null($this->lastDelete) ) {
+ $deletetime = $this->lastDelete->log_timestamp;
if ( ($deletetime - $this->starttime) > 0 ) {
$this->deletedSinceEdit = true;
}
if ( 'save' == $this->formtype ) {
if ( !$this->attemptSave() ) {
+ wfProfileOut( "$fname-business-end" );
+ wfProfileOut( $fname );
return;
}
}
}
$this->showEditForm();
+ wfProfileOut( "$fname-business-end" );
+ wfProfileOut( $fname );
}
/**
* @todo document
*/
function importFormData( &$request ) {
+ global $wgLang ;
+ $fname = 'EditPage::importFormData';
+ wfProfileIn( $fname );
+
if( $request->wasPosted() ) {
# These fields need to be checked for encoding.
# Also remove trailing whitespace, but don't remove _initial_
$this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
$this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
$this->mMetaData = rtrim( $request->getText( 'metadata' ) );
- $this->summary = $request->getText( 'wpSummary' );
+ # Truncate for whole multibyte characters. +5 bytes for ellipsis
+ $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
$this->edittime = $request->getVal( 'wpEdittime' );
$this->starttime = $request->getVal( 'wpStarttime' );
$this->live = $request->getCheck( 'live' );
$this->editintro = $request->getText( 'editintro' );
+ wfProfileOut( $fname );
}
/**
}
function showIntro() {
- global $wgOut;
+ global $wgOut, $wgUser;
$addstandardintro=true;
if($this->editintro) {
$introtitle=Title::newFromText($this->editintro);
}
}
if($addstandardintro) {
- $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
+ if ( $wgUser->isLoggedIn() )
+ $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
+ else
+ $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
}
}
function attemptSave() {
global $wgSpamRegex, $wgFilterCallback, $wgUser, $wgOut;
+ $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 ) ) ) {
+ # Error messages or other handling should be performed by the filter function
+ wfProfileOut( $fname );
+ wfProfileOut( "$fname-checks" );
return false;
}
if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
# Check block state against master, thus 'false'.
$this->blockedIPpage();
+ wfProfileOut( "$fname-checks" );
+ wfProfileOut( $fname );
return false;
}
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 ) {
# Don't save a new article if it's blank.
- if ( ( '' == $this->textbox1 ) ||
- ( wfMsg( 'newarticletext' ) == $this->textbox1 ) ) {
+ if ( ( '' == $this->textbox1 ) ) {
$wgOut->redirect( $this->mTitle->getFullURL() );
+ wfProfileOut( $fname );
return false;
- }
- if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$this->textbox1,
- &$this->summary, &$this->minoredit, &$this->watchthis, NULL)))
- {
-
- $isComment=($this->section=='new');
- $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
- $this->minoredit, $this->watchthis, false, $isComment);
- wfRunHooks('ArticleSaveComplete', array(&$this->mArticle, &$wgUser, $this->textbox1,
- $this->summary, $this->minoredit,
- $this->watchthis, NULL));
}
+
+ $isComment=($this->section=='new');
+ $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
+ $this->minoredit, $this->watchthis, false, $isComment);
+
+ wfProfileOut( $fname );
return false;
}
if ( $this->isConflict) {
wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
$this->mArticle->getTimestamp() . "'\n" );
- $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
- $this->section, $this->textbox1, $this->summary, $this->edittime);
+ $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime);
}
else {
wfDebug( "EditPage::editForm getting section '$this->section'\n" );
- $text = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
- $this->section, $this->textbox1, $this->summary);
+ $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary);
}
- # Suppress edit conflict with self
- if ( ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
+ # 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 {
}
if ( $this->isConflict ) {
+ wfProfileOut( $fname );
return true;
}
# All's well
+ wfProfileIn( "$fname-sectionanchor" );
$sectionanchor = '';
if( $this->section == 'new' ) {
if( $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::getTextOfLastEditWithSectionReplacedOrAdded
+ # 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,
$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
$this->textbox1 = $text;
$this->section = '';
- if (wfRunHooks('ArticleSave', array(&$this->mArticle, &$wgUser, &$text,
- &$this->summary, &$this->minoredit,
- &$this->watchthis, &$sectionanchor)))
- {
- # update the article here
- if($this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
- $this->watchthis, '', $sectionanchor ))
- {
- wfRunHooks('ArticleSaveComplete',
- array(&$this->mArticle, &$wgUser, $text,
- $this->summary, $this->minoredit,
- $this->watchthis, $sectionanchor));
- return false;
- } else {
- $this->isConflict = 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;
}
$this->edittime = $this->mArticle->getTimestamp();
$this->textbox1 = $this->mArticle->getContent( true );
$this->summary = '';
- $this->proxyCheck();
+ 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() {
+ function showEditForm( $formCallback=null ) {
global $wgOut, $wgUser, $wgAllowAnonymousMinor, $wgLang, $wgContLang;
+ $fname = 'EditPage::showEditForm';
+ wfProfileIn( $fname );
+
$sk =& $wgUser->getSkin();
$wgOut->setRobotpolicy( 'noindex,nofollow' );
// Add an confirmation checkbox and explanation.
$toolbar = '';
$hidden = 'type="hidden" style="display:none;"';
- $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $query->user_name , $query->log_comment ));
+ $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ));
$recreate .=
"<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
"<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
{$toolbar}
<form id="editform" name="editform" method="post" action="$action"
enctype="multipart/form-data">
+END
+);
+ if( is_callable( $formCallback ) ) {
+ call_user_func_array( $formCallback, array( &$wgOut ) );
+ }
+ $wgOut->addHTML( <<<END
$recreate
{$commentsubject}
<textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
#$wgOut->addHTML( '<div id="wikiPreview">' . $difftext . '</div>' );
$wgOut->addHTML( $this->getDiff() );
}
+
+ wfProfileOut( $fname );
}
/**
*/
function getTemplatesUsed() {
global $wgUser;
+
+ $fname = 'EditPage::getTemplatesUsed';
+ wfProfileIn( $fname );
+
$sk =& $wgUser->getSkin();
$templates = '';
}
$templates .= '</ul>';
}
+ wfProfileOut( $fname );
return $templates;
}
'log_comment',
'log_params',
'user_name', ),
- array( 'log_namespace="' . $this->mTitle->getNamespace() . '"',
- 'log_title="' . $this->mTitle->getDBkey() . '"',
- 'log_type="delete"',
- 'log_action="delete"',
+ array( 'log_namespace' => $this->mTitle->getNamespace(),
+ 'log_title' => $this->mTitle->getDBkey(),
+ 'log_type' => 'delete',
+ 'log_action' => 'delete',
'user_id=log_user' ),
$fname,
array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
*/
function getPreviewText() {
global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
+
+ $fname = 'EditPage::getPreviewText';
+ wfProfileIn( $fname );
+
$previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
"<p class='previewnote'>" . htmlspecialchars( wfMsg( 'previewnote' ) ) . "</p>\n";
if ( $this->isConflict ) {
}
$parserOutput = $wgParser->parse( $previewtext , $wgTitle, $parserOptions );
$wgOut->addHTML( $parserOutput->mText );
+ wfProfileOut( $fname );
return $previewhead;
} else {
# if user want to see preview when he edit an article
$wgOut->addCategoryLinks($parserOutput->getCategoryLinks());
$wgOut->addLanguageLinks($parserOutput->getLanguageLinks());
+
+ wfProfileOut( $fname );
return $previewhead . $previewHTML;
}
}
* @todo document
*/
function blockedIPpage() {
- global $wgOut, $wgUser, $wgContLang, $wgIP;
+ global $wgOut, $wgUser, $wgContLang;
$wgOut->setPageTitle( wfMsg( 'blockedtitle' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$id = $wgUser->blockedBy();
$reason = $wgUser->blockedFor();
- $ip = $wgIP;
+ $ip = wfGetIP();
if ( is_numeric( $id ) ) {
$name = User::whoIs( $id );
$wgOut->returnToMain( false );
}
- /**
- * Forks processes to scan the originating IP for an open proxy server
- * MemCached can be used to skip IPs that have already been scanned
- */
- function proxyCheck() {
- global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
- global $wgIP, $wgUseMemCached, $wgMemc, $wgDBname, $wgProxyMemcExpiry;
-
- if ( !$wgBlockOpenProxies ) {
- return;
- }
-
- # Get MemCached key
- $skip = false;
- if ( $wgUseMemCached ) {
- $mcKey = $wgDBname.':proxy:ip:'.$wgIP;
- $mcValue = $wgMemc->get( $mcKey );
- if ( $mcValue ) {
- $skip = true;
- }
- }
-
- # Fork the processes
- if ( !$skip ) {
- $title = Title::makeTitle( NS_SPECIAL, 'Blockme' );
- $iphash = md5( $wgIP . $wgProxyKey );
- $url = $title->getFullURL( 'ip='.$iphash );
-
- foreach ( $wgProxyPorts as $port ) {
- $params = implode( ' ', array(
- escapeshellarg( $wgProxyScriptPath ),
- escapeshellarg( $wgIP ),
- escapeshellarg( $port ),
- escapeshellarg( $url )
- ));
- exec( "php $params &>/dev/null &" );
- }
- # Set MemCached key
- if ( $wgUseMemCached ) {
- $wgMemc->set( $mcKey, 1, $wgProxyMemcExpiry );
- }
- }
- }
-
/**
* @access private
* @todo document
$toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
}
- $toolbar.="addInfobox('" . wfEscapeJsString( wfMsg( "infobox" ) ) .
- "','" . wfEscapeJsString( wfMsg( "infobox_alert" ) ) . "');\n";
$toolbar.="document.writeln(\"</div>\");\n";
-
$toolbar.="/*]]>*/\n</script>";
return $toolbar;
}
* @return string HTML
*/
function getDiff() {
+ global $wgUser;
+
require_once( 'DifferenceEngine.php' );
$oldtext = $this->mArticle->fetchContent();
- $newtext = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded(
+ $newtext = $this->mArticle->replaceSection(
$this->section, $this->textbox1, $this->summary, $this->edittime );
$oldtitle = wfMsg( 'currentrev' );
$newtitle = wfMsg( 'yourtext' );
- if ( $oldtext != wfMsg( 'noarticletext' ) || $newtext != '' ) {
+ if ( $oldtext != wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) || $newtext != '' ) {
$difftext = DifferenceEngine::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
}