r84621 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84620‎ | r84621 | r84622 >
Date:18:49, 23 March 2011
Author:ashley
Status:deferred
Tags:
Comment:
ImageTagging: some cleanup:
*moved ImageTagPage class from the main setup file into its own file
*rewrote some SQL queries to use the Database abstraction layer properly
*removed unused globals
*bumped version number
*coding style tweaks
Modified paths:
  • /trunk/extensions/ImageTagging/ImageTagPage.php (added) (history)
  • /trunk/extensions/ImageTagging/ImageTagging.php (modified) (history)
  • /trunk/extensions/ImageTagging/ImageTagging_body.php (modified) (history)
  • /trunk/extensions/ImageTagging/img_tagging.js (modified) (history)

Diff [purge]

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 @@
77 * @ingroup Extensions
88 */
99
10 -define('TAGGEDIMGS_PER_PAGE', 12);
 10+define( 'TAGGEDIMGS_PER_PAGE', 12 );
1111
1212 /**
1313 * Photos tagged gallery
@@ -19,62 +19,84 @@
2020 /**
2121 * Create a new tagged images object.
2222 */
23 - function __construct() {
24 - global $wgLang, $wgAllowRealName, $wgRequest, $wgOut;
 23+ public function __construct() {
 24+ global $wgRequest, $wgOut;
2525
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' );
2727
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' ) );
3030 $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();
3435
35 - parent::__construct('TaggedImages');
 36+ parent::__construct( 'TaggedImages' );
3637 }
3738
3839 /**
3940 * 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;
4446
4547 wfProfileIn( __METHOD__ );
4648
47 - $db = wfGetDB(DB_SLAVE);
 49+ $dbr = wfGetDB( DB_SLAVE );
4850
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+ }
5367
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+ );
5680
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, '' );
6584 }
66 - $db->freeResult($res);
6785
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 ) {
7295 $this->mCount = $o->img_count;
7396 }
74 - $db->freeResult($res);
7597
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() );
79101
80102 wfProfileOut( __METHOD__ );
81103 }
@@ -82,25 +104,27 @@
83105 /**
84106 * Add an image to the gallery.
85107 *
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.
88111 */
89 - function add( $image, $html='' ) {
 112+ function add( $image, $html = '' ) {
90113 $this->mImages[] = array( &$image, $html );
91114 }
92115
93116 /**
94117 * Add an image at the beginning of the gallery.
95118 *
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.
98122 */
99 - function insert( $image, $html='' ) {
 123+ function insert( $image, $html = '' ) {
100124 array_unshift( $this->mImages, array( &$image, $html ) );
101125 }
102126
103127 /**
104 - * isEmpty() returns true if the gallery contains no images
 128+ * @return Boolean: true if the gallery contains no images
105129 */
106130 function isEmpty() {
107131 return empty( $this->mImages );
@@ -111,56 +135,89 @@
112136
113137 $numPages = $this->mCount / TAGGEDIMGS_PER_PAGE;
114138
115 - if (!$this->mQuery) $this->mQuery = "all";
 139+ if ( !$this->mQuery ) {
 140+ $this->mQuery = 'all';
 141+ }
116142
117 - $queryTitle = Title::newFromText($this->mQuery, NS_MAIN);
 143+ $queryTitle = Title::newFromText( $this->mQuery, NS_MAIN );
118144
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+ );
120152
121153 wfProfileOut( __METHOD__ );
122154 return $html;
123155 }
124156
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 {
129162 $html = '<b>' . $pageText . '</b>';
 163+ }
130164
131165 $html .= '&#160;';
132166 return $html;
133167 }
134168
135 - function pagerHTML($topBottom) {
 169+ function pagerHTML( $topBottom ) {
136170 global $wgOut;
137171
138172 $titleObj = SpecialPage::getTitleFor( 'TaggedImages' );
139173
140174 $maxPages = 5; // 5 real pagers
141 - $numPages = ceil($this->mCount / TAGGEDIMGS_PER_PAGE);
 175+ $numPages = ceil( $this->mCount / TAGGEDIMGS_PER_PAGE );
142176
143 - if ( $numPages <= 1 ) return '';
 177+ if ( $numPages <= 1 ) {
 178+ return '';
 179+ }
144180
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;\">";
146182
147 - $hrefPrefix = $titleObj->escapeLocalURL("q=" . $this->mQuery . "&page=");
 183+ $hrefPrefix = $titleObj->escapeLocalURL(
 184+ 'q=' . $this->mQuery . '&page='
 185+ );
148186
149187 // build prev button
150188 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+ );
152195 }
153196
154197 // 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+ }
158205
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+ );
160212 }
161213
162214 // 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+ );
165222 }
166223
167224 $html .= '</span>';
@@ -176,7 +233,6 @@
177234 * - the image name
178235 * - the additional text provided when adding the image
179236 * - the size of the image
180 - *
181237 */
182238 function toHTML() {
183239 global $wgLang, $wgUser, $wgOut;
@@ -185,7 +241,7 @@
186242
187243 $s = '<div>';
188244 $s .= $this->pagerStatusHTML();
189 - $s .= $this->pagerHTML('top');
 245+ $s .= $this->pagerHTML( 'top' );
190246 $s .= '</div>';
191247
192248 $s .= '<table class="gallery" cellspacing="0" cellpadding="0">';
@@ -200,7 +256,7 @@
201257 // Not an image. Just print the name and skip.
202258 if ( $nt->getNamespace() != NS_IMAGE ) {
203259 $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" : '');
205261 $i++;
206262 continue;
207263 }
@@ -213,7 +269,7 @@
214270 $sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20 ) ) ) . "<br />\n" :
215271 '';
216272
217 - $s .= ($i%4==0) ? '<tr>' : '';
 273+ $s .= ( $i%4 == 0 ) ? '<tr>' : '';
