jenkins-bot has submitted this change and it was merged.
Change subject: Override Skin::doEditSectionLink
......................................................................
Override Skin::doEditSectionLink
So that in future we can reduce the amount of hacks in editor.js
Also, in the process, change editor hash to #editor/[section] from
#editor-[section]. This is a more widespread pattern for hash routes,
used e.g. in Backbone.
Change-Id: I8cfaed6313c398deabdea809f53f65d4b7f4da42
---
M MobileFrontend.php
M includes/formatters/MobileFormatter.php
M includes/formatters/MobileFormatterHTML.php
M includes/skins/SkinMobile.php
M includes/skins/SkinMobileWML.php
M javascripts/modules/editor/editor.js
M less/common/hacks.less
M less/common/ui.less
M less/modules/editor.less
M stylesheets/common/ui.css
M stylesheets/modules/editor.css
M tests/MobileFormatterTest.php
12 files changed, 82 insertions(+), 33 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MobileFrontend.php b/MobileFrontend.php
index 73fe178..acc982b 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -240,11 +240,13 @@
'HTML' => array(),
// WML view
'WML' => array(
+ // FIXME: remove when SkinMobile::doEditSectionLink present in
cached pages
'.mw-editsection',
'sup.reference', // References generally don't work in WML due
to per-section views
),
// Text extracts
'extracts' => array(
+ // FIXME: remove .mw-editsection when
SkinMobile::doEditSectionLink present in cached pages
'table', 'div', '.mw-editsection', 'sup.reference',
'.noexcerpt', '.error'
),
);
diff --git a/includes/formatters/MobileFormatter.php
b/includes/formatters/MobileFormatter.php
index 598a4d4..ba26b81 100644
--- a/includes/formatters/MobileFormatter.php
+++ b/includes/formatters/MobileFormatter.php
@@ -220,7 +220,7 @@
// So, using old style for now.
$s = '<div id="content_0" class="content_block openSection">'
. preg_replace_callback(
- '%<h2(.*)<span class="mw-headline"
[^>]*>(.+)</span>[\s\r\n]*</h2>%sU',
+ '%<h2(.*)<span class="mw-headline"
[^>]*>(.+)</span>(.*)[\s\r\n]*</h2>%sU',
array( $this, 'headingTransformCallback' ),
$s
);
diff --git a/includes/formatters/MobileFormatterHTML.php
b/includes/formatters/MobileFormatterHTML.php
index 6e43c02..c9de39e 100644
--- a/includes/formatters/MobileFormatterHTML.php
+++ b/includes/formatters/MobileFormatterHTML.php
@@ -55,6 +55,7 @@
array( 'id' => $headlineId ),
$matches[2]
)
+ . $matches[3]
. Html::closeElement( 'h2' )
. Html::openElement( 'div',
array( 'class' => 'content_block', 'id' =>
'content_' . $this->headings )
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index 05159af..8fda301 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -23,6 +23,19 @@
}
}
+ /**
+ * Overrides Skin::doEditSectionLink
+ */
+ public function doEditSectionLink( Title $nt, $section, $tooltip =
null, $lang = false ) {
+ $lang = wfGetLangObj( $lang );
+ $message = wfMessage( 'mobile-frontend-editor-edit'
)->inLanguage( $lang )->text();
+ return Html::element( 'a', array(
+ 'href' => '#editor/' . $section,
+ 'data-section' => $section,
+ 'class' => 'edit-page'
+ ), $message );
+ }
+
public function outputPage( OutputPage $out = null ) {
global $wgMFNoindexPages;
wfProfileIn( __METHOD__ );
diff --git a/includes/skins/SkinMobileWML.php b/includes/skins/SkinMobileWML.php
index d817f26..1c391d5 100644
--- a/includes/skins/SkinMobileWML.php
+++ b/includes/skins/SkinMobileWML.php
@@ -9,6 +9,13 @@
$this->setContext( $context );
}
+ /**
+ * Overrides Skin::doEditSectionLink
+ */
+ public function doEditSectionLink( Title $nt, $section, $tooltip =
null, $lang = false ) {
+ return '';
+ }
+
public function outputPage( OutputPage $out = null ) {
wfProfileIn( __METHOD__ );
if ( !$out ) {
diff --git a/javascripts/modules/editor/editor.js
b/javascripts/modules/editor/editor.js
index 59fe089..e5f0e23 100644
--- a/javascripts/modules/editor/editor.js
+++ b/javascripts/modules/editor/editor.js
@@ -14,25 +14,22 @@
} );
function addEditButton( section, container ) {
- return $( '<a class="edit-page" href="#editor-' + section +
'">' ).
+ return $( '<a class="edit-page" href="#editor/' + section +
'">' ).
text( mw.msg( 'mobile-frontend-editor-edit' ) ).
- prependTo( container ).
- // FIXME change when micro.tap.js in stable
- on( M.tapEvent( 'mouseup' ), function( ev ) {
- // prevent folding section when clicking Edit
- ev.stopPropagation();
- } );
+ prependTo( container );
}
- function addCtaButton( hash, container, returnToQuery ) {
- addEditButton( '', container ).
+ function makeCta( $el, hash, returnToQuery ) {
+ $el.
// FIXME change when micro.tap.js in stable
on( M.tapEvent( 'mouseup' ), function( ev ) {
ev.preventDefault();
+ // prevent folding section when clicking Edit
+ ev.stopPropagation();
// need to use toggle() because we do
ev.stopPropagation() (in addEditButton())
drawer.
render( { queryParams: {
- returnto: mw.config.get(
'wgPageName' ) + '#' + hash,
+ returnto: mw.config.get(
'wgPageName' ) + hash,
returntoquery: returnToQuery
} } ).
toggle();
@@ -41,7 +38,7 @@
on( 'click', false );
}
- // FIXME [ParserOutput]: This is nasty
+ // FIXME: remove when SkinMobile::doEditSectionLink present in cached
pages
function extractSectionIdFromEditLink( $a ) {
var editHref = $a.attr( 'href' ),
qs = editHref.split( '?' )[ 1 ],
@@ -52,7 +49,7 @@
function init( page ) {
var isNew = mw.config.get( 'wgArticleId' ) === 0;
- M.router.route( /^editor-(\d+)$/, function( sectionId ) {
+ M.router.route( /^editor\/(\d+)$/, function( sectionId ) {
var title = page ? page.title : mw.config.get(
'wgTitle' ),
// Note in current implementation Page title is
prefixed with namespace
ns = page ? '' : mw.config.get(
'wgCanonicalNamespace' );
@@ -76,10 +73,22 @@
addEditButton( 1, '#ca-edit' );
}
+ // FIXME change when micro.tap.js in stable
+ $( '.edit-page' ).on( M.tapEvent( 'mouseup' ), function( ev ) {
+ // prevent folding section when clicking Edit
+ ev.stopPropagation();
+ } );
+
+ // FIXME: remove when SkinMobile::doEditSectionLink present in
cached pages
$( 'h2 .mw-editsection' ).each( function() {
var section = extractSectionIdFromEditLink( $( this
).find( 'a' ) );
if ( section ) {
- addEditButton( section, $( this ).parent() );
+ addEditButton( section, $( this ).parent() ).
+ // FIXME change when micro.tap.js in
stable
+ on( M.tapEvent( 'mouseup' ), function(
ev ) {
+ // prevent folding section when
clicking Edit
+ ev.stopPropagation();
+ } );
}
$( this ).remove();
} );
@@ -91,17 +100,32 @@
drawer.render( { queryParams :{ returntoquery:
'article_action=edit' } } ).show();
} );
- $( 'h2 .mw-editsection' ).each( function() {
- var $heading = $( this ).parent(), section;
+ $( '.edit-page' ).each( function() {
+ var $a = $( this ), $heading = $( this ).closest( 'h2'
);
if ( mw.config.get( 'wgMFMode' ) === 'stable' ) {
- addCtaButton( $heading.attr( 'id' ), $heading );
+ makeCta( $a, '#' + $heading.attr( 'id' ) );
+ } else {
+ if ( !M.isTestA ) {
+ makeCta( $a, $a.attr( 'href' ) );
+ } else {
+ makeCta( $a, '#' + $heading.attr( 'id'
), 'article_action=edit' );
+ }
+ }
+ } );
+
+ // FIXME: remove when SkinMobile::doEditSectionLink present in
cached pages
+ $( 'h2 .mw-editsection' ).each( function() {
+ var $heading = $( this ).closest( 'h2' ), $a =
addEditButton( '', $heading ), section;
+
+ if ( mw.config.get( 'wgMFMode' ) === 'stable' ) {
+ makeCta( $a, '#' + $heading.attr( 'id' ) );
} else {
if ( !M.isTestA ) {
section = extractSectionIdFromEditLink(
$( this ).find( 'a' ) );
- addCtaButton( 'editor-' + section,
$heading );
+ makeCta( $a, '#editor/' + section );
} else {
- addCtaButton( $heading.attr( 'id' ),
$heading, 'article_action=edit' );
+ makeCta( $a, '#' + $heading.attr( 'id'
), 'article_action=edit' );
}
}
} );
@@ -117,8 +141,9 @@
}
} else {
// FIXME change when micro.tap.js in stable
- $( '#ca-edit' ).on( M.tapEvent( 'click' ), function() {
+ $( '#ca-edit, .edit-page' ).on( M.tapEvent( 'click' ),
function( ev ) {
popup.show( mw.msg( isEditingSupported ?
'mobile-frontend-editor-disabled' : 'mobile-frontend-editor-unavailable' ),
'toast' );
+ ev.preventDefault();
} );
}
diff --git a/less/common/hacks.less b/less/common/hacks.less
index aa5ea1b..6a99af7 100644
--- a/less/common/hacks.less
+++ b/less/common/hacks.less
@@ -89,7 +89,7 @@
}
}
-// FIXME: [ParserOutput] This hides the default edit link (see bug 49208)
+// FIXME: remove when SkinMobile::doEditSectionLink present in cached pages
.editsection,
.mw-editsection {
display: none;
diff --git a/less/common/ui.less b/less/common/ui.less
index 3c95fac..a9ead35 100644
--- a/less/common/ui.less
+++ b/less/common/ui.less
@@ -128,7 +128,9 @@
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
}
-#mw-mf-menu-page {
+// FIXME: remove #mw-mf-menu-page
+#mw-mf-menu-page,
+.edit-page {
display: none;
}
diff --git a/less/modules/editor.less b/less/modules/editor.less
index 1441d77..1643707 100644
--- a/less/modules/editor.less
+++ b/less/modules/editor.less
@@ -1,6 +1,6 @@
@import "../mixins.less";
-.section_heading {
+.section {
.edit-page {
position: absolute;
background: url(../common/images/pagemenu/edit.png) 100%
@headingMargin no-repeat;
@@ -11,10 +11,9 @@
top: 0;
bottom: 0;
right: 0;
- display: none;
}
- &.openSection .edit-page {
+ h2.openSection .edit-page {
display: block;
}
}
diff --git a/stylesheets/common/ui.css b/stylesheets/common/ui.css
index 6b24cc9..b217744 100644
--- a/stylesheets/common/ui.css
+++ b/stylesheets/common/ui.css
@@ -434,7 +434,8 @@
position: relative;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
}
-#mw-mf-menu-page {
+#mw-mf-menu-page,
+.edit-page {
display: none;
}
.client-js .searchSubmit {
diff --git a/stylesheets/modules/editor.css b/stylesheets/modules/editor.css
index 3531c23..7c275a0 100644
--- a/stylesheets/modules/editor.css
+++ b/stylesheets/modules/editor.css
@@ -5,7 +5,7 @@
* Please edit the corresponding less file instead.
* See README.mediawiki for details on installing.
*/
-.section_heading .edit-page {
+.section .edit-page {
position: absolute;
background: url(../common/images/pagemenu/edit.png) 100% 9pt no-repeat;
/* use -webkit prefix for older android browsers eg. nexus 1 */
@@ -19,9 +19,8 @@
top: 0;
bottom: 0;
right: 0;
- display: none;
}
-.section_heading.openSection .edit-page {
+.section h2.openSection .edit-page {
display: block;
}
.stub .edit-page {
diff --git a/tests/MobileFormatterTest.php b/tests/MobileFormatterTest.php
index 571fd5b..c21296a 100644
--- a/tests/MobileFormatterTest.php
+++ b/tests/MobileFormatterTest.php
@@ -57,21 +57,21 @@
),
// \n</h2> in headers
array(
- '<h2><span class="editsection">[<a
href="/w/index.php?title=California_Gold_Rush&action=edit&section=2"
title="Edit section: Forty-niners">edit</a>]</span> <span class="mw-headline"
id="Forty-niners">Forty-niners</span>
+ '<h2><span class="mw-headline"
id="Forty-niners">Forty-niners</span><a class="edit-page"
href="#editor/2">Edit</a>
</h2>' . $longLine,
$summarySection.
- '<div class="section"><h2
class="section_heading" id="section_1"><span
id="Forty-niners">Forty-niners</span></h2><div class="content_block"
id="content_1">'
+ '<div class="section"><h2
class="section_heading" id="section_1"><span
id="Forty-niners">Forty-niners</span><a class="edit-page"
href="#editor/2">Edit</a></h2><div class="content_block" id="content_1">'
. $longLine . '</div>'
. $anchor . '</div>',
$enableSections
),
// Bug 36670
array(
- '<h2><span class="editsection">[<a
href="/w/index.php?title=California_Gold_Rush&action=edit&section=1"
title="Edit section: History">edit</a>]</span> <span class="mw-headline"
id="History"><span id="Overview"></span>History</span></h2>'
+ '<h2><span class="mw-headline"
id="History"><span id="Overview"></span>History</span><a class="edit-page"
href="#editor/2">Edit</a></h2>'
. $longLine,
$summarySection.
- '<div class="section"><h2
class="section_heading" id="section_1"><span id="History"><span
id="Overview"></span>History</span></h2><div class="content_block"
id="content_1">'
+ '<div class="section"><h2
class="section_heading" id="section_1"><span id="History"><span
id="Overview"></span>History</span><a class="edit-page"
href="#editor/2">Edit</a></h2><div class="content_block" id="content_1">'
. $longLine . '</div>'
. $anchor
. '</div>',
--
To view, visit https://gerrit.wikimedia.org/r/83597
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8cfaed6313c398deabdea809f53f65d4b7f4da42
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: JGonera <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits