Nischayn22 has uploaded a new change for review.

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

Change subject: Added inline diffs
......................................................................

Added inline diffs

Change-Id: Iadd5a56f1dec9eaf2a91a80a6eaaafd03dcb376d
---
A .gitignore
M RecentActivityFeed.php
M SpecialRecentActivityFeed.php
A modules/ext.inlinediff.js
4 files changed, 204 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RecentActivityFeed 
refs/changes/58/158058/1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e4e5f6c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*~
\ No newline at end of file
diff --git a/RecentActivityFeed.php b/RecentActivityFeed.php
index b2cf20d..cba6cd4 100644
--- a/RecentActivityFeed.php
+++ b/RecentActivityFeed.php
@@ -21,4 +21,15 @@
 $wgAutoloadClasses[ 'SpecialRecentActivityFeed' ] = __DIR__ . 
'/SpecialRecentActivityFeed.php'; # Location of the SpecialRecentActivityFeed 
class (Tell MediaWiki to load this file)
 $wgMessagesDirs[ 'RecentActivityFeed' ] = __DIR__ . "/i18n"; # Location of 
localisation files (Tell MediaWiki to load them)
 $wgExtensionMessagesFiles[ 'RecentActivityFeedAlias' ] = __DIR__ . 
'/RecentActivityFeed.alias.php';
-$wgSpecialPages[ 'RecentActivityFeed' ] = 'SpecialRecentActivityFeed'; # Tell 
MediaWiki about the new special page and its class name
\ No newline at end of file
+$wgSpecialPages[ 'RecentActivityFeed' ] = 'SpecialRecentActivityFeed'; # Tell 
MediaWiki about the new special page and its class name
+
+
+$wgResourceModules['ext.RecentActivityFeed.inlinediff'] = array(
+                                          'scripts' => 
'modules/ext.inlinediff.js',
+                                          'styles' => array(),
+                                          'messages' => array(
+                                                     ),
+                                                     'dependencies' => array(),
+ 'localBasePath' => __DIR__,
+ 'remoteExtPath' => 'RecentActivityFeed',
+);
diff --git a/SpecialRecentActivityFeed.php b/SpecialRecentActivityFeed.php
index 5f3e980..3e23db4 100644
--- a/SpecialRecentActivityFeed.php
+++ b/SpecialRecentActivityFeed.php
@@ -249,6 +249,9 @@
                } else {
                        $this->getOutput()->addHTML( $rclistOutput );
                }
+
+                // Too less code to move to a different function yet.
+                $this->getOutput()->addModules( 
'ext.RecentActivityFeed.inlinediff' );
        }
 
 
