Add BaseTemplateAfterPortlet hook to add html after portlets
authoraude <aude.wiki@gmail.com>
Mon, 16 Dec 2013 17:26:30 +0000 (18:26 +0100)
committeraude <aude.wiki@gmail.com>
Wed, 12 Mar 2014 15:52:17 +0000 (16:52 +0100)
Allows extensions to move away from using (or abusing) the
SkinTemplateOutputPageBeforeExec hook to add things in places
such as after the list of language links.

Also explicitly check that $template->data['language_urls'] is not false.
Extensions can set it to an empty array to have the language links
header be displayed.

Bug: 57094
Change-Id: I099fb2ff48e02a2e3564a484aea906263e40bb53

RELEASE-NOTES-1.23
docs/hooks.txt
includes/SkinTemplate.php
skins/CologneBlue.php
skins/MonoBook.php
skins/Vector.php
skins/cologneblue/screen.css
skins/monobook/main.css

index 38302f8..3a809d3 100644 (file)
@@ -125,6 +125,7 @@ production.
   buttons.
 * Special:UserLogin/signup now does AJAX checks for invalid and taken usernames,
   displaying the error live.
+* Added BaseTemplateAfterPortlet hook to allow injecting html after portlets in skins.
 
 === Bug fixes in 1.23 ===
 * (bug 41759) The "updated since last visit" markers (on history pages, recent
index e7fa89b..a833484 100644 (file)
@@ -709,6 +709,12 @@ pages or galleries in category pages.
 $name: Image name being checked
 &$bad: Whether or not the image is "bad"
 
+'BaseTemplateAfterPortlet': After output of portlets, allow injecting
+custom HTML after the section. Any uses of the hook need to handle escaping.
+$template BaseTemplate
+$portlet: string portlet name
+&$html: string
+
 'BeforeDisplayNoArticleText': Before displaying message key "noarticletext" or
 "noarticletext-nopermission" at Article::showMissingArticle().
 $article: article object
index 780b228..bf572d0 100644 (file)
@@ -1738,6 +1738,19 @@ abstract class BaseTemplate extends QuickTemplate {
                return $boxes;
        }
 
+       /**
+        * @param string $name
+        */
+       protected function renderAfterPortlet( $name ) {
+               $content = '';
+               wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
+
+               if ( $content !== '' ) {
+                       echo "<div class='after-portlet after-portlet-$name'>$content</div>";
+               }
+
+       }
+
        /**
         * Makes a link, usually used by makeListItem to generate a link for an item
         * in a list used in navigation lists, portlets, portals, sidebars, etc...
index a7c62b3..9344feb 100644 (file)
@@ -90,21 +90,37 @@ class CologneBlueTemplate extends BaseTemplate {
                        return "";
                }
 
+               $html = '';
+
                // We override SkinTemplate->formatLanguageName() in SkinCologneBlue
                // not to capitalize the language names.
                $language_urls = $this->data['language_urls'];
-               if ( empty( $language_urls ) ) {
-                       return "";
-               }
+               if ( !empty( $language_urls ) ) {
+                       $s = array();
+                       foreach ( $language_urls as $key => $data ) {
+                               $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
+                       }
 
-               $s = array();
-               foreach ( $language_urls as $key => $data ) {
-                       $s[] = $this->makeListItem( $key, $data, array( 'tag' => 'span' ) );
+                       $html = wfMessage( 'otherlanguages' )->text()
+                               . wfMessage( 'colon-separator' )->text()
+                               . $this->getSkin()->getLanguage()->pipeList( $s );
                }
 
-               return wfMessage( 'otherlanguages' )->text()
-                       . wfMessage( 'colon-separator' )->text()
-                       . $this->getSkin()->getLanguage()->pipeList( $s );
+               $html .= $this->renderAfterPortlet( 'lang' );
+
+               return $html;
+       }
+
+       /**
+        * @param string $name
+        */
+       protected function renderAfterPortlet( $name ) {
+               $content = '';
+               wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
+
+               $html = $content !== '' ? "<div class='after-portlet after-portlet-$name'>$content</div>" : '';
+
+               return $html;
        }
 
        function pageTitleLinks() {
@@ -517,6 +533,8 @@ class CologneBlueTemplate extends BaseTemplate {
                                $role = ( $heading == 'search' ) ? 'search' : 'navigation';
                                $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
                        }
+
+                       $s .= $this->renderAfterPortlet( $heading );
                }
 
                $s .= "</div>\n";
index bd914ce..34f5965 100644 (file)
@@ -221,6 +221,8 @@ echo $footerEnd;
                                } ?>
 
                        </form>
