Avoid undefined variable error on null edits
[lhc/web/wiklou.git] / includes / EditPage.php
index 002f0ed..d6d714d 100644 (file)
@@ -154,7 +154,10 @@ class EditPage {
         */
        function edit() {
                global $wgOut, $wgUser, $wgRequest, $wgTitle;
-
+               
+               if ( ! wfRunHooks( 'AlternateEdit', array( &$this  ) ) )
+                       return;
+               
                $fname = 'EditPage::edit';
                wfProfileIn( $fname );
                wfDebug( "$fname: enter\n" );
@@ -199,6 +202,12 @@ class EditPage {
                                return;
                        }
                }
+               if ( !$this->mTitle->userCan( 'create' ) && !$this->mTitle->exists() ) {
+                       wfDebug( "$fname: no create permission\n" );
+                       $this->noCreatePermission();
+                       wfProfileOut( $fname );
+                       return;
+               }
                if ( wfReadOnly() ) {
                        wfDebug( "$fname: read-only mode is engaged\n" );
                        if( $this->save || $this->preview ) {
@@ -510,6 +519,14 @@ class EditPage {
                # If article is new, insert it.
                $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
                if ( 0 == $aid ) {
+                       // Late check for create permission, just in case *PARANOIA*
+                       if ( !$this->mTitle->userCan( 'create' ) ) {
+                               wfDebug( "$fname: no create permission\n" );
+                               $this->noCreatePermission();
+                               wfProfileOut( $fname );
+                               return;
+                       }
+                       
                        # Don't save a new article if it's blank.
                        if ( ( '' == $this->textbox1 ) ) {
                                        $wgOut->redirect( $this->mTitle->getFullURL() );
@@ -675,13 +692,12 @@ class EditPage {
                        }
                        $wgOut->setPageTitle( $s );
                        if ( !$this->checkUnicodeCompliantBrowser() ) {
-                               $this->mArticle->setOldSubtitle();
                                $wgOut->addWikiText( wfMsg( 'nonunicodebrowser') );
                        }
                        if ( isset( $this->mArticle )
                             && isset( $this->mArticle->mRevision )
                             && !$this->mArticle->mRevision->isCurrent() ) {
-                               $this->mArticle->setOldSubtitle();
+                               $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
                                $wgOut->addWikiText( wfMsg( 'editingold' ) );
                        }
                }
@@ -845,6 +861,14 @@ END
                if( is_callable( $formCallback ) ) {
                        call_user_func_array( $formCallback, array( &$wgOut ) );
                }
+
+               // Put these up at the top to ensure they aren't lost on early form submission
+               $wgOut->addHTML( "
+<input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
+<input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
+<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
+<input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
+
                $wgOut->addHTML( <<<END
 $recreate
 {$commentsubject}
@@ -853,11 +877,20 @@ cols='{$cols}'{$ew} $hidden>
 END
 . htmlspecialchars( $this->safeUnicodeOutput( $this->textbox1 ) ) .
 "
-</textarea><br />
+</textarea>
+
+               " );
+               
+               $wgOut->addWikiText( $copywarn );
+
+               $wgOut->addHTML( "
 {$metadata}
 {$editsummary}
 {$checkboxhtml}
 {$safemodehtml}
+");
+
+               $wgOut->addHTML( "
 <div class='editButtons'>
 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
 " title=\"".wfMsg('tooltip-save')."\"/>
@@ -866,16 +899,15 @@ END
 <input tabindex='7' id='wpDiff' type='submit' value=\"{$diff}\" name=\"wpDiff\" accesskey=\"".wfMsg('accesskey-diff')."\"".
 " title=\"".wfMsg('tooltip-diff')."\"/> <span class='editHelp'>{$cancel} | {$edithelp}</span></div>
 </div>
+" );
+
+               $wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
+
+               $wgOut->addHTML( "
 <div class='templatesUsed'>
 {$templates}
 </div>
 " );
-               $wgOut->addWikiText( $copywarn );
-               $wgOut->addHTML( "
-<input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
-<input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
-<input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
-<input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
 
                if ( $wgUser->isLoggedIn() ) {
                        /**
@@ -894,8 +926,10 @@ END
                if ( $this->isConflict ) {
                        require_once( "DifferenceEngine.php" );
                        $wgOut->addWikiText( '==' . wfMsg( "yourdiff" ) . '==' );
-                       DifferenceEngine::showDiff( $this->textbox2, $this->textbox1,
-                         wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
+
+                       $de = new DifferenceEngine( $this->mTitle );
+                       $de->setText( $this->textbox2, $this->textbox1 );
+                       $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
 
                        $wgOut->addWikiText( '==' . wfMsg( "yourtext" ) . '==' );
                        $wgOut->addHTML( "<textarea tabindex=6 id='wpTextbox2' name=\"wpTextbox2\" rows='{$rows}' cols='{$cols}' wrap='virtual'>"
@@ -1017,7 +1051,7 @@ END
         * @todo document
         */
        function getPreviewText() {
-               global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
+               global $wgOut, $wgUser, $wgTitle, $wgParser;
 
                $fname = 'EditPage::getPreviewText';
                wfProfileIn( $fname );
@@ -1223,7 +1257,7 @@ END
         * The necessary JavaScript code can be found in style/wikibits.js.
         */
        function getEditToolbar() {
-               global $wgStylePath, $wgLang, $wgMimeType, $wgJsMimeType;
+               global $wgStylePath, $wgLang, $wgJsMimeType;
 
                /**
                 * toolarray an array of arrays which each include the filename of
@@ -1381,8 +1415,12 @@ END
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
                $oldtitle = wfMsg( 'currentrev' );
                $newtitle = wfMsg( 'yourtext' );
-               if ( $oldtext != wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) || $newtext != '' ) {
-                       $difftext = DifferenceEngine::getDiff( $oldtext, $newtext, $oldtitle, $newtitle );
+               if ( $oldtext !== false  || $newtext != '' ) {
+                       $de = new DifferenceEngine( $this->mTitle );
+                       $de->setText( $oldtext, $newtext );
+                       $difftext = $de->getDiff( $oldtitle, $newtitle );
+               } else {
+                       $difftext = '';
                }
 
                return '<div id="wikiDiff">' . $difftext . '</div>';
@@ -1503,6 +1541,11 @@ END
                return strtr( $result, array( "&#x0" => "&#x" ) );
        }
        
+       function noCreatePermission() {
+               global $wgOut;
+               $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
+               $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );
+       }
 
 }