From 30eb5ddd8beca984b2928f4fafbcd6548f8157da Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Thu, 9 Feb 2012 23:04:37 -0500 Subject: [PATCH 1/5] More type hints! --- contrib/admin/main.php | 5 +++-- contrib/artists/theme.php | 4 ++-- contrib/blocks/main.php | 1 + contrib/bookmarks/main.php | 3 ++- contrib/bulk_add/main.php | 2 +- contrib/downtime/main.php | 5 +++-- contrib/downtime/theme.php | 2 +- contrib/emoticons/main.php | 1 + contrib/emoticons/theme.php | 2 +- contrib/favorites/main.php | 2 +- contrib/featured/theme.php | 2 +- contrib/forum/main.php | 2 +- contrib/handle_flash/main.php | 8 ++++---- contrib/home/theme.php | 2 +- contrib/link_image/main.php | 2 +- contrib/link_image/theme.php | 6 +++--- contrib/mass_tagger/main.php | 2 +- contrib/rating/main.php | 6 +++--- contrib/rating/theme.php | 4 ++-- contrib/res_limit/main.php | 1 + contrib/resize/main.php | 8 +++----- contrib/resize/theme.php | 9 ++++----- contrib/rss_comments/main.php | 1 + contrib/rss_images/main.php | 3 ++- contrib/simpletest/main.php | 1 + contrib/twitter_soc/main.php | 1 + contrib/twitter_soc/theme.php | 2 +- contrib/word_filter/main.php | 3 ++- core/util.inc.php | 12 ++++++------ ext/ext_manager/theme.php | 2 +- ext/handle_pixel/main.php | 19 ++++++++++--------- 31 files changed, 66 insertions(+), 57 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index e03cd69d..881aa2e3 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -137,7 +137,7 @@ class AdminPage extends Extension { $database->Execute("DELETE FROM tags WHERE count=0"); } - private function dbdump($page) { + private function dbdump(Page $page) { $matches = array(); preg_match("#(\w+)://(\w+):(\w+)@([\w\.\-]+)/([\w_]+)(\?.*)?#", DATABASE_DSN, $matches); $software = $matches[1]; @@ -146,6 +146,7 @@ class AdminPage extends Extension { $hostname = $matches[4]; $database = $matches[5]; + // TODO: Support more than just MySQL.. switch($software) { case 'mysql': $cmd = "mysqldump -h$hostname -u$username -p$password $database"; @@ -222,7 +223,7 @@ class AdminPage extends Extension { $database->execute("ALTER TABLE images AUTO_INCREMENT=".$count); } - private function imgdump($page) { + private function imgdump(Page $page) { global $database; $zip = new ZipArchive; $images = $database->get_all("SELECT * FROM images"); diff --git a/contrib/artists/theme.php b/contrib/artists/theme.php index 0f60df72..58e7842e 100644 --- a/contrib/artists/theme.php +++ b/contrib/artists/theme.php @@ -1,7 +1,7 @@ Author"; } @@ -16,7 +16,7 @@ class ArtistsTheme extends Themelet { //$this->display_paginator($page, "artist/list", null, $pageNumber, $totalPages); } - public function sidebar_options($mode, $artistID=NULL, $is_admin=FALSE){ + public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE){ global $page; if($mode == "neutral"){ diff --git a/contrib/blocks/main.php b/contrib/blocks/main.php index f3ee274d..6bfca98a 100644 --- a/contrib/blocks/main.php +++ b/contrib/blocks/main.php @@ -2,6 +2,7 @@ /* * Name: Generic Blocks * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Add HTML to some space * Documentation: diff --git a/contrib/bookmarks/main.php b/contrib/bookmarks/main.php index 8e47bc83..ea983689 100644 --- a/contrib/bookmarks/main.php +++ b/contrib/bookmarks/main.php @@ -2,6 +2,7 @@ /** * Name: Bookmarks * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Allow users to bookmark searches */ @@ -59,7 +60,7 @@ class Bookmarks extends Extension { else {return array();} } - private function add_bookmark($url, $title) { + private function add_bookmark(/*string*/ $url, /*string*/ $title) { global $database; $sql = "INSERT INTO bookmark(owner_id, url, title) VALUES (?, ?, ?)"; $database->Execute($sql, array($user->id, $url, $title)); diff --git a/contrib/bulk_add/main.php b/contrib/bulk_add/main.php index 90f6f96a..1325213f 100644 --- a/contrib/bulk_add/main.php +++ b/contrib/bulk_add/main.php @@ -53,7 +53,7 @@ class BulkAdd extends Extension { } } - private function add_dir($base, $subdir="") { + private function add_dir(/*string*/ $base, $subdir="") { global $page; if(!is_dir($base)) { diff --git a/contrib/downtime/main.php b/contrib/downtime/main.php index 3e87bdf3..462e530f 100644 --- a/contrib/downtime/main.php +++ b/contrib/downtime/main.php @@ -2,6 +2,7 @@ /* * Name: Downtime * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Show a "down for maintenance" page * Documentation: @@ -14,14 +15,14 @@ class Downtime extends Extension { public function get_priority() {return 10;} - public function onSetupBuilding($event) { + public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Downtime"); $sb->add_bool_option("downtime", "Disable non-admin access: "); $sb->add_longtext_option("downtime_message", "
"); $event->panel->add_block($sb); } - public function onPageRequest($event) { + public function onPageRequest(PageRequestEvent $event) { global $config, $page, $user; if($config->get_bool("downtime")) { diff --git a/contrib/downtime/theme.php b/contrib/downtime/theme.php index e529209e..a78ee2fa 100644 --- a/contrib/downtime/theme.php +++ b/contrib/downtime/theme.php @@ -12,7 +12,7 @@ class DowntimeTheme extends Themelet { /** * Display $message and exit */ - public function display_message($message) { + public function display_message(/*string*/ $message) { global $config, $user; $theme_name = $config->get_string('theme'); $data_href = get_base_href(); diff --git a/contrib/emoticons/main.php b/contrib/emoticons/main.php index be958040..ec7a071d 100644 --- a/contrib/emoticons/main.php +++ b/contrib/emoticons/main.php @@ -2,6 +2,7 @@ /* * Name: Emoticon Filter * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Lets users use graphical smilies * Documentation: diff --git a/contrib/emoticons/theme.php b/contrib/emoticons/theme.php index a21a2088..22eaa350 100644 --- a/contrib/emoticons/theme.php +++ b/contrib/emoticons/theme.php @@ -1,6 +1,6 @@ Emoticon list"; diff --git a/contrib/favorites/main.php b/contrib/favorites/main.php index 7c14554f..a3d683e5 100644 --- a/contrib/favorites/main.php +++ b/contrib/favorites/main.php @@ -167,7 +167,7 @@ class Favorites extends Extension { } } - private function add_vote($image_id, $user_id, $do_set) { + private function add_vote(/*int*/ $image_id, /*int*/ $user_id, /*bool*/ $do_set) { global $database; if ($do_set) { $database->Execute( diff --git a/contrib/featured/theme.php b/contrib/featured/theme.php index 74a4134e..76503e34 100644 --- a/contrib/featured/theme.php +++ b/contrib/featured/theme.php @@ -8,7 +8,7 @@ class FeaturedTheme extends Themelet { $page->add_block(new Block("Featured Image", $this->build_featured_html($image), "left", 3)); } - public function get_buttons_html($image_id) { + public function get_buttons_html(/*int*/ $image_id) { global $user; return " ".make_form(make_link("featured_image/set"))." diff --git a/contrib/forum/main.php b/contrib/forum/main.php index cd5ccdaf..15e8e092 100644 --- a/contrib/forum/main.php +++ b/contrib/forum/main.php @@ -173,7 +173,7 @@ class Forum extends Extension { } } - private function get_total_pages_for_thread($threadID) + private function get_total_pages_for_thread(/*int*/ $threadID) { global $database, $config; $result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID)); diff --git a/contrib/handle_flash/main.php b/contrib/handle_flash/main.php index 21b19b30..e59b8892 100644 --- a/contrib/handle_flash/main.php +++ b/contrib/handle_flash/main.php @@ -16,7 +16,7 @@ class FlashFileHandler extends DataHandlerExtension { return in_array(strtolower($ext), $exts); } - protected function create_image_from_data($filename, $metadata) { + protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { global $config; $image = new Image(); @@ -44,7 +44,7 @@ class FlashFileHandler extends DataHandlerExtension { return $image; } - protected function check_contents($file) { + protected function check_contents(/*string*/ $file) { if(!file_exists($file)) return false; $fp = fopen($file, "r"); @@ -55,7 +55,7 @@ class FlashFileHandler extends DataHandlerExtension { return true; } - private function str_to_binarray($string) { + private function str_to_binarray(/*string*/ $string) { $binary = array(); $length = strlen($string); for($j=0; $j<$length; $j++) { @@ -76,7 +76,7 @@ class FlashFileHandler extends DataHandlerExtension { return $int; } - private function swf_get_bounds($filename) { + private function swf_get_bounds(/*string*/ $filename) { $fp = fopen($filename, "r"); $head = fread($fp, 3); $version = fread($fp, 1); diff --git a/contrib/home/theme.php b/contrib/home/theme.php index f35644b0..440c104a 100644 --- a/contrib/home/theme.php +++ b/contrib/home/theme.php @@ -25,7 +25,7 @@ EOD ); } - public function build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text) { + public function build_body(/*string*/ $sitename, /*string*/ $main_links, /*string*/ $main_text, /*string*/ $contact_link, $num_comma, /*string*/ $counter_text) { $main_links_html = empty($main_links) ? "" : ""; $message_html = empty($main_text) ? "" : "
$main_text
"; $counter_html = empty($counter_text) ? "" : "
$counter_text
"; diff --git a/contrib/link_image/main.php b/contrib/link_image/main.php index ab52935e..ee53f1c0 100644 --- a/contrib/link_image/main.php +++ b/contrib/link_image/main.php @@ -21,7 +21,7 @@ class LinkImage extends Extension { $config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)'); } - private function hostify($str) { + private function hostify(/*string*/ $str) { $str = str_replace(" ", "%20", $str); if(strpos($str, "ttp://") > 0) { return $str; diff --git a/contrib/link_image/theme.php b/contrib/link_image/theme.php index a447f6a7..1e5d2196 100644 --- a/contrib/link_image/theme.php +++ b/contrib/link_image/theme.php @@ -51,7 +51,7 @@ class LinkImageTheme extends Themelet { 50)); } - protected function url ($url,$content,$type) { + protected function url (/*string*/ $url, /*string*/ $content, /*string*/ $type) { if ($content == NULL) {$content=$url;} switch ($type) { @@ -67,7 +67,7 @@ class LinkImageTheme extends Themelet { return $text; } - protected function img ($src,$type) { + protected function img (/*string*/ $src, /*string*/ $type) { switch ($type) { case "html": $text = ""; @@ -81,7 +81,7 @@ class LinkImageTheme extends Themelet { return $text; } - protected function link_code($label,$content,$id=NULL) { + protected function link_code(/*string*/ $label, /*string*/ $content, $id=NULL) { return " diff --git a/contrib/mass_tagger/main.php b/contrib/mass_tagger/main.php index 751cfcdf..f91c05a5 100644 --- a/contrib/mass_tagger/main.php +++ b/contrib/mass_tagger/main.php @@ -31,7 +31,7 @@ class MassTagger extends Extension { if($event->get_arg(0) == "tag") $this->_apply_mass_tags( $config, $page, $user, $event ); } - private function _apply_mass_tags( $config, $page, $user, $event ) { + private function _apply_mass_tags( $config, Page $page, $user, $event ) { if( !isset($_POST['ids']) or !isset($_POST['tag']) ) return; $tag = $_POST['tag']; diff --git a/contrib/rating/main.php b/contrib/rating/main.php index ac9ba0fb..072f11e2 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -167,7 +167,7 @@ class Ratings extends Extension { return $sqes; } - public static function privs_to_sql($sqes) { + public static function privs_to_sql(/*string*/ $sqes) { $arr = array(); $length = strlen($sqes); for($i=0; $i<$length; $i++) { @@ -177,7 +177,7 @@ class Ratings extends Extension { return $set; } - public static function rating_to_human($rating) { + public static function rating_to_human(/*string*/ $rating) { switch($rating) { case "s": return "Safe"; case "q": return "Questionable"; @@ -225,7 +225,7 @@ class Ratings extends Extension { } } - private function set_rating($image_id, $rating, $old_rating) { + private function set_rating(/*int*/ $image_id, /*string*/ $rating, /*string*/ $old_rating) { global $database; if($old_rating != $rating){ $database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id)); diff --git a/contrib/rating/theme.php b/contrib/rating/theme.php index 87efa7ef..11667a96 100644 --- a/contrib/rating/theme.php +++ b/contrib/rating/theme.php @@ -1,7 +1,7 @@ add_block(new Block("Bulk Rating", $html)); } - public function rating_to_name($rating) { + public function rating_to_name(/*string*/ $rating) { switch($rating) { case 's': return "Safe"; case 'q': return "Questionable"; diff --git a/contrib/res_limit/main.php b/contrib/res_limit/main.php index b9657a17..c17ad203 100644 --- a/contrib/res_limit/main.php +++ b/contrib/res_limit/main.php @@ -2,6 +2,7 @@ /* * Name: Resolution Limiter * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Allows the admin to set min / max image dimentions */ diff --git a/contrib/resize/main.php b/contrib/resize/main.php index 38075290..51b1bf24 100644 --- a/contrib/resize/main.php +++ b/contrib/resize/main.php @@ -143,16 +143,14 @@ class ResizeImage extends Extension { // Private functions + /* ----------------------------- */ /* This function could be made much smaller by using the ImageReplaceEvent ie: Pretend that we are replacing the image with a resized copy. */ - private function resize_image($image_id, $width, $height) { - global $config; - global $user; - global $page; - global $database; + private function resize_image(/*int*/ $image_id, /*int*/ $width, /*int*/ $height) { + global $config, $user, $page, $database; if ( ($height <= 0) && ($width <= 0) ) { throw new ImageResizeException("Invalid options for height and width. ($width x $height)"); diff --git a/contrib/resize/theme.php b/contrib/resize/theme.php index ee920b81..c331dbbb 100644 --- a/contrib/resize/theme.php +++ b/contrib/resize/theme.php @@ -4,9 +4,8 @@ class ResizeImageTheme extends Themelet { /* * Display a link to resize an image */ - public function get_resize_html($image_id) { - global $user; - global $config; + public function get_resize_html(/*int*/ $image_id) { + global $user, $config; $i_image_id = int_escape($image_id); @@ -20,14 +19,14 @@ class ResizeImageTheme extends Themelet { return $html; } - public function display_resize_error(Page $page, $title, $message) { + public function display_resize_error(Page $page, /*string*/ $title, /*string*/ $message) { $page->set_title("Resize Image"); $page->set_heading("Resize Image"); $page->add_block(new NavBlock()); $page->add_block(new Block($title, $message)); } - public function display_resize_page(Page $page, $image_id) { + public function display_resize_page(Page $page, /*int*/ $image_id) { global $config; $default_width = $config->get_int('resize_default_width'); diff --git a/contrib/rss_comments/main.php b/contrib/rss_comments/main.php index d7c02b87..a141cc39 100644 --- a/contrib/rss_comments/main.php +++ b/contrib/rss_comments/main.php @@ -2,6 +2,7 @@ /* * Name: RSS for Comments * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Self explanatory */ diff --git a/contrib/rss_images/main.php b/contrib/rss_images/main.php index 26924d62..55bad355 100644 --- a/contrib/rss_images/main.php +++ b/contrib/rss_images/main.php @@ -2,6 +2,7 @@ /* * Name: RSS for Images * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Self explanatory */ @@ -33,7 +34,7 @@ class RSS_Images extends Extension { } - private function do_rss($images, $search_terms, $page_number) { + private function do_rss($images, $search_terms, /*int*/ $page_number) { global $page; global $config; $page->set_mode("data"); diff --git a/contrib/simpletest/main.php b/contrib/simpletest/main.php index 38666898..f0b91ffb 100644 --- a/contrib/simpletest/main.php +++ b/contrib/simpletest/main.php @@ -2,6 +2,7 @@ /* * Name: SimpleTest integration * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: adds unit testing to SCore */ diff --git a/contrib/twitter_soc/main.php b/contrib/twitter_soc/main.php index 90f60658..c81a2d6a 100644 --- a/contrib/twitter_soc/main.php +++ b/contrib/twitter_soc/main.php @@ -2,6 +2,7 @@ /* * Name: Tweet! * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Show a twitter feed with the Sea of Clouds script */ diff --git a/contrib/twitter_soc/theme.php b/contrib/twitter_soc/theme.php index be5c68fe..efbf7959 100644 --- a/contrib/twitter_soc/theme.php +++ b/contrib/twitter_soc/theme.php @@ -4,7 +4,7 @@ class TwitterSocTheme extends Themelet { /* * Show $text on the $page */ - public function display_feed(Page $page, $username) { + public function display_feed(Page $page, /*string*/ $username) { $page->add_block(new Block("Tweets", '

Follow us on Twitter diff --git a/contrib/word_filter/main.php b/contrib/word_filter/main.php index df13e73f..f85cc3de 100644 --- a/contrib/word_filter/main.php +++ b/contrib/word_filter/main.php @@ -2,6 +2,7 @@ /* * Name: Word Filter * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * License: GPLv2 * Description: Simple search and replace */ @@ -22,7 +23,7 @@ class WordFilter extends Extension { $event->panel->add_block($sb); } - private function filter($text) { + private function filter(/*string*/ $text) { $map = $this->get_map(); foreach($map as $search => $replace) { $search = trim($search); diff --git a/core/util.inc.php b/core/util.inc.php index fa2758d8..482d4263 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -648,16 +648,16 @@ define("SCORE_LOG_NOTSET", 0); /** * A shorthand way to send a LogEvent */ -function log_msg($section, $priority, $message) { +function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message) { send_event(new LogEvent($section, $priority, $message)); } // More shorthand ways of logging -function log_debug($section, $message) {log_msg($section, SCORE_LOG_DEBUG, $message);} -function log_info($section, $message) {log_msg($section, SCORE_LOG_INFO, $message);} -function log_warning($section, $message) {log_msg($section, SCORE_LOG_WARNING, $message);} -function log_error($section, $message) {log_msg($section, SCORE_LOG_ERROR, $message);} -function log_critical($section, $message) {log_msg($section, SCORE_LOG_CRITICAL, $message);} +function log_debug(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_DEBUG, $message);} +function log_info(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_INFO, $message);} +function log_warning(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_WARNING, $message);} +function log_error(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_ERROR, $message);} +function log_critical(/*string*/ $section, /*string*/ $message) {log_msg($section, SCORE_LOG_CRITICAL, $message);} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php index 25f4aac7..7dd74d5c 100644 --- a/ext/ext_manager/theme.php +++ b/ext/ext_manager/theme.php @@ -1,7 +1,7 @@ Enabled" : ""; $html = " diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 2904ed0f..b5bb9601 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -2,6 +2,7 @@ /** * Name: Handle Pixel * Author: Shish + * Link: http://code.shishnet.org/shimmie2/ * Description: Handle JPEG, PNG, GIF, etc files */ @@ -17,7 +18,7 @@ class PixelFileHandler extends DataHandlerExtension { return in_array(strtolower($ext), $exts); } - protected function create_image_from_data($filename, $metadata) { + protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { global $config; $image = new Image(); @@ -38,7 +39,7 @@ class PixelFileHandler extends DataHandlerExtension { return $image; } - protected function check_contents($file) { + protected function check_contents(/*string*/ $file) { $valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG); if(!file_exists($file)) return false; $info = getimagesize($file); @@ -47,7 +48,7 @@ class PixelFileHandler extends DataHandlerExtension { return false; } - protected function create_thumb($hash) { + protected function create_thumb(/*string*/ $hash) { $outname = warehouse_path("thumbs", $hash); if(file_exists($outname)) { return true; @@ -55,7 +56,7 @@ class PixelFileHandler extends DataHandlerExtension { return $this->create_thumb_force($hash); } - protected function create_thumb_force($hash) { + protected function create_thumb_force(/*string*/ $hash) { $inname = warehouse_path("images", $hash); $outname = warehouse_path("thumbs", $hash); global $config; @@ -76,7 +77,7 @@ class PixelFileHandler extends DataHandlerExtension { } // IM thumber {{{ - private function make_thumb_convert($inname, $outname) { + private function make_thumb_convert(/*string*/ $inname, /*string*/ $outname) { global $config; $w = $config->get_int("thumb_width"); @@ -113,7 +114,7 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} // epeg thumber {{{ - private function make_thumb_epeg($inname, $outname) { + private function make_thumb_epeg(/*string*/ $inname, /*string*/ $outname) { global $config; $w = $config->get_int("thumb_width"); exec("epeg $inname -c 'Created by EPEG' --max $w $outname"); @@ -121,7 +122,7 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} // GD thumber {{{ - private function make_thumb_gd($inname, $outname) { + private function make_thumb_gd(/*string*/ $inname, /*string*/ $outname) { global $config; $thumb = $this->get_thumb($inname); $ok = imagejpeg($thumb, $outname, $config->get_int('thumb_quality')); @@ -129,7 +130,7 @@ class PixelFileHandler extends DataHandlerExtension { return $ok; } - private function get_thumb($tmpname) { + private function get_thumb(/*string*/ $tmpname) { global $config; $info = getimagesize($tmpname); @@ -165,7 +166,7 @@ class PixelFileHandler extends DataHandlerExtension { } } - private function read_file($fname) { + private function read_file(/*string*/ $fname) { $fp = fopen($fname, "r"); if(!$fp) return false; From a95766c410d696fd15aff22dfb3d4610ea6acbbd Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Fri, 10 Feb 2012 00:08:03 -0500 Subject: [PATCH 2/5] More type hints. --- contrib/tag_history/theme.php | 10 +++++----- ext/image/main.php | 6 ++---- ext/upload/main.php | 13 +++++-------- ext/upload/theme.php | 6 +++--- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/contrib/tag_history/theme.php b/contrib/tag_history/theme.php index 842ed8bd..77ee1ad8 100644 --- a/contrib/tag_history/theme.php +++ b/contrib/tag_history/theme.php @@ -7,7 +7,7 @@ class Tag_HistoryTheme extends Themelet { var $messages = array(); - public function display_history_page(Page $page, $image_id, $history) { + public function display_history_page(Page $page, /*int*/ $image_id, /*array*/ $history) { global $user; $start_string = "

@@ -50,7 +50,7 @@ class Tag_HistoryTheme extends Themelet { $page->add_block(new Block("Tag History", $history_html, "main", 10)); } - public function display_global_page(Page $page, $history) { + public function display_global_page(Page $page, /*array*/ $history) { $start_string = "
".make_form(make_link("tag_history/revert"))." @@ -91,7 +91,7 @@ class Tag_HistoryTheme extends Themelet { $page->add_block(new Block("Tag History", $history_html, "main", 10)); } - public function display_history_link(Page $page, $image_id) { + public function display_history_link(Page $page, /*int*/ $image_id) { $link = 'Tag History'; $page->add_block(new Block(null, $link, "main", 5)); } @@ -99,7 +99,7 @@ class Tag_HistoryTheme extends Themelet { /* * Add a section to the admin page. */ - public function display_admin_block($validation_msg='') { + public function display_admin_block(/*string*/ $validation_msg='') { global $page; if (!empty($validation_msg)) { @@ -130,7 +130,7 @@ class Tag_HistoryTheme extends Themelet { $page->add_block(new Block("Revert by IP", $html)); } - public function add_status($title, $body) { + public function add_status(/*string*/ $title, /*string*/ $body) { $this->messages[] = '

'. $title .'
'. $body .'

'; } } diff --git a/ext/image/main.php b/ext/image/main.php index b6d842b0..9446a3e3 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -3,6 +3,7 @@ * Name: Image Manager * Author: Shish * Modified by: jgen + * Link: http://code.shishnet.org/shimmie2/ * Description: Handle the image database * Visibility: admin */ @@ -280,10 +281,7 @@ class ImageIO extends Extension { // add image {{{ private function add_image($image) { - global $page; - global $user; - global $database; - global $config; + global $page, $user, $database, $config; /* * Validate things diff --git a/ext/upload/main.php b/ext/upload/main.php index d438febb..6966d198 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -1,7 +1,8 @@ + * Link: http://code.shishnet.org/shimmie2/ * Description: Allows people to upload files to the website */ @@ -18,7 +19,7 @@ class DataUploadEvent extends Event { * @param $tmpname The temporary file used for upload. * @param $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source". */ - public function DataUploadEvent(User $user, $tmpname, $metadata) { + public function DataUploadEvent(User $user, /*string*/ $tmpname, /*array*/ $metadata) { assert(file_exists($tmpname)); $this->user = $user; @@ -272,9 +273,7 @@ class Upload extends Extension { * @retval bool TRUE on upload successful. */ private function try_upload($file, $tags, $source, $replace='') { - global $page; - global $config; - global $user; + global $page, $config, $user; if(empty($source)) $source = null; @@ -322,9 +321,7 @@ class Upload extends Extension { * @retval bool TRUE on transload successful. */ private function try_transload($url, $tags, $source, $replace='') { - global $page; - global $config; - global $user; + global $page, $config, $user; $ok = true; diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 2a493007..986dd8ad 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -155,7 +155,7 @@ class UploadTheme extends Themelet { } /* only allows 1 file to be uploaded - for replacing another image file */ - public function display_replace_page(Page $page, $image_id) { + public function display_replace_page(Page $page, /*int*/ $image_id) { global $config, $page; $page->add_html_header(""); $tl_enabled = ($config->get_string("transload_engine", "none") != "none"); @@ -211,7 +211,7 @@ class UploadTheme extends Themelet { $page->add_block(new Block("Upload Replacement Image", $html, "main", 20)); } - public function display_upload_status(Page $page, $ok) { + public function display_upload_status(Page $page, /*bool*/ $ok) { if($ok) { $page->set_mode("redirect"); $page->set_redirect(make_link()); @@ -223,7 +223,7 @@ class UploadTheme extends Themelet { } } - public function display_upload_error(Page $page, $title, $message) { + public function display_upload_error(Page $page, /*string*/ $title, /*string*/ $message) { $page->add_block(new Block($title, $message)); } From c34656563c43c11503720724089e1f9df27bb398 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Fri, 10 Feb 2012 00:19:08 -0500 Subject: [PATCH 3/5] Fix for tag history not recording first set of tags. Issue #111 --- contrib/tag_history/main.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 8525c9ea..054ee199 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -9,7 +9,7 @@ class Tag_History extends Extension { // in before tags are actually set, so that "get current tags" works public function get_priority() {return 40;} - public function onInitExtEvent(InitExtEvent $event) { + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_int("history_limit", -1); @@ -19,7 +19,7 @@ class Tag_History extends Extension { } } - public function onAdminBuildingEvent(AdminBuildingEvent $event) { + public function onAdminBuilding(AdminBuildingEvent $event) { global $user; if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) { @@ -110,8 +110,7 @@ class Tag_History extends Extension { } protected function install() { - global $database; - global $config; + global $database, $config; if($config->get_int("ext_tag_history_version") < 1) { $database->create_table("tag_histories", " @@ -188,7 +187,7 @@ class Tag_History extends Extension { * This function is used by process_revert_all_changes_by_ip() * to just revert an image's tag history. */ - private function process_revert_request_only($revert_id) + private function process_revert_request_only(/*int*/ $revert_id) { if(empty($revert_id)) { return; @@ -214,7 +213,7 @@ class Tag_History extends Extension { send_event(new TagSetEvent(Image::by_id($stored_image_id), $stored_tags)); } - public function get_tag_history_from_revert($revert_id) + public function get_tag_history_from_revert(/*int*/ $revert_id) { global $database; $row = $database->get_row(" @@ -225,7 +224,7 @@ class Tag_History extends Extension { return ($row ? $row : null); } - public function get_tag_history_from_id($image_id) + public function get_tag_history_from_id(/*int*/ $image_id) { global $database; $row = $database->get_all(" @@ -315,7 +314,7 @@ class Tag_History extends Extension { /* * this function is called when an image has been deleted */ - private function delete_all_tag_history($image_id) + private function delete_all_tag_history(/*int*/ $image_id) { global $database; $database->execute("DELETE FROM tag_histories WHERE image_id = ?", array($image_id)); @@ -326,25 +325,32 @@ class Tag_History extends Extension { */ private function add_tag_history($image, $tags) { - global $database; - global $config; - global $user; + global $database, $config, $user; $new_tags = Tag::implode($tags); $old_tags = Tag::implode($image->get_tag_array()); - log_debug("tag_history", "adding tag history: [$old_tags] -> [$new_tags]"); + if($new_tags == $old_tags) return; + + if (empty($old_tags)) { + /* no old tags, so we are probably adding the image for the first time */ + log_debug("tag_history", "adding new tag history: [$new_tags]"); + } else { + log_debug("tag_history", "adding tag history: [$old_tags] -> [$new_tags]"); + } + $allowed = $config->get_int("history_limit"); if($allowed == 0) return; // if the image has no history, make one with the old tags $entries = $database->get_one("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id)); if($entries == 0){ + /* We have no tag history for this image, so we will use the new_tags as the starting tags for this image. */ /* these two queries could probably be combined */ $database->execute(" INSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set) VALUES (?, ?, ?, ?, now())", - array($image->id, $old_tags, 1, '127.0.0.1')); // TODO: Pick appropriate user id + array($image->id, $new_tags, 1, '127.0.0.1')); // TODO: Pick appropriate user id $entries++; } From 551a0f0a7634a6c71a49808a5ed59bcdc418aa49 Mon Sep 17 00:00:00 2001 From: "green-ponies (jgen)" Date: Fri, 10 Feb 2012 00:37:52 -0500 Subject: [PATCH 4/5] Note for other people. --- contrib/tag_history/main.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index 054ee199..02f42948 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -366,6 +366,13 @@ class Tag_History extends Extension { if($entries > $allowed) { // TODO: Make these queries better + /* + MySQL does NOT allow you to modify the same table which you use in the SELECT part. + Which means that these will probably have to stay as TWO separate queries... + + http://dev.mysql.com/doc/refman/5.1/en/subquery-restrictions.html + http://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause + */ $min_id = $database->get_one("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id)); $database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id)); } From e535b1f0027c52ea72f3c8cd7c8b735fdc1c73cb Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 11 Feb 2012 10:37:50 +0000 Subject: [PATCH 5/5] only show samefag ID if showing regular IDs --- ext/comment/theme.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/comment/theme.php b/ext/comment/theme.php index e4b63f04..acdabed2 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -171,14 +171,14 @@ class CommentListTheme extends Themelet { $anoncode2 = ""; if($this->show_anon_id) { $anoncode = ''.$this->anon_id.''; - } - if($user->can("view_ip")) { - #$style = " style='color: ".$this->get_anon_colour($comment->poster_ip).";'"; - if(!array_key_exists($comment->poster_ip, $this->anon_map)) { - $this->anon_map[$comment->poster_ip] = $this->anon_id; - } - if($this->anon_map[$comment->poster_ip] != $this->anon_id) { - $anoncode2 = '('.$this->anon_map[$comment->poster_ip].')'; + if($user->can("view_ip")) { + #$style = " style='color: ".$this->get_anon_colour($comment->poster_ip).";'"; + if(!array_key_exists($comment->poster_ip, $this->anon_map)) { + $this->anon_map[$comment->poster_ip] = $this->anon_id; + } + if($this->anon_map[$comment->poster_ip] != $this->anon_id) { + $anoncode2 = '('.$this->anon_map[$comment->poster_ip].')'; + } } } $h_userlink = "" . $h_name . $anoncode . $anoncode2 . "";