218274 $thumb = $img->getThumbnail( 120, 120 );
219275 $vpad = floor( ( 150 - $thumb->height ) /2 ) - 2;
220276 $s .= '<td><div class="gallerybox">' . '<div class="thumb" style="padding: ' . $vpad . 'px 0;">';
@@ -225,14 +281,14 @@
226282 $textlink . $text . $nb .
227283 '</div>';
228284 $s .= "</div></td>\n";
229 - $s .= ($i%4==3) ? '</tr>' : '';
 285+ $s .= ( $i%4 == 3 ) ? '</tr>' : '';
230286 $i++;
231287 }
232288 if ( $i %4 != 0 ) {
233289 $s .= "</tr>\n";
234290 }
235291 $s .= '</table>';
236 - $s .= $this->pagerHTML('bottom');
 292+ $s .= $this->pagerHTML( 'bottom' );
237293 return $s;
238294 }
239295 } //class
Index: trunk/extensions/ImageTagging/img_tagging.js
@@ -1,4 +1,3 @@
2 -
32 var kBoxRatio = .28;
43 var kBoxMinDim = 84;
54 var kBoxBorderWidth = 4;
@@ -10,418 +9,438 @@
1110 var imageElem = null;
1211 var taggingBusy = false;
1312
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';
2221
23 -function gid(id) {
24 - return document.getElementById(id);
 22+function gid( id ) {
 23+ return document.getElementById( id );
2524 }
2625
2726 function setupImageTagging() {
28 - var imgDiv = gid('file');
29 - imgDiv.onclick = function(e) {
 27+ var imgDiv = gid( 'file' );
 28+ imgDiv.onclick = function( e ) {
3029
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;
3435
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 );
3738
38 - clickAt(e.clientX - imgDivAbsLoc.x, e.clientY - imgDivAbsLoc.y);
 39+ clickAt( e.clientX - imgDivAbsLoc.x, e.clientY - imgDivAbsLoc.y );
3940
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+ };
4353 }
4454
4555 function tearDownImageTagging() {
46 - var imgDiv = gid('file');
 56+ var imgDiv = gid( 'file' );
4757
48 - imgDiv.onclick = function(e) {
49 - e.stopPropagation();
50 - e.preventDefault();
51 - }
 58+ imgDiv.onclick = function( e ) {
 59+ e.stopPropagation();
 60+ e.preventDefault();
 61+ }
5262 }
5363
5464 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;
6767
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+ }
7273
73 - if ( result ) {
74 - var articleName = gid('imgName').value;
 74+ if ( result ) {
 75+ var articleName = gid( 'imgName' ).value;
7576
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+ }
8183
82 - window.location.href = loginPageURL;
83 - }
 84+ window.location.href = loginPageURL;
 85+ }
