Allow to customise addHelpLink() target via system message
authorFederico Leva <federicoleva@tiscali.it>
Sat, 2 May 2015 11:37:19 +0000 (13:37 +0200)
committerFederico Leva <federicoleva@tiscali.it>
Fri, 15 May 2015 08:14:28 +0000 (10:14 +0200)
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

22 files changed:
RELEASE-NOTES-1.25
includes/OutputPage.php
includes/actions/Action.php
includes/actions/DeleteAction.php
includes/page/Article.php
includes/page/CategoryPage.php
includes/specialpage/SpecialPage.php
includes/specials/SpecialAllMessages.php
includes/specials/SpecialBlock.php
includes/specials/SpecialDiff.php
includes/specials/SpecialEditTags.php
includes/specials/SpecialMergeHistory.php
includes/specials/SpecialMovepage.php
includes/specials/SpecialNewimages.php
includes/specials/SpecialNewpages.php
includes/specials/SpecialPreferences.php
includes/specials/SpecialRandomInCategory.php
includes/specials/SpecialRevisiondelete.php
includes/specials/SpecialSpecialpages.php
includes/specials/SpecialUndelete.php
includes/specials/SpecialUpload.php
includes/specials/SpecialUserrights.php

index 8bc51be..594ba7c 100644 (file)
@@ -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.
index 8f9f9c6..adcc188 100644 (file)
@@ -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(
index aca4363..fa75e08 100644 (file)
@@ -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
index 82424eb..be21a6f 100644 (file)
@@ -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();
        }
 }
index 91e9971..f271820 100644 (file)
@@ -1505,6 +1505,27 @@ class Article implements Page {
                        '</div>';
        }
 
+       /**
+        * 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
         */
index 2edf1af..caebcd7 100644 (file)
@@ -115,6 +115,6 @@ class CategoryPage extends Article {
                );
                $out = $this->getContext()->getOutput();
                $out->addHTML( $viewer->getHTML() );
-               $out->addHelpLink( 'Help:Categories' );
+               $this->addHelpLink( 'Help:Categories' );
        }
 }
index f9d1e8a..a7a43b0 100644 (file)
@@ -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
index 91eade1..6a86af2 100644 (file)
@@ -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,
index 3f13510..323575a 100644 (file)
@@ -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 ) {
index 9f91a10..8b5d31a 100644 (file)
@@ -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' );
                }
 
index bfd1717..f41a1f1 100644 (file)
@@ -206,7 +206,7 @@ class SpecialEditTags extends UnlistedSpecialPage {
                        $this->targetObj->getPrefixedText()
                ) );
 
-               $out->addHelpLink( 'Help:Tags' );
+               $this->addHelpLink( 'Help:Tags' );
                $out->addHTML( "<ul>" );
 
                $numRevisions = 0;
index b6cf8e4..1f0b6d4 100644 (file)
@@ -187,7 +187,7 @@ class SpecialMergeHistory extends SpecialPage {
                                '</form>'
                );
 
-               $out->addHelpLink( 'Help:Merge history' );
+               $this->addHelpLink( 'Help:Merge history' );
        }
 
        private function showHistory() {
index a519bd0..ae1fefe 100644 (file)
@@ -140,7 +140,7 @@ class MovePageForm extends UnlistedSpecialPage {
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
                $out->addModules( 'mediawiki.special.movePage' );
-               $out->addHelpLink( 'Help:Moving a page' );
+               $this->addHelpLink( 'Help:Moving a page' );
 
                $newTitle = $this->newTitle;
 
index de19fa4..00c8e05 100644 (file)
@@ -31,7 +31,7 @@ class SpecialNewFiles extends IncludableSpecialPage {
                $this->outputHeader();
 
                $out = $this->getOutput();
-               $out->addHelpLink( 'Help:New images' );
+               $this->addHelpLink( 'Help:New images' );
 
                $pager = new NewFilesPager( $this->getContext(), $par );
 
index 594628f..899c736 100644 (file)
@@ -127,7 +127,7 @@ class SpecialNewpages extends IncludableSpecialPage {
                $this->showNavigation = !$this->including(); // Maybe changed in setup
                $this->setup( $par );
 
-               $out->addHelpLink( 'Help:New pages' );
+               $this->addHelpLink( 'Help:New pages' );
 
                if ( !$this->including() ) {
                        // Settings
index ef61f94..7371da7 100644 (file)
@@ -55,7 +55,7 @@ class SpecialPreferences extends SpecialPage {
                        );
                }
 
-               $out->addHelpLink( 'Help:Preferences' );
+               $this->addHelpLink( 'Help:Preferences' );
 
                $htmlForm = Preferences::getFormObject( $this->getUser(), $this->getContext() );
                $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) );
index b6f19ec..b5c9e19 100644 (file)
@@ -68,7 +68,7 @@ class SpecialRandomInCategory extends FormSpecialPage {
        }
 
        protected function getFormFields() {
-               $this->getOutput()->addHelpLink( 'Help:RandomInCategory' );
+               $this->addHelpLink( 'Help:RandomInCategory' );
 
                $form = array(
                        'category' => array(
index 62025e7..c044146 100644 (file)
@@ -368,7 +368,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $out->wrapWikiMsg( "<strong>$1</strong>", array( $this->typeLabels['selected'],
                        $this->getLanguage()->formatNum( count( $this->ids ) ), $this->targetObj->getPrefixedText() ) );
 
-               $out->addHelpLink( 'Help:RevisionDelete' );
+               $this->addHelpLink( 'Help:RevisionDelete' );
                $out->addHTML( "<ul>" );
 
                $numRevisions = 0;
index ed3ad5b..eaa9007 100644 (file)
@@ -45,7 +45,7 @@ class SpecialSpecialpages extends UnlistedSpecialPage {
                        return;
                }
 
-               $out->addHelpLink( 'Help:Special pages' );
+               $this->addHelpLink( 'Help:Special pages' );
                $this->outputPageList( $groups );
        }
 
index de2365e..f2362a1 100644 (file)
@@ -791,7 +791,7 @@ class SpecialUndelete extends SpecialPage {
                        return;
                }
 
-               $out->addHelpLink( 'Help:Undelete' );
+               $this->addHelpLink( 'Help:Undelete' );
                if ( $this->mAllowed ) {
                        $out->setPageTitle( $this->msg( 'undeletepage' ) );
                } else {
index 3f1ea42..2d8f978 100644 (file)
@@ -160,7 +160,7 @@ class SpecialUpload extends SpecialPage {
                        throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' );
                }
 
-               $this->getOutput()->addHelpLink( 'Help:Managing files' );
+               $this->addHelpLink( 'Help:Managing files' );
 
                # Check permissions
                $user = $this->getUser();
index 785a844..758e3c0 100644 (file)
@@ -135,7 +135,7 @@ class UserrightsPage extends SpecialPage {
 
                $out = $this->getOutput();
                $out->addModuleStyles( 'mediawiki.special' );
-               $out->addHelpLink( 'Help:Assigning permissions' );
+               $this->addHelpLink( 'Help:Assigning permissions' );
 
                // show the general form
                if ( count( $available['add'] ) || count( $available['remove'] ) ) {