remove extra whitespace; testing commit notifications
[lhc/web/wiklou.git] / includes / EditPage.php
index bd40200..3a8038a 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';
@@ -410,9 +410,10 @@ class EditPage {
                        }
                }
 
-               if(!$this->mTitle->getArticleID() && ('initial' == $this->formtype || $this->firsttime )) { # new article
+               # Show applicable editing introductions
+               if( $this->formtype == 'initial' || $this->firsttime )
                        $this->showIntro();
-               }
+       
                if( $this->mTitle->isTalkPage() ) {
                        $wgOut->addWikiText( wfMsg( 'talkpagetext' ) );
                }
@@ -585,25 +586,39 @@ class EditPage {
                return $this->mTokenOk;
        }
 
-       /** */
-       function showIntro() {
+       /**
+        * Show all applicable editing introductions
+        */
+       private 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() )
+               if( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
+                       if( $wgUser->isLoggedIn() ) {
                                $wgOut->addWikiText( wfMsg( 'newarticletext' ) );
-                       else
+                       } else {
                                $wgOut->addWikiText( wfMsg( 'newarticletextanon' ) );
+                       }
+                       $this->showDeletionLog( $wgOut );
+               }
+       }
+       
+       /**
+        * Attempt to show a custom editing introduction, if supplied
+        *
+        * @return bool
+        */
+       private function showCustomIntro() {
+               if( $this->editintro ) {
+                       $title = Title::newFromText( $this->editintro );
+                       if( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
+                               global $wgOut;
+                               $revision = Revision::newFromTitle( $title );
+                               $wgOut->addSecondaryWikiText( $revision->getText() );
+                               return true;
+                       } else {
+                               return false;
+                       }
+               } else {
+                       return false;
                }
        }
 
@@ -813,7 +828,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 +896,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 +962,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 +1010,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,7 +1104,7 @@ class EditPage {
                        }
 
                        if ( 'diff' == $this->formtype ) {
-                               $wgOut->addHTML( $this->getDiff() );
+                               $this->showDiff();
                        }
                }
 
@@ -1113,7 +1130,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,7 +1286,7 @@ END
                        }
 
                        if ( $this->formtype == 'diff') {
-                               $wgOut->addHTML( $this->getDiff() );
+                               $this->showDiff();
                        }
 
                }
@@ -1495,7 +1512,7 @@ END
                $wgOut->setArticleRelated( false );
 
                $wgOut->addWikiText( wfMsg( 'nosuchsectiontext', $this->section ) );
-               $wgOut->returnToMain( false );
+               $wgOut->returnToMain( false, $this->mTitle->getPrefixedUrl() );
        }
 
        /**
@@ -1891,10 +1908,8 @@ END
         *
         * If this is a section edit, we'll replace the section as for final
         * save and then make a comparison.
-        *
-        * @return string HTML
         */
-       function getDiff() {
+       function showDiff() {
                $oldtext = $this->mArticle->fetchContent();
                $newtext = $this->mArticle->replaceSection(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
@@ -1905,11 +1920,13 @@ END
                        $de = new DifferenceEngine( $this->mTitle );
                        $de->setText( $oldtext, $newtext );
                        $difftext = $de->getDiff( $oldtitle, $newtitle );
+                       $de->showDiffStyle();
                } else {
                        $difftext = '';
                }
 
-               return '<div id="wikiDiff">' . $difftext . '</div>';
+               global $wgOut;
+               $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
        }
 
        /**
@@ -2032,7 +2049,32 @@ 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->addWikiText( wfMsg( 'recreate-deleted-warn' ) );
+                       $viewer = new LogViewer( $reader );
+                       $viewer->showList( $out );
+                       $out->addHtml( '</div>' );                      
+               }                               
+       }
+       
 }
 
 ?>