Welterkj has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/144467

Change subject: Backward compatibility fix for MW version <1.21.
......................................................................

Backward compatibility fix for MW version <1.21.

The problem is that the GraphViz extension 1.0+ uses two hooks and
one function that were introduced in MW 1.21 (PageContentSave,
PageContentSaveComplete and WikiPage::doEdit respectively).

The fix is for the extension to use the older hooks and function
for MW versions <1.21 (ArticleSave, ArticleSaveComplete and
WikiPage::doEditContent respectively).

Change-Id: Ie353c40ff784e49cb7740059c2e653443dfa0cce
---
M GraphViz.php
M GraphViz_body.php
M README.md
M RELEASE-NOTES.md
M UploadLocalFile.php
5 files changed, 68 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GraphViz 
refs/changes/67/144467/1

diff --git a/GraphViz.php b/GraphViz.php
index 752a315..3343cf9 100644
--- a/GraphViz.php
+++ b/GraphViz.php
@@ -92,11 +92,20 @@
        $GLOBALS['wgAutoloadClasses']['GraphRenderParms'] = $dir . 
"GraphRenderParms.php";
        $GLOBALS['wgAutoloadClasses']['UploadLocalFile'] = $dir . 
"UploadLocalFile.php";
        $GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'GraphViz::onParserInit';
-       $GLOBALS['wgHooks']['PageContentSave'][] = 
'GraphViz::onPageContentSave';
-       $GLOBALS['wgHooks']['PageContentSaveComplete'][] = 
'GraphViz::onPageContentSaveComplete';
        $GLOBALS['wgHooks']['OutputPageParserOutput'][] = 
'GraphViz::onOutputPageParserOutput';
        $GLOBALS['wgHooks']['ArticleDeleteComplete'][] = 
'GraphViz::onArticleDeleteComplete';
 
