From 5e34cd30d250d31fd965127c3db31abe0a28d312 Mon Sep 17 00:00:00 2001 From: David McCabe Date: Thu, 1 Nov 2007 04:08:42 +0000 Subject: [PATCH] Split mTitle into uiTitle and dbTitle; this is explained at the top of EditPage.php. --- includes/EditPage.php | 146 ++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 62 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index ea6ecffe27..7814423b4a 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -8,6 +8,12 @@ * The actual database and text munging is still in Article, * but it should get easier to call those from alternate * interfaces. + * + * EditPage now holds references to two distinct Titles: + * $uiTitle is the page that forms submit to, links point to, + * redirects go to, etc. $dbTitle (as well as $mArticle) is the + * page in the database that is actually being edited. These are + * usually the same, but they are now allowed to be different. */ class EditPage { const AS_SUCCESS_UPDATE = 200; @@ -34,7 +40,8 @@ class EditPage { const AS_SPAM_ERROR = 232; var $mArticle; - var $mTitle; + var $dbTitle; + var $uiTitle; var $mMetaData = ''; var $isConflict = false; var $isCssJsSubpage = false; @@ -65,9 +72,15 @@ class EditPage { # extensions should take care to _append_ to the present value public $editFormPageTop; // Before even the preview public $editFormTextTop; + public $editFormTextBeforeContent; public $editFormTextAfterWarn; public $editFormTextAfterTools; public $editFormTextBottom; + + /* $didSave should be set to true whenever an article was succesfully altered. */ + public $didSave = false; + + public $suppressIntro = false; /** * @todo document @@ -76,11 +89,13 @@ class EditPage { function EditPage( $article ) { $this->mArticle =& $article; global $wgTitle; - $this->mTitle =& $wgTitle; + $this->uiTitle =& $wgTitle; + $this->dbTitle =& $article->getTitle(); # Placeholders for text injection by hooks (empty per default) $this->editFormPageTop = $this->editFormTextTop = + $this->editFormTextBeforeContent = $this->editFormTextAfterWarn = $this->editFormTextAfterTools = $this->editFormTextBottom = ""; @@ -101,10 +116,10 @@ class EditPage { wfProfileIn( __METHOD__ ); $text = ''; - if( !$this->mTitle->exists() ) { - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { + if( !$this->dbTitle->exists() ) { + if ( $this->dbTitle->getNamespace() == NS_MEDIAWIKI ) { # If this is a system message, get the default text. - $text = wfMsgWeirdKey ( $this->mTitle->getText() ) ; + $text = wfMsgWeirdKey ( $this->dbTitle->getText() ) ; } else { # If requested, preload some text. $text = $this->getPreloadedText( $preload ); @@ -341,9 +356,9 @@ class EditPage { return; } - $permErrors = $this->mTitle->getUserPermissionsErrors('edit', $wgUser); - if( !$this->mTitle->exists() ) - $permErrors += array_diff( $this->mTitle->getUserPermissionsErrors('create', $wgUser), $permErrors ); + $permErrors = $this->dbTitle->getUserPermissionsErrors('edit', $wgUser); + if( !$this->dbTitle->exists() ) + $permErrors += array_diff( $this->dbTitle->getUserPermissionsErrors('create', $wgUser), $permErrors ); # Ignore some permissions errors. $remove = array(); @@ -395,8 +410,8 @@ class EditPage { $this->isConflict = false; // css / js subpages of user pages get a special treatment - $this->isCssJsSubpage = $wgTitle->isCssJsSubpage(); - $this->isValidCssJsSubpage = $wgTitle->isValidCssJsSubpage(); + $this->isCssJsSubpage = $this->dbTitle->isCssJsSubpage(); + $this->isValidCssJsSubpage = $this->dbTitle->isValidCssJsSubpage(); /* Notice that we can't use isDeleted, because it returns true if article is ever deleted * no matter it's current state @@ -408,7 +423,7 @@ class EditPage { * deletes. This is done on every preview and save request. Move it further down * to only perform it on saves */ - if ( $this->mTitle->isDeleted() ) { + if ( $this->dbTitle->isDeleted() ) { $this->lastDelete = $this->getLastDelete(); if ( !is_null($this->lastDelete) ) { $deletetime = $this->lastDelete->log_timestamp; @@ -423,7 +438,7 @@ class EditPage { if( $this->formtype == 'initial' || $this->firsttime ) $this->showIntro(); - if( $this->mTitle->isTalkPage() ) { + if( $this->dbTitle->isTalkPage() ) { $wgOut->addWikiText( wfMsg( 'talkpagetext' ) ); } @@ -449,8 +464,8 @@ class EditPage { wfProfileOut( $fname ); return; } - if( !$this->mTitle->getArticleId() ) - wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) ); + if( !$this->dbTitle->getArticleId() ) + wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->dbTitle ) ); } $this->showEditForm(); @@ -474,10 +489,10 @@ class EditPage { } elseif( $this->section == 'new' ) { // Nothing *to* preview for new sections return false; - } elseif( ( $wgRequest->getVal( 'preload' ) !== '' || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) { + } elseif( ( $wgRequest->getVal( 'preload' ) !== '' || $this->dbTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) { // Standard preference behaviour return true; - } elseif( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) { + } elseif( !$this->dbTitle->exists() && $this->dbTitle->getNamespace() == NS_CATEGORY ) { // Categories are special return true; } else { @@ -554,7 +569,7 @@ class EditPage { $this->watchthis = $request->getCheck( 'wpWatchthis' ); # Don't force edit summaries when a user is editing their own user or talk page - if( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK ) && $this->mTitle->getText() == $wgUser->getName() ) { + if( ( $this->dbTitle->mNamespace == NS_USER || $this->dbTitle->mNamespace == NS_USER_TALK ) && $this->dbTitle->getText() == $wgUser->getName() ) { $this->allowBlankSummary = true; } else { $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ); @@ -610,7 +625,8 @@ class EditPage { */ private function showIntro() { global $wgOut, $wgUser; - if( !$this->showCustomIntro() && !$this->mTitle->exists() ) { + if( $this->suppressIntro ) return; + if( !$this->showCustomIntro() && !$this->dbTitle->exists() ) { if( $wgUser->isLoggedIn() ) { $wgOut->addWikiText( wfMsg( 'newarticletext' ) ); } else { @@ -671,7 +687,7 @@ class EditPage { wfProfileOut( $fname ); return self::AS_SPAM_ERROR; } - if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section ) ) { + if ( $wgFilterCallback && $wgFilterCallback( $this->dbTitle, $this->textbox1, $this->section ) ) { # Error messages or other handling should be performed by the filter function wfProfileOut( "$fname-checks" ); wfProfileOut( $fname ); @@ -688,7 +704,7 @@ class EditPage { wfProfileOut( $fname ); return self::AS_HOOK_ERROR_EXPECTED; } - if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) { + if ( $wgUser->isBlockedFrom( $this->uiTitle, false ) ) { # Check block state against master, thus 'false'. wfProfileOut( "$fname-checks" ); wfProfileOut( $fname ); @@ -738,11 +754,11 @@ class EditPage { wfProfileOut( "$fname-checks" ); # If article is new, insert it. - $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE ); + $aid = $this->dbTitle->getArticleID( GAID_FOR_UPDATE ); if ( 0 == $aid ) { // Late check for create permission, just in case *PARANOIA* - if ( !$this->mTitle->userCan( 'create' ) ) { + if ( !$this->dbTitle->userCan( 'create' ) ) { wfDebug( "$fname: no create permission\n" ); wfProfileOut( $fname ); return self::AS_NO_CREATE_PERMISSION; @@ -913,8 +929,8 @@ class EditPage { $this->textbox1 = $this->getContent(false); if ($this->textbox1 === false) return false; - if ( !$this->mArticle->exists() && $this->mArticle->mTitle->getNamespace() == NS_MEDIAWIKI ) - $this->textbox1 = wfMsgWeirdKey( $this->mArticle->mTitle->getText() ); + if ( !$this->mArticle->exists() && $this->dbTitle->getNamespace() == NS_MEDIAWIKI ) + $this->textbox1 = wfMsgWeirdKey( $this->dbTitle->getText() ); wfProxyCheck(); return true; } @@ -945,7 +961,7 @@ class EditPage { } if ( $this->isConflict ) { - $s = wfMsg( 'editconflict', $this->mTitle->getPrefixedText() ); + $s = wfMsg( 'editconflict', $this->uiTitle->getPrefixedText() ); $wgOut->setPageTitle( $s ); $wgOut->addWikiText( wfMsg( 'explainconflict' ) ); @@ -956,9 +972,9 @@ class EditPage { if( $this->section != '' ) { if( $this->section == 'new' ) { - $s = wfMsg('editingcomment', $this->mTitle->getPrefixedText() ); + $s = wfMsg('editingcomment', $this->uiTitle->getPrefixedText() ); } else { - $s = wfMsg('editingsection', $this->mTitle->getPrefixedText() ); + $s = wfMsg('editingsection', $this->uiTitle->getPrefixedText() ); $matches = array(); if( !$this->summary && !$this->preview && !$this->diff ) { preg_match( "/^(=+)(.+)\\1/mi", @@ -973,7 +989,7 @@ class EditPage { } } } else { - $s = wfMsg( 'editing', $this->mTitle->getPrefixedText() ); + $s = wfMsg( 'editing', $this->uiTitle->getPrefixedText() ); } $wgOut->setPageTitle( $s ); @@ -1018,17 +1034,17 @@ class EditPage { if( $this->isValidCssJsSubpage ) { $wgOut->addWikiText( wfMsg( 'usercssjsyoucanpreview' ) ); } else { - $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage() ) ); + $wgOut->addWikiText( wfMsg( 'userinvalidcssjstitle', $this->uiTitle->getSkinFromCssJsSubpage() ) ); } } } - if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { + if( $this->dbTitle->getNamespace() == NS_MEDIAWIKI ) { # Show a warning if editing an interface message $wgOut->addWikiText( wfMsg( 'editinginterface' ) ); - } elseif( $this->mTitle->isProtected( 'edit' ) ) { + } elseif( $this->dbTitle->isProtected( 'edit' ) ) { # Is the title semi-protected? - if( $this->mTitle->isSemiProtected() ) { + if( $this->dbTitle->isSemiProtected() ) { $notice = wfMsg( 'semiprotectedpagewarning' ); if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' ) $notice = ''; @@ -1038,9 +1054,9 @@ class EditPage { } $wgOut->addWikiText( $notice ); } - if ( $this->mTitle->isCascadeProtected() ) { + if ( $this->dbTitle->isCascadeProtected() ) { # Is this page under cascading protection from some source pages? - list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources(); + list($cascadeSources, /* $restrictions */) = $this->dbTitle->getCascadeProtectionSources(); if ( count($cascadeSources) > 0 ) { # Explain, and list the titles responsible $notice = wfMsgExt( 'cascadeprotectedwarning', array('parsemag'), count($cascadeSources) ) . "\n"; @@ -1075,12 +1091,12 @@ class EditPage { $q = 'action=submit'; #if ( "no" == $redirect ) { $q .= "&redirect=no"; } - $action = $this->mTitle->escapeLocalURL( $q ); + $action = $this->uiTitle->escapeLocalURL( $q ); $summary = wfMsg('summary'); $subject = wfMsg('subject'); - $cancel = $sk->makeKnownLink( $this->mTitle->getPrefixedText(), + $cancel = $sk->makeKnownLink( $this->uiTitle->getPrefixedText(), wfMsgExt('cancel', array('parseinline')) ); $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' )); $edithelp = ''. @@ -1106,10 +1122,10 @@ class EditPage { if( $wgUser->getOption( 'watchdefault' ) ) { # Watch all edits $this->watchthis = true; - } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) { + } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->dbTitle->exists() ) { # Watch creations $this->watchthis = true; - } elseif( $this->mTitle->userIsWatching() ) { + } elseif( $this->dbTitle->userIsWatching() ) { # Already watched $this->watchthis = true; } @@ -1141,12 +1157,12 @@ class EditPage { if( $this->section == 'new' ) { $commentsubject="\n
\n
"; $editsummary = ''; - $subjectpreview = $summarytext && $this->preview ? "
".wfMsg('subject-preview').':'.$sk->commentBlock( $this->summary, $this->mTitle )."
\n" : ''; + $subjectpreview = $summarytext && $this->preview ? "
".wfMsg('subject-preview').':'.$sk->commentBlock( $this->summary, $this->dbTitle )."
\n" : ''; $summarypreview = ''; } else { $commentsubject = ''; $editsummary="\n
\n
"; - $summarypreview = $summarytext && $this->preview ? "
".wfMsg('summary-preview').':'.$sk->commentBlock( $this->summary, $this->mTitle )."
\n" : ''; + $summarypreview = $summarytext && $this->preview ? "
".wfMsg('summary-preview').':'.$sk->commentBlock( $this->summary, $this->dbTitle )."
\n" : ''; $subjectpreview = ''; } @@ -1219,6 +1235,7 @@ END $recreate {$commentsubject} {$subjectpreview} +{$this->editFormTextBeforeContent}