From: Federico Leva Date: Sat, 2 May 2015 11:37:19 +0000 (+0200) Subject: Allow to customise addHelpLink() target via system message X-Git-Tag: 1.31.0-rc.0~11402^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=e928d5bdd0fbc63;hp=01799a7cb33c707a675d8222ff9543934791aa13;p=lhc%2Fweb%2Fwiklou.git Allow to customise addHelpLink() target via system message Method similar to SpecialPage::outputHeader() to avoid registering tons of system messages and to have -summary and -helppage tidily listed together in Special:AllMessages by default. Bug: T45591 Change-Id: Ic849dde00be7379c1909a8486cf20f48c5aea5cf --- diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 8bc51be505..594ba7c7f2 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -382,6 +382,10 @@ changes to languages because of Bugzilla reports. bugs and ensure better reading experience for different variants. === Other changes in 1.25 === +* (T45591) Links to MediaWiki.org translatable help were added to indicators, + mostly in special pages. Local custom target titles can be placed in the + relevant '(namespace-X|action name|special page name)-helppage' system + message. Extensions can use the addHelpLink() function to do the same. * The skin autodiscovery mechanism, deprecated in MediaWiki 1.23, has been removed. See https://www.mediawiki.org/wiki/Manual:Skin_autodiscovery for migration guide for creators and users of custom skins that relied on it. diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8f9f9c6645..adcc1884e6 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1401,8 +1401,10 @@ class OutputPage extends ContextSource { /** * Adds help link with an icon via page indicators. - * @param string $to - * @param bool $overrideBaseUrl + * Link target can be overridden by a local message containing a wikilink: + * the message key is: lowercase action or special page name + '-helppage'. + * @param string $to Target MediaWiki.org page title or encoded URL. + * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o. * @since 1.25 */ public function addHelpLink( $to, $overrideBaseUrl = false ) { @@ -1415,6 +1417,7 @@ class OutputPage extends ContextSource { $toUrlencoded = wfUrlencode( str_replace( ' ', '_', $to ) ); $helpUrl = "//www.mediawiki.org/wiki/Special:MyLanguage/$toUrlencoded"; } + $link = Html::rawElement( 'a', array( diff --git a/includes/actions/Action.php b/includes/actions/Action.php index aca4363fce..fa75e089ac 100644 --- a/includes/actions/Action.php +++ b/includes/actions/Action.php @@ -376,6 +376,25 @@ abstract class Action { return $this->msg( strtolower( $this->getName() ) )->escaped(); } + /** + * Adds help link with an icon via page indicators. + * Link target can be overridden by a local message containing a wikilink: + * the message key is: lowercase action name + '-helppage'. + * @param string $to Target MediaWiki.org page title or encoded URL. + * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o. + * @since 1.25 + */ + public function addHelpLink( $to, $overrideBaseUrl = false ) { + $msg = wfMessage( $wgContLang->lc( $this->getActionName() ) . '-helppage' ); + + if ( !$msg->isDisabled() ) { + $helpUrl = Skin::makeUrl( $msg->plain() ); + $this->getOutput()->addHelpLink( $helpUrl, true ); + } else { + $this->getOutput()->addHelpLink( $to, $overrideBaseUrl ); + } + } + /** * The main action entry point. Do all output for display and send it to the context * output. Do not use globals $wgOut, $wgRequest, etc, in implementations; use diff --git a/includes/actions/DeleteAction.php b/includes/actions/DeleteAction.php index 82424eb00e..be21a6f16a 100644 --- a/includes/actions/DeleteAction.php +++ b/includes/actions/DeleteAction.php @@ -48,7 +48,7 @@ class DeleteAction extends FormlessAction { 'mediawiki.ui.checkbox', ) ); } - $out->addHelpLink( 'Help:Sysop deleting and undeleting' ); + $this->addHelpLink( 'Help:Sysop deleting and undeleting' ); $this->page->delete(); } } diff --git a/includes/page/Article.php b/includes/page/Article.php index 91e9971573..f271820d7e 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -1505,6 +1505,27 @@ class Article implements Page { ''; } + /** + * Adds help link with an icon via page indicators. + * Link target can be overridden by a local message containing a wikilink: + * the message key is: 'namespace-' + namespace number + '-helppage'. + * @param string $to Target MediaWiki.org page title or encoded URL. + * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o. + * @since 1.25 + */ + public function addHelpLink( $to, $overrideBaseUrl = false ) { + $msg = wfMessage( + 'namespace-' . $this->getTitle()->getNamespace() . '-helppage' + ); + + if ( !$msg->isDisabled() ) { + $helpUrl = Skin::makeUrl( $msg->plain() ); + $this->getOutput()->addHelpLink( $helpUrl, true ); + } else { + $this->getOutput()->addHelpLink( $to, $overrideBaseUrl ); + } + } + /** * Handle action=render */ diff --git a/includes/page/CategoryPage.php b/includes/page/CategoryPage.php index 2edf1af19a..caebcd7dae 100644 --- a/includes/page/CategoryPage.php +++ b/includes/page/CategoryPage.php @@ -115,6 +115,6 @@ class CategoryPage extends Article { ); $out = $this->getContext()->getOutput(); $out->addHTML( $viewer->getHTML() ); - $out->addHelpLink( 'Help:Categories' ); + $this->addHelpLink( 'Help:Categories' ); } } diff --git a/includes/specialpage/SpecialPage.php b/includes/specialpage/SpecialPage.php index f9d1e8a636..a7a43b0e30 100644 --- a/includes/specialpage/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -632,6 +632,26 @@ class SpecialPage { } } + /** + * Adds help link with an icon via page indicators. + * Link target can be overridden by a local message containing a wikilink: + * the message key is: lowercase special page name + '-helppage'. + * @param string $to Target MediaWiki.org page title or encoded URL. + * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o. + * @since 1.25 + */ + public function addHelpLink( $to, $overrideBaseUrl = false ) { + global $wgContLang; + $msg = $this->msg( $wgContLang->lc( $this->getName() ) . '-helppage' ); + + if ( !$msg->isDisabled() ) { + $helpUrl = Skin::makeUrl( $msg->plain() ); + $this->getOutput()->addHelpLink( $helpUrl, true ); + } else { + $this->getOutput()->addHelpLink( $to, $overrideBaseUrl ); + } + } + /** * Get the group that the special page belongs in on Special:SpecialPage * Use this method, instead of getGroupName to allow customization diff --git a/includes/specials/SpecialAllMessages.php b/includes/specials/SpecialAllMessages.php index 91eade14eb..6a86af2d87 100644 --- a/includes/specials/SpecialAllMessages.php +++ b/includes/specials/SpecialAllMessages.php @@ -59,7 +59,7 @@ class SpecialAllMessages extends SpecialPage { $this->outputHeader( 'allmessagestext' ); $out->addModuleStyles( 'mediawiki.special' ); - $out->addHelpLink( 'Help:System message' ); + $this->addHelpLink( 'Help:System message' ); $this->table = new AllMessagesTablePager( $this, diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 3f13510de2..323575a2ce 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -103,7 +103,7 @@ class SpecialBlock extends FormSpecialPage { $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit'; $form->setSubmitTextMsg( $msg ); - $this->getOutput()->addHelpLink( 'Help:Blocking users' ); + $this->addHelpLink( 'Help:Blocking users' ); # Don't need to do anything if the form has been posted if ( !$this->getRequest()->wasPosted() && $this->preErrors ) { diff --git a/includes/specials/SpecialDiff.php b/includes/specials/SpecialDiff.php index 9f91a10c9c..8b5d31a8fb 100644 --- a/includes/specials/SpecialDiff.php +++ b/includes/specials/SpecialDiff.php @@ -57,7 +57,7 @@ class SpecialDiff extends RedirectSpecialPage { $this->mAddedRedirectParams['diff'] = $parts[1]; } else { // Wrong number of parameters, bail out - $this->getOutput()->addHelpLink( 'Help:Diff' ); + $this->addHelpLink( 'Help:Diff' ); throw new ErrorPageError( 'nopagetitle', 'nopagetext' ); } diff --git a/includes/specials/SpecialEditTags.php b/includes/specials/SpecialEditTags.php index bfd1717256..f41a1f1ded 100644 --- a/includes/specials/SpecialEditTags.php +++ b/includes/specials/SpecialEditTags.php @@ -206,7 +206,7 @@ class SpecialEditTags extends UnlistedSpecialPage { $this->targetObj->getPrefixedText() ) ); - $out->addHelpLink( 'Help:Tags' ); + $this->addHelpLink( 'Help:Tags' ); $out->addHTML( "