diff --git a/modules/ext.inlinediff.js b/modules/ext.inlinediff.js
new file mode 100644
index 0000000..865eecb
--- /dev/null
+++ b/modules/ext.inlinediff.js
@@ -0,0 +1,188 @@
+/*
+ * Borrowed from 
https://en.wikipedia.org/wiki/User:Writ_Keeper/Scripts/commonHistory.js
+ * as per http://www.mediawiki.org/wiki/Editor_campaigns/Activity_feed
+ */
+(function( $ ) {
+
+diffRequestLocked = "f";
+if(typeof inspectText == "undefined")
+{
+  inspectText = "inspect diff";
+}
+if(typeof showText == "undefined")
+{
+  showText = "show diff";
+}
+if(typeof hideText == "undefined")
+{
+  hideText = "hide diff";
+}
+  function inspectionEachHelper(index, element)
+  {
+    var findString;
+    if(wgAction == "history" || $(element).hasClass("mw-enhanced-rc-nested"))
+    {
+      findString = 'a:contains("prev")';
+    }
+    else
+    {
+      findString = 'a:contains("diff")';
+    }
+
+    var regex;
+
+    if(wgCanonicalSpecialPageName == "Contributions")
+    {
+      regex = /&oldid=(\d+)$/;
+
+    }
+    else
+    {
+      regex = /&diff=(\d+)&oldid=/;
+    }
+    var diffLink = $(element).find(findString);
+    if(diffLink.length > 0 && !(/(\.js|\.css)&/.test(diffLink[0].href)))
+    {
+      var regexResult = regex.exec(diffLink[0].href);
+      if(regexResult != null && regexResult.length >= 2)
+      {
+        var diffID = regexResult[1];
+        var inlineDiffButton;
+        if(typeof inlineDiffBigUI === "undefined")
+        {
+          inlineDiffButton = document.createElement("a");
+          inlineDiffButton.href = "#";
+          inlineDiffButton.innerHTML = '<b><span style="color:black;"> 
[</span><span style="color:#339900;">'+inspectText+'</span><span 
style="color:black;">] </span></b>';
+        }
+        else
+        {
+          inlineDiffButton = document.createElement("input");
+          inlineDiffButton.type = "button";
+          inlineDiffButton.value = "Inspect edit";
+        }
+        inlineDiffButton.id = diffID;
+        $(inlineDiffButton).click(function(){ return 
inspectWatchlistDiff(this);});
+        $(element).find('.comment').append(inlineDiffButton);
+      }
+    }
+  }
+  function addWatchlistInspectionBoxes() {
+
+
+    var entries = $("#mw-content-text table.mw-enhanced-rc");
+    if(entries.length == 0)
+    {
+      $(".mw-changeslist").each(function(ind, el)
+                                    {
+                                      
$(el).children("div").each(inspectionEachHelper);
+                                    });
+    }
+    else
+    {
+      entries.each(inspectionEachHelper);
+      $("td.mw-enhanced-rc-nested").each(inspectionEachHelper);
+    }
+    mw.loader.load('mediawiki.action.history.diff');
+  }
+
+  function inspectWatchlistDiff(button)
+  {
+    if(diffRequestLocked === "t")
+    {
+      alert("An old request is still being processed, please wait...");
+      return false;
+    }
+    else
+    {
+      diffRequestLocked = "t";
+      
$.getJSON("/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp&rvdiffto=prev&revids="+button.id,
 function(response, status)
+                {
+                  if(response == null)
+                  {
+                    alert("Request failed!");
+                    diffRequestLocked = "f";
+                    return false;
+                  }
+
+                  var diffString = 
response.query.pages[Object.keys(response.query.pages)[0]].revisions[0].diff["*"];
+
+                  if(diffString == null)
+                  {
+                    alert("Request failed!");
+                    diffRequestLocked = "f";
+                    return false;
+                  }
+
+                  var newTable = document.createElement("table");
+                  newTable.className = "diff";
+                  $(newTable).html('<colgroup><col class="diff-marker"><col 
class="diff-content"><col class="diff-marker"><col 
class="diff-content"></colgroup>');
+
+                  $(newTable).append(diffString);
+                  if($("#"+ button.id).parent("td").length > 0 && !($("#"+ 
button.id).parent("td").hasClass("mw-enhanced-rc-nested")))
+                  {
+                    $("#"+ 
button.id).parents("table.mw-enhanced-rc:first").after(newTable);
+                  }
+                  else
+                  {
+                    $(newTable).insertAfter("#"+ button.id);
+                  }
+                  newTable.id = button.id + "display";
+
+                  $(button).unbind("click");
+                  if(typeof inlineDiffBigUI === "undefined")
+                  {
+                    $(button).html('<b><span style="color:black;"> 
[</span><span style="color:#339900;">'+hideText+'</span><span 
style="color:black;">] </span></b>');
+                    $(button).click(function(){ return 
hideSmallEditInspection(this);});
+                  }
+                  else
+                  {
+                    $(button).attr("value","Hide edit");
+                    $(button).click(function(){ return 
hideEditInspection(this);});
+                  }
+
+                  diffRequestLocked = "f";
+                });
+
+    }
+    return false;
+  }
+
+  function showEditInspection(button)
+  {
+    $("#"+button.id+"display").css("display", "");
+    $(button).attr("value","Hide edit");
+    $(button).unbind("click");
+    $(button).click(function(){ return hideEditInspection(this);});
+    return false;
+  }
+
+  function hideEditInspection(button)
+  {
+    $("#"+button.id+"display").css("display", "none");
+    $(button).attr("value","Show edit");
+    $(button).unbind("click");
+    $(button).click(function(){ return showEditInspection(this);});
+    return false;
+  }
+
+  function showSmallEditInspection(button)
+  {
+    $("#"+button.id+"display").css("display", "");
+    $(button).html('<b><span style="color:black;"> [</span><span 
style="color:#339900;">'+hideText+'</span><span style="color:black;">] 
</span></b>');
+    $(button).unbind("click");
+    $(button).click(function(){ return hideSmallEditInspection(this);});
+    return false;
+  }
+
+  function hideSmallEditInspection(button)
+  {
+    $("#"+button.id+"display").css("display", "none");
+    $(button).html('<b><span style="color:black;"> [</span><span 
style="color:#339900;">'+showText+'</span><span style="color:black;">] 
</span></b>');
+    $(button).unbind("click");
+    $(button).click(function(){ return showSmallEditInspection(this);});
+    return false;
+  }
+
+  $(document).ready(addWatchlistInspectionBoxes);
+//  $(document).ready(alert);
+})( window.jQuery );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iadd5a56f1dec9eaf2a91a80a6eaaafd03dcb376d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RecentActivityFeed
Gerrit-Branch: master
Gerrit-Owner: Nischayn22 <nischay...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to