r34656 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34655‎ | r34656 | r34657 >
Date:12:43, 12 May 2008
Author:greg
Status:old
Tags:
Comment:
Remove more hardcoding, fix SQL calls, fix notify calls, etc.
Basically do the bare minimum to actually get it somewhat working.
(The extension still needs lots of work)
Modified paths:
  • /trunk/extensions/ImageTagging/ImageTagPage.php (modified) (history)
  • /trunk/extensions/ImageTagging/SpecialTaggedImages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ImageTagging/ImageTagPage.php
@@ -18,6 +18,12 @@
1919 $wgHooks['ArticleFromTitle'][] = 'wfArticleFromTitle';
2020
2121
 22+$dir = dirname(__FILE__) . '/';
 23+$wgAutoloadClasses['TaggedImages'] = $dir . 'SpecialTaggedImages.php';
 24+$wgSpecialPages['TaggedImages'] = 'TaggedImages';
 25+
 26+
 27+
2228 /********************
2329 * End Trie Handlers
2430 ********************/
@@ -30,8 +36,8 @@
3137 {
3238 $db =& wfGetDB(DB_SLAVE);
3339 $res = $db->query("SELECT article_tag, tag_rect, unique_id, COUNT(article_tag) AS count FROM ".
34 - " `$wgDBname`.`imagetags` ".
35 - " WHERE article_tag='" . addslashes($wgTitle->getText()). "'" . /*LIMIT 1"*/ " GROUP BY article_tag" );
 40+ $db->tableName('imagetags').
 41+ " WHERE article_tag='" . addslashes($wgTitle->getText()). "' GROUP BY article_tag" );
3642
3743 if ($o = $db->fetchObject($res)) {
3844 $taggedImagesObj = Title::newFromText('TaggedImages', NS_SPECIAL);
@@ -92,12 +98,14 @@
9399 wfPurgeTitle($imgTitle);
94100
95101 $db =& wfGetDB(DB_MASTER);
96 - $db->insert("`$wgDBname`.`imagetags`",
97 - array( 'img_page_id' => 0,//$img->getTitle()->getArticleID(),
98 - 'img_name' => $imgName,
99 - 'article_tag' => $tagName,
100 - 'tag_rect' => $tagRect,
101 - 'user_text' => $userText));
 102+ $db->insert('imagetags',
 103+ array(
 104+ 'img_page_id' => 0,
 105+ 'img_name' => $imgName,
 106+ 'article_tag' => $tagName,
 107+ 'tag_rect' => $tagRect,
 108+ 'user_text' => $userText)
 109+ );
102110
103111 $wgOut->clearHTML();
104112 $wgOut->addHTML("<!-- added tag for image $imgName to database! -->");
@@ -108,7 +116,8 @@
109117 $logComment = "Image [[$link|$imgName]] was tagged to article [[$tagName]] by $userText";
110118 $logPage->addEntry( 'tag', $imgTitle, $logComment);
111119
112 - EmailNotification::notifyOnPageChange($imgTitle, wfTimestampNow(), $logComment, false);
 120+ $enotif = new EmailNotification;
 121+ $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false);
113122 }
114123 else {
115124 $wgOut->clearHTML();
@@ -150,7 +159,7 @@
151160 wfPurgeTitle($imgTitle);
152161
153162 $db =& wfGetDB(DB_MASTER);
154 - $db->delete("`$wgDBname`.`imagetags`", array('unique_id' => $tagID));
 163+ $db->delete('imagetags', array('unique_id' => $tagID));
155164
156165 $wgOut->clearHTML();
157166 $wgOut->addHTML("<!-- removed tag to database! -->");
@@ -160,7 +169,8 @@
161170 $logComment = "Removed tag to article [[$tagName]] by $userText";
162171 $logPage->addEntry( 'tag', $imgTitle, $logComment);
163172
164 - EmailNotification::notifyOnPageChange($imgTitle, wfTimestampNow(), $logComment, false);
 173+ $enotif = new EmailNotification;
 174+ $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false);
