Merge pull request #129 from green-ponies/master

Type hints
This commit is contained in:
Shish Moom 2012-02-11 01:22:43 -08:00
commit 6da4da8060
35 changed files with 81 additions and 77 deletions

View file

@ -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");

View file

@ -1,7 +1,7 @@
<?php
class ArtistsTheme extends Themelet {
public function get_author_editor_html($author) {
public function get_author_editor_html(/*string*/ $author) {
$h_author = html_escape($author);
return "<tr><td>Author</td><td><input class='editor_author' type='text' name='tag_edit__author' value='$h_author'></td></tr>";
}
@ -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"){

View file

@ -2,6 +2,7 @@
/*
* Name: Generic Blocks
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Add HTML to some space
* Documentation:

View file

@ -2,6 +2,7 @@
/**
* Name: Bookmarks
* Author: Shish <webmaster@shishnet.org>
* 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));

View file

@ -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)) {

View file

@ -2,6 +2,7 @@
/*
* Name: Downtime
* Author: Shish <webmaster@shishnet.org>
* 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", "<br>");
$event->panel->add_block($sb);
}
public function onPageRequest($event) {
public function onPageRequest(PageRequestEvent $event) {
global $config, $page, $user;
if($config->get_bool("downtime")) {

View file

@ -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();

View file

@ -2,6 +2,7 @@
/*
* Name: Emoticon Filter
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Lets users use graphical smilies
* Documentation:

View file

@ -1,6 +1,6 @@
<?php
class EmoticonListTheme extends Themelet {
public function display_emotes($list) {
public function display_emotes(/*array*/ $list) {
global $page;
$data_href = get_base_href();
$html = "<html><head><title>Emoticon list</title></head><body>";

View file

@ -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(

View file

@ -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"))."

View file

@ -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));

View file

@ -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);

View file

@ -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) ? "" : "<div class='space' id='links'>$main_links</div>";
$message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>";
$counter_html = empty($counter_text) ? "" : "<div class='space' id='counter'>$counter_text</div>";

View file

@ -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;

View file

@ -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 = "<img src=\"$src\" />";
@ -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 "
<tr>
<td><label for='".$id."' title='Click to select the textbox'>$label</label></td>

View file

@ -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'];

View file

@ -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));

View file

@ -1,7 +1,7 @@
<?php
class RatingsTheme extends Themelet {
public function get_rater_html($image_id, $rating) {
public function get_rater_html(/*int*/ $image_id, /*string*/ $rating) {
$i_image_id = int_escape($image_id);
$s_checked = $rating == 's' ? " checked" : "";
$q_checked = $rating == 'q' ? " checked" : "";
@ -50,7 +50,7 @@ class RatingsTheme extends Themelet {
$page->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";

View file

@ -2,6 +2,7 @@
/*
* Name: Resolution Limiter
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Allows the admin to set min / max image dimentions
*/

View file

@ -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)");

View file

@ -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');

View file

@ -2,6 +2,7 @@
/*
* Name: RSS for Comments
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Self explanatory
*/

View file

@ -2,6 +2,7 @@
/*
* Name: RSS for Images
* Author: Shish <webmaster@shishnet.org>
* 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");

View file

@ -2,6 +2,7 @@
/*
* Name: SimpleTest integration
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: adds unit testing to SCore
*/

View file

@ -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 = "
<div style='text-align: left'>
@ -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 = "
<div style='text-align: left'>
".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 = '<a href="'.make_link('tag_history/'.$image_id).'">Tag History</a>';
$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[] = '<p><b>'. $title .'</b><br>'. $body .'</p>';
}
}

View file

@ -2,6 +2,7 @@
/*
* Name: Tweet!
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Show a twitter feed with the Sea of Clouds script
*/

View file

@ -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", '
<div class="tweet_soc"></div>
<p><a href="http://twitter.com/'.url_escape($username).'">Follow us on Twitter</a>

View file

@ -2,6 +2,7 @@
/*
* Name: Word Filter
* Author: Shish <webmaster@shishnet.org>
* 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);

View file

@ -671,16 +671,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);}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\

View file

@ -1,7 +1,7 @@
<?php
class ExtManagerTheme extends Themelet {
public function display_table(Page $page, $extensions, $editable) {
public function display_table(Page $page, /*array*/ $extensions, /*bool*/ $editable) {
global $user;
$en = $editable ? "<th>Enabled</th>" : "";
$html = "

View file

@ -2,6 +2,7 @@
/**
* Name: Handle Pixel
* Author: Shish <webmaster@shishnet.org>
* 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;

View file

@ -3,6 +3,7 @@
* Name: Image Manager
* Author: Shish <webmaster@shishnet.org>
* Modified by: jgen <jgen.tech@gmail.com>
* 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

View file

@ -1,7 +1,8 @@
<?php
/**
* Name: Uploader
* Author: Shish
* Author: Shish <webmaster@shishnet.org>
* 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;

View file

@ -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("<link rel='stylesheet' href='".get_base_href()."/ext/upload/_style.css' type='text/css'>");
$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));
}