8486
85 - return;
86 - }
 87+ return;
 88+ }
8789
88 - if ( !tagStatusDiv ) {
89 - tagStatusDiv = document.getElementById('tagStatusDiv');
 90+ if ( !tagStatusDiv ) {
 91+ tagStatusDiv = document.getElementById( 'tagStatusDiv' );
9092
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+ }
9496
95 - tagStatusDiv.style.display = "block";
96 - setupImageTagging();
 97+ tagStatusDiv.style.display = 'block';
 98+ setupImageTagging();
9799 }
98100
99101 function doneAddingTags() {
100 - tagStatusDiv.style.display = "none";
101 - hideTagBox();
102 - tearDownImageTagging();
 102+ tagStatusDiv.style.display = 'none';
 103+ hideTagBox();
 104+ tearDownImageTagging();
103105 }
104106
105 -function typeTag (event) {
106 - //suggestKeyDown(event);
107 - /*switch (event.keyCode) {
 107+function typeTag( event ) {
 108+ //suggestKeyDown( event );
 109+ /*switch ( event.keyCode ) {
108110 case 13: // return
109 - case 3: // enter
110 - submitTag();
 111+ case 3: // enter
 112+ submitTag();
111113 break;
112 - default:
113 - suggestKeyDown(event);
114 - break;
 114+ default:
 115+ suggestKeyDown( event );
 116+ break;
115117 }*/
116118 }
117119
118120 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+ }
123125
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+ }
138140
139 - if (!request)
140 - alert("Error initializing XMLHttpRequest!");
 141+ if ( !request ) {
 142+ alert( 'Error initializing XMLHttpRequest in img_tagging.js!' );
 143+ }
141144
142 - return request;
 145+ return request;
143146 }
144147
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' );
148151 }
149152
150153 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+ }
157160
158 - var request = createRequest();
159 - if ( request ) {
160 - taggingBusy = true;
 161+ var request = createRequest();
 162+ if ( request ) {
 163+ taggingBusy = true;
161164
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;
169175
170 - setTaggingStatus(kMessageAddTagSuccess, false);
171 - taggingBusy = false;
172 - }
173 - };
 176+ setTaggingStatus( kMessageAddTagSuccess, false );
 177+ taggingBusy = false;
 178+ }
 179+ };
174180
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+ }
180186 }
181187
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;
186192
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();
195203
196 - taggingBusy = false;
197 - }
198 - };
199 - request.send(null);
 204+ taggingBusy = false;
 205+ }
 206+ };
 207+ request.send( null );
200208
201 - var removeTagMsg = gid(kMessageRemovingTag).getAttribute("value");
202 - elem.setAttribute("onclick", null);
203 - elem.innerHTML = "&nbsp;" + removeTagMsg;
 209+ var removeTagMsg = gid( kMessageRemovingTag ).getAttribute( 'value' );
 210+ elem.setAttribute( 'onclick', null );
 211+ elem.innerHTML = '&nbsp;' + removeTagMsg;
204212
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+}
213221
214222 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' ) );
218226
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);
220228
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;
223231
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;
226234
227 - //alert("percents " + percentX + ", " + percentY);
 235+ //alert("percents " + percentX + ", " + percentY);
