# HG changeset patch # User Dan # Date 1183315893 14400 # Node ID efae425e9b98b583b1d00409d0183b1c9248ab48 # Parent 80f52593bee96447029d30d12e524d8e163d6572 Finally implemented the new image tag code diff -r 80f52593bee9 -r efae425e9b98 includes/render.php --- a/includes/render.php Sun Jul 01 14:19:20 2007 -0400 +++ b/includes/render.php Sun Jul 01 14:51:33 2007 -0400 @@ -243,29 +243,7 @@ if ( !$plaintext ) { // Process images - - $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\|([0-9]+)\|([0-9]+)\]\]#is', $text, $matchlist); - $matches = Array(); - $matches['images'] =& $matchlist[1]; - $matches['widths'] =& $matchlist[2]; - $matches['heights'] =& $matchlist[3]; - for($i=0;$inslist['File'].$matches['images'][$i])) $text = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].'|'.$matches['widths'][$i].'|'.$matches['heights'][$i].']]', - ''.$matches['images'][$i].'', - $text); - } - - $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\]\]#is', $text, $matchlist); - $matches = Array(); - $matches['images'] = $matchlist[1]; - for($i=0;$inslist['File'].$matches['images'][$i])) $text = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].']]', - ''.$matches['images'][$i].'', - $text); - } - + $text = RenderMan::process_image_tags($text); } if($do_params) @@ -334,27 +312,7 @@ //return '
'.htmlspecialchars($message).'
'; - $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\|([0-9]+)\|([0-9]+)\]\]#is', $message, $matchlist); - $matches = Array(); - $matches['images'] = $matchlist[1]; - $matches['widths'] = $matchlist[2]; - $matches['heights'] = $matchlist[3]; - for($i=0;$inslist['File'].$matches['images'][$i])) $message = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].'|'.$matches['widths'][$i].'|'.$matches['heights'][$i].']]', - ''.$matches['images'][$i].'', - $message); - } - - $j = preg_match_all('#\[\[:'.$paths->nslist['File'].'([\w\s0-9_\(\)!@%\^\+\|\.-]+?)\]\]#is', $message, $matchlist); - $matches = Array(); - $matches['images'] = $matchlist[1]; - for($i=0;$inslist['File'].$matches['images'][$i])) $message = str_replace('[[:'.$paths->nslist['File'].$matches['images'][$i].']]', - ''.$matches['images'][$i].'', - $message); - } + $message = RenderMan::process_image_tags($message); } @@ -786,6 +744,135 @@ return ''.$renderer->format($diff).'
'; } + /** + * Changes wikitext image tags to HTML. + * @param string The wikitext to process + * @return string + */ + + function process_image_tags($text) + { + global $db, $session, $paths, $template, $plugins; // Common objects + + // Wicked huh? + $regex = '/\[\[:' . $paths->nslist['File'] . '([\w\s0-9_\(\)!@%\^\+\|\.-]+?)((\|thumb)|(\|([0-9]+)x([0-9]+)))?(\|left|\|right)?(\|(.+))?\]\]/i'; + + preg_match_all($regex, $text, $matches); + + foreach ( $matches[0] as $i => $match ) + { + + $full_tag =& $matches[0][$i]; + $filename =& $matches[1][$i]; + $scale_type =& $matches[2][$i]; + $width =& $matches[5][$i]; + $height =& $matches[6][$i]; + $clear =& $matches[7][$i]; + $caption =& $matches[8][$i]; + + if ( !isPage( $paths->nslist['File'] . $filename ) ) + { + continue; + } + + if ( $scale_type == '|thumb' ) + { + $r_width = 225; + $r_height = 225; + + $url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); + } + else if ( !empty($width) && !empty($height) ) + { + $r_width = $width; + $r_height = $height; + + $url = makeUrlNS('Special', 'DownloadFile/' . $filename, 'preview&width=' . $r_width . '&height=' . $r_height, true); + } + else + { + $url = makeUrlNS('Special', 'DownloadFile/' . $filename); + } + + $img_tag = ''; + $complete_tag .= $img_tag; + $complete_tag .= ''; + + $mag_button = '[ + ]'; + + if ( !empty($caption) ) + { + $cap = substr($caption, 1); + $complete_tag .= $mag_button . $cap; + } + + $complete_tag .= ''; + } + else + { + $complete_tag .= ''; + $complete_tag .= $img_tag; + $complete_tag .= ''; + } + + $complete_tag = "$complete_tag\n\n"; + + $pos = strpos($text, $full_tag) - 3; + + while(true) + { + $check1 = substr($text, $pos, 3); + $check2 = substr($text, $pos, 1); + if ( $check1 == '

' || $pos == 0 || $check2 == "\n" ) + { + // die('found at pos '.$pos); + break; + } + $pos--; + } + + $text = substr($text, 0, $pos) . $complete_tag . substr($text, $pos + 1); + + $text = str_replace($full_tag, '', $text); + + unset($full_tag, $filename, $scale_type, $width, $height, $clear, $caption, $r_width, $r_height); + + } + + return $text; + } + } ?> diff -r 80f52593bee9 -r efae425e9b98 includes/wikiengine/Parse/Mediawiki/Wikilink.php --- a/includes/wikiengine/Parse/Mediawiki/Wikilink.php Sun Jul 01 14:19:20 2007 -0400 +++ b/includes/wikiengine/Parse/Mediawiki/Wikilink.php Sun Jul 01 14:51:33 2007 -0400 @@ -100,6 +100,11 @@ { $default = $this->conf; parent::Text_Wiki_Parse($obj); + + global $paths; + $this->imageConf = array( + 'prefix' => array(':' . $paths->nslist['File']) + ); // override config options for image if specified if (in_array('Image', $this->wiki->disable)) { diff -r 80f52593bee9 -r efae425e9b98 includes/wikiformat.php --- a/includes/wikiformat.php Sun Jul 01 14:19:20 2007 -0400 +++ b/includes/wikiformat.php Sun Jul 01 14:51:33 2007 -0400 @@ -66,7 +66,8 @@ 'Html', 'Include', 'Embed', - 'Tighten' + 'Tighten', + 'Image' ); var $parseConf = array();