Index: trunk/extensions/GeeQuBox/GeeQuBox.php |
— | — | @@ -18,10 +18,12 @@ |
19 | 19 | die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' ); |
20 | 20 | } |
21 | 21 | |
| 22 | +define('EXTPATH','GeeQuBox'); |
| 23 | + |
22 | 24 | $wgExtensionCredits['parserhook'][] = array( |
23 | 25 | 'path' => __FILE__, |
24 | 26 | 'name' => 'GeeQuBox', |
25 | | - 'version' => '0.02', |
| 27 | + 'version' => '0.02.1', |
26 | 28 | 'author' => array( '[http://www.mediawiki.org/wiki/User:Clausekwis David Raison]' ), |
27 | 29 | 'url' => 'http://www.mediawiki.org/wiki/Extension:GeeQuBox', |
28 | 30 | 'descriptionmsg' => 'geequbox-desc' |
— | — | @@ -36,7 +38,7 @@ |
37 | 39 | // ResourceLoader needs to know where your files are; specify your |
38 | 40 | // subdir relative to "extensions" or $wgExtensionAssetsPath |
39 | 41 | 'localBasePath' => dirname( __FILE__ ), |
40 | | - 'remoteExtPath' => 'GeeQuBox' |
| 42 | + 'remoteExtPath' => EXTPATH |
41 | 43 | ); |
42 | 44 | |
43 | 45 | |
— | — | @@ -60,7 +62,7 @@ |
61 | 63 | */ |
62 | 64 | class GeeQuBox { |
63 | 65 | |
64 | | - private $_page; |
| 66 | + private static $_page; |
65 | 67 | private $_hasGallery; |
66 | 68 | |
67 | 69 | public function gqbAddLightBox( $page ) { |
— | — | @@ -68,7 +70,7 @@ |
69 | 71 | return false; |
70 | 72 | |
71 | 73 | try { |
72 | | - $this->_page = $page; |
| 74 | + self::$_page = $page; |
73 | 75 | $this->_gqbReplaceHref( $page ); |
74 | 76 | $this->_gqbAddScripts( $page ); |
75 | 77 | return true; |
— | — | @@ -95,10 +97,18 @@ |
96 | 98 | private function _gqbAddScripts() { |
97 | 99 | global $wgExtensionAssetsPath; |
98 | 100 | |
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 | + }); |
102 | 111 | $j("li.gallerybox a.image").lightBox({ |
| 112 | + fixedNavigation: true, |
103 | 113 | imageLoading: "'. $eDir .'images/lightbox-ico-loading.gif", |
104 | 114 | imageBtnClose: "'. $eDir .'images/lightbox-btn-close.gif", |
105 | 115 | imageBtnPrev: "'. $eDir .'images/lightbox-btn-prev.gif", |
— | — | @@ -124,33 +134,28 @@ |
125 | 135 | * approach but there doesn't seem to be an alternative approach.) |
126 | 136 | */ |
127 | 137 | private function _gqbReplaceHref() { |
128 | | - $page = $this->_page->getHTML(); |
| 138 | + global $wgGqbDefaultWidth; |
| 139 | + |
| 140 | + $page = self::$_page->getHTML(); |
129 | 141 | $pattern = '~href="https://www.mediawiki.org/wiki/([^"]+)"\s*class="image"~'; |
130 | 142 | $replaced = preg_replace_callback($pattern,'self::_gqbReplaceMatches',$page); |
131 | 143 | |
132 | | - $this->_page->clearHTML(); |
133 | | - $this->_page->addHTML( $replaced ); |
| 144 | + self::$_page->clearHTML(); |
| 145 | + self::$_page->addHTML( $replaced ); |
134 | 146 | } |
135 | 147 | |
136 | 148 | private static function _gqbReplaceMatches( $matches ) { |
137 | 149 | global $wgGqbDefaultWidth; |
| 150 | + |
138 | 151 | $titleObj = Title::newFromText( rawurldecode( $matches[1] ) ); |
139 | 152 | $image = wfFindFile( $titleObj, false, false, true ); |
140 | 153 | $realwidth = (Integer) $image->getWidth(); |
141 | 154 | $width = ( $realwidth > $wgGqbDefaultWidth ) ? $wgGqbDefaultWidth : $realwidth; |
142 | | - // do not create a thumbnail when the image is smaller than the default width requested |
143 | 155 | $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"'; |
145 | 159 | } |
146 | 160 | |
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 | | - |
156 | 161 | } |
157 | 162 | |