+       $oldVersion = version_compare( $GLOBALS['wgVersion'], '1.21', '<' );
+       if ( $oldVersion ) {
+               # Do stuff for MediaWiki 1.20 and older
+               $GLOBALS['wgHooks']['ArticleSave'][] = 
'GraphViz::onArticleSave';
+               $GLOBALS['wgHooks']['ArticleSaveComplete'][] = 
'GraphViz::onArticleSaveComplete';
+       } else {
+               # Do stuff for MediaWiki 1.21 and newer
+               $GLOBALS['wgHooks']['PageContentSave'][] = 
'GraphViz::onPageContentSave';
+               $GLOBALS['wgHooks']['PageContentSaveComplete'][] = 
'GraphViz::onPageContentSaveComplete';
+       }
+
        $GLOBALS['wgExtensionCredits']['parserhook'][] = array(
                'name' => 'Graphviz',
                'path' => __FILE__,
diff --git a/GraphViz_body.php b/GraphViz_body.php
index f431738..a5af37b 100644
--- a/GraphViz_body.php
+++ b/GraphViz_body.php
@@ -312,14 +312,31 @@
        }
 
        /**
-        * Hook function to record when a page is being saved.
+        * Hook function front-end to GraphViz::onTitleSave.
         * @author Keith Welter
         */
        public static function onPageContentSave( $wikiPage, $user, $content, 
$summary, $isMinor, $isWatch, $section, $flags, $status ) {
                $titleText = $wikiPage->getTitle()->getFulltext();
+               return self::onTitleSave( $titleText );
+       }
+
+       /**
+        * Function to record when a page with the given title is being saved.
+        * @author Keith Welter
+        */
+       public static function onTitleSave( $titleText ) {
                self::$titlesBeingSaved[$titleText] = '';
                wfDebug( __METHOD__ . ": saving: $titleText\n" );
                return true;
+       }
+
+       /**
+        * Backwards-compatible (< MW 1.21) hook function front-end to 
GraphViz::onTitleSave.
+        * @author Keith Welter
+        */
+       public static function onArticleSave( &$article, &$user, &$text, 
&$summary, $minor, $watchthis, $sectionanchor, &$flags, &$status ) {
+               $titleText = $article->getTitle()->getFulltext();
+               return self::onTitleSave( $titleText );
        }
 
        /**
@@ -331,14 +348,23 @@
        }
 
        /**
-        * Hook function to clean-up when a page is done being saved.  Firstly, 
this function invokes
-        * deleteInactiveFiles() to delete inactive graph files associated with 
a page when
-        * it is done being saved.  Lastly, this function removes the record 
that the page is being
-        * saved as well as the list of active files for the page.
+        * Hook function front-end to GraphViz::onTitleSaveComplete.
         * @author Keith Welter
         */
        public static function onPageContentSaveComplete( $wikiPage, $user, 
$content, $summary, $isMinor, $isWatch, $section, $flags, $revision, $status, 
$baseRevId ) {
                $titleText = $wikiPage->getTitle()->getFulltext();
+               return self::onTitleSaveComplete( $titleText );
+       }
+
+       /**
+        * Function to clean-up when a page with the given title is done being 
saved.  
+        * Firstly, this function invokes deleteInactiveFiles() to delete 
inactive 
+        * graph files associated with a page when it is done being saved.  
Lastly, 
+        * this function removes the record that the page is being saved as 
well as 
+        * the list of active files for the page.
+        * @author Keith Welter
+        */
+       public static function onTitleSaveComplete( $titleText ) {
                self::deleteInactiveFiles( $titleText );
                wfDebug( __METHOD__ . ": done saving: $titleText\n" );
                unset( self::$titlesBeingSaved[$titleText] );
@@ -346,6 +372,15 @@
        }
 
        /**
+        * Backwards-compatible (< MW 1.21) hook function front-end to 
GraphViz::onTitleSaveComplete.
+        * @author Keith Welter
+        */
+       public static function onArticleSaveComplete( &$article, &$user, $text, 
$summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, 
$baseRevId ) {
+               $titleText = $article->getTitle()->getFulltext();
+               return self::onTitleSaveComplete( $titleText );
+       }
+
+       /**
         * Record an active graph file for the given title text.
         * An active graph file is one that is referenced by wiki text that is 
being saved.
         * @param[in] string $titleText is the title of the page being saved.
diff --git a/README.md b/README.md
index 7442671..37d7ad6 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@
 ```json
 {
        "require": {
-               "mediawiki/graph-viz": "~1.1.*"
+               "mediawiki/graph-viz": "~1.1"
        }
 }
 ```
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 1b7a4af..735d388 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -1,6 +1,9 @@
 These are the release notes for the [MediaWiki][mediawiki] [GraphViz 
extension][gv_ext].
 
-## GraphViz 1.3.0 ## (2014-06-27)
+## GraphViz 1.3.1 ## (2014-07-07)
+* Fix for [bug 67587](https://bugzilla.wikimedia.org/show_bug.cgi?id=67587).
+
+## GraphViz 1.3.0 ## (2014-06-30)
 * Added README.md and RELEASE-NOTES.md.
 
 ## GraphViz 1.2.0 ## (2014-06-25)
@@ -26,8 +29,8 @@
 ### New features
 * rendered graph and message sequence chart images are uploaded to the wiki
 * graphs and message sequence charts are only re-rendered when the source 
changes
-* embedded links work properly when the rendered image is resized (powered by 
[[Extension:ImageMap]])
-* embedded links support tooltips (powered by [[Extension:ImageMap]])
+* embedded links work properly when the rendered image is resized (powered by 
[ImageMap][image_map_ext])
+* embedded links support tooltips (powered by [ImageMap][image_map_ext])
 * support for the DOT [image 
attribute](http://www.graphviz.org/content/attrs#dimage image)
 * deterministic file clean-up (active files are retained, inactive files are 
deleted)
 * support for multiple message sequence charts per page (uniquifier)
diff --git a/UploadLocalFile.php b/UploadLocalFile.php
index 5fedb9f..bbe6648 100644
--- a/UploadLocalFile.php
+++ b/UploadLocalFile.php
@@ -246,8 +246,16 @@
 
                if ( $exists && isset( $pageText ) ) {
                        $wikiPage = new WikiFilePage( $title );
-                       $content = ContentHandler::makeContent( $pageText, 
$title );
-                       $status = $wikiPage->doEditContent( $content, $comment, 
EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user );
+
+                       $oldVersion = version_compare( $GLOBALS['wgVersion'], 
'1.21', '<' );
+                       if ( $oldVersion ) {
+                               # Do stuff for MediaWiki 1.20 and older
+                               $status = $wikiPage->doEdit( $pageText, 
$comment, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user );
+                       } else {
+                               # Do stuff for MediaWiki 1.21 and newer
+                               $content = ContentHandler::makeContent( 
$pageText, $title );
+                               $status = $wikiPage->doEditContent( $content, 
$comment, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user );
+                       }
                }
 
                return true;

-- 
To view, visit https://gerrit.wikimedia.org/r/144467
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie353c40ff784e49cb7740059c2e653443dfa0cce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GraphViz
Gerrit-Branch: master
Gerrit-Owner: Welterkj <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to