Index: trunk/extensions/ImageTagging/ImageTagPage.php |
— | — | @@ -0,0 +1,262 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ImageTagPage extends ImagePage { |
| 5 | + |
| 6 | + function openShowImage() { |
| 7 | + global $wgOut, $wgUser, $wgScriptPath; |
| 8 | + |
| 9 | + wfProfileIn( __METHOD__ ); |
| 10 | + |
| 11 | + $wgOut->addScriptFile( $wgScriptPath . '/extensions/ImageTagging/img_tagging.js' ); |
| 12 | + $wgOut->addScriptFile( $wgScriptPath . '/extensions/ImageTagging/json.js' ); |
| 13 | + |
| 14 | + $imgName = $this->getTitle()->getText(); |
| 15 | + $wgOut->addHTML( "<input type='hidden' value='$imgName' id='imgName' />" ); |
| 16 | + $wgOut->addHTML( "<input type='hidden' value='$wgScriptPath/extensions/ImageTagging' id='imgPath' />" ); |
| 17 | + |
| 18 | + if ( $wgUser->isLoggedIn() ) { |
| 19 | + $wgOut->addHTML( '<input type="hidden" value="1" id="userLoggedIn" />' ); |
| 20 | + } |
| 21 | + |
| 22 | + if ( |
| 23 | + $wgUser->isAllowed( 'edit' ) && |
| 24 | + $this->mTitle->userCan( 'edit', true ) && |
| 25 | + ( $this->mTitle->isProtected( 'edit' ) == false || in_array( 'sysop', $wgUser->getGroups() ) ) |
| 26 | + ) |
| 27 | + { |
| 28 | + $wgOut->addHTML( '<input type="hidden" value="1" id="canEditPage" />' ); |
| 29 | + } |
| 30 | + |
| 31 | + $this->modifiedImagePageOpenShowImage(); |
| 32 | + |
| 33 | + if ( $this->getFile()->exists() ) { |
| 34 | + $tagList = wfGetImageTags( $this->getFile(), $imgName ); |
| 35 | + |
| 36 | + #if ( $tagList ) |
| 37 | + $wgOut->addHTML( "<div id=\"tagListDiv\"><span id=\"tagList\">$tagList</span></div>" ); |
| 38 | + } |
| 39 | + |
| 40 | + wfProfileOut( __METHOD__ ); |
| 41 | + } |
| 42 | + |
| 43 | + function modifiedImagePageOpenShowImage() { |
| 44 | + global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgEnableUploads; |
| 45 | + |
| 46 | + wfProfileIn( __METHOD__ ); |
| 47 | + |
| 48 | + $full_url = $this->getFile()->getURL(); |
| 49 | + $anchoropen = ''; |
| 50 | + $anchorclose = ''; |
| 51 | + |
| 52 | + if( $wgUser->getOption( 'imagesize' ) == '' ) { |
| 53 | + $sizeSel = User::getDefaultOption( 'imagesize' ); |
| 54 | + } else { |
| 55 | + $sizeSel = intval( $wgUser->getOption( 'imagesize' ) ); |
| 56 | + } |
| 57 | + if( !isset( $wgImageLimits[$sizeSel] ) ) { |
| 58 | + $sizeSel = User::getDefaultOption( 'imagesize' ); |
| 59 | + } |
| 60 | + $max = $wgImageLimits[$sizeSel]; |
| 61 | + $maxWidth = $max[0]; |
| 62 | + $maxHeight = $max[1]; |
| 63 | + $maxWidth = 600; |
| 64 | + $maxHeight = 460; |
| 65 | + $sk = $wgUser->getSkin(); |
| 66 | + |
| 67 | + if ( $this->getFile()->exists() ) { |
| 68 | + # image |
| 69 | + $width = $this->getFile()->getWidth(); |
| 70 | + $height = $this->getFile()->getHeight(); |
| 71 | + $showLink = false; |
| 72 | + |
| 73 | + if ( $this->getFile()->allowInlineDisplay() && $width && $height) { |
| 74 | + # image |
| 75 | + |
| 76 | + # "Download high res version" link below the image |
| 77 | + $msg = wfMsgHtml( |
| 78 | + 'show-big-image', |
| 79 | + $width, $height, |
| 80 | + intval( $this->getFile()->getSize() / 1024 ) |
| 81 | + ); |
| 82 | + |
| 83 | + # We'll show a thumbnail of this image |
| 84 | + if ( $width > $maxWidth || $height > $maxHeight ) { |
| 85 | + # Calculate the thumbnail size. |
| 86 | + # First case, the limiting factor is the width, not the height. |
| 87 | + if ( $width / $height >= $maxWidth / $maxHeight ) { |
| 88 | + $height = round( $height * $maxWidth / $width); |
| 89 | + $width = $maxWidth; |
| 90 | + # Note that $height <= $maxHeight now. |
| 91 | + } else { |
| 92 | + $newwidth = floor( $width * $maxHeight / $height); |
| 93 | + $height = round( $height * $newwidth / $width ); |
| 94 | + $width = $newwidth; |
| 95 | + # Note that $height <= $maxHeight now, but might not be identical |
| 96 | + # because of rounding. |
| 97 | + } |
| 98 | + |
| 99 | + $thumbnail = $this->getFile()->getThumbnail( $width ); |
| 100 | + if ( $thumbnail == null ) { |
| 101 | + $url = $this->getFile()->getViewURL(); |
| 102 | + } else { |
| 103 | + $url = $thumbnail->getURL(); |
| 104 | + } |
| 105 | + |
| 106 | + $anchoropen = "<a href=\"{$full_url}\">"; |
| 107 | + $anchorclose = "</a><br />"; |
| 108 | + if( $this->getFile()->mustRender() ) { |
| 109 | + $showLink = true; |
| 110 | + } else { |
| 111 | + $anchorclose .= "\n$anchoropen{$msg}</a>"; |
| 112 | + } |
| 113 | + } else { |
| 114 | + $url = $this->getFile()->getViewURL(); |
| 115 | + $showLink = true; |
| 116 | + } |
| 117 | + |
| 118 | + //$anchoropen = ''; |
| 119 | + //$anchorclose = ''; |
| 120 | + // $width = 'auto'; //'100%'; |
| 121 | + // $height = 'auto'; //'100%'; |
| 122 | + $wgOut->addHTML( |
| 123 | + '<div class="fullImageLink" id="file">' . |
| 124 | + "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" style=\"max-width: {$maxWidth}px;\" alt=\"" . |
| 125 | + htmlspecialchars( $wgRequest->getVal( 'image' ) ) . '" />' . |
| 126 | + $anchoropen . $anchorclose . '</div>' |
| 127 | + ); |
| 128 | + } else { |
| 129 | + # if direct link is allowed but it's not a renderable image, show an icon. |
| 130 | + if ( $this->getFile()->isSafeFile() ) { |
| 131 | + $icon= $this->getFile()->iconThumb(); |
| 132 | + |
| 133 | + $wgOut->addHTML( |
| 134 | + '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' . |
| 135 | + $icon->toHtml() . |
| 136 | + '</a></div>' |
| 137 | + ); |
| 138 | + } |
| 139 | + |
| 140 | + $showLink = true; |
| 141 | + } |
| 142 | + |
| 143 | + if ( $showLink ) { |
| 144 | + $filename = wfEscapeWikiText( $this->getFile()->getName() ); |
| 145 | + $info = wfMsg( |
| 146 | + 'file-info', |
| 147 | + $sk->formatSize( $this->getFile()->getSize() ), |
| 148 | + $this->getFile()->getMimeType() |
| 149 | + ); |
| 150 | + |
| 151 | + if ( !$this->getFile()->isSafeFile() ) { |
| 152 | + $warning = wfMsg( 'mediawarning' ); |
| 153 | + $wgOut->addWikiText( <<<END |
| 154 | +<div class="fullMedia"> |
| 155 | +<span class="dangerousLink">[[Media:$filename|$filename]]</span> |
| 156 | +<span class="fileInfo"> ($info)</span> |
| 157 | +</div> |
| 158 | + |
| 159 | +<div class="mediaWarning">$warning</div> |
| 160 | +END |
| 161 | + ); |
| 162 | + } else { |
| 163 | + $wgOut->addWikiText( <<<END |
| 164 | +<div class="fullMedia"> |
| 165 | +[[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span> |
| 166 | +</div> |
| 167 | +END |
| 168 | + ); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + if( $this->getFile()->fromSharedDirectory ) { |
| 173 | + $this->printSharedImageText(); |
| 174 | + } |
| 175 | + } else { |
| 176 | + # Image does not exist |
| 177 | + $nofile = wfMsgHtml( 'filepage-nofile' ); |
| 178 | + if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) { |
| 179 | + // Only show an upload link if the user can upload |
| 180 | + $nofile .= ' '.$sk->makeKnownLinkObj( |
| 181 | + SpecialPage::getTitleFor( 'Upload' ), |
| 182 | + wfMsgHtml( 'filepage-nofile-link' ), |
| 183 | + 'wpDestFile=' . urlencode( $this->displayImg->getName() ) |
| 184 | + ); |
| 185 | + } |
| 186 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 187 | + $wgOut->addHTML( '<div id="mw-imagepage-nofile">' . $nofile . '</div>' ); |
| 188 | + } |
| 189 | + |
| 190 | + wfProfileOut( __METHOD__ ); |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * Create the TOC |
| 195 | + * |
| 196 | + * @access private |
| 197 | + * |
| 198 | + * @param $metadata Boolean: whether or not to show the metadata link |
| 199 | + * @return string |
| 200 | + */ |
| 201 | + function showTOC( $metadata ) { |
| 202 | + global $wgLang, $wgUser, $wgScriptPath; |
| 203 | + |
| 204 | + $metadataHTML = ''; |
| 205 | + if ( $metadata ) { |
| 206 | + $metadataHTML = '<li><a href="#metadata">' . |
| 207 | + wfMsgHtml( 'metadata' ) . '</a></li>'; |
| 208 | + } |
| 209 | + |
| 210 | + $r = '<ul id="filetoc"> |
| 211 | + <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li> |
| 212 | + <li><a href="#filehistory">' . wfMsgHtml( 'imagetagging-imghistory' ) . '</a></li> |
| 213 | + <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' . |
| 214 | + $metadataHTML . ' |
| 215 | + <li><a href="javascript:addImageTags()">' . |
| 216 | + wfMsgHtml( 'imagetagging-addimagetag' ) . '</a>' . |
| 217 | + wfMsg( 'imagetagging-new' ) .'</li>' |
| 218 | + . '</ul>'; |
| 219 | + |
| 220 | + $r .= '<div id="tagStatusDiv" style="margin: 5px 5px 10px 5px; padding: 10px; border: solid 1px #ffe222; background: #fffbe2; display: none;"><table style="background-color: #fffbe2;"><tr><td width="450" height="30" align="center" style="padding-left: 20px;"><img src="' . $wgScriptPath . '/extensions/ImageTagging/progress-wheel.gif" id="progress_wheel" style="display:none;"><div id="tagging_message" style="background: #fffbe2;">' . |
| 221 | + wfMsgHtml( 'imagetagging-tagging-instructions' ) . |
| 222 | + '</td><td valign="middle"><input type="button" onclick="doneAddingTags();" id="done_tagging" name="done_tagging" value="' . |
| 223 | + wfMsgHtml( 'imagetagging-done-button' ) . '" /></div></td></tr></table></div>'; |
| 224 | + |
| 225 | + $r .= '<div style="position: absolute; font: verdana, sans-serif; top: 10px; left: 10px; display: none; width:284px; height:24px; padding: 4px 6px; background-color: #eeeeee; color: #444444; border: 2px solid #555555; z-index:2;" id="tagEditField"> |
| 226 | + |
| 227 | + <span style="position: absolute; left: 4px; top: 6px;">' . |
| 228 | + wfMsg( 'imagetagging-article' ) . "</span> |
| 229 | + |
| 230 | + <!-- TAH: don't use the popup just yet |
| 231 | + <select name='tagType'> |
| 232 | + <option selected>Article</option> |
| 233 | + <option>Category</option> |
| 234 | + </select> |
| 235 | + -->"; |
| 236 | + |
| 237 | + $r .= '<input style="position: absolute; left: 189px; top: 6px; width: 39px; height: 20px;" type="submit" name="' . wfMsgHtml( 'imagetagging-tag-button' ) . "' value='" . wfMsgHtml( 'imagetagging-tag-button' ) . '" onclick="submitTag()" />'; |
| 238 | + $r .= '<input style="position: absolute; left: 232px; top: 6px; width: 60px; height: 20px;" type="button" name="' . wfMsgHtml( 'imagetagging-tagcancel-button' ) . "' value='" . wfMsgHtml( 'imagetagging-tagcancel-button' ) . '" onclick="hideTagBox()" />'; |
| 239 | + |
| 240 | + $r .= '<input type="text" style="position: absolute; left: 46px; top: 6px; background-color:white; width: 140px; height:18px;" name="articleTag" id="articleTag" value="" title="' . wfMsgHtml( 'imagetagging-articletotag' ) . '" onkeyup="typeTag(event);" />'; |
| 241 | + |
| 242 | + $r .= '</div>'; |
| 243 | + |
| 244 | + $r .= '<div id="popup" style="position:absolute; background-color: #eeeeee; top: 0px; left: 0px; z-index:3; visibility:hidden;"></div>'; |
| 245 | + |
| 246 | + #$r .= '</div>'; |
| 247 | + |
| 248 | + // TAH: adding this to grab edit tokens from javascript |
| 249 | + $token = $wgUser->editToken(); |
| 250 | + $r .= "<input type=\"hidden\" value=\"$token\" name=\"wpEditToken\" id=\"wpEditToken\" />\n"; |
| 251 | + $r .= "<input type=\"hidden\" id=\"addingtagmessage\" value=\"" . wfMsg( 'imagetagging-addingtag' ) . "\">\n"; |
| 252 | + $r .= "<input type=\"hidden\" id=\"removingtagmessage\" value=\"" . wfMsg( 'imagetagging-removingtag' ) . "\">\n"; |
| 253 | + $r .= "<input type=\"hidden\" id=\"addtagsuccessmessage\" value=\"" . wfMsg( 'imagetagging-addtagsuccess' ) . "\">\n"; |
| 254 | + $r .= "<input type=\"hidden\" id=\"removetagsuccessmessage\" value=\"" . wfMsg( 'imagetagging-removetagsuccess' ) . "\">\n"; |
| 255 | + |
| 256 | + $r .= "<input type=\"hidden\" id=\"oneactionatatimemessage\" value=\"" . wfMsg( 'imagetagging-oneactionatatimemessage' ) . "\">\n"; |
| 257 | + $r .= "<input type=\"hidden\" id=\"canteditneedloginmessage\" value=\"" . wfMsg( 'imagetagging-canteditneedloginmessage' ) . "\">\n"; |
| 258 | + $r .= "<input type=\"hidden\" id=\"canteditothermessage\" value=\"" . wfMsg( 'imagetagging-canteditothermessage' ) . "\">\n"; |
| 259 | + $r .= "<input type=\"hidden\" id=\"oneuniquetagmessage\" value=\"" . wfMsg( 'imagetagging-oneuniquetagmessage' ) . "\">\n"; |
| 260 | + |
| 261 | + return $r; |
| 262 | + } |
| 263 | +} |
\ No newline at end of file |
Index: trunk/extensions/ImageTagging/ImageTagging_body.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * @ingroup Extensions |
8 | 8 | */ |
9 | 9 | |
10 | | -define('TAGGEDIMGS_PER_PAGE', 12); |
| 10 | +define( 'TAGGEDIMGS_PER_PAGE', 12 ); |
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Photos tagged gallery |
— | — | @@ -19,62 +19,84 @@ |
20 | 20 | /** |
21 | 21 | * Create a new tagged images object. |
22 | 22 | */ |
23 | | - function __construct() { |
24 | | - global $wgLang, $wgAllowRealName, $wgRequest, $wgOut; |
| 23 | + public function __construct() { |
| 24 | + global $wgRequest, $wgOut; |
25 | 25 | |
26 | | - $wgOut->addScript("<style type=\"text/css\">/*<![CDATA[*/ @import \"$GLOBALS[wgScriptPath]/extensions/ImageTagging/img_tagging.css?$GLOBALS[wgStyleVersion]\"; /*]]>*/</style>\n"); |
| 26 | + $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/ImageTagging/img_tagging.css' ); |
27 | 27 | |
28 | | - $this->mQuery = preg_replace( "/[\"'<>]/", "", $wgRequest->getText('q') ); |
29 | | - $this->mStartPage = preg_replace( "/[\"'<>]/", "", $wgRequest->getVal('page') ); |
| 28 | + $this->mQuery = preg_replace( "/[\"'<>]/", '', $wgRequest->getText( 'q' ) ); |
| 29 | + $this->mStartPage = preg_replace( "/[\"'<>]/", '', $wgRequest->getVal( 'page' ) ); |
30 | 30 | $this->mCount = 0; |
31 | | - if ( ! $this->mStartPage ) |
32 | | - $this->mStartPage = 0; |
33 | | - $this->mImages = array(); |
| 31 | + if ( !$this->mStartPage ) { |
| 32 | + $this->mStartPage = 0; |
| 33 | + } |
| 34 | + $this->mImages = array(); |
34 | 35 | |
35 | | - parent::__construct('TaggedImages'); |
| 36 | + parent::__construct( 'TaggedImages' ); |
36 | 37 | } |
37 | 38 | |
38 | 39 | /** |
39 | 40 | * Start doing stuff |
40 | | - * @access public |
41 | | - */ |
42 | | - function execute( $par ) { |
43 | | - global $wgDBname, $wgOut; |
| 41 | + * |
| 42 | + * @param $par Mixed: parameter passed to the special page or null |
| 43 | + */ |
| 44 | + public function execute( $par ) { |
| 45 | + global $wgOut; |
44 | 46 | |
45 | 47 | wfProfileIn( __METHOD__ ); |
46 | 48 | |
47 | | - $db = wfGetDB(DB_SLAVE); |
| 49 | + $dbr = wfGetDB( DB_SLAVE ); |
48 | 50 | |
49 | | - $WHERECLAUSE = ''; |
50 | | - if ($this->mQuery) { |
51 | | - $WHERECLAUSE = " WHERE article_tag='$this->mQuery'"; |
52 | | - } |
| 51 | + $where = array(); |
| 52 | + if ( $this->mQuery ) { |
| 53 | + $where = array( |
| 54 | + 'article_tag' => $this->mQuery |
| 55 | + ); |
| 56 | + } |
| 57 | + $foo = $dbr->select( |
| 58 | + 'imagetags', |
| 59 | + 'img_name', |
| 60 | + $where, |
| 61 | + __METHOD__ |
| 62 | + ); |
| 63 | + $imageNames = array(); |
| 64 | + foreach ( $foo as $omg ) { |
| 65 | + $imageNames[] = $omg; |
| 66 | + } |
53 | 67 | |
54 | | - $imagetable = $db->tableName( 'image' ); |
55 | | - $imagetagstable = $db->tableName( 'imagetags' ); |
| 68 | + $imageNamesString = implode( ',' $imageNames ); // @todo CHECKME |
| 69 | + $res = $dbr->select( |
| 70 | + 'image', |
| 71 | + array( 'img_name', 'img_timestamp' ), |
| 72 | + array( "img_name IN $imageNamesString" ), |
| 73 | + __METHOD__, |
| 74 | + array( |
| 75 | + 'ORDER BY' => 'img_timestamp DESC', |
| 76 | + 'LIMIT' => TAGGEDIMGS_PER_PAGE, |
| 77 | + 'OFFSET' => $this->mStartPage * TAGGEDIMGS_PER_PAGE |
| 78 | + ) |
| 79 | + ); |
56 | 80 | |
57 | | - $SQL = "SELECT img_name, img_timestamp FROM $imagetable WHERE img_name IN (SELECT img_name FROM $imagetagstable $WHERECLAUSE) ORDER BY img_timestamp DESC"; |
58 | | - |
59 | | - $SQL = $db->LimitResult($SQL, TAGGEDIMGS_PER_PAGE, $this->mStartPage * TAGGEDIMGS_PER_PAGE); |
60 | | - |
61 | | - $res = $db->query($SQL); |
62 | | - while ($o = $db->fetchObject($res)) { |
63 | | - $img = wfFindFile($o->img_name); |
64 | | - $this->add($img, ''); |
| 81 | + foreach( $res as $o ) { |
| 82 | + $img = wfFindFile( $o->img_name ); |
| 83 | + $this->add( $img, '' ); |
65 | 84 | } |
66 | | - $db->freeResult($res); |
67 | 85 | |
68 | | - $res = $db->query("SELECT COUNT(img_name) as img_count FROM $imagetagstable". |
69 | | - ( $this->mQuery ? " WHERE article_tag='" . $this->mQuery . "'" : "" ) . |
70 | | - " GROUP BY article_tag"); |
71 | | - if ( $o = $db->fetchObject($res) ) { |
| 86 | + $res = $dbr->select( |
| 87 | + 'imagetags', |
| 88 | + 'COUNT(img_name) AS img_count', |
| 89 | + $where, |
| 90 | + __METHOD__, |
| 91 | + array( 'GROUP BY' => 'article_tag' ) |
| 92 | + ); |
| 93 | + $o = $dbr->fetchObject( $res ); |
| 94 | + if ( $o ) { |
72 | 95 | $this->mCount = $o->img_count; |
73 | 96 | } |
74 | | - $db->freeResult($res); |
75 | 97 | |
76 | | - $wgOut->setPageTitle( wfMsg('imagetagging-taggedimages-title', $this->mQuery ? $this->mQuery : "all" ) ); |
77 | | - $wgOut->setRobotPolicy('noindex,nofollow'); |
78 | | - $wgOut->addHTML($this->toHTML()); |
| 98 | + $wgOut->setPageTitle( wfMsg( 'imagetagging-taggedimages-title', $this->mQuery ? $this->mQuery : 'all' ) ); |
| 99 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 100 | + $wgOut->addHTML( $this->toHTML() ); |
79 | 101 | |
80 | 102 | wfProfileOut( __METHOD__ ); |
81 | 103 | } |
— | — | @@ -82,25 +104,27 @@ |
83 | 105 | /** |
84 | 106 | * Add an image to the gallery. |
85 | 107 | * |
86 | | - * @param Image $image Image object that is added to the gallery |
87 | | - * @param string $html Additional HTML text to be shown. The name and size of the image are always shown. |
| 108 | + * @param $image Object: Image object that is added to the gallery |
| 109 | + * @param $html String: additional HTML text to be shown. The name and size |
| 110 | + * of the image are always shown. |
88 | 111 | */ |
89 | | - function add( $image, $html='' ) { |
| 112 | + function add( $image, $html = '' ) { |
90 | 113 | $this->mImages[] = array( &$image, $html ); |
91 | 114 | } |
92 | 115 | |
93 | 116 | /** |
94 | 117 | * Add an image at the beginning of the gallery. |
95 | 118 | * |
96 | | - * @param Image $image Image object that is added to the gallery |
97 | | - * @param string $html Additional HTML text to be shown. The name and size of the image are always shown. |
| 119 | + * @param $image Object: Image object that is added to the gallery |
| 120 | + * @param $html String: additional HTML text to be shown. The name and size |
| 121 | + * of the image are always shown. |
98 | 122 | */ |
99 | | - function insert( $image, $html='' ) { |
| 123 | + function insert( $image, $html = '' ) { |
100 | 124 | array_unshift( $this->mImages, array( &$image, $html ) ); |
101 | 125 | } |
102 | 126 | |
103 | 127 | /** |
104 | | - * isEmpty() returns true if the gallery contains no images |
| 128 | + * @return Boolean: true if the gallery contains no images |
105 | 129 | */ |
106 | 130 | function isEmpty() { |
107 | 131 | return empty( $this->mImages ); |
— | — | @@ -111,56 +135,89 @@ |
112 | 136 | |
113 | 137 | $numPages = $this->mCount / TAGGEDIMGS_PER_PAGE; |
114 | 138 | |
115 | | - if (!$this->mQuery) $this->mQuery = "all"; |
| 139 | + if ( !$this->mQuery ) { |
| 140 | + $this->mQuery = 'all'; |
| 141 | + } |
116 | 142 | |
117 | | - $queryTitle = Title::newFromText($this->mQuery, NS_MAIN); |
| 143 | + $queryTitle = Title::newFromText( $this->mQuery, NS_MAIN ); |
118 | 144 | |
119 | | - $html = wfMsg('imagetagging-taggedimages-displaying', $this->mStartPage*TAGGEDIMGS_PER_PAGE + 1, min(($this->mStartPage+1)*TAGGEDIMGS_PER_PAGE,$this->mCount), $this->mCount, '<a href="' . $queryTitle->getLocalURL() . '">' . $this->mQuery . '</a>'); |
| 145 | + $html = wfMsg( |
| 146 | + 'imagetagging-taggedimages-displaying', |
| 147 | + $this->mStartPage * TAGGEDIMGS_PER_PAGE + 1, |
| 148 | + min( ( $this->mStartPage + 1 ) * TAGGEDIMGS_PER_PAGE, $this->mCount ), |
| 149 | + $this->mCount, |
| 150 | + '<a href="' . $queryTitle->getLocalURL() . '">' . $this->mQuery . '</a>' |
| 151 | + ); |
120 | 152 | |
121 | 153 | wfProfileOut( __METHOD__ ); |
122 | 154 | return $html; |
123 | 155 | } |
124 | 156 | |
125 | | - function pageNoLink($pageNum, $pageText, $hrefPrefix, $cur) { |
126 | | - if ( $cur == false ) |
127 | | - $html = '<a href="'. $hrefPrefix . $pageNum . '">' . $pageText . '</a>'; |
128 | | - else |
| 157 | + function pageNoLink( $pageNum, $pageText, $hrefPrefix, $cur ) { |
| 158 | + if ( $cur == false ) { |
| 159 | + $html = '<a href="'. $hrefPrefix . $pageNum . '">' . $pageText . |
| 160 | + '</a>'; |
| 161 | + } else { |
129 | 162 | $html = '<b>' . $pageText . '</b>'; |
| 163 | + } |
130 | 164 | |
131 | 165 | $html .= ' '; |
132 | 166 | return $html; |
133 | 167 | } |
134 | 168 | |
135 | | - function pagerHTML($topBottom) { |
| 169 | + function pagerHTML( $topBottom ) { |
136 | 170 | global $wgOut; |
137 | 171 | |
138 | 172 | $titleObj = SpecialPage::getTitleFor( 'TaggedImages' ); |
139 | 173 | |
140 | 174 | $maxPages = 5; // 5 real pagers |
141 | | - $numPages = ceil($this->mCount / TAGGEDIMGS_PER_PAGE); |
| 175 | + $numPages = ceil( $this->mCount / TAGGEDIMGS_PER_PAGE ); |
142 | 176 | |
143 | | - if ( $numPages <= 1 ) return ''; |
| 177 | + if ( $numPages <= 1 ) { |
| 178 | + return ''; |
| 179 | + } |
144 | 180 | |
145 | | - $html = '<span id="{$topBottom}pager" class="pager" style="float: right; text-align: right; right: 30px;">'; |
| 181 | + $html = "<span id=\"{$topBottom}pager\" class=\"pager\" style=\"float: right; text-align: right; right: 30px;\">"; |
146 | 182 | |
147 | | - $hrefPrefix = $titleObj->escapeLocalURL("q=" . $this->mQuery . "&page="); |
| 183 | + $hrefPrefix = $titleObj->escapeLocalURL( |
| 184 | + 'q=' . $this->mQuery . '&page=' |
| 185 | + ); |
148 | 186 | |
149 | 187 | // build prev button |
150 | 188 | if ( $this->mStartPage - 1 >= 0 ) { |
151 | | - $html .= $this->pageNoLink($this->mStartPage-1, wfMsg('allpagesprev'), $hrefPrefix, false); |
| 189 | + $html .= $this->pageNoLink( |
| 190 | + $this->mStartPage - 1, |
| 191 | + wfMsg( 'allpagesprev' ), |
| 192 | + $hrefPrefix, |
| 193 | + false |
| 194 | + ); |
152 | 195 | } |
153 | 196 | |
154 | 197 | // build page # buttons |
155 | | - for ( $i=$this->mStartPage-2; $i < $this->mStartPage + $maxPages; $i++ ) { |
156 | | - if ( $i >= $numPages ) break; |
157 | | - if ( $i < 0 ) continue; |
| 198 | + for ( $i = $this->mStartPage - 2; $i < $this->mStartPage + $maxPages; $i++ ) { |
| 199 | + if ( $i >= $numPages ) { |
| 200 | + break; |
| 201 | + } |
| 202 | + if ( $i < 0 ) { |
| 203 | + continue; |
| 204 | + } |
158 | 205 | |
159 | | - $html .= $this->pageNoLink($i, $i+1, $hrefPrefix, ($this->mStartPage == $i)); |
| 206 | + $html .= $this->pageNoLink( |
| 207 | + $i, |
| 208 | + $i + 1, |
| 209 | + $hrefPrefix, |
| 210 | + ( $this->mStartPage == $i ) |
| 211 | + ); |
160 | 212 | } |
161 | 213 | |
162 | 214 | // build next button |
163 | | - if ( $this->mStartPage < $numPages-1 ) { |
164 | | - $html .= $this->pageNoLink($this->mStartPage+1, wfMsg('allpagesnext'), $hrefPrefix, false); |
| 215 | + if ( $this->mStartPage < $numPages - 1 ) { |
| 216 | + $html .= $this->pageNoLink( |
| 217 | + $this->mStartPage + 1, |
| 218 | + wfMsg( 'allpagesnext' ), |
| 219 | + $hrefPrefix, |
| 220 | + false |
| 221 | + ); |
165 | 222 | } |
166 | 223 | |
167 | 224 | $html .= '</span>'; |
— | — | @@ -176,7 +233,6 @@ |
177 | 234 | * - the image name |
178 | 235 | * - the additional text provided when adding the image |
179 | 236 | * - the size of the image |
180 | | - * |
181 | 237 | */ |
182 | 238 | function toHTML() { |
183 | 239 | global $wgLang, $wgUser, $wgOut; |
— | — | @@ -185,7 +241,7 @@ |
186 | 242 | |
187 | 243 | $s = '<div>'; |
188 | 244 | $s .= $this->pagerStatusHTML(); |
189 | | - $s .= $this->pagerHTML('top'); |
| 245 | + $s .= $this->pagerHTML( 'top' ); |
190 | 246 | $s .= '</div>'; |
191 | 247 | |
192 | 248 | $s .= '<table class="gallery" cellspacing="0" cellpadding="0">'; |
— | — | @@ -200,7 +256,7 @@ |
201 | 257 | // Not an image. Just print the name and skip. |
202 | 258 | if ( $nt->getNamespace() != NS_IMAGE ) { |
203 | 259 | $s .= '<td><div class="gallerybox" style="height: 152px;">' . |
204 | | - htmlspecialchars( $nt->getText() ) . '</div></td>' . (($i%4==3) ? "</tr>\n" : ''); |
| 260 | + htmlspecialchars( $nt->getText() ) . '</div></td>' . ( ( $i%4 == 3 ) ? "</tr>\n" : ''); |
205 | 261 | $i++; |
206 | 262 | continue; |
207 | 263 | } |
— | — | @@ -213,7 +269,7 @@ |
214 | 270 | $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20 ) ) ) . "<br />\n" : |
215 | 271 | ''; |
216 | 272 | |
217 | | - $s .= ($i%4==0) ? '<tr>' : ''; |
| 273 | + $s .= ( $i%4 == 0 ) ? '<tr>' : ''; |
218 | 274 | $thumb = $img->getThumbnail( 120, 120 ); |
219 | 275 | $vpad = floor( ( 150 - $thumb->height ) /2 ) - 2; |
220 | 276 | $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">'; |
— | — | @@ -225,14 +281,14 @@ |
226 | 282 | $textlink . $text . $nb . |
227 | 283 | '</div>'; |
228 | 284 | $s .= "</div></td>\n"; |
229 | | - $s .= ($i%4==3) ? '</tr>' : ''; |
| 285 | + $s .= ( $i%4 == 3 ) ? '</tr>' : ''; |
230 | 286 | $i++; |
231 | 287 | } |
232 | 288 | if ( $i %4 != 0 ) { |
233 | 289 | $s .= "</tr>\n"; |
234 | 290 | } |
235 | 291 | $s .= '</table>'; |
236 | | - $s .= $this->pagerHTML('bottom'); |
| 292 | + $s .= $this->pagerHTML( 'bottom' ); |
237 | 293 | return $s; |
238 | 294 | } |
239 | 295 | } //class |
Index: trunk/extensions/ImageTagging/img_tagging.js |
— | — | @@ -1,4 +1,3 @@ |
2 | | - |
3 | 2 | var kBoxRatio = .28; |
4 | 3 | var kBoxMinDim = 84; |
5 | 4 | var kBoxBorderWidth = 4; |
— | — | @@ -10,418 +9,438 @@ |
11 | 10 | var imageElem = null; |
12 | 11 | var taggingBusy = false; |
13 | 12 | |
14 | | -var kMessageAddingTag = "addingtagmessage"; |
15 | | -var kMessageRemovingTag = "removingtagmessage"; |
16 | | -var kMessageAddTagSuccess = "addtagsuccessmessage"; |
17 | | -var kMessageRemoveTagSuccess = "removetagsuccessmessage"; |
18 | | -var kMessageOneActionAtATime = "oneactionatatimemessage"; |
19 | | -var kMessageCantEditNeedLogin = "canteditneedloginmessage"; |
20 | | -var kMessageCantEditOther = "canteditothermessage"; |
21 | | -var kMessageOneUniqueTag = "oneuniquetagmessage"; |
| 13 | +var kMessageAddingTag = 'addingtagmessage'; |
| 14 | +var kMessageRemovingTag = 'removingtagmessage'; |
| 15 | +var kMessageAddTagSuccess = 'addtagsuccessmessage'; |
| 16 | +var kMessageRemoveTagSuccess = 'removetagsuccessmessage'; |
| 17 | +var kMessageOneActionAtATime = 'oneactionatatimemessage'; |
| 18 | +var kMessageCantEditNeedLogin = 'canteditneedloginmessage'; |
| 19 | +var kMessageCantEditOther = 'canteditothermessage'; |
| 20 | +var kMessageOneUniqueTag = 'oneuniquetagmessage'; |
22 | 21 | |
23 | | -function gid(id) { |
24 | | - return document.getElementById(id); |
| 22 | +function gid( id ) { |
| 23 | + return document.getElementById( id ); |
25 | 24 | } |
26 | 25 | |
27 | 26 | function setupImageTagging() { |
28 | | - var imgDiv = gid('file'); |
29 | | - imgDiv.onclick = function(e) { |
| 27 | + var imgDiv = gid( 'file' ); |
| 28 | + imgDiv.onclick = function( e ) { |
30 | 29 | |
31 | | - if (!e) var e = window.event; |
32 | | - //var tg = (window.event) ? e.srcElement : e.target; |
33 | | - //if (tg.nodeName != 'DIV') return; |
| 30 | + if ( !e ) { |
| 31 | + var e = window.event; |
| 32 | + } |
| 33 | + //var tg = (window.event) ? e.srcElement : e.target; |
| 34 | + //if (tg.nodeName != 'DIV') return; |
34 | 35 | |
35 | | - // Mouseout took place when mouse actually left layer |
36 | | - var imgDivAbsLoc = getElemAbsPosition(imgDiv); |
| 36 | + // Mouseout took place when mouse actually left layer |
| 37 | + var imgDivAbsLoc = getElemAbsPosition( imgDiv ); |
37 | 38 | |
38 | | - clickAt(e.clientX - imgDivAbsLoc.x, e.clientY - imgDivAbsLoc.y); |
| 39 | + clickAt( e.clientX - imgDivAbsLoc.x, e.clientY - imgDivAbsLoc.y ); |
39 | 40 | |
40 | | - if(e.preventDefault) { e.preventDefault() } else { e.returnResult = false } |
41 | | - if(e.stopPropagation) { e.stopPropagation() } else { e.cancelBubble = true } |
42 | | - }; |
| 41 | + if( e.preventDefault ) { |
| 42 | + e.preventDefault(); |
| 43 | + } else { |
| 44 | + e.returnResult = false; |
| 45 | + } |
| 46 | + |
| 47 | + if( e.stopPropagation ) { |
| 48 | + e.stopPropagation(); |
| 49 | + } else { |
| 50 | + e.cancelBubble = true; |
| 51 | + } |
| 52 | + }; |
43 | 53 | } |
44 | 54 | |
45 | 55 | function tearDownImageTagging() { |
46 | | - var imgDiv = gid('file'); |
| 56 | + var imgDiv = gid( 'file' ); |
47 | 57 | |
48 | | - imgDiv.onclick = function(e) { |
49 | | - e.stopPropagation(); |
50 | | - e.preventDefault(); |
51 | | - } |
| 58 | + imgDiv.onclick = function( e ) { |
| 59 | + e.stopPropagation(); |
| 60 | + e.preventDefault(); |
| 61 | + } |
52 | 62 | } |
53 | 63 | |
54 | 64 | function addImageTags() { |
55 | | - if ( gid('canEditPage') == null ) { /* page isn't editable */ |
56 | | - var result = false; |
57 | | - var re = /http:\/\/([^\/]*)\//g; |
58 | | - var matches = re.exec(window.location.href); |
59 | | - if ( !matches ) { |
60 | | - // TAH: firefox bug: have to do it twice for it to work |
61 | | - matches = re.exec(window.location.href); |
62 | | - } |
63 | | - var domain = matches[1]; |
64 | | - var subdomainRe = /(.*).wikia.com/; |
65 | | - matches = subdomainRe.exec(domain); |
66 | | - var subdomain = matches ? matches[1] : null; |
| 65 | + if ( gid( 'canEditPage' ) == null ) { /* page isn't editable */ |
| 66 | + var result = false; |
67 | 67 | |
68 | | - if ( gid('userLoggedIn') == null ) |
69 | | - result = confirm(gid(kMessageCantEditNeedLogin).value); |
70 | | - else |
71 | | - alert(gid(kMessageCantEditOther).value); |
| 68 | + if ( gid( 'userLoggedIn' ) == null ) { |
| 69 | + result = confirm( gid( kMessageCantEditNeedLogin ).value ); |
| 70 | + } else { |
| 71 | + alert( gid( kMessageCantEditOther ).value ); |
| 72 | + } |
72 | 73 | |
73 | | - if ( result ) { |
74 | | - var articleName = gid('imgName').value; |
| 74 | + if ( result ) { |
| 75 | + var articleName = gid( 'imgName' ).value; |
75 | 76 | |
76 | | - var loginPageURL = "http://" + domain; |
77 | | - if ( articleName && articleName.length > 0 ) |
78 | | - loginPageURL += wgScriptPath + "/index.php?title=Special:Userlogin&returnto=Image:"+articleName; |
79 | | - else |
80 | | - loginPageURL += wgScriptPath + "/Special:Userlogin"; |
| 77 | + var loginPageURL = 'http://' + domain; |
| 78 | + if ( articleName && articleName.length > 0 ) { |
| 79 | + loginPageURL += wgScriptPath + '/index.php?title=Special:UserLogin&returnto=Image:' + articleName; |
| 80 | + } else { |
| 81 | + loginPageURL += wgScriptPath + '/Special:UserLogin'; |
| 82 | + } |
81 | 83 | |
82 | | - window.location.href = loginPageURL; |
83 | | - } |
| 84 | + window.location.href = loginPageURL; |
| 85 | + } |
84 | 86 | |
85 | | - return; |
86 | | - } |
| 87 | + return; |
| 88 | + } |
87 | 89 | |
88 | | - if ( !tagStatusDiv ) { |
89 | | - tagStatusDiv = document.getElementById('tagStatusDiv'); |
| 90 | + if ( !tagStatusDiv ) { |
| 91 | + tagStatusDiv = document.getElementById( 'tagStatusDiv' ); |
90 | 92 | |
91 | | - var bodyContent = gid('bodyContent') || gid('content') || document; |
92 | | - bodyContent.insertBefore(tagStatusDiv, gid('file')); |
93 | | - } |
| 93 | + var bodyContent = gid( 'bodyContent' ) || gid( 'content') || document; |
| 94 | + bodyContent.insertBefore( tagStatusDiv, gid( 'file' ) ); |
| 95 | + } |
94 | 96 | |
95 | | - tagStatusDiv.style.display = "block"; |
96 | | - setupImageTagging(); |
| 97 | + tagStatusDiv.style.display = 'block'; |
| 98 | + setupImageTagging(); |
97 | 99 | } |
98 | 100 | |
99 | 101 | function doneAddingTags() { |
100 | | - tagStatusDiv.style.display = "none"; |
101 | | - hideTagBox(); |
102 | | - tearDownImageTagging(); |
| 102 | + tagStatusDiv.style.display = 'none'; |
| 103 | + hideTagBox(); |
| 104 | + tearDownImageTagging(); |
103 | 105 | } |
104 | 106 | |
105 | | -function typeTag (event) { |
106 | | - //suggestKeyDown(event); |
107 | | - /*switch (event.keyCode) { |
| 107 | +function typeTag( event ) { |
| 108 | + //suggestKeyDown( event ); |
| 109 | + /*switch ( event.keyCode ) { |
108 | 110 | case 13: // return |
109 | | - case 3: // enter |
110 | | - submitTag(); |
| 111 | + case 3: // enter |
| 112 | + submitTag(); |
111 | 113 | break; |
112 | | - default: |
113 | | - suggestKeyDown(event); |
114 | | - break; |
| 114 | + default: |
| 115 | + suggestKeyDown( event ); |
| 116 | + break; |
115 | 117 | }*/ |
116 | 118 | } |
117 | 119 | |
118 | 120 | function createRequest() { |
119 | | - if ( taggingBusy ) { |
120 | | - alert(gid(kMessageOneActionAtATime).value); |
121 | | - return null; |
122 | | - } |
| 121 | + if ( taggingBusy ) { |
| 122 | + alert( gid( kMessageOneActionAtATime ).value ); |
| 123 | + return null; |
| 124 | + } |
123 | 125 | |
124 | | - var request = null; |
125 | | - try { |
126 | | - request = new XMLHttpRequest(); |
127 | | - } catch (trymicrosoft) { |
128 | | - try { |
129 | | - request = new ActiveXObject("Msxml2.XMLHTTP"); |
130 | | - } catch (othermicrosoft) { |
131 | | - try { |
132 | | - request = new ActiveXObject("Microsoft.XMLHTTP"); |
133 | | - } catch (failed) { |
134 | | - request = null; |
135 | | - } |
136 | | - } |
137 | | - } |
| 126 | + var request = null; |
| 127 | + try { |
| 128 | + request = new XMLHttpRequest(); |
| 129 | + } catch ( trymicrosoft ) { |
| 130 | + try { |
| 131 | + request = new ActiveXObject( 'Msxml2.XMLHTTP' ); |
| 132 | + } catch ( othermicrosoft ) { |
| 133 | + try { |
| 134 | + request = new ActiveXObject( 'Microsoft.XMLHTTP' ); |
| 135 | + } catch ( failed ) { |
| 136 | + request = null; |
| 137 | + } |
| 138 | + } |
| 139 | + } |
138 | 140 | |
139 | | - if (!request) |
140 | | - alert("Error initializing XMLHttpRequest!"); |
| 141 | + if ( !request ) { |
| 142 | + alert( 'Error initializing XMLHttpRequest in img_tagging.js!' ); |
| 143 | + } |
141 | 144 | |
142 | | - return request; |
| 145 | + return request; |
143 | 146 | } |
144 | 147 | |
145 | | -function setTaggingStatus(msg, busy) { |
146 | | - gid("progress_wheel").style.display = busy ? "block" : "none"; |
147 | | - gid("tagging_message").innerHTML = gid(msg).getAttribute("value"); |
| 148 | +function setTaggingStatus( msg, busy ) { |
| 149 | + gid( 'progress_wheel' ).style.display = busy ? 'block' : 'none'; |
| 150 | + gid( 'tagging_message' ).innerHTML = gid( msg ).getAttribute( 'value' ); |
148 | 151 | } |
149 | 152 | |
150 | 153 | function submitTag() { |
151 | | - var tagValue = gid("articleTag").value; |
152 | | - // if tag already exists |
153 | | - if ( gid(tagValue + "-tag") != null ) { |
154 | | - alert(gid(kMessageOneUniqueTag).value); |
155 | | - return null; |
156 | | - } |
| 154 | + var tagValue = gid( 'articleTag' ).value; |
| 155 | + // if tag already exists |
| 156 | + if ( gid( tagValue + '-tag' ) != null ) { |
| 157 | + alert( gid( kMessageOneUniqueTag ).value ); |
| 158 | + return null; |
| 159 | + } |
157 | 160 | |
158 | | - var request = createRequest(); |
159 | | - if ( request ) { |
160 | | - taggingBusy = true; |
| 161 | + var request = createRequest(); |
| 162 | + if ( request ) { |
| 163 | + taggingBusy = true; |
161 | 164 | |
162 | | - var imgValue = gid("imgName").value; |
163 | | - var url = "?action=addTag"; |
164 | | - var args = "rect="+getStringTagRect()+"&imgName="+escape(imgValue)+"&tagName="+encodeURIComponent(tagValue)+"&wpEditToken="+gid('wpEditToken').value; |
165 | | - request.open("GET", url + "&" + args, true); |
166 | | - request.onload = function(e) { |
167 | | - if ( request && request.responseText ) { |
168 | | - gid('tagListDiv').innerHTML = request.responseText; |
| 165 | + var imgValue = gid( 'imgName' ).value; |
| 166 | + var url = '?action=addTag'; |
| 167 | + var args = 'rect=' + getStringTagRect() + '&imgName=' + |
| 168 | + escape( imgValue ) + '&tagName=' + |
| 169 | + encodeURIComponent( tagValue ) + |
| 170 | + '&wpEditToken=' + gid( 'wpEditToken' ).value; |
| 171 | + request.open( 'GET', url + '&' + args, true ); |
| 172 | + request.onload = function( e ) { |
| 173 | + if ( request && request.responseText ) { |
| 174 | + gid( 'tagListDiv' ).innerHTML = request.responseText; |
169 | 175 | |
170 | | - setTaggingStatus(kMessageAddTagSuccess, false); |
171 | | - taggingBusy = false; |
172 | | - } |
173 | | - }; |
| 176 | + setTaggingStatus( kMessageAddTagSuccess, false ); |
| 177 | + taggingBusy = false; |
| 178 | + } |
| 179 | + }; |
174 | 180 | |
175 | | - //alert("adding tag with name: " + tagValue + ", rectStr: " + getStringTagRect() + ", imgName: " + imgValue + ", and maybe editToekn: " + gid('wpEditToken').value); |
176 | | - request.send(null); |
177 | | - setTaggingStatus(kMessageAddingTag, true); |
178 | | - hideTagBox(); |
179 | | - } |
| 181 | + //alert("adding tag with name: " + tagValue + ", rectStr: " + getStringTagRect() + ", imgName: " + imgValue + ", and maybe editToekn: " + gid('wpEditToken').value); |
| 182 | + request.send( null ); |
| 183 | + setTaggingStatus( kMessageAddingTag, true ); |
| 184 | + hideTagBox(); |
| 185 | + } |
180 | 186 | } |
181 | 187 | |
182 | | -function removeTag(tagID, elem, tagValue) { |
183 | | - var request = createRequest(); |
184 | | - if ( request ) { |
185 | | - taggingBusy = true; |
| 188 | +function removeTag( tagID, elem, tagValue ) { |
| 189 | + var request = createRequest(); |
| 190 | + if ( request ) { |
| 191 | + taggingBusy = true; |
186 | 192 | |
187 | | - var url = "?action=removeTag"; |
188 | | - var args = "rect="+getStringTagRect()+"&tagID="+tagID+"&imgName="+escape(gid('imgName').value)+"&tagName="+encodeURIComponent(tagValue); |
189 | | - request.open("GET", url + "&" + args, true); |
190 | | - request.onload = function(e) { |
191 | | - if ( request && request.responseText ) { |
192 | | - //alert("removeTag response: " + request.responseText); |
193 | | - gid('tagListDiv').innerHTML = request.responseText; |
194 | | - hideTagBox(); |
| 193 | + var url = '?action=removeTag'; |
| 194 | + var args = 'rect=' + getStringTagRect() + '&tagID=' + tagID + |
| 195 | + '&imgName=' + escape( gid( 'imgName' ).value ) + |
| 196 | + '&tagName=' + encodeURIComponent( tagValue ); |
| 197 | + request.open( 'GET', url + '&' + args, true ); |
| 198 | + request.onload = function( e ) { |
| 199 | + if ( request && request.responseText ) { |
| 200 | + //alert("removeTag response: " + request.responseText); |
| 201 | + gid( 'tagListDiv' ).innerHTML = request.responseText; |
| 202 | + hideTagBox(); |
195 | 203 | |
196 | | - taggingBusy = false; |
197 | | - } |
198 | | - }; |
199 | | - request.send(null); |
| 204 | + taggingBusy = false; |
| 205 | + } |
| 206 | + }; |
| 207 | + request.send( null ); |
200 | 208 | |
201 | | - var removeTagMsg = gid(kMessageRemovingTag).getAttribute("value"); |
202 | | - elem.setAttribute("onclick", null); |
203 | | - elem.innerHTML = " " + removeTagMsg; |
| 209 | + var removeTagMsg = gid( kMessageRemovingTag ).getAttribute( 'value' ); |
| 210 | + elem.setAttribute( 'onclick', null ); |
| 211 | + elem.innerHTML = ' ' + removeTagMsg; |
204 | 212 | |
205 | | - if ( elem.parentNode ) { |
206 | | - var progressElem = document.createElement('img'); |
207 | | - progressElem.src = gid("imgPath").value + "/progress-wheel.gif"; |
208 | | - progressElem.setAttribute("style", "vertical-align: bottom;"); |
209 | | - elem.parentNode.insertBefore(progressElem, elem); |
210 | | - } |
211 | | - } |
212 | | -} |
| 213 | + if ( elem.parentNode ) { |
| 214 | + var progressElem = document.createElement( 'img' ); |
| 215 | + progressElem.src = gid( 'imgPath' ).value + '/progress-wheel.gif'; |
| 216 | + progressElem.setAttribute( 'style', 'vertical-align: bottom;' ); |
| 217 | + elem.parentNode.insertBefore( progressElem, elem ); |
| 218 | + } |
| 219 | + } |
| 220 | +} |
213 | 221 | |
214 | 222 | function getStringTagRect() { |
215 | | - var tagBoxFrame = getElemFrame(tagBoxDiv, true); |
216 | | - var imgDivFrame = getElemAbsPosition(gid('file')); |
217 | | - var imgFrame = getImgFrame(findChild(gid('file'), 'img')); |
| 223 | + var tagBoxFrame = getElemFrame( tagBoxDiv, true ); |
| 224 | + var imgDivFrame = getElemAbsPosition( gid( 'file' ) ); |
| 225 | + var imgFrame = getImgFrame( findChild( gid( 'file' ), 'img' ) ); |
218 | 226 | |
219 | | - //alert("getStringTagRect, tagBoxFrame: " + tagBoxFrame.x + ", " + tagBoxFrame.y + ", w/h: " + tagBoxFrame.width + ", " + tagBoxFrame.height + ", imgDivFrame: " + imgDivFrame.x + ", " + imgDivFrame.y + ", diff: " + (tagBoxFrame.x - imgDivFrame.x) + ", " + (tagBoxFrame.y - imgDivFrame.y) + ", imgFrame: " + imgFrame.width + ", " + imgFrame.height); |
| 227 | + //alert("getStringTagRect, tagBoxFrame: " + tagBoxFrame.x + ", " + tagBoxFrame.y + ", w/h: " + tagBoxFrame.width + ", " + tagBoxFrame.height + ", imgDivFrame: " + imgDivFrame.x + ", " + imgDivFrame.y + ", diff: " + (tagBoxFrame.x - imgDivFrame.x) + ", " + (tagBoxFrame.y - imgDivFrame.y) + ", imgFrame: " + imgFrame.width + ", " + imgFrame.height); |
220 | 228 | |
221 | | - tagBoxFrame.x = tagBoxFrame.x - imgDivFrame.x; |
222 | | - tagBoxFrame.y = tagBoxFrame.y - imgDivFrame.y; |
| 229 | + tagBoxFrame.x = tagBoxFrame.x - imgDivFrame.x; |
| 230 | + tagBoxFrame.y = tagBoxFrame.y - imgDivFrame.y; |
223 | 231 | |
224 | | - var percentX = (tagBoxFrame.x + tagBoxFrame.width/2.0) / imgFrame.width; |
225 | | - var percentY = (tagBoxFrame.y + tagBoxFrame.height/2.0) / imgFrame.height; |
| 232 | + var percentX = ( tagBoxFrame.x + tagBoxFrame.width / 2.0 ) / imgFrame.width; |
| 233 | + var percentY = ( tagBoxFrame.y + tagBoxFrame.height / 2.0 ) / imgFrame.height; |
226 | 234 | |
227 | | - //alert("percents " + percentX + ", " + percentY); |
| 235 | + //alert("percents " + percentX + ", " + percentY); |
228 | 236 | |
229 | | - return escape(percentX + "," + percentY); |
| 237 | + return escape( percentX + ',' + percentY ); |
230 | 238 | } |
231 | 239 | |
232 | | -function tagBoxPercent(xPercent, yPercent, showEditUI) { |
233 | | - var imgRect = getImgFrame(findChild(gid('file'), 'img')); |
234 | | - tagBoxAt(xPercent * imgRect.width, yPercent * imgRect.height, showEditUI); |
| 240 | +function tagBoxPercent( xPercent, yPercent, showEditUI ) { |
| 241 | + var imgRect = getImgFrame( findChild( gid( 'file' ), 'img' ) ); |
| 242 | + tagBoxAt( xPercent * imgRect.width, yPercent * imgRect.height, showEditUI ); |
235 | 243 | } |
236 | 244 | |
237 | | -function tagBoxAt(boxCenterX, boxCenterY, showEditUI) { |
238 | | - var imgDiv = gid('file'); |
| 245 | +function tagBoxAt( boxCenterX, boxCenterY, showEditUI ) { |
| 246 | + var imgDiv = gid( 'file' ); |
239 | 247 | |
240 | | - if ( !tagBoxDiv ) { |
241 | | - tagBoxDiv = document.createElement('div'); |
242 | | - tagBoxDiv.style.border = kBoxBorderWidth + "px solid gray"; |
243 | | - tagBoxDiv.style.display = "block"; |
244 | | - tagBoxDiv.style.position = "absolute"; |
| 248 | + if ( !tagBoxDiv ) { |
| 249 | + tagBoxDiv = document.createElement( 'div' ); |
| 250 | + tagBoxDiv.style.border = kBoxBorderWidth + 'px solid gray'; |
| 251 | + tagBoxDiv.style.display = 'block'; |
| 252 | + tagBoxDiv.style.position = 'absolute'; |
245 | 253 | |
246 | | - tagBoxInnerDiv = document.createElement('div'); |
247 | | - tagBoxInnerDiv.style.border = Math.floor(kBoxBorderWidth/2.0) + "px solid white"; |
248 | | - tagBoxInnerDiv.style.display = "block"; |
249 | | - tagBoxInnerDiv.style.position = "absolute"; |
250 | | - tagBoxInnerDiv.style.left = "0px"; |
251 | | - tagBoxInnerDiv.style.top = "0px"; |
| 254 | + tagBoxInnerDiv = document.createElement( 'div' ); |
| 255 | + tagBoxInnerDiv.style.border = Math.floor( kBoxBorderWidth / 2.0 ) + 'px solid white'; |
| 256 | + tagBoxInnerDiv.style.display = 'block'; |
| 257 | + tagBoxInnerDiv.style.position = 'absolute'; |
| 258 | + tagBoxInnerDiv.style.left = '0px'; |
| 259 | + tagBoxInnerDiv.style.top = '0px'; |
252 | 260 | |
253 | | - tagBoxDiv.appendChild(tagBoxInnerDiv); |
254 | | - imgDiv.appendChild(tagBoxDiv); |
255 | | - } |
| 261 | + tagBoxDiv.appendChild( tagBoxInnerDiv ); |
| 262 | + imgDiv.appendChild( tagBoxDiv ); |
| 263 | + } |
256 | 264 | |
257 | | - var imgRect = getImgFrame(findChild(gid('file'), 'img')); |
258 | | - var boxDim = kBoxRatio * Math.min(imgRect.width, imgRect.height); |
259 | | - if ( boxDim < kBoxMinDim ) |
260 | | - boxDim = kBoxMinDim; |
| 265 | + var imgRect = getImgFrame( findChild( gid( 'file' ), 'img' ) ); |
| 266 | + var boxDim = kBoxRatio * Math.min( imgRect.width, imgRect.height ); |
| 267 | + if ( boxDim < kBoxMinDim ) { |
| 268 | + boxDim = kBoxMinDim; |
| 269 | + } |
261 | 270 | |
262 | | - var boxX = boxCenterX - boxDim/2.0; |
263 | | - var boxY = boxCenterY - boxDim/2.0; |
264 | | - if ( boxX + boxDim >= imgRect.width ) |
265 | | - boxX = imgRect.width - boxDim; |
266 | | - if ( boxX <= 0 ) |
267 | | - boxX = 0; |
268 | | - if ( boxY + boxDim >= imgRect.height ) |
269 | | - boxY = imgRect.height - boxDim; |
270 | | - if ( boxY <= 0 ) |
271 | | - boxY = 0; |
| 271 | + var boxX = boxCenterX - boxDim / 2.0; |
| 272 | + var boxY = boxCenterY - boxDim / 2.0; |
| 273 | + if ( boxX + boxDim >= imgRect.width ) { |
| 274 | + boxX = imgRect.width - boxDim; |
| 275 | + } |
| 276 | + if ( boxX <= 0 ) { |
| 277 | + boxX = 0; |
| 278 | + } |
| 279 | + if ( boxY + boxDim >= imgRect.height ) { |
| 280 | + boxY = imgRect.height - boxDim; |
| 281 | + } |
| 282 | + if ( boxY <= 0 ) { |
| 283 | + boxY = 0; |
| 284 | + } |
272 | 285 | |
273 | | - boxX += imgDiv.offsetLeft; |
274 | | - boxY += imgDiv.offsetTop; |
| 286 | + boxX += imgDiv.offsetLeft; |
| 287 | + boxY += imgDiv.offsetTop; |
275 | 288 | |
276 | | - boxCenterX = boxX + boxDim/2.0; |
277 | | - boxCenterY = boxY + boxDim/2.0; |
| 289 | + boxCenterX = boxX + boxDim / 2.0; |
| 290 | + boxCenterY = boxY + boxDim / 2.0; |
278 | 291 | |
279 | | - setTagBoxRect(boxX, boxY, boxDim, boxDim); |
280 | | - tagBoxDiv.style.display = "block"; |
| 292 | + setTagBoxRect( boxX, boxY, boxDim, boxDim ); |
| 293 | + tagBoxDiv.style.display = 'block'; |
281 | 294 | |
282 | | - if ( !tagEditFieldDiv ) |
283 | | - tagEditFieldDiv = gid('tagEditField'); |
| 295 | + if ( !tagEditFieldDiv ) { |
| 296 | + tagEditFieldDiv = gid( 'tagEditField' ); |
| 297 | + } |
284 | 298 | |
285 | | - if ( showEditUI ) { |
286 | | - var tagEditFrame = getElemFrame(tagEditFieldDiv); |
287 | | - setElemPosition(tagEditFieldDiv, boxCenterX - tagEditFrame.width/2.0, boxCenterY + boxDim/2.0 + 10); |
| 299 | + if ( showEditUI ) { |
| 300 | + var tagEditFrame = getElemFrame( tagEditFieldDiv ); |
| 301 | + setElemPosition( |
| 302 | + tagEditFieldDiv, |
| 303 | + boxCenterX - tagEditFrame.width / 2.0, |
| 304 | + boxCenterY + boxDim / 2.0 + 10 |
| 305 | + ); |
288 | 306 | |
289 | | - if ( tagEditFieldDiv.style.display != "block" ) |
290 | | - gid('articleTag').value = ""; |
291 | | - tagEditFieldDiv.style.display = "block"; |
| 307 | + if ( tagEditFieldDiv.style.display != 'block' ) { |
| 308 | + gid( 'articleTag' ).value = ''; |
| 309 | + } |
| 310 | + tagEditFieldDiv.style.display = 'block'; |
292 | 311 | |
293 | | - gid('articleTag').focus(); |
294 | | - } |
| 312 | + gid( 'articleTag' ).focus(); |
| 313 | + } |
295 | 314 | } |
296 | 315 | |
297 | | -function clickAt(xLocation, yLocation) { |
298 | | - if ( !imageElem ) { |
299 | | - var imgFileDiv = gid('file'); |
300 | | - imageElem = findChild(imgFileDiv, 'img'); |
301 | | - } |
302 | | - |
303 | | - var imgRect = getImgFrame(findChild(gid('file'), 'img')); |
304 | | - tagBoxPercent(xLocation / imgRect.width, yLocation / imgRect.height, true); |
| 316 | +function clickAt( xLocation, yLocation ) { |
| 317 | + if ( !imageElem ) { |
| 318 | + var imgFileDiv = gid( 'file' ); |
| 319 | + imageElem = findChild( imgFileDiv, 'img' ); |
| 320 | + } |
| 321 | + |
| 322 | + var imgRect = getImgFrame( findChild( gid( 'file' ), 'img' ) ); |
| 323 | + tagBoxPercent( xLocation / imgRect.width, yLocation / imgRect.height, true ); |
305 | 324 | } |
306 | 325 | |
307 | | -function setElemFrame(elem, newFrame) { |
308 | | - setElemPosition(elem, newFrame.x, newFrame.y); |
309 | | - elem.style["width"] = newFrame.width + "px"; |
310 | | - elem.style["height"] = newFrame.height + "px"; |
| 326 | +function setElemFrame( elem, newFrame ) { |
| 327 | + setElemPosition( elem, newFrame.x, newFrame.y ); |
| 328 | + elem.style['width'] = newFrame.width + 'px'; |
| 329 | + elem.style['height'] = newFrame.height + 'px'; |
311 | 330 | } |
312 | 331 | |
313 | | -function setElemRect(elem, x, y, width, height) { |
314 | | - setElemFrame(elem, {x:x, y:y, width:width, height:height}); |
| 332 | +function setElemRect( elem, x, y, width, height ) { |
| 333 | + setElemFrame( elem, { x: x, y: y, width: width, height: height} ); |
315 | 334 | } |
316 | 335 | |
317 | | -function setElemPosition(elem, x, y) { |
318 | | - elem.style["left"] = x + "px"; |
319 | | - elem.style["top"] = y + "px"; |
| 336 | +function setElemPosition( elem, x, y ) { |
| 337 | + elem.style['left'] = x + 'px'; |
| 338 | + elem.style['top'] = y + 'px'; |
320 | 339 | } |
321 | 340 | |
322 | | -function getImgFrame(img) { |
323 | | - return {x:0, y:0, width:img.width, height:img.height}; |
| 341 | +function getImgFrame( img ) { |
| 342 | + return { x: 0, y: 0, width: img.width, height: img.height }; |
324 | 343 | } |
325 | 344 | |
326 | | -function getElemAbsPosition(elem) { |
327 | | - var curleft = 0, curtop = 0; |
328 | | - var obj = elem; |
329 | | - if (obj.offsetParent) { |
330 | | - while (obj.offsetParent) |
331 | | - { |
332 | | - curleft += obj.offsetLeft; |
| 345 | +function getElemAbsPosition( elem ) { |
| 346 | + var curleft = 0, curtop = 0; |
| 347 | + var obj = elem; |
| 348 | + if ( obj.offsetParent ) { |
| 349 | + while ( obj.offsetParent ) { |
| 350 | + curleft += obj.offsetLeft; |
333 | 351 | curtop += obj.offsetTop; |
334 | 352 | obj = obj.offsetParent; |
335 | 353 | } |
| 354 | + } else if ( obj.y ) { |
| 355 | + curtop += obj.y; |
| 356 | + curleft += obj.x; |
336 | 357 | } |
337 | | - else if (obj.y) { |
338 | | - curtop += obj.y; |
339 | | - curleft += obj.x; |
340 | | - } |
341 | 358 | |
342 | | - return {x: curleft, y:curtop}; |
| 359 | + return { x: curleft, y: curtop }; |
343 | 360 | } |
344 | 361 | |
345 | | -function getElemFrame(elem, globalPos) { |
346 | | - var style = elem.style; |
347 | | - var x, y, width, height; |
348 | | - |
349 | | - if ( elem == document ) { |
350 | | - x = 0; y = 0; width = window.width; height = window.height; |
351 | | - } |
352 | | - else { |
353 | | - if ( globalPos ) { |
354 | | - var t = getElemAbsPosition(elem); |
355 | | - x = t.x; |
356 | | - y = t.y; |
357 | | - }else { |
358 | | - x = parseFloat(style["left"]); |
359 | | - y = parseFloat(style["top"]); |
360 | | - } |
361 | | - |
362 | | - width = parseFloat(style["width"]); |
363 | | - height = parseFloat(style["height"]); |
364 | | - } |
| 362 | +function getElemFrame( elem, globalPos ) { |
| 363 | + var style = elem.style; |
| 364 | + var x, y, width, height; |
365 | 365 | |
366 | | - return {x:x, y:y, width:width, height:height}; |
| 366 | + if ( elem == document ) { |
| 367 | + x = 0; |
| 368 | + y = 0; |
| 369 | + width = window.width; |
| 370 | + height = window.height; |
| 371 | + } else { |
| 372 | + if ( globalPos ) { |
| 373 | + var t = getElemAbsPosition( elem ); |
| 374 | + x = t.x; |
| 375 | + y = t.y; |
| 376 | + } else { |
| 377 | + x = parseFloat( style['left'] ); |
| 378 | + y = parseFloat( style['top'] ); |
| 379 | + } |
| 380 | + |
| 381 | + width = parseFloat( style['width'] ); |
| 382 | + height = parseFloat( style['height'] ); |
| 383 | + } |
| 384 | + |
| 385 | + return { x: x, y: y, width: width, height: height }; |
367 | 386 | } |
368 | 387 | |
369 | | -function findChild (element, nodeName) { |
| 388 | +function findChild( element, nodeName ) { |
370 | 389 | var child; |
371 | | - for (child = element.firstChild; child != null; child = child.nextSibling){ |
372 | | - if (child.nodeName.toLowerCase() == nodeName) |
| 390 | + for ( child = element.firstChild; child != null; child = child.nextSibling ) { |
| 391 | + if ( child.nodeName.toLowerCase() == nodeName ) { |
373 | 392 | return child; |
| 393 | + } |
374 | 394 | } |
375 | 395 | return null; |
376 | 396 | } |
377 | 397 | |
378 | | -function setTagBoxRect(boxX, boxY, boxDim, boxDim) { |
379 | | - setElemRect(tagBoxDiv, boxX, boxY, boxDim, boxDim); |
380 | | - setElemRect(tagBoxInnerDiv, 0, 0, boxDim-kBoxBorderWidth, boxDim-kBoxBorderWidth); |
| 398 | +function setTagBoxRect( boxX, boxY, boxDim, boxDim ) { |
| 399 | + setElemRect( tagBoxDiv, boxX, boxY, boxDim, boxDim ); |
| 400 | + setElemRect( tagBoxInnerDiv, 0, 0, boxDim - kBoxBorderWidth, boxDim - kBoxBorderWidth ); |
381 | 401 | } |
382 | 402 | |
383 | 403 | function hideTagBox() { |
384 | | - tagBoxDiv.style.display = "none"; |
385 | | - gid('tagEditField').style.display = "none"; |
| 404 | + tagBoxDiv.style.display = 'none'; |
| 405 | + gid( 'tagEditField' ).style.display = 'none'; |
386 | 406 | } |
387 | 407 | |
388 | 408 | function tagUIVisible() { |
389 | | - return ( tagBoxDiv.style.display != "none" ); |
390 | | -} |
| 409 | + return ( tagBoxDiv.style.display != 'none' ); |
| 410 | +} |
391 | 411 | |
392 | | - |
393 | 412 | function focusInstructions() { |
394 | | - window.location.hash = 'tagging_instructions'; |
| 413 | + window.location.hash = 'tagging_instructions'; |
395 | 414 | } |
396 | 415 | |
397 | 416 | function imageMouseUp() { |
398 | | - if (tagging) { |
399 | | - gid('name').focus(); |
400 | | - gid('name').select(); |
401 | | - } |
| 417 | + if ( tagging ) { |
| 418 | + gid( 'name' ).focus(); |
| 419 | + gid( 'name' ).select(); |
| 420 | + } |
402 | 421 | } |
403 | 422 | |
404 | | -function imageMouseDown(event, image, tagsID) { |
405 | | - if (tagging) { |
406 | | - activeImageMouseX = mousePosX(event) - findX(image); |
407 | | - activeImageMouseY = mousePosY(event) - findY(image); |
408 | | - |
409 | | - updateFrame(image, activeImageMouseX, activeImageMouseY); |
410 | | - return false; |
411 | | - } |
| 423 | +function imageMouseDown( event, image, tagsID ) { |
| 424 | + if ( tagging ) { |
| 425 | + activeImageMouseX = mousePosX( event ) - findX( image ); |
| 426 | + activeImageMouseY = mousePosY( event ) - findY( image ); |
| 427 | + |
| 428 | + updateFrame( image, activeImageMouseX, activeImageMouseY ); |
| 429 | + return false; |
| 430 | + } |
412 | 431 | } |
413 | 432 | |
414 | | -function frameMouseDown(event) { |
415 | | - if (tagging) { |
416 | | - image = ge('myphoto'); |
417 | | - activeImageMouseX = mousePosX(event) - findX(image); |
418 | | - activeImageMouseY = mousePosY(event) - findY(image); |
419 | | - updateFrame(image, activeImageMouseX, activeImageMouseY); |
420 | | - } |
| 433 | +function frameMouseDown( event ) { |
| 434 | + if ( tagging ) { |
| 435 | + image = ge( 'myphoto' ); |
| 436 | + activeImageMouseX = mousePosX( event ) - findX( image ); |
| 437 | + activeImageMouseY = mousePosY( event ) - findY( image ); |
| 438 | + updateFrame( image, activeImageMouseX, activeImageMouseY ); |
| 439 | + } |
421 | 440 | } |
422 | 441 | |
423 | 442 | function frameMouseUp() { |
424 | | - if (tagging) { |
425 | | - gid('name').focus(); |
426 | | - gid('name').select(); |
427 | | - } |
| 443 | + if ( tagging ) { |
| 444 | + gid( 'name' ).focus(); |
| 445 | + gid( 'name' ).select(); |
| 446 | + } |
428 | 447 | } |
\ No newline at end of file |
Index: trunk/extensions/ImageTagging/ImageTagging.php |
— | — | @@ -3,30 +3,46 @@ |
4 | 4 | * ImageTagging extension by Wikia, Inc. |
5 | 5 | * Lets a user select regions of an embedded image and associate an article with that region |
6 | 6 | * |
| 7 | + * @file |
| 8 | + * @ingroup Extensions |
| 9 | + * @version 1.2 |
7 | 10 | * @author Tristan Harris |
8 | 11 | * @author Tomasz Klim |
9 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 13 | + * @link http://www.mediawiki.org/wiki/Extension:ImageTagging Documentation |
10 | 14 | */ |
11 | 15 | |
12 | | -$wgHooks['UnknownAction'][] = 'addTag'; |
13 | | -$wgHooks['UnknownAction'][] = 'removeTag'; |
14 | | -$wgHooks['UnknownAction'][] = 'tagSearch'; |
| 16 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 17 | + die( 'This is not a valid entry point to MediaWiki.' ); |
| 18 | +} |
15 | 19 | |
16 | | -$wgExtensionFunctions[] = 'wfImageTagPageSetup'; |
| 20 | +// Extension credits that will show up on Special:Version |
17 | 21 | $wgExtensionCredits['other'][] = array( |
18 | 22 | 'path' => __FILE__, |
19 | 23 | 'name' => 'Image Tagging', |
20 | | - 'author' => 'Wikia, Inc. (Tristan Harris, Tomasz Klim)', |
21 | | - 'version' => '1.1', |
| 24 | + 'author' => array( 'Tristan Harris', 'Tomasz Klim' ), |
| 25 | + 'version' => '1.2', |
22 | 26 | 'url' => 'http://www.mediawiki.org/wiki/Extension:ImageTagging', |
23 | 27 | 'descriptionmsg' => 'imagetagging-desc', |
24 | 28 | ); |
25 | 29 | |
| 30 | +// Set up logging |
| 31 | +$wgLogTypes[] = 'tag'; |
| 32 | +$wgLogNames['tag'] = 'tag-logpagename'; |
| 33 | +$wgLogHeaders['tag'] = 'tag-logpagetext'; |
| 34 | +$wgLogActions['tag'] = 'imagetagging-log-tagged'; |
| 35 | + |
| 36 | +$wgHooks['UnknownAction'][] = 'addTag'; |
| 37 | +$wgHooks['UnknownAction'][] = 'removeTag'; |
| 38 | +$wgHooks['UnknownAction'][] = 'tagSearch'; |
| 39 | + |
26 | 40 | // other hooks to try: 'ParserAfterTidy', ... |
27 | 41 | #$wgHooks['OutputPageBeforeHTML'][] = 'wfCheckArticleImageTags'; |
28 | 42 | $wgHooks['ArticleFromTitle'][] = 'wfArticleFromTitle'; |
29 | 43 | |
30 | | -$dir = dirname(__FILE__) . '/'; |
| 44 | +// Set up the Special:TaggedImages special page |
| 45 | +$dir = dirname( __FILE__ ) . '/'; |
| 46 | +$wgAutoloadClasses['ImageTagPage'] = $dir . 'ImageTagPage.php'; |
31 | 47 | $wgAutoloadClasses['TaggedImages'] = $dir . 'ImageTagging_body.php'; |
32 | 48 | $wgExtensionMessagesFiles['ImageTagging'] = $dir . 'ImageTagging.i18n.php'; |
33 | 49 | $wgExtensionAliasesFiles['ImageTagging'] = $dir . 'ImageTagging.alias.php'; |
— | — | @@ -36,38 +52,45 @@ |
37 | 53 | * End Trie Handlers |
38 | 54 | ********************/ |
39 | 55 | |
40 | | -function wfCheckArticleImageTags($outputPage, $text) { |
41 | | - global $wgOut, $wgDBname, $wgTitle; |
42 | | - |
| 56 | +function wfCheckArticleImageTags( $outputPage, $text ) { |
43 | 57 | if ( $outputPage->isArticle() ) { |
44 | | - $db = wfGetDB(DB_SLAVE); |
45 | | - $res = $db->query("SELECT article_tag, tag_rect, unique_id, COUNT(article_tag) AS count FROM ". |
46 | | - $db->tableName('imagetags'). |
47 | | - " WHERE article_tag='" . addslashes($wgTitle->getText()). "' GROUP BY article_tag" ); |
| 58 | + $dbr = wfGetDB( DB_SLAVE ); |
| 59 | + $res = $dbr->select( |
| 60 | + 'imagetags', |
| 61 | + array( |
| 62 | + 'article_tag', 'tag_rect', 'unique_id', |
| 63 | + 'COUNT(article_tag) AS count' |
| 64 | + ), |
| 65 | + array( 'article_tag' => $outputPage->getTitle()->getText() ), |
| 66 | + __METHOD__, |
| 67 | + array( 'GROUP BY' => 'article_tag' ) |
| 68 | + ); |
48 | 69 | |
49 | | - if ($o = $db->fetchObject($res)) { |
50 | | - $taggedImagesObj = Title::newFromText('TaggedImages', NS_SPECIAL); |
51 | | - $titleText = $wgTitle->getText(); |
| 70 | + $o = $db->fetchObject( $res ); |
| 71 | + if ( $o ) { |
| 72 | + $taggedImagesObj = SpecialPage::getTitleFor( 'TaggedImages' ); |
| 73 | + $titleText = $outputPage->getTitle()->getText(); |
52 | 74 | |
53 | | - $wgOut->addHTML(' |
54 | | - <a href="' . $taggedImagesObj->getLocalUrl('q='.$titleText) . '"> |
| 75 | + $outputPage->addHTML(' |
| 76 | + <a href="' . $taggedImagesObj->getLocalURL( 'q=' . $titleText ) . '"> |
55 | 77 | <span style="position:absolute; |
56 | | - z-index:1; |
57 | | - border:none; |
58 | | - background:none; |
59 | | - right:30px; |
60 | | - top:3.7em; |
61 | | - float:right; |
62 | | - margin:0.0em; |
63 | | - padding:0.0em; |
64 | | - line-height:1.7em; /*1.5em*/ |
65 | | - text-align:right; |
66 | | - text-indent:0; |
67 | | - font-size:100%; |
68 | | - text-transform:none; |
69 | | - white-space:nowrap;" id="coordinates" class="plainlinksneverexpand"> |
70 | | - ' . wfMsg('imagetagging-imagetag-seemoreimages', $titleText, $o->count) . |
71 | | - '</span></a>'); |
| 78 | + z-index: 1; |
| 79 | + border: none; |
| 80 | + background: none; |
| 81 | + right: 30px; |
| 82 | + top: 3.7em; |
| 83 | + float: right; |
| 84 | + margin: 0.0em; |
| 85 | + padding: 0.0em; |
| 86 | + line-height: 1.7em; /*1.5em*/ |
| 87 | + text-align: right; |
| 88 | + text-indent: 0; |
| 89 | + font-size: 100%; |
| 90 | + text-transform: none; |
| 91 | + white-space: nowrap;" id="coordinates" class="plainlinksneverexpand"> |
| 92 | + ' . wfMsg( 'imagetagging-imagetag-seemoreimages', $titleText, $o->count ) . |
| 93 | + '</span></a>' |
| 94 | + ); |
72 | 95 | } |
73 | 96 | } |
74 | 97 | return true; |
— | — | @@ -76,142 +99,161 @@ |
77 | 100 | // TKL 2006-03-07: it doesn't work in new MediaWiki, modification required in includes/Wiki.php (class name change only) |
78 | 101 | // $wgNamespaceTemplates[NS_IMAGE] = 'ImageTagPage'; |
79 | 102 | |
80 | | -function addTag($action, $article) { |
81 | | - if($action != 'addTag') return true; |
| 103 | +function addTag( $action, $article ) { |
| 104 | + if( $action != 'addTag' ) { |
| 105 | + return true; |
| 106 | + } |
82 | 107 | |
83 | | - global $wgRequest, $wgDBname, $wgOut, $wgUser; |
| 108 | + global $wgRequest, $wgOut, $wgUser; |
84 | 109 | |
85 | 110 | wfProfileIn( __METHOD__ ); |
86 | 111 | |
87 | | - $wgOut->setArticleBodyOnly(true); |
| 112 | + $wgOut->setArticleBodyOnly( true ); |
88 | 113 | |
89 | | - $tagRect = $wgRequest->getText('rect'); |
90 | | - $tagName = $wgRequest->getText('tagName'); |
91 | | - $imgName = $wgRequest->getText('imgName'); |
| 114 | + $tagRect = $wgRequest->getText( 'rect' ); |
| 115 | + $tagName = $wgRequest->getText( 'tagName' ); |
| 116 | + $imgName = $wgRequest->getText( 'imgName' ); |
92 | 117 | $userText = $wgUser->getName(); |
93 | 118 | |
94 | | - $tagRect = preg_replace( "/[\"'<>]/", "", $tagRect ); |
95 | | - $tagName = preg_replace( "/[\"'<>]/", "", $tagName ); |
96 | | - $imgName = preg_replace( "/[\"'<>]/", "", $imgName ); |
| 119 | + $tagRect = preg_replace( "/[\"'<>]/", '', $tagRect ); |
| 120 | + $tagName = preg_replace( "/[\"'<>]/", '', $tagName ); |
| 121 | + $imgName = preg_replace( "/[\"'<>]/", '', $imgName ); |
97 | 122 | |
98 | | - $img = wfFindFile($imgName); |
99 | | - if ($img) { |
| 123 | + $img = wfFindFile( $imgName ); |
| 124 | + if ( $img ) { |
100 | 125 | $imgTitle = $img->getTitle(); |
101 | 126 | |
102 | | - wfPurgeTitle($imgTitle); |
| 127 | + wfPurgeTitle( $imgTitle ); |
103 | 128 | |
104 | | - $db = wfGetDB(DB_MASTER); |
105 | | - $db->insert('imagetags', |
106 | | - array( |
107 | | - 'img_page_id' => 0, |
108 | | - 'img_name' => $imgName, |
109 | | - 'article_tag' => $tagName, |
110 | | - 'tag_rect' => $tagRect, |
111 | | - 'user_text' => $userText) |
| 129 | + $dbw = wfGetDB( DB_MASTER ); |
| 130 | + $dbw->insert( |
| 131 | + 'imagetags', |
| 132 | + array( |
| 133 | + 'img_page_id' => 0, |
| 134 | + 'img_name' => $imgName, |
| 135 | + 'article_tag' => $tagName, |
| 136 | + 'tag_rect' => $tagRect, |
| 137 | + 'user_text' => $userText |
| 138 | + ), |
| 139 | + __METHOD__ |
112 | 140 | ); |
113 | 141 | |
114 | 142 | $wgOut->clearHTML(); |
115 | | - $wgOut->addHTML("<!-- added tag for image $imgName to database! -->"); |
116 | | - $wgOut->addHTML( wfGetImageTags($img, $imgName) ); |
| 143 | + $wgOut->addHTML( "<!-- added tag for image $imgName to database! -->" ); |
| 144 | + $wgOut->addHTML( wfGetImageTags( $img, $imgName ) ); |
117 | 145 | |
118 | 146 | $logPage = new LogPage( 'tag' ); |
119 | 147 | $link = basename( $img->title->getLocalURL() ); |
120 | | - $logComment = wfMsg('imagetagging-log-tagged', $link, $imgName, $tagName, $userText); |
121 | | - $logPage->addEntry( 'tag', $imgTitle, $logComment); |
| 148 | + $logComment = wfMsg( |
| 149 | + 'imagetagging-log-tagged', |
| 150 | + $link, $imgName, $tagName, $userText |
| 151 | + ); |
| 152 | + $logPage->addEntry( 'tag', $imgTitle, $logComment ); |
122 | 153 | |
123 | 154 | $enotif = new EmailNotification; |
124 | | - $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false); |
| 155 | + $enotif->notifyOnPageChange( |
| 156 | + $wgUser, $imgTitle, wfTimestampNow(), $logComment, false |
| 157 | + ); |
125 | 158 | } else { |
126 | 159 | $wgOut->clearHTML(); |
127 | | - $wgOut->addHTML("<!-- ERROR: img named $imgName --> |
128 | | - <script type='text/javascript'> |
129 | | - alert(\"Error adding tag!\"); |
130 | | - </script>"); |
| 160 | + $wgOut->addHTML( |
| 161 | + "<!-- ERROR: img named $imgName --> |
| 162 | + <script type='text/javascript'> |
| 163 | + alert(\"Error adding tag!\"); |
| 164 | + </script>" |
| 165 | + ); |
131 | 166 | } |
132 | | - wfProfileOut( __METHOD__ ); |
| 167 | + wfProfileOut( __METHOD__ ); |
133 | 168 | return false; |
134 | 169 | } |
135 | 170 | |
136 | | -function removeTag($action, $article) { |
137 | | - if ($action != 'removeTag') return true; |
| 171 | +function removeTag( $action, $article ) { |
| 172 | + if ( $action != 'removeTag' ) { |
| 173 | + return true; |
| 174 | + } |
138 | 175 | |
139 | | - global $wgRequest, $wgOut, $wgDBname, $wgUser; |
| 176 | + global $wgRequest, $wgOut, $wgUser; |
140 | 177 | |
141 | 178 | wfProfileIn( __METHOD__ ); |
142 | 179 | |
143 | | - $wgOut->setArticleBodyOnly(true); |
| 180 | + $wgOut->setArticleBodyOnly( true ); |
144 | 181 | |
145 | | - $tagID = $wgRequest->getVal('tagID'); |
146 | | - $tagName = $wgRequest->getText('tagName'); |
147 | | - $imgName = $wgRequest->getText('imgName'); |
| 182 | + $tagID = $wgRequest->getVal( 'tagID' ); |
| 183 | + $tagName = $wgRequest->getText( 'tagName' ); |
| 184 | + $imgName = $wgRequest->getText( 'imgName' ); |
148 | 185 | $userText = $wgUser->getName(); |
149 | 186 | |
150 | | - $tagID = preg_replace( "/[\"'<>]/", "", $tagID ); |
151 | | - $tagName = preg_replace( "/[\"'<>]/", "", $tagName ); |
152 | | - $imgName = preg_replace( "/[\"'<>]/", "", $imgName ); |
| 187 | + $tagID = preg_replace( "/[\"'<>]/", '', $tagID ); |
| 188 | + $tagName = preg_replace( "/[\"'<>]/", '', $tagName ); |
| 189 | + $imgName = preg_replace( "/[\"'<>]/", '', $imgName ); |
153 | 190 | |
154 | | - $img = wfFindFile($imgName); |
155 | | - if ($img) { |
| 191 | + $img = wfFindFile( $imgName ); |
| 192 | + if ( $img ) { |
156 | 193 | $imgTitle = $img->getTitle(); |
157 | 194 | |
158 | | - wfPurgeTitle($imgTitle); |
| 195 | + wfPurgeTitle( $imgTitle ); |
159 | 196 | |
160 | | - $db = wfGetDB(DB_MASTER); |
161 | | - $db->delete('imagetags', array('unique_id' => $tagID)); |
| 197 | + $dbw = wfGetDB( DB_MASTER ); |
| 198 | + $dbw->delete( 'imagetags', array( 'unique_id' => $tagID ), __METHOD__ ); |
162 | 199 | |
163 | 200 | $wgOut->clearHTML(); |
164 | | - $wgOut->addHTML("<!-- removed tag to database! -->"); |
165 | | - $wgOut->addHTML( wfGetImageTags($img, $imgName) ); |
| 201 | + $wgOut->addHTML( '<!-- removed tag from the database! -->' ); |
| 202 | + $wgOut->addHTML( wfGetImageTags( $img, $imgName ) ); |
166 | 203 | |
167 | 204 | $logPage = new LogPage( 'tag' ); |
168 | | - $logComment = wfMsg('imagetagging-logentry', $tagName, $userText); |
169 | | - $logPage->addEntry( 'tag', $imgTitle, $logComment); |
| 205 | + $logComment = wfMsg( 'imagetagging-logentry', $tagName, $userText ); |
| 206 | + $logPage->addEntry( 'tag', $imgTitle, $logComment ); |
170 | 207 | |
171 | 208 | $enotif = new EmailNotification; |
172 | | - $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false); |
| 209 | + $enotif->notifyOnPageChange( |
| 210 | + $wgUser, $imgTitle, wfTimestampNow(), $logComment, false |
| 211 | + ); |
173 | 212 | } else { |
174 | 213 | $wgOut->clearHTML(); |
175 | | - $wgOut->addHTML("<!-- ERROR: img named $imgName --> |
176 | | - <script type='text/javascript'> |
177 | | - alert(\"Error removing tag!\"); |
178 | | - </script>"); |
| 214 | + $wgOut->addHTML( |
| 215 | + "<!-- ERROR: img named $imgName --> |
| 216 | + <script type='text/javascript'> |
| 217 | + alert(\"Error removing tag!\"); |
| 218 | + </script>" |
| 219 | + ); |
179 | 220 | } |
180 | 221 | |
181 | 222 | wfProfileOut( __METHOD__ ); |
182 | 223 | return false; |
183 | 224 | } |
184 | 225 | |
185 | | -function tagSearch($action, $article) { |
186 | | - if($action != 'tagSearch') return true; |
| 226 | +function tagSearch( $action, $article ) { |
| 227 | + if( $action != 'tagSearch' ) { |
| 228 | + return true; |
| 229 | + } |
187 | 230 | |
188 | | - global $wgRequest, $wgDBname, $wgOut, $wgUser; |
| 231 | + global $wgRequest, $wgOut; |
189 | 232 | |
190 | 233 | wfProfileIn( __METHOD__ ); |
191 | 234 | |
192 | | - $wgOut->setArticleBodyOnly(true); |
| 235 | + $wgOut->setArticleBodyOnly( true ); |
193 | 236 | |
194 | | - $query = $wgRequest->getText('q'); |
195 | | - $query = preg_replace( "/[\"'<>]/", "", $query ); |
| 237 | + $query = $wgRequest->getText( 'q' ); |
| 238 | + $query = preg_replace( "/[\"'<>]/", '', $query ); |
196 | 239 | |
197 | 240 | $search = SearchEngine::create(); |
198 | 241 | $search->setLimitOffset( 10, 0 ); |
199 | | - $search->setNamespaces( array(NS_MAIN) ); |
| 242 | + $search->setNamespaces( array( NS_MAIN ) ); |
200 | 243 | $search->showRedirects = true; |
201 | 244 | $titleMatches = $search->searchTitle( $query ); |
202 | 245 | |
203 | 246 | $numResults = ( $titleMatches ? $titleMatches->numRows() : 0 ); |
204 | | - if ( $numResults > 0 ) |
205 | | - $wgOut->addHTML(wfTagSearchShowMatches($titleMatches)); |
| 247 | + if ( $numResults > 0 ) { |
| 248 | + $wgOut->addHTML( wfTagSearchShowMatches( $titleMatches ) ); |
| 249 | + } |
206 | 250 | |
207 | | - #echo "numResults: " . $numResults . ", query: " . $query; |
208 | | - |
209 | 251 | wfProfileOut( __METHOD__ ); |
210 | 252 | return false; |
211 | 253 | } |
212 | 254 | |
213 | 255 | /** |
214 | | - * @param SearchResultSet $matches |
215 | | - * @param string $terms partial regexp for highlighting terms |
| 256 | + * @param $matches SearchResultSet |
| 257 | + * @param $terms String: partial regexp for highlighting terms |
216 | 258 | */ |
217 | 259 | function wfTagSearchShowMatches( &$matches ) { |
218 | 260 | global $wgContLang; |
— | — | @@ -223,7 +265,8 @@ |
224 | 266 | |
225 | 267 | $out = "<searchresults>\n"; |
226 | 268 | |
227 | | - while( $result = $matches->next() ) { |
| 269 | + $result = $matches->next(); |
| 270 | + while( $result ) { |
228 | 271 | $out .= wfTagSearchHitXML( $result, $terms ); |
229 | 272 | } |
230 | 273 | $out .= "</searchresults>\n"; |
— | — | @@ -237,8 +280,8 @@ |
238 | 281 | |
239 | 282 | /** |
240 | 283 | * Format a single hit result |
241 | | - * @param SearchResult $result |
242 | | - * @param string $terms partial regexp for highlighting terms |
| 284 | + * @param $result SearchResult |
| 285 | + * @param $terms String: partial regexp for highlighting terms |
243 | 286 | */ |
244 | 287 | function wfTagSearchHitXML( $result, $terms ) { |
245 | 288 | global $wgUser, $wgContLang; |
— | — | @@ -268,11 +311,11 @@ |
269 | 312 | |
270 | 313 | $extract = ''; |
271 | 314 | foreach ( $lines as $line ) { |
272 | | - if ( 0 == $contextlines ) { |
| 315 | + if ( $contextlines == 0 ) { |
273 | 316 | break; |
274 | 317 | } |
275 | 318 | ++$lineno; |
276 | | - if ( ! preg_match( $pat1, $line, $m ) ) { |
| 319 | + if ( !preg_match( $pat1, $line, $m ) ) { |
277 | 320 | continue; |
278 | 321 | } |
279 | 322 | $contextlines--; |
— | — | @@ -287,7 +330,7 @@ |
288 | 331 | $found = $m[2]; |
289 | 332 | |
290 | 333 | $line = htmlspecialchars( $pre . $found . $post ); |
291 | | - $pat2 = '/(' . $terms . ")/i"; |
| 334 | + $pat2 = '/(' . $terms . ')/i'; |
292 | 335 | $line = preg_replace( $pat2, "<span class='searchmatch'>\\1</span>", $line ); |
293 | 336 | |
294 | 337 | $extract .= "<br /><small>{$lineno}: {$line}</small>\n"; |
— | — | @@ -297,7 +340,7 @@ |
298 | 341 | return "<result>\n<link>{$link}</link>\n<context>{$extract}</context>\n</result>\n"; |
299 | 342 | } |
300 | 343 | |
301 | | -function wfPurgeTitle($title) { |
| 344 | +function wfPurgeTitle( $title ) { |
302 | 345 | global $wgUseSquid; |
303 | 346 | |
304 | 347 | wfProfileIn( __METHOD__ ); |
— | — | @@ -317,53 +360,69 @@ |
318 | 361 | wfProfileOut( __METHOD__ ); |
319 | 362 | } |
320 | 363 | |
321 | | -function wfGetImageTags($img, $imgName) { |
322 | | - global $wgDBname, $wgUser, $wgOut, $wgLang; |
| 364 | +function wfGetImageTags( $img, $imgName ) { |
| 365 | + global $wgUser, $wgOut, $wgLang; |
323 | 366 | |
324 | 367 | wfProfileIn( __METHOD__ ); |
325 | 368 | |
326 | 369 | $sk = $wgUser->getSkin(); |
327 | | - $db = wfGetDB(DB_SLAVE); |
328 | | - $db->selectDB($wgDBname); |
| 370 | + $db = wfGetDB( DB_SLAVE ); |
329 | 371 | $res = $db->select( |
330 | | - array("imagetags"), |
331 | | - array("article_tag", "tag_rect", "unique_id"), |
332 | | - array("img_name" => $imgName), |
333 | | - __METHOD__ ); |
| 372 | + array( 'imagetags' ), |
| 373 | + array( 'article_tag', 'tag_rect', 'unique_id' ), |
| 374 | + array( 'img_name' => $imgName ), |
| 375 | + __METHOD__ |
| 376 | + ); |
334 | 377 | |
335 | 378 | $html = ''; |
336 | | - $wgOut->addHTML("<!-- this many image tags: " . count($res) . " from img " . $img->name . " -->"); |
337 | | - while ($o = $db->fetchObject($res)) { |
338 | | - if ( strlen($html) > 0 ) |
| 379 | + $wgOut->addHTML( '<!-- this many image tags: ' . count( $res ) . ' from img ' . $img->name . ' -->' ); |
| 380 | + foreach( $res as $o ) { |
| 381 | + if ( strlen( $html ) > 0 ) { |
339 | 382 | $html .= ', '; |
| 383 | + } |
340 | 384 | |
341 | | - $wgOut->addHTML("<!-- tag rect: " . $o->tag_rect . ", tag title: " . $o->article_tag . ", unique_id: " . $o->unique_id . "-->"); |
| 385 | + $wgOut->addHTML( |
| 386 | + '<!-- tag rect: ' . $o->tag_rect . ', tag title: ' . |
| 387 | + $o->article_tag . ', unique_id: ' . $o->unique_id . '-->' |
| 388 | + ); |
342 | 389 | |
343 | 390 | $span = '<span id="' . $o->article_tag . '-tag" onmouseout="hideTagBox()" onmouseover="tagBoxPercent(' . $o->tag_rect . ', false)">'; |
344 | 391 | |
345 | | - #echo "article tag: " . $o->article_tag . "\n"; |
346 | | - $articleTitle = Title::newFromText($o->article_tag); |
| 392 | + $articleTitle = Title::newFromText( $o->article_tag ); |
347 | 393 | |
348 | 394 | #$articleLink = '<a href="' . $articleTitle->escapeFullURL() . '" onmouseout="hideTagBox()">' . $o->article_tag . '</a>'; |
349 | | - $articleLink = $sk->makeLinkObj($articleTitle); |
| 395 | + $articleLink = $sk->makeLinkObj( $articleTitle ); |
350 | 396 | |
351 | | - $specialImagesTitle = Title::newFromText("Special:TaggedImages"); |
| 397 | + $specialImagesTitle = SpecialPage::getTitleFor( 'TaggedImages' ); |
352 | 398 | |
353 | | - $imagesLink = '<a onmouseover="tagBoxPercent(' . $o->tag_rect . ', false)" onmouseout="hideTagBox()" href="' . $specialImagesTitle->escapeFullURL("q=".$o->article_tag) . '">' . wfMsgHtml('imagetagging-images') . '</a>'; |
| 399 | + $imagesLink = '<a onmouseover="tagBoxPercent(' . $o->tag_rect . ', false)" onmouseout="hideTagBox()" href="' . |
| 400 | + $specialImagesTitle->escapeFullURL( 'q=' . $o->article_tag ) . '">' . |
| 401 | + wfMsgHtml( 'imagetagging-images' ) . '</a>'; |
354 | 402 | |
355 | | - $removeLink = '<a href="#" onclick="removeTag(' . $o->unique_id . ', this, \'' . addslashes( $o->article_tag ) . '\'); return false;">' . wfMsgHtml('imagetagging-removetag') . '</a>'; |
| 403 | + $removeLink = '<a href="#" onclick="removeTag(' . $o->unique_id . |
| 404 | + ', this, \'' . addslashes( $o->article_tag ) . '\'); return false;">' . |
| 405 | + wfMsgHtml( 'imagetagging-removetag' ) . '</a>'; |
356 | 406 | |
357 | | - $html .= $span . $articleLink . ' (' . $wgLang->pipeList( array( $imagesLink, $removeLink ) ) . ')</span>'; |
| 407 | + $html .= $span . $articleLink . ' (' . |
| 408 | + $wgLang->pipeList( array( $imagesLink, $removeLink ) ) . ')</span>'; |
358 | 409 | } |
359 | | - $db->freeResult($res); |
360 | 410 | |
361 | | - if ( $html ) |
362 | | - $html = wfMsg('imagetagging-inthisimage', $html); |
| 411 | + if ( $html ) { |
| 412 | + $html = wfMsg( 'imagetagging-inthisimage', $html ); |
| 413 | + } |
363 | 414 | |
364 | 415 | wfProfileOut( __METHOD__ ); |
365 | 416 | return $html; |
366 | 417 | } |
367 | 418 | |
| 419 | +/** |
| 420 | + * Initializes ImageTagPage instead of MediaWiki's standard ImagePage for pages |
| 421 | + * in the image namespace and for users who are not blocked. |
| 422 | + * |
| 423 | + * @param $title Object: Title object |
| 424 | + * @param $article Object: Article object (or ImageTagPage) |
| 425 | + * @return Boolean: true |
| 426 | + */ |
368 | 427 | function wfArticleFromTitle( &$title, &$article ) { |
369 | 428 | global $wgUser; |
370 | 429 | |
— | — | @@ -375,249 +434,4 @@ |
376 | 435 | |
377 | 436 | wfProfileOut( __METHOD__ ); |
378 | 437 | return true; |
379 | | -} |
380 | | - |
381 | | -function wfImageTagPageSetup() { |
382 | | - global $wgLogTypes, $wgLogNames, $wgLogHeaders, $wgLogActions; |
383 | | - //Set up logging |
384 | | - $wgLogTypes[] = 'tag'; |
385 | | - $wgLogNames['tag'] = 'tag-logpagename'; |
386 | | - $wgLogHeaders['tag'] = 'tag-logpagetext'; |
387 | | - $wgLogActions['tag'] = 'imagetagging-log-tagged'; |
388 | | - |
389 | | - wfLoadExtensionMessages('ImageTagging'); |
390 | | - |
391 | | - class ImageTagPage extends ImagePage { |
392 | | - function openShowImage() { |
393 | | - global $wgOut, $wgUser, $wgServer, $wgStyleVersion, $wgJsMimeType, $wgScriptPath; |
394 | | - |
395 | | - wfProfileIn( __METHOD__ ); |
396 | | - |
397 | | - $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/ImageTagging/img_tagging.js?$wgStyleVersion\"></script>\n" ); |
398 | | - $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/ImageTagging/json.js?$wgStyleVersion\"></script>\n" ); |
399 | | - |
400 | | - $imgName = $this->getTitle()->getText(); |
401 | | - $wgOut->addHTML("<input type='hidden' value='$imgName' id='imgName' />"); |
402 | | - $wgOut->addHTML("<input type='hidden' value='$wgScriptPath/extensions/ImageTagging' id='imgPath' />"); |
403 | | - |
404 | | - if ( $wgUser->isLoggedIn() ) |
405 | | - $wgOut->addHTML("<input type='hidden' value='1' id='userLoggedIn'/>"); |
406 | | - |
407 | | - if ( $wgUser->isAllowed('edit') && |
408 | | - $this->mTitle->userCan( 'edit', true ) && |
409 | | - ( $this->mTitle->isProtected('edit') == false || in_array( 'sysop', $wgUser->getGroups() ) ) ) |
410 | | - $wgOut->addHTML("<input type='hidden' value='1' id='canEditPage'/>"); |
411 | | - |
412 | | - $this->modifiedImagePageOpenShowImage(); |
413 | | - |
414 | | - if ( $this->getFile()->exists() ) { |
415 | | - $tagList = wfGetImageTags($this->getFile(), $imgName); |
416 | | - |
417 | | - #if ( $tagList ) |
418 | | - $wgOut->addHTML("<div id='tagListDiv'><span id='tagList'>$tagList</span></div>"); |
419 | | - } |
420 | | - |
421 | | - wfProfileOut( __METHOD__ ); |
422 | | - } |
423 | | - |
424 | | - function modifiedImagePageOpenShowImage() { |
425 | | - global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgEnableUploads; |
426 | | - |
427 | | - wfProfileIn( __METHOD__ ); |
428 | | - |
429 | | - $full_url = $this->getFile()->getURL(); |
430 | | - $anchoropen = ''; |
431 | | - $anchorclose = ''; |
432 | | - |
433 | | - if( $wgUser->getOption( 'imagesize' ) == '' ) { |
434 | | - $sizeSel = User::getDefaultOption( 'imagesize' ); |
435 | | - } else { |
436 | | - $sizeSel = intval( $wgUser->getOption( 'imagesize' ) ); |
437 | | - } |
438 | | - if( !isset( $wgImageLimits[$sizeSel] ) ) { |
439 | | - $sizeSel = User::getDefaultOption( 'imagesize' ); |
440 | | - } |
441 | | - $max = $wgImageLimits[$sizeSel]; |
442 | | - $maxWidth = $max[0]; |
443 | | - $maxHeight = $max[1]; |
444 | | - $maxWidth = 600; |
445 | | - $maxHeight = 460; |
446 | | - $sk = $wgUser->getSkin(); |
447 | | - |
448 | | - if ( $this->getFile()->exists() ) { |
449 | | - # image |
450 | | - $width = $this->getFile()->getWidth(); |
451 | | - $height = $this->getFile()->getHeight(); |
452 | | - $showLink = false; |
453 | | - |
454 | | - if ( $this->getFile()->allowInlineDisplay() and $width and $height) { |
455 | | - # image |
456 | | - |
457 | | - # "Download high res version" link below the image |
458 | | - $msg = wfMsgHtml('show-big-image', $width, $height, intval( $this->getFile()->getSize()/1024 ) ); |
459 | | - |
460 | | - # We'll show a thumbnail of this image |
461 | | - if ( $width > $maxWidth || $height > $maxHeight ) { |
462 | | - # Calculate the thumbnail size. |
463 | | - # First case, the limiting factor is the width, not the height. |
464 | | - if ( $width / $height >= $maxWidth / $maxHeight ) { |
465 | | - $height = round( $height * $maxWidth / $width); |
466 | | - $width = $maxWidth; |
467 | | - # Note that $height <= $maxHeight now. |
468 | | - } else { |
469 | | - $newwidth = floor( $width * $maxHeight / $height); |
470 | | - $height = round( $height * $newwidth / $width ); |
471 | | - $width = $newwidth; |
472 | | - # Note that $height <= $maxHeight now, but might not be identical |
473 | | - # because of rounding. |
474 | | - } |
475 | | - |
476 | | - $thumbnail = $this->getFile()->getThumbnail( $width ); |
477 | | - if ( $thumbnail == null ) { |
478 | | - $url = $this->getFile()->getViewURL(); |
479 | | - } else { |
480 | | - $url = $thumbnail->getURL(); |
481 | | - } |
482 | | - |
483 | | - $anchoropen = "<a href=\"{$full_url}\">"; |
484 | | - $anchorclose = "</a><br />"; |
485 | | - if( $this->getFile()->mustRender() ) { |
486 | | - $showLink = true; |
487 | | - } else { |
488 | | - $anchorclose .= "\n$anchoropen{$msg}</a>"; |
489 | | - } |
490 | | - } else { |
491 | | - $url = $this->getFile()->getViewURL(); |
492 | | - $showLink = true; |
493 | | - } |
494 | | - |
495 | | - //$anchoropen = ''; |
496 | | - //$anchorclose = ''; |
497 | | - // $width = 'auto'; //'100%'; |
498 | | - // $height = 'auto'; //'100%'; |
499 | | - $wgOut->addHTML( '<div class="fullImageLink" id="file">' . |
500 | | - "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" style=\"max-width: {$maxWidth}px;\" alt=\"" . |
501 | | - htmlspecialchars( $wgRequest->getVal( 'image' ) ).'" />' . |
502 | | - $anchoropen . $anchorclose . '</div>' ); |
503 | | - } else { |
504 | | - #if direct link is allowed but it's not a renderable image, show an icon. |
505 | | - if ($this->getFile()->isSafeFile()) { |
506 | | - $icon= $this->getFile()->iconThumb(); |
507 | | - |
508 | | - $wgOut->addHTML( '<div class="fullImageLink" id="file"><a href="' . $full_url . '">' . |
509 | | - $icon->toHtml() . |
510 | | - '</a></div>' ); |
511 | | - } |
512 | | - |
513 | | - $showLink = true; |
514 | | - } |
515 | | - |
516 | | - if ($showLink) { |
517 | | - $filename = wfEscapeWikiText( $this->getFile()->getName() ); |
518 | | - $info = wfMsg( 'file-info', |
519 | | - $sk->formatSize( $this->getFile()->getSize() ), |
520 | | - $this->getFile()->getMimeType() ); |
521 | | - |
522 | | - if (!$this->getFile()->isSafeFile()) { |
523 | | - $warning = wfMsg( 'mediawarning' ); |
524 | | - $wgOut->addWikiText( <<<END |
525 | | -<div class="fullMedia"> |
526 | | -<span class="dangerousLink">[[Media:$filename|$filename]]</span> |
527 | | -<span class="fileInfo"> ($info)</span> |
528 | | -</div> |
529 | | - |
530 | | -<div class="mediaWarning">$warning</div> |
531 | | -END |
532 | | - ); |
533 | | - } else { |
534 | | - $wgOut->addWikiText( <<<END |
535 | | -<div class="fullMedia"> |
536 | | -[[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span> |
537 | | -</div> |
538 | | -END |
539 | | - ); |
540 | | - } |
541 | | - } |
542 | | - |
543 | | - if($this->getFile()->fromSharedDirectory) { |
544 | | - $this->printSharedImageText(); |
545 | | - } |
546 | | - } else { |
547 | | - # Image does not exist |
548 | | - $nofile = wfMsgHtml( 'filepage-nofile' ); |
549 | | - if ( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) { |
550 | | - // Only show an upload link if the user can upload |
551 | | - $nofile .= ' '.$sk->makeKnownLinkObj( |
552 | | - SpecialPage::getTitleFor( 'Upload' ), |
553 | | - wfMsgHtml('filepage-nofile-link'), |
554 | | - 'wpDestFile=' . urlencode( $this->displayImg->getName() ) |
555 | | - ); |
556 | | - } |
557 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
558 | | - $wgOut->addHTML( '<div id="mw-imagepage-nofile">' . $nofile . '</div>' ); |
559 | | - } |
560 | | - |
561 | | - wfProfileOut( __METHOD__ ); |
562 | | - } |
563 | | - |
564 | | - /** |
565 | | - * Create the TOC |
566 | | - * |
567 | | - * @access private |
568 | | - * |
569 | | - * @param bool $metadata Whether or not to show the metadata link |
570 | | - * @return string |
571 | | - */ |
572 | | - function showTOC( $metadata ) { |
573 | | - global $wgLang, $wgUser; |
574 | | - |
575 | | - $r = '<ul id="filetoc"> |
576 | | - <li><a href="#file">' . $wgLang->getNsText( NS_IMAGE ) . '</a></li> |
577 | | - <li><a href="#filehistory">' . wfMsgHtml( 'imagetagging-imghistory' ) . '</a></li> |
578 | | - <li><a href="#filelinks">' . wfMsgHtml( 'imagelinks' ) . '</a></li>' . |
579 | | - ($metadata ? '<li><a href="#metadata">' . wfMsgHtml( 'metadata' ) . '</a></li>' : '') . ' |
580 | | - <li><a href="javascript:addImageTags()">' . wfMsgHtml( 'imagetagging-addimagetag' ) . '</a>'. wfMsg('imagetagging-new') .'</li>' |
581 | | - . '</ul>'; |
582 | | - |
583 | | - $r .= '<div id="tagStatusDiv" style="margin: 5px 5px 10px 5px; padding: 10px; border: solid 1px #ffe222; background: #fffbe2; display: none;"><table style="background-color: #fffbe2;"><tr><td width="450" height="30" align="center" style="padding-left: 20px;"><img src="/extensions/ImageTagging/progress-wheel.gif" id="progress_wheel" style="display:none;"><div id="tagging_message" style="background: #fffbe2;">' . wfMsgHtml('imagetagging-tagging-instructions') . '</td><td valign="middle"><input type="button" onclick="doneAddingTags();" id="done_tagging" name="done_tagging" value="' . wfMsgHtml('imagetagging-done-button') . '" /></div></td></tr></table></div>'; |
584 | | - |
585 | | - $r .= "<div style='position: absolute; font: verdana, sans-serif; top: 10px; left: 10px; display: none; width:284px; height:24px; padding: 4px 6px; background-color: #eeeeee; color: #444444; border: 2px solid #555555; z-index:2;' id='tagEditField'> |
586 | | - |
587 | | - <span style='position: absolute; left: 4px; top: 6px;'>". wfMsg('imagetagging-article') ."</span> |
588 | | - |
589 | | - <!-- TAH: don't use the popup just yet |
590 | | - <select name='tagType'> |
591 | | - <option selected>Article</option> |
592 | | - <option>Category</option> |
593 | | - </select> |
594 | | - -->"; |
595 | | - |
596 | | - $r .= "<input style='position: absolute; left: 189px; top: 6px; width: 39px; height: 20px;' type='submit' name='". wfMsgHtml('imagetagging-tag-button') ."' value='" . wfMsgHtml('imagetagging-tag-button') . "' onclick='submitTag()'/>"; |
597 | | - $r .= "<input style='position: absolute; left: 232px; top: 6px; width: 60px; height: 20px;' type='button' name='" . wfMsgHtml('imagetagging-tagcancel-button') . "' value='" . wfMsgHtml('imagetagging-tagcancel-button') . "' onclick='hideTagBox()'/>"; |
598 | | - |
599 | | - $r .= "<input type='text' style='position: absolute; left: 46px; top: 6px; background-color:white; width: 140px; height:18px;' name='articleTag' id='articleTag' value='' title='". wfMsgHtml('imagetagging-articletotag') ."' onkeyup='typeTag(event);' />"; |
600 | | - |
601 | | - $r .= '</div>'; |
602 | | - |
603 | | - $r .= '<div id="popup" style="position:absolute; background-color: #eeeeee; top: 0px; left: 0px; z-index:3; visibility:hidden;"></div>'; |
604 | | - |
605 | | - #$r .= '</div>'; |
606 | | - |
607 | | - // TAH: adding this to grab edit tokens from javascript |
608 | | - $token = $wgUser->editToken(); |
609 | | - $r .= "<input type=\"hidden\" value=\"$token\" name=\"wpEditToken\" id=\"wpEditToken\" />\n"; |
610 | | - $r .= "<input type=\"hidden\" id=\"addingtagmessage\" value=\"" . wfMsg('imagetagging-addingtag') . "\">\n"; |
611 | | - $r .= "<input type=\"hidden\" id=\"removingtagmessage\" value=\"" . wfMsg('imagetagging-removingtag') . "\">\n"; |
612 | | - $r .= "<input type=\"hidden\" id=\"addtagsuccessmessage\" value=\"" . wfMsg('imagetagging-addtagsuccess') . "\">\n"; |
613 | | - $r .= "<input type=\"hidden\" id=\"removetagsuccessmessage\" value=\"" . wfMsg('imagetagging-removetagsuccess') . "\">\n"; |
614 | | - |
615 | | - $r .= "<input type=\"hidden\" id=\"oneactionatatimemessage\" value=\"" . wfMsg('imagetagging-oneactionatatimemessage') . "\">\n"; |
616 | | - $r .= "<input type=\"hidden\" id=\"canteditneedloginmessage\" value=\"" . wfMsg('imagetagging-canteditneedloginmessage') . "\">\n"; |
617 | | - $r .= "<input type=\"hidden\" id=\"canteditothermessage\" value=\"" . wfMsg('imagetagging-canteditothermessage') . "\">\n"; |
618 | | - $r .= "<input type=\"hidden\" id=\"oneuniquetagmessage\" value=\"" . wfMsg('imagetagging-oneuniquetagmessage') . "\">\n"; |
619 | | - |
620 | | - return $r; |
621 | | - } |
622 | | - } |
623 | | - |
624 | | -} |
| 438 | +} |
\ No newline at end of file |