Jdlrobson has submitted this change and it was merged.
Change subject: [Alpha] Talk: Write the number of talk topics in the talk bubble
......................................................................
[Alpha] Talk: Write the number of talk topics in the talk bubble
This gives a sense of the underlying talk page without the user
having to go to the talk page.
Every time talk page is saved, save a property page_top_level_section_count
storing the number of topics
Change-Id: I4833a35b121eb4cd1f2e857079cadea6146d30c8
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
M includes/skins/SkinMobile.php
M includes/skins/SkinMobileBase.php
4 files changed, 47 insertions(+), 8 deletions(-)
Approvals:
JGonera: Looks good to me, but someone else must approve
Jdlrobson: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/MobileFrontend.php b/MobileFrontend.php
index fe988cd..e42b1c2 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -89,6 +89,8 @@
$wgHooks['APIGetDescription'][] = 'ApiParseExtender::onAPIGetDescription';
$wgHooks['OpenSearchXml'][] = 'ApiQueryExtracts::onOpenSearchXml';
+$wgHooks['LinksUpdate'][] = 'MobileFrontendHooks::onLinksUpdate';
+
$wgHooks['MakeGlobalVariablesScript'][] =
'MobileFrontendHooks::onMakeGlobalVariablesScript';
$wgHooks['EnableMobileModules'][] =
'MobileFrontendHooks::onEnableMobileModules';
$wgHooks['RequestContextCreateSkin'][] =
'MobileFrontendHooks::onRequestContextCreateSkin';
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index ba386bf..fa3874c 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -32,6 +32,29 @@
}
/**
+ * LinksUpdate hook handler - saves a count of h2 elements that occur
in the WikiPage
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdate
+ *
+ * @param LinksUpdate $lu
+ * @return bool
+ */
+ public static function onLinksUpdate( LinksUpdate $lu ) {
+ if ( $lu->getTitle()->isTalkPage() ) {
+ $parserOutput = $lu->getParserOutput();
+ $sections = $parserOutput->getSections();
+ $numTopics = 0;
+ foreach( $sections as $section ) {
+ if ( $section['toclevel'] == 1 ) {
+ $numTopics += 1;
+ }
+ }
+ $lu->mProperties['page_top_level_section_count'] =
$numTopics;
+ }
+
+ return true;
+ }
+
+ /**
* MakeGlobalVariablesScript hook handler
* @see
http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
* Adds various mobile specific config variables
@@ -209,7 +232,7 @@
* @return bool
*/
public static function onResourceLoaderTestModules( array
&$testModules, ResourceLoader &$resourceLoader ) {
- global $wgResourceModules, $wgResourceLoaderDebug;
+ global $wgResourceModules;
$testModuleBoilerplate = array(
'localBasePath' => dirname( __DIR__ ),
diff --git a/includes/skins/SkinMobile.php b/includes/skins/SkinMobile.php
index ac29479..eceeb75 100644
--- a/includes/skins/SkinMobile.php
+++ b/includes/skins/SkinMobile.php
@@ -6,7 +6,7 @@
public $template = 'SkinMobileTemplate';
protected function prepareTemplate() {
- global $wgAppleTouchIcon, $wgMFCustomLogos, $wgVersion,
$wgMFTrademarkSitename;
+ global $wgAppleTouchIcon, $wgMFCustomLogos,
$wgMFTrademarkSitename;
wfProfileIn( __METHOD__ );
$tpl = parent::prepareTemplate();
@@ -172,13 +172,26 @@
if ( $pageHeading ) {
$preBodyText = Html::rawElement( 'h1',
$headingOptions, $pageHeading );
// talk page link for logged in alpha users
- if ( $inAlpha && $user->isLoggedIn() ) {
- $talkLabel = wfMessage(
'mobile-frontend-talk-overlay-header' ); // FIXME: make this the number of
sections on the talk page
- if ( $title->getNamespace() !== NS_TALK
) {
- $preBodyText .= Html::element(
'a',
- array( 'href' =>
$title->getTalkPage()->getFullUrl(), 'id' => 'talk' ),
- $talkLabel );
+ if ( $inAlpha && $user->isLoggedIn() &&
!$title->isTalkPage() ) {
+ $talkTitle = $title->getTalkPage();
+ if ( $talkTitle->getArticleID() ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $numTopics = $dbr->selectField(
'page_props', 'pp_value',
+ array( 'pp_page' =>
$talkTitle->getArticleID(), 'pp_propname' => 'page_top_level_section_count' ),
+ __METHOD__
+ );
+ } else {
+ $numTopics = 0;
}
+ if ( $numTopics ) {
+ $talkLabel =
$this->getLanguage()->formatNum( $numTopics );
+ } else {
+ $talkLabel = wfMessage(
'mobile-frontend-talk-overlay-header' );
+ }
+ // @todo: Redlink support when we have
good editing
+ $preBodyText .= Html::element( 'a',
+ array( 'href' =>
$talkTitle->getLocalURL(), 'id' => 'talk' ),
+ $talkLabel );
}
}
diff --git a/includes/skins/SkinMobileBase.php
b/includes/skins/SkinMobileBase.php
index d095780..0597252 100644
--- a/includes/skins/SkinMobileBase.php
+++ b/includes/skins/SkinMobileBase.php
@@ -111,6 +111,7 @@
$tpl->setRef( 'skin', $this );
$tpl->set( 'wgScript', wfScript() );
+ $this->initPage( $this->getOutput() );
$url = MobileContext::singleton()->getDesktopUrl( wfExpandUrl(
$this->getRequest()->appendQuery(
'mobileaction=toggle_view_desktop' )
) );
--
To view, visit https://gerrit.wikimedia.org/r/60093
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4833a35b121eb4cd1f2e857079cadea6146d30c8
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[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