165175 }
166176 else {
167177 $wgOut->clearHTML();
@@ -391,7 +401,6 @@
392402 $wgMessageCache->addMessage('removetagsuccess', "Removed tag.");
393403 $wgMessageCache->addMessage('oneactionatatimemessage', "Removed tag.");
394404 $wgMessageCache->addMessage('canteditneedloginmessage', "You can't edit this page. It may be because you need to login to tag images. Do you want to login now?");
395 - $wgMessageCache->addMessage('canteditothermessage', "You can't edit this page, either because you don't have the rights, or because this page has been locked for other reasons. For more information, see http://www.wikia.com/wiki/Protection");
396405 $wgMessageCache->addMessage('oneactionatatimemessage', "Sorry, only one tagging action at a time. Please wait for the existing action to complete.");
397406 $wgMessageCache->addMessage('oneuniquetagmessage', "Sorry, this image already has a tag with this name.");
398407 $wgMessageCache->addMessage('imagetag_seemoreimages', 'See more images of &#8220;$1&#8221; ($2)');
@@ -401,32 +410,27 @@
402411 class ImageTagPage extends ImagePage
403412 {
404413 function openShowImage() {
405 - global $wgOut, $wgUser, $wgServer, $wgImageTaggingPath, $wgStyleVersion;
 414+ global $wgOut, $wgUser, $wgServer, $wgImageTaggingPath, $wgStyleVersion, $wgJsMimeType, $wgScriptPath;
406415
407416 wfProfileIn( __METHOD__ );
408417
409 - // TKL 2007-03-09: get files only from extensions directory, and not from skins/common
410 - if ( $wgImageTaggingPath == '' ) { $wgImageTaggingPath = '/wiki/extensions/wikia/ImageTagging/'; }
411418
412 - $wgOut->addScript('<script type="text/javascript" src="' . $wgImageTaggingPath . 'img_tagging.js?'.$wgStyleVersion.'" charset="utf-8"></script>');
413 - $wgOut->addScript('<script type="text/javascript" src="' . $wgImageTaggingPath . 'json.js?'.$wgStyleVersion.'" charset="utf-8"></script>');
 419+ global $wgJsMimeType, $wgScriptPath ;
 420+ $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/ImageTagging/img_tagging.js?$wgStyleVersion\"></script>\n" );
 421+ $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/ImageTagging/json.js?$wgStyleVersion\"></script>\n" );
414422
415 - // TKL commented out 2007-03-06
416 - // $wgOut->addHTML('<script type="text/javascript"> var baseUrl = "{$wgServer}/wiki/"; </script>');
417 - // $wgOut->addScript('<script type="text/javascript" src="' . $wgImageTaggingPath . 'WSuggest.js"></script>');
 423+ $imgName = $this->getTitle()->getText();
 424+ $wgOut->addHTML("<input type='hidden' value='$imgName' id='imgName' />");
 425+ $wgOut->addHTML("<input type='hidden' value='$wgScriptPath/extensions/magTagging' id='imgPath' />");
418426
419 - $imgName = $this->getTitle()->getText();
420 - $wgOut->addHTML("<input type='hidden' value='" . $imgName . "' id='imgName' />");
421 - $wgOut->addHTML("<input type='hidden' value='" . $wgImageTaggingPath . "' id='imgPath' />");
 427+ if ( $wgUser->isLoggedIn() )
 428+ $wgOut->addHTML("<input type='hidden' value='1' id='userLoggedIn'/>");
 429+
 430+ if ( $wgUser->isAllowed('edit') &&
 431+ $this->mTitle->userCanEdit() &&
 432+ ( $this->mTitle->isProtected('edit') == false || in_array( 'sysop', $wgUser->getGroups() ) ) )
 433+ $wgOut->addHTML("<input type='hidden' value='1' id='canEditPage'/>");
422434
423 - if ( $wgUser->isLoggedIn() )
424 - $wgOut->addHTML("<input type='hidden' value='1' id='userLoggedIn'/>");
425 -
426 - if ( $wgUser->isAllowed('edit') &&
427 - $this->mTitle->userCanEdit() &&
428 - ( $this->mTitle->isProtected('edit') == false || in_array( 'sysop', $wgUser->getGroups() ) ) )
429 - $wgOut->addHTML("<input type='hidden' value='1' id='canEditPage'/>");
430 -
431435 $this->modifiedImagePageOpenShowImage();
432436
433437 if ( $this->img->exists() ) {
Index: trunk/extensions/ImageTagging/SpecialTaggedImages.php
@@ -5,7 +5,7 @@
66 * @subpackage SpecialPage
77 */
88
9 -define(TAGGEDIMGS_PER_PAGE, 12);
 9+define('TAGGEDIMGS_PER_PAGE', 12);
1010
1111
1212 $wgExtensionFunctions[] = 'wfSpecialTaggedImages';
@@ -64,27 +64,31 @@
6565
6666 $db =& wfGetDB(DB_SLAVE);
6767
68 - # COUNT(img_name) AS img_count
69 -/*
70 - $res = $db->query("SELECT " . ( $this->mQuery ? "" : "DISTINCT " ) . "imagetags.img_name, image.img_timestamp FROM " .
71 - " `$wgDBname`.`imagetags` LEFT JOIN `$wgDBname`.`image` ON imagetags.img_name = image.img_name ".
72 - ( $this->mQuery ? " WHERE article_tag='" . $this->mQuery . "'" : "" ) .
73 - " GROUP BY unique_id " .
74 - " ORDER BY image.img_timestamp desc " .
75 - " LIMIT " . ($this->mStartPage * TAGGEDIMGS_PER_PAGE) .
76 - ", " . TAGGEDIMGS_PER_PAGE);
77 -*/
 68+ $WHERECLAUSE = '';
 69+ if ($this->mQuery) {
 70+ $WHERECLAUSE = " WHERE article_tag='$this->mQuery'";
 71+ }
7872
79 - $res = $db->query("SELECT image.img_name, image.img_timestamp FROM starwars.image WHERE image.img_name IN (SELECT imagetags.img_name FROM imagetags ".($this->mQuery ? " WHERE imagetags.article_tag='" . $this->mQuery . "'" : "")." GROUP by imagetags.unique_id) ORDER BY image.img_timestamp DESC LIMIT " . ($this->mStartPage * TAGGEDIMGS_PER_PAGE) . ", " . TAGGEDIMGS_PER_PAGE);
 73+ $imagetable = $db->tableName( 'image' );
 74+ $imagetagstable = $db->tableName( 'imagetags' );
8075
 76+ $SQL = "
 77+SELECT img_name, img_timestamp
 78+FROM $imagetable
 79+WHERE img_name IN
 80+ (SELECT img_name FROM $imagetagstable $WHERECLAUSE)
 81+ORDER BY img_timestamp DESC";
 82+
 83+ $SQL = $db->LimitResult($SQL, TAGGEDIMGS_PER_PAGE, $this->mStartPage * TAGGEDIMGS_PER_PAGE);
 84+
 85+ $res = $db->query($SQL);
8186 while ($o = $db->fetchObject($res)) {
8287 $img = Image::newFromName($o->img_name);
8388 $this->add($img, '');
8489 }
8590 $db->freeResult($res);
8691
87 - $res = $db->query("SELECT COUNT(img_name) as img_count FROM " .
88 - " `$wgDBname`.`imagetags` ".
 92+ $res = $db->query("SELECT COUNT(img_name) as img_count FROM $imagetagstable".
8993 ( $this->mQuery ? " WHERE article_tag='" . $this->mQuery . "'" : "" ) .
9094 " GROUP BY article_tag");
9195 if ( $o = $db->fetchObject($res) ) {

Status & tagging log