* (bug 10181) Support the XCache object caching mechanism [patch from Kurt Radwanski]
[lhc/web/wiklou.git] / includes / EditPage.php
index bd40200..888726c 100644 (file)
@@ -107,13 +107,13 @@ class EditPage {
                                        $undorev = Revision::newFromId($undo);
                                        $oldrev = $undorev ? $undorev->getPrevious() : null;
                                }
-                               
+
                                #Sanity check, make sure it's the right page.
                                # Otherwise, $text will be left as-is.
                                if ( !is_null($undorev) && !is_null($oldrev) && $undorev->getPage()==$oldrev->getPage() && $undorev->getPage()==$this->mArticle->getID() ) {
                                        $undorev_text = $undorev->getText();
-                    $oldrev_text = $oldrev->getText();
-                    $currev_text = $text;
+                                       $oldrev_text = $oldrev->getText();
+                                       $currev_text = $text;
 
                                        #No use doing a merge if it's just a straight revert.
                                        if ( $currev_text != $undorev_text ) {
@@ -294,7 +294,7 @@ class EditPage {
                global $wgOut, $wgUser, $wgRequest, $wgTitle;
                global $wgEmailConfirmToEdit;
 
-               if ( ! wfRunHooks( 'AlternateEdit', array( &$this  ) ) )
+               if ( ! wfRunHooks( 'AlternateEdit', array( &$this ) ) )
                        return;
 
                $fname = 'EditPage::edit';
@@ -604,6 +604,8 @@ class EditPage {
                                $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
                        else
                                $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
+                               # Let the user know about previous deletions if applicable
+                               $this->showDeletionLog( $wgOut );
                }
        }
 
@@ -813,7 +815,7 @@ class EditPage {
                }
 
                #And a similar thing for new sections
-                if( $this->section == 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary' ) ) {
+               if( $this->section == 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary' ) ) {
                        if (trim($this->summary) == '') {
                                $this->missingSummary = true;
                                wfProfileOut( $fname );
@@ -881,7 +883,7 @@ class EditPage {
                $this->summary = '';
                $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() );
                wfProxyCheck();
@@ -947,9 +949,9 @@ class EditPage {
                                $wgOut->addWikiText( wfMsg( 'missingsummary' ) );
                        }
 
-                        if( $this->missingSummary && $this->section == 'new' ) {
-                                $wgOut->addWikiText( wfMsg( 'missingcommentheader' ) );
-                        }
+                       if( $this->missingSummary && $this->section == 'new' ) {
+                               $wgOut->addWikiText( wfMsg( 'missingcommentheader' ) );
+                       }
 
                        if( !$this->hookError == '' ) {
                                $wgOut->addWikiText( $this->hookError );
@@ -995,20 +997,22 @@ class EditPage {
                                if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' )
                                        $notice = '';
                        } else {
-                               # It's either cascading protection or regular protection; work out which
-                               list($cascadeSources, $restrictions) = $this->mTitle->getCascadeProtectionSources();
-                               if ( !$cascadeSources || count( $cascadeSources ) == 0 ) {
-                                       # Regular protection
-                                       $notice = wfMsg( 'protectedpagewarning' );
-                               } else {
-                                       # Cascading protection; explain, and list the titles responsible
-                                       $notice = wfMsg( 'cascadeprotectedwarning' ) . "\n";
-                                       foreach( $cascadeSources as $source )
-                                               $notice .= '* [[:' . $source->getPrefixedText() . "]]\n";
-                               }
+                       # Then it must be protected based on static groups (regular)
+                               $notice = wfMsg( 'protectedpagewarning' );
                        }
                        $wgOut->addWikiText( $notice );
                }
+               if ( $this->mTitle->isCascadeProtected() ) {
+                       # Is this page under cascading protection from some source pages?
+                       list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
+                       if ( count($cascadeSources) > 0 ) {
+                               # Explain, and list the titles responsible
+                               $notice = wfMsgExt( 'cascadeprotectedwarning', array('parsemag'), count($cascadeSources) ) . "\n";
+                               foreach( $cascadeSources as $id => $page )
+                                       $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
+                               }
+                       $wgOut->addWikiText( $notice );
+               }
 
                if ( $this->kblength === false ) {
                        $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
@@ -1087,6 +1091,7 @@ class EditPage {
                        }
 
                        if ( 'diff' == $this->formtype ) {
+                               $wgOut->addStyle( 'common/diff.css' );
                                $wgOut->addHTML( $this->getDiff() );
                        }
                }
@@ -1113,7 +1118,7 @@ class EditPage {
                if( !$this->preview && !$this->diff ) {
                        $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
                }
-               $templates = ($this->preview || $this->section) ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates();
+               $templates = ($this->preview || $this->section != '') ? $this->mPreviewTemplates : $this->mArticle->getUsedTemplates();
                $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
 
                global $wgUseMetadataEdit ;
@@ -1269,6 +1274,7 @@ END
                        }
 
                        if ( $this->formtype == 'diff') {
+                               $wgOut->addStyle( 'common/diff.css' );
                                $wgOut->addHTML( $this->getDiff() );
                        }
 
@@ -1495,7 +1501,7 @@ END
                $wgOut->setArticleRelated( false );
 
                $wgOut->addWikiText( wfMsg( 'nosuchsectiontext', $this->section ) );
-               $wgOut->returnToMain( false );
+               $wgOut->returnToMain( false, $this->mTitle->getPrefixedUrl() );
        }
 
        /**
@@ -2032,6 +2038,46 @@ END
                $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
                $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );
        }
+       
+       /**
+        * If there are rows in the deletion log for this page, show them,
+        * along with a nice little note for the user
+        *
+        * @param OutputPage $out
+        */
+       private function showDeletionLog( $out ) {
+               $title = $this->mArticle->getTitle();
+               $reader = new LogReader(
+                       new FauxRequest(
+                               array(
+                                       'page' => $title->getPrefixedText(),
+                                       'type' => 'delete',
+                                       )
+                       )
+               );
+               if( $reader->hasRows() ) {
+                       $out->addHtml( '<div id="mw-recreate-deleted-warn">' );
+                       $out->addHtml( $this->buildWarningDismisser() );
+                       $out->addWikiText( wfMsg( 'recreate-deleted-warn' ) );
+                       $viewer = new LogViewer( $reader );
+                       $viewer->showList( $out );
+                       $out->addHtml( '</div>' );                      
+               }                               
+       }
+       
+       /**
+        * Builds a JavaScript fragment that injects a link to dismiss the
+        * "recreating deleted" warning
+        *
+        * @return string
+        */
+       private function buildWarningDismisser() {
+               return '<script type="text/javascript">'
+                       . 'document.write( \'<div class="mw-recreate-deleted-control">'
+                       . '<a href="javascript:dismissRecreateWarning();">'
+                       . wfMsgHtml( 'recreate-deleted-dismiss' ) . '</a></div>\' );'
+                       . '</script>';                  
+       }
 
 }