Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/173338
Change subject: Hygiene: Remove M.getLeadSection
......................................................................
Hygiene: Remove M.getLeadSection
Put this method on the Page view itself.
Use M.getCurrentPage in modules where used.
Change-Id: I80212583c36f6c1275d48f9cc5243bb8f08f6a61
---
M includes/Resources.php
M javascripts/Page.js
M javascripts/application.js
M javascripts/modules/editor/init.js
M javascripts/modules/issues/init.js
M javascripts/modules/toc/init.js
M javascripts/modules/uploads/init.js
M javascripts/modules/wikigrok/init.js
8 files changed, 37 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/38/173338/1
diff --git a/includes/Resources.php b/includes/Resources.php
index b75a793..e2beaf0 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -252,7 +252,7 @@
),
'mobile.editor.common' => $wgMFResourceFileModuleBoilerplate + array(
- 'class' => 'ResourceLoaderParsedMessageModule',
+ //'class' => 'ResourceLoaderParsedMessageModule',
'dependencies' => array(
'mobile.stable',
'mobile.templates',
@@ -346,7 +346,7 @@
),
'mobile.uploads' => $wgMFResourceFileModuleBoilerplate + array(
- 'class' => 'ResourceLoaderParsedMessageModule',
+ //'class' => 'ResourceLoaderParsedMessageModule',
'dependencies' => array(
'mobile.stable',
'mobile.templates',
@@ -436,7 +436,7 @@
),
'mobile.search' => $wgMFResourceFileModuleBoilerplate + array(
- 'class' => 'ResourceLoaderParsedMessageModule',
+ //'class' => 'ResourceLoaderParsedMessageModule',
'dependencies' => array(
'mobile.pagelist.scripts',
'mobile.overlays',
@@ -805,7 +805,7 @@
),
'mobile.languages' => $wgMFResourceFileModuleBoilerplate + array(
- 'class' => 'ResourceLoaderParsedMessageModule',
+ //'class' => 'ResourceLoaderParsedMessageModule',
'dependencies' => array(
'mobile.overlays',
'mobile.templates',
diff --git a/javascripts/Page.js b/javascripts/Page.js
index 3a10fa2..604e969 100644
--- a/javascripts/Page.js
+++ b/javascripts/Page.js
@@ -23,7 +23,6 @@
*/
title: '',
displayTitle: '',
- lead: '',
protection: {
edit: [ '*' ]
},
@@ -40,6 +39,15 @@
options.displayTitle = options.displayTitle ||
options.title;
options.languageUrl = mw.util.getUrl(
'Special:MobileLanguages/' + options.title );
View.prototype.initialize.apply( this, arguments );
+ },
+
+ /**
+ * Get the lead section of the page view.
+ * @method
+ * @return {jQuery.Object}
+ */
+ getLeadSectionElement: function () {
+ return this.$( '> div' ).eq( 0 );
},
/**
@@ -144,7 +152,6 @@
this.sections = [];
this._sectionLookup = {};
this.title = options.title;
- this.lead = options.lead;
$.each( options.sections, function () {
var section = new Section( this );
diff --git a/javascripts/application.js b/javascripts/application.js
index 84315e5..ae65491 100644
--- a/javascripts/application.js
+++ b/javascripts/application.js
@@ -351,6 +351,7 @@
/**
* Determine if current page is in a specified namespace
+ * FIXME: Move to method on Page
* @method
* @param {string} namespace Name of namespace
* @return {Boolean}
@@ -361,7 +362,7 @@
/**
* Get current page view object
- *
+ * FIXME: Move to M.define( 'page' )
* @method
* @return {Page}
*/
@@ -373,27 +374,17 @@
}
}
- /**
- * Return the first section of page content
- *
- * @method
- * @return {Object}
- */
- function getLeadSection() {
- return $( '#content > div' ).eq( 0 );
- }
-
function loadCurrentPage() {
var permissions = mw.config.get( 'wgRestrictionEdit', [] );
if ( permissions.length === 0 ) {
permissions.push( '*' );
}
currentPage = new Page( {
+ el: '#content',
title: mw.config.get( 'wgPageName' ).replace( /_/g, ' '
),
protection: {
edit: permissions
},
- lead: getLeadSection().html(),
isMainPage: mw.config.get( 'wgIsMainPage' ),
isWatched: $( '#ca-watch' ).hasClass(
watchIcon.getGlyphClassName() ),
sections: pageApi.getSectionsFromHTML( $( '#content' )
),
@@ -408,7 +399,6 @@
inNamespace: inNamespace,
getCurrentPage: getCurrentPage,
getOrigin: getOrigin,
- getLeadSection: getLeadSection,
getSessionId: getSessionId,
isWideScreen: isWideScreen,
lockViewport: lockViewport,
diff --git a/javascripts/modules/editor/init.js
b/javascripts/modules/editor/init.js
index 7485990..d30265c 100644
--- a/javascripts/modules/editor/init.js
+++ b/javascripts/modules/editor/init.js
@@ -153,7 +153,7 @@
// Make sure we never create two edit links by accident
if ( $( '#ca-edit .edit-page' ).length === 0 ) {
// FIXME: unfortunately the main page is special cased.
- if ( mw.config.get( 'wgIsMainPage' ) || isNewPage ||
M.getLeadSection().text() ) {
+ if ( mw.config.get( 'wgIsMainPage' ) || isNewPage ||
page.getLeadSectionElement().text() ) {
// if lead section is not empty, open editor
with lead section
addEditButton( 0, '#ca-edit' );
} else {
diff --git a/javascripts/modules/issues/init.js
b/javascripts/modules/issues/init.js
index ee550c4..01e6ff7 100644
--- a/javascripts/modules/issues/init.js
+++ b/javascripts/modules/issues/init.js
@@ -24,8 +24,13 @@
return $container.html();
}
+ /*
+ * Render a banner in a containing element.
+ * @param {jQuery.Object} $container to render the page issues
banner inside.
+ * @param {string} labelText what the label of the page issues
banner should say
+ * @param {string} headingText the heading of the overlay that
is created when the page issues banner is clicked
+ */
function createBanner( $container, labelText, headingText ) {
- $container = $container || M.getLeadSection();
var selector = 'table.ambox, table.tmbox',
$metadata = $container.find( selector ),
issues = [],
@@ -81,7 +86,9 @@
}
}
- initPageIssues();
+ // Setup the issues banner on the page
+ initPageIssues( M.getCurrentPage().getLeadSectionElement() );
+ // Show it in edit preview.
M.on( 'edit-preview', function ( overlay ) {
initPageIssues( overlay.$el );
} );
diff --git a/javascripts/modules/toc/init.js b/javascripts/modules/toc/init.js
index 49c065f..94552ae 100644
--- a/javascripts/modules/toc/init.js
+++ b/javascripts/modules/toc/init.js
@@ -12,7 +12,7 @@
sections: sections
} );
if ( mw.config.get( 'wgMFPageSections' ) ) {
- toc.appendTo( M.getLeadSection() );
+ toc.appendTo( page.getLeadSectionElement() );
} else {
// don't show toc at end of page, when no
sections there
toc.insertAfter( '#toc' );
diff --git a/javascripts/modules/uploads/init.js
b/javascripts/modules/uploads/init.js
index 35c31ac..3923c5d 100644
--- a/javascripts/modules/uploads/init.js
+++ b/javascripts/modules/uploads/init.js
@@ -17,10 +17,9 @@
}
function initialize() {
- // FIXME: make some general function for that (or a page object
with a method)
var
- // FIXME: not updated on dynamic page loads
- isEditable = mw.config.get( 'wgIsPageEditable' ),
+ page = M.getCurrentPage(),
+ $lead = page.getLeadSectionElement(),
validNamespace = ( M.inNamespace( '' ) ||
M.inNamespace( 'user' ) || M.inNamespace( 'file' ) );
// Only show upload page action in File namespace if page
doesn't already exist.
@@ -29,11 +28,11 @@
$( '#ca-upload' ).remove();
}
} else {
- if ( !isEditable || !validNamespace ||
+ if ( page.isEditable( user ) || !validNamespace ||
// FIXME: Anonymous users cannot upload
but really this should also check rights of user via getRights
// (without triggering an additional
HTTP request)
user.isAnon() ||
- mw.util.getParamValue( 'action' ) ||
!needsPhoto( M.getLeadSection() ) || mw.config.get( 'wgIsMainPage' ) ) {
+ mw.util.getParamValue( 'action' ) ||
!needsPhoto( $lead ) || mw.config.get( 'wgIsMainPage' ) ) {
$( '#ca-upload' ).remove();
}
}
diff --git a/javascripts/modules/wikigrok/init.js
b/javascripts/modules/wikigrok/init.js
index a69dae6..f0af48b 100644
--- a/javascripts/modules/wikigrok/init.js
+++ b/javascripts/modules/wikigrok/init.js
@@ -87,7 +87,8 @@
var WikiGrokDialog = M.require( versionConfig.view );
// Initialize the dialog and insert it into the page
(but don't display yet)
- function init() {
+ // FIXME: why is this a function and not just inline
code?
+ function init( page ) {
var dialog = new WikiGrokDialog( {
itemId: wikidataID,
title: mw.config.get( 'wgTitle' ),
@@ -95,14 +96,16 @@
testing: ( idOverride ) ? true : false
} );
+ // FIXME: If the table of contents code is not
loaded the dialog will still
+ // get added to the end of the lead section.
if ( $( '.toc-mobile' ).length ) {
dialog.insertBefore( '.toc-mobile' );
} else {
- dialog.appendTo( M.getLeadSection() );
+ dialog.appendTo(
page.getLeadSectionElement() );
}
}
- init();
+ init( M.getCurrentPage() );
} ).fail( function () {
var data = {
error: 'no-impression-cannot-load-interface',
--
To view, visit https://gerrit.wikimedia.org/r/173338
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I80212583c36f6c1275d48f9cc5243bb8f08f6a61
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits