fix getAutosummary() for cases where is empty
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 5 Apr 2012 14:38:53 +0000 (16:38 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Thu, 5 Apr 2012 14:38:53 +0000 (16:38 +0200)
Change-Id: I21143dff15bf47ff9fa5ee51a88b046988c8367a

includes/ContentHandler.php
includes/WikiPage.php

index 4eb4061..a6269eb 100644 (file)
@@ -274,20 +274,20 @@ abstract class ContentHandler {
     /**
      * Return an applicable autosummary if one exists for the given edit.
      *
-     * @param $oldContent Content: the previous text of the page.
-     * @param $newContent Content: The submitted text of the page.
+     * @param $oldContent Content|null: the previous text of the page.
+     * @param $newContent Content|null: The submitted text of the page.
      * @param $flags Int bitmask: a bitmask of flags submitted for the edit.
      *
      * @return string An appropriate autosummary, or an empty string.
      */
-    public function getAutosummary( Content $oldContent, Content $newContent, $flags ) {
+    public function getAutosummary( Content $oldContent = null, Content $newContent = null, $flags ) {
         global $wgContLang;
 
         # Decide what kind of autosummary is needed.
 
         # Redirect autosummaries
-        $ot = $oldContent->getRedirectTarget();
-        $rt = $newContent->getRedirectTarget();
+        $ot = !empty( $ot ) ? $oldContent->getRedirectTarget() : false;
+        $rt = !empty( $rt ) ? $newContent->getRedirectTarget() : false;
 
         if ( is_object( $rt ) && ( !is_object( $ot ) || !$rt->equals( $ot ) || $ot->getFragment() != $rt->getFragment() ) ) {
 
index e992efd..f91f758 100644 (file)
@@ -1375,6 +1375,7 @@ class WikiPage extends Page {
 
                # Provide autosummaries if one is not provided and autosummaries are enabled.
                if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) {
+            if ( !$old_content ) $old_content = null;
                        $summary = $handler->getAutosummary( $old_content, $content, $flags );
                }
 
@@ -2560,8 +2561,8 @@ class WikiPage extends Page {
                # NOTE: stub for backwards-compatibility. assumes the given text is wikitext. will break horribly if it isn't.
 
         $handler = ContentHandler::getForModelName( CONTENT_MODEL_WIKITEXT );
-        $oldContent = $handler->unserialize( $oldtext );
-        $newContent = $handler->unserialize( $newtext );
+        $oldContent = $oldtext ? $handler->unserialize( $oldtext ) : null;
+        $newContent = $newtext ? $handler->unserialize( $newtext ) : null;
 
         return $handler->getAutosummary( $oldContent, $newContent, $flags );
        }