Avoid undefined variable error on null edits
[lhc/web/wiklou.git] / includes / EditPage.php
index 4e39380..d6d714d 100644 (file)
@@ -202,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 ) {
@@ -513,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() );
@@ -1037,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 );
@@ -1243,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
@@ -1527,6 +1541,11 @@ END
                return strtr( $result, array( "&#x0" => "&#x" ) );
        }
        
+       function noCreatePermission() {
+               global $wgOut;
+               $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
+               $wgOut->addWikiText( wfMsg( 'nocreatetext' ) );
+       }
 
 }