APIEDIT_VODAFONE BRANCH MERGE:
authorRoan Kattouw <catrope@users.mediawiki.org>
Mon, 3 Mar 2008 16:40:42 +0000 (16:40 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Mon, 3 Mar 2008 16:40:42 +0000 (16:40 +0000)
* Adding EditPage::wasDeletedSinceLastEdit() to replace code in EditPage::edit() to avoid duplicating it in internalAttemptSave().
* Adding $wgTitle === null check to showEditForm() as some extensions (like ConfirmEdit) call it. For further explanation see comment.

includes/EditPage.php

index f2a7327..36424ba 100644 (file)
@@ -318,6 +318,25 @@ class EditPage {
                $this->mArticle->mContent = $t ;
                $this->mMetaData = $s ;
        }
+       
+       protected function wasDeletedSinceLastEdit() {
+               /* Note that we rely on the logging table, which hasn't been always there,
+                * but that doesn't matter, because this only applies to brand new
+                * deletes. 
+                */
+               if ( $this->deletedSinceEdit )
+                       return true;
+               if ( $this->mTitle->isDeleted() ) {
+                       $this->lastDelete = $this->getLastDelete();
+                       if ( !is_null($this->lastDelete) ) {
+                               $deletetime = $this->lastDelete->log_timestamp;
+                               if ( ($deletetime - $this->starttime) > 0 ) {
+                                       $this->deletedSinceEdit = true;
+                               }
+                       }
+               }
+               return $this->deletedSinceEdit;
+       }
 
        function submit() {
                $this->edit();
@@ -418,27 +437,6 @@ class EditPage {
                $this->isCssJsSubpage      = $this->mTitle->isCssJsSubpage();
                $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
 
-               /* Notice that we can't use isDeleted, because it returns true if article is ever deleted
-                * no matter it's current state
-                */
-               $this->deletedSinceEdit = false;
-               if ( $this->edittime != '' ) {
-                       /* Note that we rely on logging table, which hasn't been always there,
-                        * but that doesn't matter, because this only applies to brand new
-                        * deletes. This is done on every preview and save request. Move it further down
-                        * to only perform it on saves
-                        */
-                       if ( $this->mTitle->isDeleted() ) {
-                               $this->lastDelete = $this->getLastDelete();
-                               if ( !is_null($this->lastDelete) ) {
-                                       $deletetime = $this->lastDelete->log_timestamp;
-                                       if ( ($deletetime - $this->starttime) > 0 ) {
-                                               $this->deletedSinceEdit = true;
-                                       }
-                               }
-                       }
-               }
-
                # Show applicable editing introductions
                if( $this->formtype == 'initial' || $this->firsttime )
                        $this->showIntro();
@@ -797,7 +795,7 @@ class EditPage {
 
                # If the article has been deleted while editing, don't save it without
                # confirmation
-               if ( $this->deletedSinceEdit && !$this->recreate ) {
+               if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
                        wfProfileOut( "$fname-checks" );
                        wfProfileOut( $fname );
                        return self::AS_ARTICLE_WAS_DELETED;
@@ -1009,6 +1007,13 @@ class EditPage {
         */
        function showEditForm( $formCallback=null ) {
                global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle;
+               
+               # If $wgTitle is null, that means we're in API mode.
+               # Some hook probably called this function  without checking
+               # for is_null($wgTitle) first. Bail out right here so we don't
+               # do lots of work just to discard it right after.
+               if(is_null($wgTitle))
+                       return;
 
                $fname = 'EditPage::showEditForm';
                wfProfileIn( $fname );
@@ -1273,7 +1278,7 @@ class EditPage {
 
                $hidden = '';
                $recreate = '';
-               if ($this->deletedSinceEdit) {
+               if ($this->wasDeletedSinceLastEdit()) {
                        if ( 'save' != $this->formtype ) {
                                $wgOut->addWikiMsg('deletedwhileediting');
                        } else {