+
+                       <?php $this->renderAfterPortlet( 'search' ); ?>
                </div>
        </div>
 <?php
@@ -242,6 +244,7 @@ echo $footerEnd;
                                } ?>
 
                        </ul>
+<?php          $this->renderAfterPortlet( 'cactions' ); ?>
                </div>
        </div>
 <?php
@@ -263,6 +266,7 @@ echo $footerEnd;
                wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
 ?>
                        </ul>
+<?php          $this->renderAfterPortlet( 'tb' ); ?>
                </div>
        </div>
 <?php
@@ -270,7 +274,7 @@ echo $footerEnd;
 
        /*************************************************************************************************/
        function languageBox() {
-               if ( $this->data['language_urls'] ) {
+               if ( $this->data['language_urls'] !== false ) {
 ?>
        <div id="p-lang" class="portlet" role="navigation">
                <h3<?php $this->html( 'userlangattributes' ) ?>><?php $this->msg( 'otherlanguages' ) ?></h3>
@@ -281,6 +285,8 @@ echo $footerEnd;
 
 <?php          } ?>
                        </ul>
+
+<?php          $this->renderAfterPortlet( 'lang' ); ?>
                </div>
        </div>
 <?php
@@ -315,9 +321,12 @@ echo $footerEnd;
                        # allow raw HTML block to be defined by extensions
                        print $cont;
                }
+
+               $this->renderAfterPortlet( $bar );
 ?>
                </div>
        </div>
 <?php
        }
+
 } // end of class
index 899a272..bb0f013 100644 (file)
@@ -274,7 +274,7 @@ class VectorTemplate extends BaseTemplate {
                                        $this->renderPortal( 'tb', $this->getToolbox(), 'toolbox', 'SkinTemplateToolboxEnd' );
                                        break;
                                case 'LANGUAGES':
-                                       if ( $this->data['language_urls'] ) {
+                                       if ( $this->data['language_urls']  !== false ) {
                                                $this->renderPortal( 'lang', $this->data['language_urls'], 'otherlanguages' );
                                        }
                                        break;
@@ -316,9 +316,12 @@ class VectorTemplate extends BaseTemplate {
                </ul>
 <?php
                } else { ?>
-               <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
-<?php
-               } ?>
+               <?php
+                       echo $content; /* Allow raw HTML block to be defined by extensions */
+               }
+
+               $this->renderAfterPortlet( $name );
+               ?>
        </div>
 </div>
 <?php
index 40a9432..ef9cf8f 100644 (file)
@@ -133,6 +133,11 @@ textarea {
        line-height: inherit;
 }
 
+div.after-portlet {
+       display: inline;
+       padding-left: .5em;
+}
+
 h1 {
        color: #666666;
        font-family: Verdana, Arial, sans-serif;
index 145b375..6d37657 100644 (file)
@@ -250,6 +250,12 @@ table.rimage {
        border: 1px solid #aaa;
        padding: 0 .8em .3em .5em;
 }
+/* allows .pBody styles to wrap around content added via BaseTemplateAfterPortlet hook */
+.pBody:after {
+       content: '';
+       clear: both;
+       display: block;
+}
 .portlet ul {
        line-height: 1.5em;
        font-size: 95%;