r82086 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82085‎ | r82086 | r82087 >
Date:22:28, 13 February 2011
Author:kwisatz
Status:deferred
Tags:
Comment:
Supports gallerytext captions.
Modified paths:
  • /trunk/extensions/GeeQuBox/GeeQuBox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GeeQuBox/GeeQuBox.php
@@ -18,10 +18,12 @@
1919 die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' );
2020 }
2121
 22+define('EXTPATH','GeeQuBox');
 23+
2224 $wgExtensionCredits['parserhook'][] = array(
2325 'path' => __FILE__,
2426 'name' => 'GeeQuBox',
25 - 'version' => '0.02',
 27+ 'version' => '0.02.1',
2628 'author' => array( '[http://www.mediawiki.org/wiki/User:Clausekwis David Raison]' ),
2729 'url' => 'http://www.mediawiki.org/wiki/Extension:GeeQuBox',
2830 'descriptionmsg' => 'geequbox-desc'
@@ -36,7 +38,7 @@
3739 // ResourceLoader needs to know where your files are; specify your
3840 // subdir relative to "extensions" or $wgExtensionAssetsPath
3941 'localBasePath' => dirname( __FILE__ ),
40 - 'remoteExtPath' => 'GeeQuBox'
 42+ 'remoteExtPath' => EXTPATH
4143 );
4244
4345
@@ -60,7 +62,7 @@
6163 */
6264 class GeeQuBox {
6365
64 - private $_page;
 66+ private static $_page;
6567 private $_hasGallery;
6668
6769 public function gqbAddLightBox( $page ) {
@@ -68,7 +70,7 @@
6971 return false;
7072
7173 try {
72 - $this->_page = $page;
 74+ self::$_page = $page;
7375 $this->_gqbReplaceHref( $page );
7476 $this->_gqbAddScripts( $page );
7577 return true;
@@ -95,10 +97,18 @@
9698 private function _gqbAddScripts() {
9799 global $wgExtensionAssetsPath;
98100
99 - $eDir = $wgExtensionAssetsPath .'/GeeQuBox/';
100 - $this->_page->addModules( 'ext.GeeQuBox' );
101 - $this->_page->addInlineScript('$j(document).ready(function(){
 101+ $eDir = $wgExtensionAssetsPath .'/'.EXTPATH.'/';
 102+ self::$_page->addModules( 'ext.GeeQuBox' );
 103+ self::$_page->addInlineScript('$j(document).ready(function(){
 104+ $("li.gallerybox").each(function(el){
 105+ var _a = $("div.thumb a", this);
 106+ var title = _a.attr("title");
 107+ var caption = $("div.gallerytext > p", this).text();
 108+ if ( caption != "" )
 109+ _a.attr("title", title + caption);
 110+ });
102111 $j("li.gallerybox a.image").lightBox({
 112+ fixedNavigation: true,
103113 imageLoading: "'. $eDir .'images/lightbox-ico-loading.gif",
104114 imageBtnClose: "'. $eDir .'images/lightbox-btn-close.gif",
105115 imageBtnPrev: "'. $eDir .'images/lightbox-btn-prev.gif",
@@ -124,33 +134,28 @@
125135 * approach but there doesn't seem to be an alternative approach.)
126136 */
127137 private function _gqbReplaceHref() {
128 - $page = $this->_page->getHTML();
 138+ global $wgGqbDefaultWidth;
 139+
 140+ $page = self::$_page->getHTML();
129141 $pattern = '~href="https://www.mediawiki.org/wiki/([^"]+)"\s*class="image"~';
130142 $replaced = preg_replace_callback($pattern,'self::_gqbReplaceMatches',$page);
131143
132 - $this->_page->clearHTML();
133 - $this->_page->addHTML( $replaced );
 144+ self::$_page->clearHTML();
 145+ self::$_page->addHTML( $replaced );
134146 }
135147
136148 private static function _gqbReplaceMatches( $matches ) {
137149 global $wgGqbDefaultWidth;
 150+
138151 $titleObj = Title::newFromText( rawurldecode( $matches[1] ) );
139152 $image = wfFindFile( $titleObj, false, false, true );
140153 $realwidth = (Integer) $image->getWidth();
141154 $width = ( $realwidth > $wgGqbDefaultWidth ) ? $wgGqbDefaultWidth : $realwidth;
142 - // do not create a thumbnail when the image is smaller than the default width requested
143155 $iPath = ( $realwidth < $wgGqbDefaultWidth ) ? $image->getURL() : $image->createThumb($width);
144 - return 'href="'. $iPath .'" class="image"'; // $image->getURL()
 156+ $title = self::$_page->parse( "'''[[:" . $titleObj->getFullText() . "|" . $titleObj->getText() . "]]'''" );
 157+
 158+ return 'href="'. $iPath .'" title="'. htmlspecialchars( $title ) .'" class="image"';
145159 }
146160
147 - /*
148 - * Code used also in SlimboxThumbs to set the size of the displayed images
149 - * This can only be done in js where the window.width is known.
150 - $out->addInlineScript( $jQ.'(document).ready(function(){
151 - if('.$jQ.'("table.gallery").val() != undefined){
152 - })' );
153 -
154 - */
155 -
156161 }
157162

Status & tagging log