Allow specifying OutputPage object in Skin::subPageSubtitle parameters
authorAlex Monk <alex@wikimedia.org>
Tue, 26 Apr 2016 16:46:46 +0000 (17:46 +0100)
committerJames D. Forrester <jforrester@wikimedia.org>
Wed, 29 Jun 2016 16:25:49 +0000 (17:25 +0100)
To avoid ending up with API callers like this:
https://gerrit.wikimedia.org/r/#/c/281463/1/ApiVisualEditorEdit.php

Bug: T97700
Change-Id: Id27380de9577ad54cb2580b76a4f236e8dd491dd

includes/skins/Skin.php

index fa46a46..729f564 100644 (file)
@@ -646,18 +646,22 @@ abstract class Skin extends ContextSource {
        }
 
        /**
+        * @param OutputPage $out Defaults to $this->getOutput() if left as null
         * @return string
         */
-       function subPageSubtitle() {
-               $out = $this->getOutput();
+       function subPageSubtitle( $out = null ) {
+               if ( $out === null ) {
+                       $out = $this->getOutput();
+               }
+               $title = $out->getTitle();
                $subpages = '';
 
                if ( !Hooks::run( 'SkinSubPageSubtitle', [ &$subpages, $this, $out ] ) ) {
                        return $subpages;
                }
 
-               if ( $out->isArticle() && MWNamespace::hasSubpages( $out->getTitle()->getNamespace() ) ) {
-                       $ptext = $this->getTitle()->getPrefixedText();
+               if ( $out->isArticle() && MWNamespace::hasSubpages( $title->getNamespace() ) ) {
+                       $ptext = $title->getPrefixedText();
                        if ( strpos( $ptext, '/' ) !== false ) {
                                $links = explode( '/', $ptext );
                                array_pop( $links );