228236
229 - return escape(percentX + "," + percentY);
 237+ return escape( percentX + ',' + percentY );
230238 }
231239
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 );
235243 }
236244
237 -function tagBoxAt(boxCenterX, boxCenterY, showEditUI) {
238 - var imgDiv = gid('file');
 245+function tagBoxAt( boxCenterX, boxCenterY, showEditUI ) {
 246+ var imgDiv = gid( 'file' );
239247
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';
245253
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';
252260
253 - tagBoxDiv.appendChild(tagBoxInnerDiv);
254 - imgDiv.appendChild(tagBoxDiv);
255 - }
 261+ tagBoxDiv.appendChild( tagBoxInnerDiv );
 262+ imgDiv.appendChild( tagBoxDiv );
 263+ }
256264
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+ }
261270
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+ }
272285
273 - boxX += imgDiv.offsetLeft;
274 - boxY += imgDiv.offsetTop;
 286+ boxX += imgDiv.offsetLeft;
 287+ boxY += imgDiv.offsetTop;
275288
276 - boxCenterX = boxX + boxDim/2.0;
277 - boxCenterY = boxY + boxDim/2.0;
 289+ boxCenterX = boxX + boxDim / 2.0;
 290+ boxCenterY = boxY + boxDim / 2.0;
278291
279 - setTagBoxRect(boxX, boxY, boxDim, boxDim);
280 - tagBoxDiv.style.display = "block";
 292+ setTagBoxRect( boxX, boxY, boxDim, boxDim );
 293+ tagBoxDiv.style.display = 'block';
281294
282 - if ( !tagEditFieldDiv )
283 - tagEditFieldDiv = gid('tagEditField');
 295+ if ( !tagEditFieldDiv ) {
 296+ tagEditFieldDiv = gid( 'tagEditField' );
 297+ }
284298
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+ );
288306
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';
292311
293 - gid('articleTag').focus();
294 - }
 312+ gid( 'articleTag' ).focus();
 313+ }
295314 }
296315
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 );
305324 }
306325
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';
311330 }
312331
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} );
315334 }
316335
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';
320339 }
321340
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 };
324343 }
325344
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;
333351 curtop += obj.offsetTop;
334352 obj = obj.offsetParent;
335353 }
 354+ } else if ( obj.y ) {
 355+ curtop += obj.y;
 356+ curleft += obj.x;
336357 }
337 - else if (obj.y) {
338 - curtop += obj.y;
339 - curleft += obj.x;
340 - }
341358
342 - return {x: curleft, y:curtop};
 359+ return { x: curleft, y: curtop };
343360 }
344361
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;
365365
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 };
367386 }
368387
369 -function findChild (element, nodeName) {
 388+function findChild( element, nodeName ) {
370389 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 ) {
373392 return child;
 393+ }
374394 }
375395 return null;
376396 }
377397
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 );
381401 }
382402
383403 function hideTagBox() {
384 - tagBoxDiv.style.display = "none";
385 - gid('tagEditField').style.display = "none";
 404+ tagBoxDiv.style.display = 'none';
 405+ gid( 'tagEditField' ).style.display = 'none';
386406 }
387407
388408 function tagUIVisible() {
389 - return ( tagBoxDiv.style.display != "none" );
390 -}
 409+ return ( tagBoxDiv.style.display != 'none' );
 410+}
391411
392 -
393412 function focusInstructions() {
394 - window.location.hash = 'tagging_instructions';
 413+ window.location.hash = 'tagging_instructions';
395414 }
396415
397416 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+ }
402421 }
403422
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+ }
412431 }
413432
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+ }
421440 }
422441
423442 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+ }
428447 }
\ No newline at end of file
Index: trunk/extensions/ImageTagging/ImageTagging.php
@@ -3,30 +3,46 @@
44 * ImageTagging extension by Wikia, Inc.
55 * Lets a user select regions of an embedded image and associate an article with that region
66 *
 7+ * @file
 8+ * @ingroup Extensions
 9+ * @version 1.2
