* (bug 8535) Allow CSS vertical alignment keywords to be used for images.
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 2 Feb 2007 00:44:42 +0000 (00:44 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 2 Feb 2007 00:44:42 +0000 (00:44 +0000)
RELEASE-NOTES
includes/Linker.php
includes/Parser.php
languages/messages/MessagesEn.php

index 54bf8f3..66d82b0 100644 (file)
@@ -158,6 +158,8 @@ lighter making things easier to read.
 * Fixed bug affecting HTML formatting in sortable table column titles
 * Merged table sorting code into wikibits.js
 * (bug 8711) Stop floats in previews from spilling into edit area
+* (bug 8535) Allow certain vertical alignment attributes to be used as image
+  keywords
 
 
 == Languages updated ==
index e562fa7..1a2f216 100644 (file)
@@ -430,7 +430,7 @@ class Linker {
 
        /** @todo document */
        function makeImageLinkObj( $nt, $label, $alt, $align = '', $width = false, $height = false, $framed = false,
-         $thumb = false, $manual_thumb = '', $page = null )
+         $thumb = false, $manual_thumb = '', $page = null, $valign = '' )
        {
                global $wgContLang, $wgUser, $wgThumbLimits, $wgGenerateThumbnailOnParse;
 
@@ -531,6 +531,9 @@ class Linker {
                                 ( $width
                                        ? ( 'width="'.$width.'" height="'.$height.'" ' )
                                        : '' ) .
+                                ( $valign
+                                       ? ( 'style="vertical-align: '.$valign.'" ' )
+                                       : '' ) .
                                 'longdesc="'.$u.'" /></a>';
                }
                if ( '' != $align ) {
index 1d27f90..590c08a 100644 (file)
@@ -4357,8 +4357,6 @@ class Parser
        function makeImage( $nt, $options ) {
                global $wgUseImageResize, $wgDjvuRenderer;
 
-               $align = '';
-
                # Check if the options text is of the form "options|alt text"
                # Options are:
                #  * thumbnail          make a thumbnail with enlarge-icon and caption, alignment depends on lang
@@ -4368,16 +4366,26 @@ class Parser
                #  * ___px              scale to ___ pixels width, no aligning. e.g. use in taxobox
                #  * center             center the image
                #  * framed             Keep original image size, no magnify-button.
+               # vertical-align values (no % or length right now):
+               #  * baseline
+               #  * sub
+               #  * super
+               #  * top
+               #  * text-top
+               #  * middle
+               #  * bottom
+               #  * text-bottom
 
                $part = explode( '|', $options);
 
+               $mwAlign = array();
+               $alignments = array( 'left', 'right', 'center', 'none', 'baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom' );
+               foreach ( $alignments as $alignment ) {
+                       $mwAlign[$alignment] =& MagicWord::get( 'img_'.$alignment );
+               }
                $mwThumb  =& MagicWord::get( 'img_thumbnail' );
                $mwManualThumb =& MagicWord::get( 'img_manualthumb' );
-               $mwLeft   =& MagicWord::get( 'img_left' );
-               $mwRight  =& MagicWord::get( 'img_right' );
-               $mwNone   =& MagicWord::get( 'img_none' );
                $mwWidth  =& MagicWord::get( 'img_width' );
-               $mwCenter =& MagicWord::get( 'img_center' );
                $mwFramed =& MagicWord::get( 'img_framed' );
                $mwPage   =& MagicWord::get( 'img_page' );
                $caption = '';
@@ -4385,6 +4393,7 @@ class Parser
                $width = $height = $framed = $thumb = false;
                $page = null;
                $manual_thumb = '' ;
+               $align = $valign = '';
 
                foreach( $part as $val ) {
                        if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
@@ -4393,36 +4402,37 @@ class Parser
                                # use manually specified thumbnail
                                $thumb=true;
                                $manual_thumb = $match;
-                       } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
-                               # remember to set an alignment, don't render immediately
-                               $align = 'right';
-                       } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
-                               # remember to set an alignment, don't render immediately
-                               $align = 'left';
-                       } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
-                               # remember to set an alignment, don't render immediately
-                               $align = 'center';
-                       } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
-                               # remember to set an alignment, don't render immediately
-                               $align = 'none';
-                       } elseif ( isset( $wgDjvuRenderer ) && $wgDjvuRenderer
-                                  && ! is_null( $match = $mwPage->matchVariableStartToEnd($val) ) ) {
-                               # Select a page in a multipage document
-                               $page = $match;
-                       } elseif ( $wgUseImageResize && !$width && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
-                               wfDebug( "img_width match: $match\n" );
-                               # $match is the image width in pixels
-                               $m = array();
-                               if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
-                                       $width = intval( $m[1] );
-                                       $height = intval( $m[2] );
+                       } else {
+                               foreach( $alignments as $alignment ) {
+                                       if ( ! is_null( $mwAlign[$alignment]->matchVariableStartToEnd($val) ) ) {
+                                               switch ( $alignment ) {
+                                                       case 'left': case 'right': case 'center': case 'none':
+                                                               $align = $alignment; break;
+                                                       default:
+                                                               $valign = $alignment;
+                                               }
+                                               continue 2;
+                                       }
+                               }
+                               if ( isset( $wgDjvuRenderer ) && $wgDjvuRenderer
+                               && ! is_null( $match = $mwPage->matchVariableStartToEnd($val) ) ) {
+                                       # Select a page in a multipage document
+                                       $page = $match;
+                               } elseif ( $wgUseImageResize && !$width && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
+                                       wfDebug( "img_width match: $match\n" );
+                                       # $match is the image width in pixels
+                                       $m = array();
+                                       if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
+                                               $width = intval( $m[1] );
+                                               $height = intval( $m[2] );
+                                       } else {
+                                               $width = intval($match);
+                                       }
+                               } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
+                                       $framed=true;
                                } else {
-                                       $width = intval($match);
+                                       $caption = $val;
                                }
-                       } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
-                               $framed=true;
-                       } else {
-                               $caption = $val;
                        }
                }
                # Strip bad stuff out of the alt text
@@ -4436,7 +4446,7 @@ class Parser
 
                # Linker does the rest
                $sk = $this->mOptions->getSkin();
-               return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height, $framed, $thumb, $manual_thumb, $page );
+               return $sk->makeImageLinkObj( $nt, $caption, $alt, $align, $width, $height, $framed, $thumb, $manual_thumb, $page, $valign );
        }
 
        /**
index 45e759f..0363db4 100644 (file)
@@ -288,6 +288,14 @@ $magicWords = array(
        'img_center'             => array( 1,    'center', 'centre'       ),
        'img_framed'             => array( 1,    'framed', 'enframed', 'frame' ),
        'img_page'               => array( 1,    'page=$1', 'page $1'     ),
+       'img_baseline'           => array( 1,    'baseline'               ),
+       'img_sub'                => array( 1,    'sub'                    ),
+       'img_super'              => array( 1,    'super', 'sup'           ),
+       'img_top'                => array( 1,    'top'                    ),
+       'img_text-top'           => array( 1,    'text-top'               ),
+       'img_middle'             => array( 1,    'middle'                 ),
+       'img_bottom'             => array( 1,    'bottom'                 ),
+       'img_text-bottom'        => array( 1,    'text-bottom'            ),
        'int'                    => array( 0,    'INT:'                   ),
        'sitename'               => array( 1,    'SITENAME'               ),
        'ns'                     => array( 0,    'NS:'                    ),