(Bug 41370) protect aginst content-less revisions
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 25 Oct 2012 07:51:23 +0000 (09:51 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Thu, 25 Oct 2012 07:51:23 +0000 (09:51 +0200)
getAutoDeletereason did not gracefully deal with revisions that would
return null as their content (e.g. for deleted revisions).

Change-Id: I4976f2d09b8666ca1bccebea346af37ee77b09f7

includes/content/ContentHandler.php

index 9c4c3af..8e8de4b 100644 (file)
@@ -802,20 +802,21 @@ abstract class ContentHandler {
                $content = $rev->getContent();
                $blank = false;
 
-               $this->checkModelID( $content->getModel() );
-
                // If the page is blank, use the text from the previous revision,
                // which can only be blank if there's a move/import/protect dummy
                // revision involved
-               if ( $content->getSize() == 0 ) {
+               if ( !$content || $content->isEmpty() ) {
                        $prev = $rev->getPrevious();
 
-                       if ( $prev )    {
-                               $content = $prev->getContent();
+                       if ( $prev ) {
+                               $rev = $prev;
+                               $content = $rev->getContent();
                                $blank = true;
                        }
                }
 
+               $this->checkModelID( $rev->getContentModel() );
+
                // Find out if there was only one contributor
                // Only scan the last 20 revisions
                $res = $dbw->select( 'revision', 'rev_user_text',
@@ -871,7 +872,7 @@ abstract class ContentHandler {
                }
 
                // Max content length = max comment length - length of the comment (excl. $1)
-               $text = $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) );
+               $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) : '';
 
                // Now replace the '$1' placeholder
                $reason = str_replace( '$1', $text, $reason );