710 * @author Tristan Harris
811 * @author Tomasz Klim
912 * @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
1014 */
1115
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+}
1519
16 -$wgExtensionFunctions[] = 'wfImageTagPageSetup';
 20+// Extension credits that will show up on Special:Version
1721 $wgExtensionCredits['other'][] = array(
1822 'path' => __FILE__,
1923 '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',
2226 'url' => 'http://www.mediawiki.org/wiki/Extension:ImageTagging',
2327 'descriptionmsg' => 'imagetagging-desc',
2428 );
2529
 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+
2640 // other hooks to try: 'ParserAfterTidy', ...
2741 #$wgHooks['OutputPageBeforeHTML'][] = 'wfCheckArticleImageTags';
2842 $wgHooks['ArticleFromTitle'][] = 'wfArticleFromTitle';
2943
30 -$dir = dirname(__FILE__) . '/';
 44+// Set up the Special:TaggedImages special page
 45+$dir = dirname( __FILE__ ) . '/';
 46+$wgAutoloadClasses['ImageTagPage'] = $dir . 'ImageTagPage.php';
3147 $wgAutoloadClasses['TaggedImages'] = $dir . 'ImageTagging_body.php';
3248 $wgExtensionMessagesFiles['ImageTagging'] = $dir . 'ImageTagging.i18n.php';
3349 $wgExtensionAliasesFiles['ImageTagging'] = $dir . 'ImageTagging.alias.php';
@@ -36,38 +52,45 @@
3753 * End Trie Handlers
3854 ********************/
3955
40 -function wfCheckArticleImageTags($outputPage, $text) {
41 - global $wgOut, $wgDBname, $wgTitle;
42 -
 56+function wfCheckArticleImageTags( $outputPage, $text ) {
4357 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+ );
4869
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();
5274
53 - $wgOut->addHTML('
54 - <a href="' . $taggedImagesObj->getLocalUrl('q='.$titleText) . '">
 75+ $outputPage->addHTML('
 76+ <a href="' . $taggedImagesObj->getLocalURL( 'q=' . $titleText ) . '">
5577 <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+ );
7295 }
7396 }
7497 return true;
@@ -76,142 +99,161 @@
77100 // TKL 2006-03-07: it doesn't work in new MediaWiki, modification required in includes/Wiki.php (class name change only)
78101 // $wgNamespaceTemplates[NS_IMAGE] = 'ImageTagPage';
79102
80 -function addTag($action, $article) {
81 - if($action != 'addTag') return true;
 103+function addTag( $action, $article ) {
 104+ if( $action != 'addTag' ) {
 105+ return true;
 106+ }
82107
83 - global $wgRequest, $wgDBname, $wgOut, $wgUser;
 108+ global $wgRequest, $wgOut, $wgUser;
84109
85110 wfProfileIn( __METHOD__ );
86111
87 - $wgOut->setArticleBodyOnly(true);
 112+ $wgOut->setArticleBodyOnly( true );
88113
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' );
92117 $userText = $wgUser->getName();
93118
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 );
97122
98 - $img = wfFindFile($imgName);
99 - if ($img) {
 123+ $img = wfFindFile( $imgName );
 124+ if ( $img ) {
100125 $imgTitle = $img->getTitle();
101126
102 - wfPurgeTitle($imgTitle);
 127+ wfPurgeTitle( $imgTitle );
103128
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__
112140 );
113141
114142 $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 ) );
117145
118146 $logPage = new LogPage( 'tag' );
119147 $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 );
122153
123154 $enotif = new EmailNotification;
124 - $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false);
 155+ $enotif->notifyOnPageChange(
 156+ $wgUser, $imgTitle, wfTimestampNow(), $logComment, false
 157+ );
