EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/160160
Change subject: Add "View Source" link to post actions menu
......................................................................
Add "View Source" link to post actions menu
This only works for javascript, a no-js implementation can be
done in a followup later.
TODO:
* I didn't style the dialog, figuring it will be slightly different
when shahyar's modal's land anyways
Bug: 60465
Change-Id: Iac224e069052f3ec75b095e73ee4160f3bb35734
---
M handlebars/compiled/flow_block_topic_moderate_post.handlebars.php
M handlebars/compiled/flow_block_topic_moderate_topic.handlebars.php
M handlebars/compiled/flow_post.handlebars.php
M handlebars/flow_post_actions.handlebars
M i18n/en.json
M i18n/qqq.json
M includes/Parsoid/Redlinker.php
M modules/new/components/flow-board.js
8 files changed, 123 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/60/160160/1
diff --git a/handlebars/compiled/flow_block_topic_moderate_post.handlebars.php
b/handlebars/compiled/flow_block_topic_moderate_post.handlebars.php
index 5b5c355..c4c36eb 100644
--- a/handlebars/compiled/flow_block_topic_moderate_post.handlebars.php
+++ b/handlebars/compiled/flow_block_topic_moderate_post.handlebars.php
@@ -233,6 +233,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li>
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ '.LCRun3::ch($cx, 'l10n',
Array(Array('flow-post-action-view-source'),Array()), 'encq').'
+ </a>
+ </li>
'.((LCRun3::ifvar($cx, ((is_array($in['links']) &&
isset($in['links']['post'])) ? $in['links']['post'] : null))) ? '
<li>
<a class="mw-ui-button mw-ui-quiet"
@@ -428,6 +437,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li>
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ '.LCRun3::ch($cx, 'l10n',
Array(Array('flow-post-action-view-source'),Array()), 'encq').'
+ </a>
+ </li>
'.((LCRun3::ifvar($cx, ((is_array($in['links']) &&
isset($in['links']['post'])) ? $in['links']['post'] : null))) ? '
<li>
<a class="mw-ui-button mw-ui-quiet"
diff --git a/handlebars/compiled/flow_block_topic_moderate_topic.handlebars.php
b/handlebars/compiled/flow_block_topic_moderate_topic.handlebars.php
index 060b841..0457ed6 100644
--- a/handlebars/compiled/flow_block_topic_moderate_topic.handlebars.php
+++ b/handlebars/compiled/flow_block_topic_moderate_topic.handlebars.php
@@ -233,6 +233,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li>
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ '.LCRun3::ch($cx, 'l10n',
Array(Array('flow-post-action-view-source'),Array()), 'encq').'
+ </a>
+ </li>
'.((LCRun3::ifvar($cx, ((is_array($in['links']) &&
isset($in['links']['post'])) ? $in['links']['post'] : null))) ? '
<li>
<a class="mw-ui-button mw-ui-quiet"
@@ -428,6 +437,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li>
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ '.LCRun3::ch($cx, 'l10n',
Array(Array('flow-post-action-view-source'),Array()), 'encq').'
+ </a>
+ </li>
'.((LCRun3::ifvar($cx, ((is_array($in['links']) &&
isset($in['links']['post'])) ? $in['links']['post'] : null))) ? '
<li>
<a class="mw-ui-button mw-ui-quiet"
diff --git a/handlebars/compiled/flow_post.handlebars.php
b/handlebars/compiled/flow_post.handlebars.php
index fabd0ab..657c780 100644
--- a/handlebars/compiled/flow_post.handlebars.php
+++ b/handlebars/compiled/flow_post.handlebars.php
@@ -200,6 +200,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li>
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ '.LCRun3::ch($cx, 'l10n',
Array(Array('flow-post-action-view-source'),Array()), 'encq').'
+ </a>
+ </li>
'.((LCRun3::ifvar($cx, ((is_array($in['links']) &&
isset($in['links']['post'])) ? $in['links']['post'] : null))) ? '
<li>
<a class="mw-ui-button mw-ui-quiet"
@@ -395,6 +404,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li>
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ '.LCRun3::ch($cx, 'l10n',
Array(Array('flow-post-action-view-source'),Array()), 'encq').'
+ </a>
+ </li>
'.((LCRun3::ifvar($cx, ((is_array($in['links']) &&
isset($in['links']['post'])) ? $in['links']['post'] : null))) ? '
<li>
<a class="mw-ui-button mw-ui-quiet"
diff --git a/handlebars/flow_post_actions.handlebars
b/handlebars/flow_post_actions.handlebars
index 49de862..eed8d27 100644
--- a/handlebars/flow_post_actions.handlebars
+++ b/handlebars/flow_post_actions.handlebars
@@ -1,6 +1,15 @@
<div class="flow-menu">
<div class="flow-menu-js-drop"><a href="javascript:void(0);"><span
class="wikiglyph wikiglyph-ellipsis"></span></a></div>
<ul class="mw-ui-button-container flow-list">
+ <li class="flow-js">
+ <a class="mw-ui-button mw-ui-quiet"
+ href="#"
+ data-flow-api-handler="viewSource"
+ data-parent-selector=".flow-post-main"
+ data-target-selector=".flow-post-content">
+ {{l10n "flow-post-action-view-source"}}
+ </a>
+ </li>
{{#if links.post}}
<li>
<a class="mw-ui-button mw-ui-quiet"
diff --git a/i18n/en.json b/i18n/en.json
index 96e7eea..5256e8d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -66,6 +66,7 @@
"flow-post-interaction-separator": " • ",
"flow-post-edited": "Post {{GENDER:$1|edited}} by $1 $2",
"flow-post-action-view": "Permalink",
+ "flow-post-action-view-source": "View Source",
"flow-post-action-post-history": "History",
"flow-post-action-suppress-post": "Suppress",
"flow-post-action-delete-post": "Delete",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ca33d6f..f7021fa 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -70,6 +70,7 @@
"flow-post-interaction-separator": "{{optional}}",
"flow-post-edited": "Text displayed to notify the user a post has been
modified. Parameters:\n* $1 - username that created the most recent revision of
the post\n* $2 - humanized timestamp, relative to now, of when the edit
occurred; rendered by MWTimestamp::getHumanTimestamp",
"flow-post-action-view": "Used as text for the link which is used to
view.\n{{Identical|Permalink}}",
+ "flow-post-action-view-source": "Used as text for the link which is
used to view wikitext source.\n{{Identical|View Source}}",
"flow-post-action-post-history": "Used as text for the link which is
used to view post-history of the topic.\n{{Identical|History}}",
"flow-post-action-suppress-post": "Used as a link in a dropdown menu to
suppress a post.\n\nFor meaning of \"suppress\" see [[Thread:Support/About
MediaWiki:Flow-post-action-suppress-post/qqq]] and [[Thread:Support/About
MediaWiki:Flow-suppress-post-content/sv]].\n{{Related|Flow-action}}\n{{Identical|Suppress}}",
"flow-post-action-delete-post": "Used as a link in a dropdown menu to
delete a post.\n{{Related|Flow-action}}\n{{Identical|Delete}}",
diff --git a/includes/Parsoid/Redlinker.php b/includes/Parsoid/Redlinker.php
index 1411ab4..f3ceeba 100644
--- a/includes/Parsoid/Redlinker.php
+++ b/includes/Parsoid/Redlinker.php
@@ -167,6 +167,9 @@
foreach ( $linkNode->attributes as $attribute ) {
$attributes[$attribute->name] =
$attribute->value;
}
+ if ( isset( $attributes['href'] ) ) {
+ $attributes['data-flow-orig-href'] =
$attributes['href'];
+ }
// let MW build link HTML based on Parsoid data
$html = Linker::link( $title, Redlinker::getInnerHtml(
$linkNode ), $attributes );
// create new DOM from this MW-built link
diff --git a/modules/new/components/flow-board.js
b/modules/new/components/flow-board.js
index 42ea5bb..f101551 100644
--- a/modules/new/components/flow-board.js
+++ b/modules/new/components/flow-board.js
@@ -203,6 +203,37 @@
////////////////////
/**
+ * Extracts the necessary api parameters to round trip a posts
html
+ * back into wikitext
+ * @param {Event} event
+ * @return {Object
+ */
+ FlowBoardComponent.UI.events.apiPreHandlers.viewSource =
function () {
+ var $this = $( this ),
+ $parent = $this.closest( $this.data(
'parent-selector' ) ),
+ $target = $parent.find( $this.data(
'target-selector' ) ).clone();
+
+ if ( !$target.length ) {
+ // @todo abort?
+ }
+
+ // we need to make an off-page clone of $target so we
can undo redlinking.
+ // The anchors that were changed via redlinking don't
roundtrip properly
+ $target.find( 'a[data-flow-orig-href]' ).each(
function( idx, el ) {
+ var $el = $( el );
+ $el.attr( 'href', $el.data( 'flow-orig-href' )
);
+ } );
+
+ return {
+ action: 'flow-parsoid-utils',
+ from: 'html',
+ to: 'wikitext',
+ content: $target.html(),
+ title: mw.config.get( 'wgTitle' )
+ };
+ };
+
+ /**
* Before activating header, sends an overrideObject to the API
to modify the request params.
* @param {Event} event
* @return {Object}
@@ -401,6 +432,30 @@
////////////////////
/**
+ * On completion of html->wikitext roundtrip pull up a dialog
with
+ * the wikitext source
+ * @param {Object} info (status:done|fail, $target: jQuery)
+ * @param {Object} data
+ * @param {jqXHR} jqxhr
+ */
+ FlowBoardComponent.UI.events.apiHandlers.viewSource = function
( info, data, jqxhr ) {
+ var board =
FlowBoardComponent.prototype.getInstanceByElement( $( this ) ),
+ $container = $( '<pre>' ).text(
data['flow-parsoid-utils'].content );
+
+ mw.loader.using( 'jquery.ui.dialog' , function() {
+ $container.dialog( {
+ 'modal': true
+ } )
+ // the $.fn.dialog function attaches the dialog
to .body, but we
+ // need to move it inside the main container so
user interactions
+ // go to the correct handlers.
+ .parent()
+ .detach()
+ .appendTo( board.$container );
+ } );
+ };
+
+ /**
* On complete board reprocessing through view-topiclist (eg.
change topic sort order), re-render any given blocks.
* @param {Object} info (status:done|fail, $target: jQuery)
* @param {Object} data
--
To view, visit https://gerrit.wikimedia.org/r/160160
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iac224e069052f3ec75b095e73ee4160f3bb35734
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits