SpecialVersion: Handle Closures in $wgHooks nicer
[lhc/web/wiklou.git] / includes / EditPage.php
index ee67d01..0ca2f80 100644 (file)
@@ -167,6 +167,12 @@ class EditPage {
         */
        const AS_PARSE_ERROR = 240;
 
+       /**
+        * Status: when changing the content model is disallowed due to
+        * $wgContentHandlerUseDB being false
+        */
+       const AS_CANNOT_USE_CUSTOM_MODEL = 241;
+
        /**
         * HTML id and name for the beginning of the edit form.
         */
@@ -1037,7 +1043,6 @@ class EditPage {
                                $undo = $wgRequest->getInt( 'undo' );
 
                                if ( $undo > 0 && $undoafter > 0 ) {
-
                                        $undorev = Revision::newFromId( $undo );
                                        $oldrev = Revision::newFromId( $undoafter );
 
@@ -1046,8 +1051,8 @@ class EditPage {
                                        # Otherwise, $content will be left as-is.
                                        if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
                                                !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
-                                               !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
-
+                                               !$oldrev->isDeleted( Revision::DELETED_TEXT )
+                                       ) {
                                                $content = $this->mArticle->getUndoContent( $undorev, $oldrev );
 
                                                if ( $content === false ) {
@@ -1242,9 +1247,9 @@ class EditPage {
 
                        if ( !$converted ) {
                                //TODO: somehow show a warning to the user!
-                               wfDebug( "Attempt to preload incompatible content: "
-                                               . "can't convert " . $content->getModel()
-                                               . " to " . $handler->getModelID() );
+                               wfDebug( "Attempt to preload incompatible content: " .
+                                       "can't convert " . $content->getModel() .
+                                       " to " . $handler->getModelID() );
 
                                return $handler->makeEmptyContent();
                        }
@@ -1362,6 +1367,7 @@ class EditPage {
                        case self::AS_HOOK_ERROR:
                                return false;
 
+                       case self::AS_CANNOT_USE_CUSTOM_MODEL:
                        case self::AS_PARSE_ERROR:
                                $wgOut->addWikiText( '<div class="error">' . $status->getWikiText() . '</div>' );
                                return true;
@@ -1544,6 +1550,7 @@ class EditPage {
         */
        function internalAttemptSave( &$result, $bot = false ) {
                global $wgUser, $wgRequest, $wgParser, $wgMaxArticleSize;
+               global $wgContentHandlerUseDB;
 
                $status = Status::newGood();
 
@@ -1664,11 +1671,19 @@ class EditPage {
                        }
                }
 
-               if ( $this->contentModel !== $this->mTitle->getContentModel()
-                       && !$wgUser->isAllowed( 'editcontentmodel' )
-               ) {
-                       $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
-                       return $status;
+               $changingContentModel = false;
+               if ( $this->contentModel !== $this->mTitle->getContentModel() ) {
+                       if ( !$wgContentHandlerUseDB ) {
+                               $status->fatal( 'editpage-cannot-use-custom-model' );
+                               $status->value = self::AS_CANNOT_USE_CUSTOM_MODEL;
+                               return $status;
+                       } elseif ( !$wgUser->isAllowed( 'editcontentmodel' ) ) {
+                               $status->setResult( false, self::AS_NO_CHANGE_CONTENT_MODEL );
+                               return $status;
+
+                       }
+                       $changingContentModel = true;
+                       $oldContentModel = $this->mTitle->getContentModel();
                }
 
                if ( $this->changeTags ) {
@@ -1967,9 +1982,39 @@ class EditPage {
                        } );
                }
 
+               // If the content model changed, add a log entry
+               if ( $changingContentModel ) {
+                       $this->addContentModelChangeLogEntry(
+                               $wgUser,
+                               $oldContentModel,
+                               $this->contentModel,
+                               $this->summary
+                       );
+               }
+
                return $status;
        }
 
+       /**
+        * @param Title $title
+        * @param string $oldModel
+        * @param string $newModel
+        * @param string $reason
+        */
+       protected function addContentModelChangeLogEntry( User $user, $oldModel, $newModel, $reason ) {
+               $log = new ManualLogEntry( 'contentmodel', 'change' );
+               $log->setPerformer( $user );
+               $log->setTarget( $this->mTitle );
+               $log->setComment( $reason );
+               $log->setParameters( array(
+                       '4::oldmodel' => $oldModel,
+                       '5::newmodel' => $newModel
+               ) );
+               $logid = $log->insert();
+               $log->publish( $logid );
+       }
+
+
        /**
         * Register the change of watch status
         */
@@ -2500,7 +2545,7 @@ class EditPage {
                $wgOut->addHTML( $this->editFormTextBeforeContent );
 
                if ( !$this->isCssJsSubpage && $showToolbar && $wgUser->getOption( 'showtoolbar' ) ) {
-                       $wgOut->addHTML( EditPage::getEditToolbar() );
+                       $wgOut->addHTML( EditPage::getEditToolbar( $this->mTitle ) );
                }
 
                if ( $this->blankArticle ) {
@@ -3400,7 +3445,7 @@ HTML
 
                $this->deletedSinceEdit = false;
 
-               if ( $this->mTitle->isDeletedQuick() ) {
+               if ( !$this->mTitle->exists() && $this->mTitle->isDeletedQuick() ) {
                        $this->lastDelete = $this->getLastDelete();
                        if ( $this->lastDelete ) {
                                $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
@@ -3641,13 +3686,18 @@ HTML
         * Shows a bulletin board style toolbar for common editing functions.
         * It can be disabled in the user preferences.
         *
+        * @param $title Title object for the page being edited (optional)
         * @return string
         */
-       static function getEditToolbar() {
+       static function getEditToolbar( $title = null ) {
                global $wgContLang, $wgOut;
                global $wgEnableUploads, $wgForeignFileRepos;
 
                $imagesAvailable = $wgEnableUploads || count( $wgForeignFileRepos );
+               $showSignature = true;
+               if ( $title ) {
+                        $showSignature = MWNamespace::wantSignatures( $title->getNamespace() );
+               }
 
                /**
                 * $toolarray is an array of arrays each of which includes the
@@ -3715,13 +3765,13 @@ HTML
                                'sample' => wfMessage( 'nowiki_sample' )->text(),
                                'tip'    => wfMessage( 'nowiki_tip' )->text(),
                        ),
-                       array(
+                       $showSignature ? array(
                                'id'     => 'mw-editbutton-signature',
                                'open'   => '--~~~~',
                                'close'  => '',
                                'sample' => '',
                                'tip'    => wfMessage( 'sig_tip' )->text(),
-                       ),
+                       ) : false,
                        array(
                                'id'     => 'mw-editbutton-hr',
                                'open'   => "\n----\n",