125158 } else {
126159 $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+ );
131166 }
132 - wfProfileOut( __METHOD__ );
 167+ wfProfileOut( __METHOD__ );
133168 return false;
134169 }
135170
136 -function removeTag($action, $article) {
137 - if ($action != 'removeTag') return true;
 171+function removeTag( $action, $article ) {
 172+ if ( $action != 'removeTag' ) {
 173+ return true;
 174+ }
138175
139 - global $wgRequest, $wgOut, $wgDBname, $wgUser;
 176+ global $wgRequest, $wgOut, $wgUser;
140177
141178 wfProfileIn( __METHOD__ );
142179
143 - $wgOut->setArticleBodyOnly(true);
 180+ $wgOut->setArticleBodyOnly( true );
144181
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' );
148185 $userText = $wgUser->getName();
149186
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 );
153190
154 - $img = wfFindFile($imgName);
155 - if ($img) {
 191+ $img = wfFindFile( $imgName );
 192+ if ( $img ) {
156193 $imgTitle = $img->getTitle();
157194
158 - wfPurgeTitle($imgTitle);
 195+ wfPurgeTitle( $imgTitle );
159196
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__ );
162199
163200 $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 ) );
166203
167204 $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 );
170207
171208 $enotif = new EmailNotification;
172 - $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false);
 209+ $enotif->notifyOnPageChange(
 210+ $wgUser, $imgTitle, wfTimestampNow(), $logComment, false
 211+ );
