Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / includes / specials / SpecialChangeContentModel.php
index b37c475..87276a1 100644 (file)
@@ -156,10 +156,20 @@ class SpecialChangeContentModel extends FormSpecialPage {
                }
 
                $this->title = Title::newFromText( $data['pagetitle'] );
+               $titleWithNewContentModel = clone $this->title;
+               $titleWithNewContentModel->setContentModel( $data['model'] );
                $user = $this->getUser();
-               // Check permissions and make sure the user has permission to edit the specific page
-               $errors = $this->title->getUserPermissionsErrors( 'editcontentmodel', $user );
-               $errors = wfMergeErrorArrays( $errors, $this->title->getUserPermissionsErrors( 'edit', $user ) );
+               // Check permissions and make sure the user has permission to:
+               $errors = wfMergeErrorArrays(
+                       // edit the contentmodel of the page
+                       $this->title->getUserPermissionsErrors( 'editcontentmodel', $user ),
+                       // edit the page under the old content model
+                       $this->title->getUserPermissionsErrors( 'edit', $user ),
+                       // edit the contentmodel under the new content model
+                       $titleWithNewContentModel->getUserPermissionsErrors( 'editcontentmodel', $user ),
+                       // edit the page under the new content model
+                       $titleWithNewContentModel->getUserPermissionsErrors( 'edit', $user )
+               );
                if ( $errors ) {
                        $out = $this->getOutput();
                        $wikitext = $out->formatPermissionsErrorMessage( $errors );
@@ -221,6 +231,22 @@ class SpecialChangeContentModel extends FormSpecialPage {
                # Truncate for whole multibyte characters.
                $reason = $wgContLang->truncate( $reason, 255 );
 
+               // Run edit filters
+               $derivativeContext = new DerivativeContext( $this->getContext() );
+               $derivativeContext->setTitle( $this->title );
+               $derivativeContext->setWikiPage( $page );
+               $status = new Status();
+               if ( !Hooks::run( 'EditFilterMergedContent',
+                               [ $derivativeContext, $newContent, $status, $reason,
+                               $user, false ] )
+               ) {
+                       if ( $status->isGood() ) {
+                               // TODO: extensions should really specify an error message
+                               $status->fatal( 'hookaborted' );
+                       }
+                       return $status;
+               }
+
                $status = $page->doEditContent(
                        $newContent,
                        $reason,