Hygiene: Add wrapHTML method
authorjdlrobson <jdlrobson@gmail.com>
Sat, 5 Mar 2016 00:52:56 +0000 (16:52 -0800)
committerjdlrobson <jdlrobson@gmail.com>
Tue, 8 Mar 2016 20:16:49 +0000 (12:16 -0800)
Put the code that wraps the parsed output html
in a method to reduce size of prepareQuickTemplate function

This allows skins to redefine the function if they wish.

Change-Id: I8a9e732d0682af89112869a2b30f61f10f531219

includes/skins/SkinTemplate.php

index d6e0377..92311b5 100644 (file)
@@ -248,6 +248,30 @@ class SkinTemplate extends Skin {
 
        }
 
+       /**
+        * Wrap the body text with language information and identifiable element
+        *
+        * @param Title $title
+        * @return string html
+        */
+       protected function wrapHTML( $title, $html ) {
+               # An ID that includes the actual body text; without categories, contentSub, ...
+               $realBodyAttribs = [ 'id' => 'mw-content-text' ];
+
+               # Add a mw-content-ltr/rtl class to be able to style based on text direction
+               # when the content is different from the UI language, i.e.:
+               # not for special pages or file pages AND only when viewing
+               if ( !in_array( $title->getNamespace(), [ NS_SPECIAL, NS_FILE ] ) &&
+                       Action::getActionName( $this ) === 'view' ) {
+                       $pageLang = $title->getPageViewLanguage();
+                       $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
+                       $realBodyAttribs['dir'] = $pageLang->getDir();
+                       $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
+               }
+
+               return Html::rawElement( 'div', $realBodyAttribs, $html );
+       }
+
        /**
         * initialize various variables and generate the template
         *
@@ -424,22 +448,8 @@ class SkinTemplate extends Skin {
                $tpl->set( 'sitenotice', $this->getSiteNotice() );
                $tpl->set( 'bottomscripts', $this->bottomScripts() );
                $tpl->set( 'printfooter', $this->printSource() );
-
-               # An ID that includes the actual body text; without categories, contentSub, ...
-               $realBodyAttribs = [ 'id' => 'mw-content-text' ];
-
-               # Add a mw-content-ltr/rtl class to be able to style based on text direction
-               # when the content is different from the UI language, i.e.:
-               # not for special pages or file pages AND only when viewing
-               if ( !in_array( $title->getNamespace(), [ NS_SPECIAL, NS_FILE ] ) &&
-                       Action::getActionName( $this ) === 'view' ) {
-                       $pageLang = $title->getPageViewLanguage();
-                       $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
-                       $realBodyAttribs['dir'] = $pageLang->getDir();
-                       $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
-               }
-
-               $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
+               // Wrap the bodyText with #mw-content-text element
+               $out->mBodytext = $this->wrapHTML( $title, $out->mBodytext );
                $tpl->setRef( 'bodytext', $out->mBodytext );
 
                $language_urls = $this->getLanguages();