173212 } else {
174213 $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+ );
179220 }
180221
181222 wfProfileOut( __METHOD__ );
182223 return false;
183224 }
184225
185 -function tagSearch($action, $article) {
186 - if($action != 'tagSearch') return true;
 226+function tagSearch( $action, $article ) {
 227+ if( $action != 'tagSearch' ) {
 228+ return true;
 229+ }
187230
188 - global $wgRequest, $wgDBname, $wgOut, $wgUser;
 231+ global $wgRequest, $wgOut;
189232
190233 wfProfileIn( __METHOD__ );
191234
192 - $wgOut->setArticleBodyOnly(true);
 235+ $wgOut->setArticleBodyOnly( true );
193236
194 - $query = $wgRequest->getText('q');
195 - $query = preg_replace( "/[\"'<>]/", "", $query );
 237+ $query = $wgRequest->getText( 'q' );
 238+ $query = preg_replace( "/[\"'<>]/", '', $query );
196239
197240 $search = SearchEngine::create();
198241 $search->setLimitOffset( 10, 0 );
199 - $search->setNamespaces( array(NS_MAIN) );
 242+ $search->setNamespaces( array( NS_MAIN ) );
200243 $search->showRedirects = true;
201244 $titleMatches = $search->searchTitle( $query );
202245
203246 $numResults = ( $titleMatches ? $titleMatches->numRows() : 0 );
204 - if ( $numResults > 0 )
205 - $wgOut->addHTML(wfTagSearchShowMatches($titleMatches));
 247+ if ( $numResults > 0 ) {
 248+ $wgOut->addHTML( wfTagSearchShowMatches( $titleMatches ) );
 249+ }
206250
207 - #echo "numResults: " . $numResults . ", query: " . $query;
208 -
209251 wfProfileOut( __METHOD__ );
210252 return false;
211253 }
212254
213255 /**
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
216258 */
217259 function wfTagSearchShowMatches( &$matches ) {
218260 global $wgContLang;
@@ -223,7 +265,8 @@
224266
225267 $out = "<searchresults>\n";
226268
227 - while( $result = $matches->next() ) {
 269+ $result = $matches->next();
 270+ while( $result ) {
228271 $out .= wfTagSearchHitXML( $result, $terms );
229272 }
230273 $out .= "</searchresults>\n";
@@ -237,8 +280,8 @@
238281
239282 /**
240283 * 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
243286 */
244287 function wfTagSearchHitXML( $result, $terms ) {
245288 global $wgUser, $wgContLang;
@@ -268,11 +311,11 @@
269312
270313 $extract = '';
271314 foreach ( $lines as $line ) {
272 - if ( 0 == $contextlines ) {
 315+ if ( $contextlines == 0 ) {
273316 break;
274317 }
275318 ++$lineno;
276 - if ( ! preg_match( $pat1, $line, $m ) ) {
 319+ if ( !preg_match( $pat1, $line, $m ) ) {
277320 continue;
278321 }
279322 $contextlines--;
@@ -287,7 +330,7 @@
288331 $found = $m[2];
289332
290333 $line = htmlspecialchars( $pre . $found . $post );
291 - $pat2 = '/(' . $terms . ")/i";
 334+ $pat2 = '/(' . $terms . ')/i';
292335 $line = preg_replace( $pat2, "<span class='searchmatch'>\\1</span>", $line );
293336
294337 $extract .= "<br /><small>{$lineno}: {$line}</small>\n";
@@ -297,7 +340,7 @@
298341 return "<result>\n<link>{$link}</link>\n<context>{$extract}</context>\n</result>\n";
299342 }
300343
301 -function wfPurgeTitle($title) {
 344+function wfPurgeTitle( $title ) {
302345 global $wgUseSquid;
303346
304347 wfProfileIn( __METHOD__ );
@@ -317,53 +360,69 @@
318361 wfProfileOut( __METHOD__ );
319362 }
320363
321 -function wfGetImageTags($img, $imgName) {
322 - global $wgDBname, $wgUser, $wgOut, $wgLang;
 364+function wfGetImageTags( $img, $imgName ) {
 365+ global $wgUser, $wgOut, $wgLang;
323366
324367 wfProfileIn( __METHOD__ );
325368
326369 $sk = $wgUser->getSkin();
327 - $db = wfGetDB(DB_SLAVE);
328 - $db->selectDB($wgDBname);
 370+ $db = wfGetDB( DB_SLAVE );
329371 $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+ );
334377
335378 $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 ) {
339382 $html .= ', ';
 383+ }
340384
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+ );
342389
343390 $span = '<span id="' . $o->article_tag . '-tag" onmouseout="hideTagBox()" onmouseover="tagBoxPercent(' . $o->tag_rect . ', false)">';
344391
345 - #echo "article tag: " . $o->article_tag . "\n";
346 - $articleTitle = Title::newFromText($o->article_tag);
 392+ $articleTitle = Title::newFromText( $o->article_tag );
347393
348394 #$articleLink = '<a href="' . $articleTitle->escapeFullURL() . '" onmouseout="hideTagBox()">' . $o->article_tag . '</a>';
349 - $articleLink = $sk->makeLinkObj($articleTitle);
 395+ $articleLink = $sk->makeLinkObj( $articleTitle );
350396
351 - $specialImagesTitle = Title::newFromText("Special:TaggedImages");
 397+ $specialImagesTitle = SpecialPage::getTitleFor( 'TaggedImages' );
352398
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>';
354402
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>';
356406
357 - $html .= $span . $articleLink . ' (' . $wgLang->pipeList( array( $imagesLink, $removeLink ) ) . ')</span>';
 407+ $html .= $span . $articleLink . ' (' .
 408+ $wgLang->pipeList( array( $imagesLink, $removeLink ) ) . ')</span>';
358409 }
359 - $db->freeResult($res);
360410
361 - if ( $html )
362 - $html = wfMsg('imagetagging-inthisimage', $html);
 411+ if ( $html ) {
 412+ $html = wfMsg( 'imagetagging-inthisimage', $html );
 413+ }
363414
364415 wfProfileOut( __METHOD__ );
365416 return $html;
366417 }
367418
 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+ */
368427 function wfArticleFromTitle( &$title, &$article ) {
369428 global $wgUser;
370429
@@ -375,249 +434,4 @@
376435
377436 wfProfileOut( __METHOD__ );
378437 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

Status & tagging log