jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Empower any skin to be the default mobile skin
......................................................................
Hygiene: Empower any skin to be the default mobile skin
Break out MobileFrontend specific code from Minerva into
MobileFrontend.skin.hooks
This change allows you to define:
$wgMFDefaultSkinClass = 'SkinVector';
and see the correct mobile footer and desktop/mobile switcher links.
The skin in mobile will load without styling as all Vector modules currently are
set to target desktop/mobile but this will allow skin developers to serve
different
styles for their skin - effectively giving them a clean state to do
mobile first design if they choose or to iterate on their existing desktop
styles to
make them mobile ready.
Changes:
* Remove mw-mobile-mode and mw-desktop-mode class - skins should not
need to know whether they are in desktop or mobile, this is what responsive
design is for.
* Deprecate SkinMinervaOutputPageBeforeExec hook. It will be replaced
by better named MobileSiteOutputPageBeforeExec
* Set target mobile in a hook for all OutputPage's operating in mobile
mode.
* Remove EnableMobileModules hook
* Now BeforePageDisplayMobile logically runs inside BeforePageDisplay hook
Change-Id: I20e46165fb76956cb7e1ef412a789d95063689bd
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
A includes/MobileFrontend.skin.hooks.php
M includes/skins/SkinMinerva.php
4 files changed, 291 insertions(+), 282 deletions(-)
Approvals:
Florianschmidtwelzow: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MobileFrontend.php b/MobileFrontend.php
index fb44638..44162a7 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -45,6 +45,7 @@
$autoloadClasses = array(
'ExtMobileFrontend' => 'MobileFrontend.body',
'MobileFrontendHooks' => 'MobileFrontend.hooks',
+ 'MobileFrontendSkinHooks' => 'MobileFrontend.skin.hooks',
'IDeviceProperties' => 'DeviceDetection',
'IDeviceDetector' => 'DeviceDetection',
@@ -143,6 +144,7 @@
$wgHooks['HTMLFileCache::useFileCache'][] =
'MobileFrontendHooks::onHTMLFileCache_useFileCache';
$wgHooks['LoginFormValidErrorMessages'][] =
'MobileFrontendHooks::onLoginFormValidErrorMessages';
$wgHooks['ResourceLoaderGetLessVars'][] =
'MobileFrontendHooks::onResourceLoaderGetLessVars';
+$wgHooks['SkinPreloadExistence'][] =
'MobileFrontendHooks::onSkinPreloadExistence';
$wgSpecialPages += array(
'History' => 'SpecialMobileHistory',
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index ee80b75..0be5e30 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -153,29 +153,7 @@
* @return bool
*/
public static function onSkinTemplateOutputPageBeforeExec( &$skin,
&$tpl ) {
- $title = $skin->getTitle();
- $context = MobileContext::singleton();
-
- if ( !$context->isBlacklistedPage() ) {
- $footerlinks = $tpl->data['footerlinks'];
- $args = $skin->getRequest()->getQueryValues();
- // avoid title being set twice
- unset( $args['title'] );
- unset( $args['useformat'] );
- $args['mobileaction'] = 'toggle_view_mobile';
-
- $mobileViewUrl = $title->getFullURL( $args );
- $mobileViewUrl =
MobileContext::singleton()->getMobileUrl( $mobileViewUrl );
-
- $link = Html::element( 'a',
- array( 'href' => $mobileViewUrl, 'class' =>
'noprint stopMobileRedirectToggle' ),
- wfMessage( 'mobile-frontend-view' )->text()
- );
- $tpl->set( 'mobileview', $link );
- $footerlinks['places'][] = 'mobileview';
- $tpl->set( 'footerlinks', $footerlinks );
- }
-
+ MobileFrontendSkinHooks::prepareFooter( $skin, $tpl );
return true;
}
@@ -332,6 +310,23 @@
}
/**
+ * SkinPreloadExistence hook handler
+ * Disables TOC in output before it grabs HTML
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/SkinPreloadExistence
+ *
+ * @param Title[] $titles
+ * @param Skin $skin
+ * @return bool
+ */
+ public static function onSkinPreloadExistence( $titles, $skin ) {
+ $context = MobileContext::singleton();
+ if ( $context->shouldDisplayMobileView() ) {
+ $skin->getOutput()->setTarget( 'mobile' );
+ }
+ return true;
+ }
+
+ /**
* ResourceLoaderGetConfigVars hook handler
* This should be used for variables which vary with the html
* and for variables this should work cross skin including anonymous
users
@@ -345,7 +340,7 @@
$config = $context->getMFConfig();
// Get the licensing agreement that is displayed in the
uploading interface.
- $wgMFUploadLicense = SkinMinerva::getLicense( 'upload' );
+ $wgMFUploadLicense = MobileFrontendSkinHooks::getLicense(
'upload' );
$vars += array(
'wgMFNearbyEndpoint' => $config->get(
'MFNearbyEndpoint' ),
'wgMFThumbnailSizes' => array(
@@ -354,10 +349,13 @@
),
'wgMFContentNamespace' => $config->get(
'MFContentNamespace' ),
'wgMFEditorOptions' => $config->get( 'MFEditorOptions'
),
- 'wgMFLicense' => SkinMinerva::getLicense( 'editor' ),
+ 'wgMFLicense' => MobileFrontendSkinHooks::getLicense(
'editor' ),
'wgMFUploadLicenseLink' => $wgMFUploadLicense['link'],
);
+ if ( $context->shouldDisplayMobileView() ) {
+ $vars['wgImagesDisabled'] = $context->imagesDisabled();
+ }
// add CodeMirror specific things, if it is installed (for
CodeMirror editor)
if ( class_exists( 'CodeMirrorHooks' ) ) {
$vars += CodeMirrorHooks::getGlobalVariables(
MobileContext::singleton() );
@@ -697,6 +695,9 @@
// in mobile view: always add vary header
$out->addVaryHeader( 'Cookie' );
+
+ // Allow modifications in mobile only mode
+ Hooks::run( 'BeforePageDisplayMobile', array( &$out,
&$sk ) );
}
return true;
diff --git a/includes/MobileFrontend.skin.hooks.php
b/includes/MobileFrontend.skin.hooks.php
new file mode 100644
index 0000000..288850f
--- /dev/null
+++ b/includes/MobileFrontend.skin.hooks.php
@@ -0,0 +1,263 @@
+<?php
+
+class MobileFrontendSkinHooks {
+
+ /**
+ * Returns HTML of terms of use link or null if it shouldn't be
displayed
+ * Note: This is called by a hook in the WikimediaMessages extension.
+ *
+ * @param $urlMsgKey Key of i18n message containing terms of use URL
(optional)
+ *
+ * @return null|string
+ */
+ protected static function getTermsLink( $sk, $urlMsgKey =
'mobile-frontend-terms-url' ) {
+ $urlMsg = $sk->msg( $urlMsgKey )->inContentLanguage();
+ if ( $urlMsg->isDisabled() ) {
+ return null;
+ }
+ $url = $urlMsg->plain();
+ // Support both page titles and URLs
+ if ( preg_match( '#^(https?:)?//#', $url ) === 0 ) {
+ $title = Title::newFromText( $url );
+ if ( !$title ) {
+ return null;
+ }
+ $url = $title->getLocalURL();
+ }
+ return Html::element(
+ 'a',
+ array( 'href' => $url ),
+ $sk->msg( 'mobile-frontend-terms-text' )->text()
+ );
+ }
+
+ /**
+ * Returns HTML of license link or empty string
+ * For example:
+ * "<a title="Wikipedia:Copyright"
href="/index.php/Wikipedia:Copyright">CC BY</a>"
+ *
+ * @param string $context The context in which the license link
appears, e.g. footer,
+ * editor, talk, or upload.
+ * @param array $attribs An associative array of extra HTML attributes
to add to the link
+ * @return string
+ */
+ public static function getLicense( $context, $attribs = array() ) {
+ $config = MobileContext::singleton()->getConfig();
+ $rightsPage = $config->get( 'RightsPage' );
+ $rightsUrl = $config->get( 'RightsUrl' );
+ $rightsText = $config->get( 'RightsText' );
+
+ // Construct the link to the licensing terms
+ if ( $rightsText ) {
+ // Use shorter text for some common licensing strings.
See Installer.i18n.php
+ // for the currently offered strings. Unfortunately,
there is no good way to
+ // comprehensively support localized licensing strings
since the license (as
+ // stored in LocalSetttings.php) is just freeform text,
not an i18n key.
+ $commonLicenses = array(
+ 'Creative Commons Attribution-Share Alike 3.0'
=> 'CC BY-SA 3.0',
+ 'Creative Commons Attribution Share Alike' =>
'CC BY-SA',
+ 'Creative Commons Attribution 3.0' => 'CC BY
3.0',
+ 'Creative Commons Attribution 2.5' => 'CC BY
2.5', // Wikinews
+ 'Creative Commons Attribution' => 'CC BY',
+ 'Creative Commons Attribution Non-Commercial
Share Alike' => 'CC BY-NC-SA',
+ 'Creative Commons Zero (Public Domain)' => 'CC0
(Public Domain)',
+ 'GNU Free Documentation License 1.3 or later'
=> 'GFDL 1.3 or later',
+ );
+
+ if ( isset( $commonLicenses[$rightsText] ) ) {
+ $rightsText = $commonLicenses[$rightsText];
+ }
+ if ( $rightsPage ) {
+ $title = Title::newFromText( $rightsPage );
+ $link = Linker::linkKnown( $title, $rightsText,
$attribs );
+ } elseif ( $rightsUrl ) {
+ $link = Linker::makeExternalLink( $rightsUrl,
$rightsText, true, '', $attribs );
+ } else {
+ $link = $rightsText;
+ }
+ } else {
+ $link = '';
+ }
+
+ // Allow other extensions (for example, WikimediaMessages) to
override
+ $msg = 'mobile-frontend-copyright';
+ Hooks::run( 'MobileLicenseLink', array( &$link, $context,
$attribs, &$msg ) );
+
+ // for plural support we need the info, if there is one or more
licenses used in the license text
+ // this check if very simple and works on the base, that more
than one license will
+ // use "and" as a connective
+ // 1 - no plural
+ // 2 - plural
+ $delimiterMsg = wfMessage( 'and' );
+ // check, if "and" isn't disabled and exists in site language
+ $isPlural = (
+ !$delimiterMsg->isDisabled() && strpos( $rightsText,
$delimiterMsg->text() ) === false ? 1 : 2
+ );
+
+ return array(
+ 'msg' => $msg,
+ 'link' => $link,
+ 'plural' => $isPlural
+ );
+ }
+
+ /**
+ * Prepares the footer for the skins serving the desktop and mobile
sites.
+ * @param Skin $skin
+ * @param QuickTemplate $tpl
+ */
+ public static function prepareFooter( $skin, $tpl ) {
+ $title = $skin->getTitle();
+ $req = $skin->getRequest();
+ $ctx = MobileContext::singleton();
+
+ // Certain pages might be blacklisted and not have a mobile
equivalent.
+ if ( !$ctx->isBlacklistedPage() ) {
+ if ( $ctx->shouldDisplayMobileView() ) {
+ MobileFrontendSkinHooks::mobileFooter( $skin,
$tpl, $ctx, $title, $req );
+ } else {
+ MobileFrontendSkinHooks::desktopFooter( $skin,
$tpl, $ctx, $title, $req );
+ }
+ }
+ }
+
+ /**
+ * Appends a mobile view link to the desktop footer
+ * @param Skin $sk
+ * @param QuickTemplate $tpl
+ * @param MobileContext $ctx
+ * @param Title $title
+ * @param Request $req
+ */
+ public static function desktopFooter( $sk, $tpl, $ctx, $title, $req ) {
+ $footerlinks = $tpl->data['footerlinks'];
+ $args = $req->getQueryValues();
+ // avoid title being set twice
+ unset( $args['title'] );
+ unset( $args['useformat'] );
+ $args['mobileaction'] = 'toggle_view_mobile';
+
+ $mobileViewUrl = $title->getFullURL( $args );
+ $mobileViewUrl = $ctx->getMobileUrl( $mobileViewUrl );
+
+ $link = Html::element( 'a',
+ array( 'href' => $mobileViewUrl, 'class' => 'noprint
stopMobileRedirectToggle' ),
+ wfMessage( 'mobile-frontend-view' )->text()
+ );
+ $tpl->set( 'mobileview', $link );
+ $footerlinks['places'][] = 'mobileview';
+ $tpl->set( 'footerlinks', $footerlinks );
+ }
+
+ /**
+ * Prepares links used in the mobile footer
+ * @param Skin $sk
+ * @param QuickTemplate $tpl
+ * @param MobileContext $ctx
+ * @param Title $title
+ * @param Request $req
+ */
+ protected static function mobileFooter( $sk, $tpl, $ctx, $title, $req )
{
+ $url = $sk->getOutput()->getProperty( 'desktopUrl' );
+ if ( $url ) {
+ $url = wfAppendQuery( $url,
'mobileaction=toggle_view_desktop' );
+ } else {
+ $url = $title->getLocalUrl(
+ $req->appendQueryValue( 'mobileaction',
'toggle_view_desktop', true )
+ );
+ }
+ $url = htmlspecialchars(
+ $ctx->getDesktopUrl( wfExpandUrl( $url, PROTO_RELATIVE
) )
+ );
+
+ $desktop = wfMessage( 'mobile-frontend-view-desktop'
)->escaped();
+ $mobile = wfMessage( 'mobile-frontend-view-mobile' )->escaped();
+
+ $sitename = self::getSitename( true );
+ $switcherHtml = <<<HTML
+<h2>{$sitename}</h2>
+<ul>
+ <li>{$mobile}</li><li><a id="mw-mf-display-toggle"
href="{$url}">{$desktop}</a></li>
+</ul>
+HTML;
+
+ // Generate the licensing text displayed in the footer of each
page.
+ // See Skin::getCopyright for desktop equivalent.
+ $license = self::getLicense( 'footer' );
+ if ( isset( $license['link'] ) && $license['link'] ) {
+ $licenseText = $sk->msg( 'mobile-frontend-copyright'
)->rawParams( $license['link'] )->text();
+ } else {
+ $licenseText = '';
+ }
+
+ // Enable extensions to add links to footer in Mobile view, too
- bug 66350
+ Hooks::run( 'MobileSiteOutputPageBeforeExec', array( &$sk,
&$tpl ) );
+ // FIXME: Deprecate this hook.
+ Hooks::run( 'SkinMinervaOutputPageBeforeExec', array( &$sk,
&$tpl ), '1.26' );
+
+ $tpl->set( 'mobile-switcher', $switcherHtml );
+ $tpl->set( 'mobile-license', $licenseText );
+ $tpl->set( 'privacy', $sk->footerLink(
'mobile-frontend-privacy-link-text', 'privacypage' ) );
+ $tpl->set( 'terms-use', self::getTermsLink( $sk ) );
+
+ $tpl->set( 'footerlinks', array(
+ 'info' => array(
+ 'mobile-switcher',
+ 'mobile-license',
+ ),
+ 'places' => array(
+ 'terms-use',
+ 'privacy',
+ ),
+ ) );
+ return $tpl;
+ }
+
+ /**
+ * Returns the site name for the footer, either as a text or <img> tag
+ * @param boolean $withPossibleTrademark If true and a trademark symbol
is specified
+ * by $wgMFTrademarkSitename, append that trademark symbol to the
sitename/logo.
+ * This param exists so that the trademark symbol can be appended
in some
+ * contexts, for example, the footer, but not in others. See bug
T95007.
+ * @return string
+ */
+ public static function getSitename( $withPossibleTrademark = false ) {
+ $config = MobileContext::singleton()->getMFConfig();
+ $customLogos = $config->get( 'MFCustomLogos' );
+ $trademarkSymbol = $config->get( 'MFTrademarkSitename' );
+ $suffix = '';
+
+ $footerSitename = wfMessage( 'mobile-frontend-footer-sitename'
)->text();
+
+ // Add a trademark symbol if needed
+ if ( $withPossibleTrademark ) {
+ // Registered trademark
+ if ( $trademarkSymbol === 'registered' ) {
+ $suffix = Html::element( 'sup', array(), '®' );
+ // Unregistered (or unspecified) trademark
+ } elseif ( $trademarkSymbol ) {
+ $suffix = Html::element( 'sup', array(), '™' );
+ }
+ }
+
+ // If there's a custom site logo, use that instead of text
+ if ( isset( $customLogos['copyright'] ) ) {
+ $attributes = array(
+ 'src' => $customLogos['copyright'],
+ 'alt' => $footerSitename . $suffix,
+ );
+ if ( isset( $customLogos['copyright-height'] ) ) {
+ $attributes['height'] =
$customLogos['copyright-height'];
+ }
+ if ( isset( $customLogos['copyright-width'] ) ) {
+ $attributes['width'] =
$customLogos['copyright-width'];
+ }
+ $sitename = Html::element( 'img', $attributes );
+ } else {
+ $sitename = $footerSitename;
+ }
+
+ return $sitename . $suffix;
+ }
+}
+
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 9893bbd..c8e3bee 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -94,8 +94,6 @@
if ( $this->isMobileMode ) {
// Set our own bodytext that has been filtered by
MobileFormatter
$tpl->set( 'bodytext', $html );
- // Construct mobile-friendly footer
- $this->prepareMobileFooterLinks( $tpl );
}
return $tpl;
@@ -188,11 +186,6 @@
$className .= ' mw-mf-special ';
}
- if ( $this->isMobileMode ) {
- $className .= ' mw-mobile-mode';
- } else {
- $className .= ' mw-desktop-mode';
- }
if ( $this->isAuthenticatedUser() ) {
$className .= ' is-authenticated';
}
@@ -690,20 +683,6 @@
if ( !isset( $tpl->data['postbodytext'] ) ) {
$tpl->set( 'postbodytext', '' ); // not currently set
in desktop skin
}
-
- // Prepare the mobile version of the footer
- if ( $this->isMobileMode ) {
- $tpl->set( 'footerlinks', array(
- 'info' => array(
- 'mobile-switcher',
- 'mobile-license',
- ),
- 'places' => array(
- 'terms-use',
- 'privacy',
- ),
- ) );
- }
}
/**
@@ -953,11 +932,6 @@
$vars['wgMFUserBlockInfo'] = $blockInfo;
}
- // Get variables that are only needed in mobile mode
- if ( $this->isMobileMode ) {
- $vars['wgImagesDisabled'] =
$this->mobileContext->imagesDisabled();
- }
-
return $vars;
}
@@ -1114,236 +1088,5 @@
public function setupSkinUserCss( OutputPage $out ) {
// Add Minerva-specific ResourceLoader modules to the page
output
$out->addModuleStyles( $this->getSkinStyles() );
- }
-
- /**
- * initialize various variables and generate the template
- * @param OutputPage $out optional parameter: The OutputPage Obj.
- */
- public function outputPage( OutputPage $out = null ) {
- // This might seem weird but now the meaning of 'mobile' is
morphing to mean 'minerva skin'
- // FIXME: Explore disabling this via a user preference and see
what explodes
- // Important: This must run before outputPage which generates
script and style tags
- // If run later incompatible desktop code will leak into
Minerva.
- $out = $this->getOutput();
- $out->setTarget( 'mobile' );
- if ( $this->isMobileMode ) {
- // FIXME: Merge these hooks?
- // EnableMobileModules is deprecated; Use
ResourceLoader instead,
- // see
https://www.mediawiki.org/wiki/ResourceLoader#Mobile
- Hooks::run( 'EnableMobileModules', array( $out,
$this->getMode() ) );
- Hooks::run( 'BeforePageDisplayMobile', array( &$out ) );
- }
- parent::outputPage();
- }
-
- // Mobile specific functions
- // @todo FIXME: Try to kill any of the functions that follow
-
- /**
- * Returns the site name for the footer, either as a text or <img> tag
- * @param boolean $withPossibleTrademark If true and a trademark symbol
is specified
- * by $wgMFTrademarkSitename, append that trademark symbol to the
sitename/logo.
- * This param exists so that the trademark symbol can be appended
in some
- * contexts, for example, the footer, but not in others. See bug
T95007.
- * @return string
- */
- public static function getSitename( $withPossibleTrademark = false ) {
- $config = MobileContext::singleton()->getMFConfig();
- $customLogos = $config->get( 'MFCustomLogos' );
- $trademarkSymbol = $config->get( 'MFTrademarkSitename' );
- $suffix = '';
-
- $footerSitename = wfMessage( 'mobile-frontend-footer-sitename'
)->text();
-
- // Add a trademark symbol if needed
- if ( $withPossibleTrademark ) {
- // Registered trademark
- if ( $trademarkSymbol === 'registered' ) {
- $suffix = Html::element( 'sup', array(), '®' );
- // Unregistered (or unspecified) trademark
- } elseif ( $trademarkSymbol ) {
- $suffix = Html::element( 'sup', array(), '™' );
- }
- }
-
- // If there's a custom site logo, use that instead of text
- if ( isset( $customLogos['copyright'] ) ) {
- $attributes = array(
- 'src' => $customLogos['copyright'],
- 'alt' => $footerSitename . $suffix,
- );
- if ( isset( $customLogos['copyright-height'] ) ) {
- $attributes['height'] =
$customLogos['copyright-height'];
- }
- if ( isset( $customLogos['copyright-width'] ) ) {
- $attributes['width'] =
$customLogos['copyright-width'];
- }
- $sitename = Html::element( 'img', $attributes );
- } else {
- $sitename = $footerSitename;
- }
-
- return $sitename . $suffix;
- }
-
- /**
- * Prepares links used in the mobile footer
- * @param QuickTemplate $tpl
- */
- protected function prepareMobileFooterLinks( $tpl ) {
- $req = $this->getRequest();
-
- $url = $this->getOutput()->getProperty( 'desktopUrl' );
- if ( $url ) {
- $url = wfAppendQuery( $url,
'mobileaction=toggle_view_desktop' );
- } else {
- $url = $this->getTitle()->getLocalUrl(
- $req->appendQueryValue( 'mobileaction',
'toggle_view_desktop', true )
- );
- }
- $url = htmlspecialchars(
- $this->mobileContext->getDesktopUrl( wfExpandUrl( $url,
PROTO_RELATIVE ) )
- );
-
- $desktop = wfMessage( 'mobile-frontend-view-desktop'
)->escaped();
- $mobile = wfMessage( 'mobile-frontend-view-mobile' )->escaped();
-
- $switcherHtml = <<<HTML
-<h2>{$this->getSitename( true )}</h2>
-<ul>
- <li>{$mobile}</li><li><a id="mw-mf-display-toggle"
href="{$url}">{$desktop}</a></li>
-</ul>
-HTML;
-
- // Generate the licensing text displayed in the footer of each
page.
- // See Skin::getCopyright for desktop equivalent.
- $license = self::getLicense( 'footer' );
- if ( isset( $license['link'] ) && $license['link'] ) {
- $licenseText = $this->msg( $license['msg']
)->rawParams( $license['link'] )->text();
- } else {
- $licenseText = '';
- }
-
- // Enable extensions to add links to footer in Mobile view, too
- bug 66350
- Hooks::run( 'SkinMinervaOutputPageBeforeExec', array( &$this,
&$tpl ) );
-
- $tpl->set( 'mobile-switcher', $switcherHtml );
- $tpl->set( 'mobile-license', $licenseText );
- $tpl->set( 'privacy', $this->footerLink(
'mobile-frontend-privacy-link-text', 'privacypage' ) );
- $tpl->set( 'terms-use', $this->getTermsLink() );
- }
-
- /**
- * Returns HTML of license link or empty string
- * For example:
- * "<a title="Wikipedia:Copyright"
href="/index.php/Wikipedia:Copyright">CC BY</a>"
- *
- * @param string $context The context in which the license link
appears, e.g. footer,
- * editor, talk, or upload.
- * @param array $attribs An associative array of extra HTML attributes
to add to the link
- * @return string
- */
- public static function getLicense( $context, $attribs = array() ) {
- $config = MobileContext::singleton()->getConfig();
- $rightsPage = $config->get( 'RightsPage' );
- $rightsUrl = $config->get( 'RightsUrl' );
- $rightsText = $config->get( 'RightsText' );
-
- // Construct the link to the licensing terms
- if ( $rightsText ) {
- // Use shorter text for some common licensing strings.
See Installer.i18n.php
- // for the currently offered strings. Unfortunately,
there is no good way to
- // comprehensively support localized licensing strings
since the license (as
- // stored in LocalSetttings.php) is just freeform text,
not an i18n key.
- $commonLicenses = array(
- 'Creative Commons Attribution-Share Alike 3.0'
=> 'CC BY-SA 3.0',
- 'Creative Commons Attribution Share Alike' =>
'CC BY-SA',
- 'Creative Commons Attribution 3.0' => 'CC BY
3.0',
- 'Creative Commons Attribution 2.5' => 'CC BY
2.5', // Wikinews
- 'Creative Commons Attribution' => 'CC BY',
- 'Creative Commons Attribution Non-Commercial
Share Alike' => 'CC BY-NC-SA',
- 'Creative Commons Zero (Public Domain)' => 'CC0
(Public Domain)',
- 'GNU Free Documentation License 1.3 or later'
=> 'GFDL 1.3 or later',
- );
-
- if ( isset( $commonLicenses[$rightsText] ) ) {
- $rightsText = $commonLicenses[$rightsText];
- }
- if ( $rightsPage ) {
- $title = Title::newFromText( $rightsPage );
- $link = Linker::linkKnown( $title, $rightsText,
$attribs );
- } elseif ( $rightsUrl ) {
- $link = Linker::makeExternalLink( $rightsUrl,
$rightsText, true, '', $attribs );
- } else {
- $link = $rightsText;
- }
- } else {
- $link = '';
- }
-
- // Allow other extensions (for example, WikimediaMessages) to
override
- $msg = 'mobile-frontend-copyright';
- Hooks::run( 'MobileLicenseLink', array( &$link, $context,
$attribs, &$msg ) );
-
- // for plural support we need the info, if there is one or more
licenses used in the license text
- // this check if very simple and works on the base, that more
than one license will
- // use "and" as a connective
- // 1 - no plural
- // 2 - plural
- $delimiterMsg = wfMessage( 'and' );
- // check, if "and" isn't disabled and exists in site language
- $isPlural = (
- !$delimiterMsg->isDisabled() && strpos( $rightsText,
$delimiterMsg->text() ) === false ? 1 : 2
- );
-
- return array(
- 'msg' => $msg,
- 'link' => $link,
- 'plural' => $isPlural
- );
- }
-
- /**
- * Returns HTML of terms of use link or null if it shouldn't be
displayed
- * Note: This is called by a hook in the WikimediaMessages extension.
- *
- * @param $urlMsgKey Key of i18n message containing terms of use URL
(optional)
- *
- * @return null|string
- */
- public function getTermsLink( $urlMsgKey = 'mobile-frontend-terms-url'
) {
- $urlMsg = $this->msg( $urlMsgKey )->inContentLanguage();
- if ( $urlMsg->isDisabled() ) {
- return null;
- }
- $url = $urlMsg->plain();
- // Support both page titles and URLs
- if ( preg_match( '#^(https?:)?//#', $url ) === 0 ) {
- $title = Title::newFromText( $url );
- if ( !$title ) {
- return null;
- }
- $url = $title->getLocalURL();
- }
- return Html::element(
- 'a',
- array( 'href' => $url ),
- $this->msg( 'mobile-frontend-terms-text' )->text()
- );
- }
-
- /**
- * Takes an array of link elements and applies mobile urls to any urls
contained in them
- * @param array $urls
- * @return array
- */
- public function mobilizeUrls( $urls ) {
- $ctx = $this->mobileContext; // $this in closures is allowed
only in PHP 5.4
- return array_map( function( $url ) use ( $ctx ) {
- $url['href'] = $ctx->getMobileUrl( $url['href'] );
- return $url;
- },
- $urls );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/243226
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I20e46165fb76956cb7e1ef412a789d95063689bd
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Isarra <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits