Linting: These actually were bugs.

This commit is contained in:
jgen 2014-04-28 03:16:09 -04:00
parent d4ac6ca451
commit 158819cb28
2 changed files with 64 additions and 32 deletions

View File

@ -9,9 +9,15 @@
*/ */
class WikiUpdateEvent extends Event { class WikiUpdateEvent extends Event {
var $user; /** @var \User */
var $wikipage; public $user;
/** @var \WikiPage */
public $wikipage;
/**
* @param User $user
* @param WikiPage $wikipage
*/
public function __construct(User $user, WikiPage $wikipage) { public function __construct(User $user, WikiPage $wikipage) {
$this->user = $user; $this->user = $user;
$this->wikipage = $wikipage; $this->wikipage = $wikipage;
@ -22,18 +28,31 @@ class WikiUpdateException extends SCoreException {
} }
class WikiPage { class WikiPage {
var $id; /** @var int|string */
public $id;
var $owner_id; var $owner_id;
var $owner_ip; var $owner_ip;
var $date; var $date;
var $title;
/** @var string */
public $title;
var $revision; var $revision;
var $locked;
var $body;
public function __construct($row) { /** @var bool */
assert(!empty($row)); public $locked;
/** @var string */
public $body;
/**
* @param mixed $row
*/
public function __construct($row=null) {
//assert(!empty($row));
if (!is_null($row)) {
$this->id = $row['id']; $this->id = $row['id'];
$this->owner_id = $row['owner_id']; $this->owner_id = $row['owner_id'];
$this->owner_ip = $row['owner_ip']; $this->owner_ip = $row['owner_ip'];
@ -43,11 +62,18 @@ class WikiPage {
$this->locked = ($row['locked'] == 'Y'); $this->locked = ($row['locked'] == 'Y');
$this->body = $row['body']; $this->body = $row['body'];
} }
}
/**
* @return null|User
*/
public function get_owner() { public function get_owner() {
return User::by_id($this->owner_id); return User::by_id($this->owner_id);
} }
/**
* @return bool
*/
public function is_locked() { public function is_locked() {
return $this->locked; return $this->locked;
} }
@ -55,8 +81,7 @@ class WikiPage {
class Wiki extends Extension { class Wiki extends Extension {
public function onInitExt(InitExtEvent $event) { public function onInitExt(InitExtEvent $event) {
global $database; global $database, $config;
global $config;
if($config->get_int("ext_wiki_version", 0) < 1) { if($config->get_int("ext_wiki_version", 0) < 1) {
$database->create_table("wiki_pages", " $database->create_table("wiki_pages", "
@ -105,7 +130,7 @@ class Wiki extends Extension {
if($this->can_edit($user, $this->get_page($title))) { if($this->can_edit($user, $this->get_page($title))) {
$wikipage = $this->get_page($title); $wikipage = $this->get_page($title);
$wikipage->rev = $rev; $wikipage->revision = $rev;
$wikipage->body = $body; $wikipage->body = $body;
$wikipage->locked = $lock; $wikipage->locked = $lock;
try { try {
@ -160,7 +185,7 @@ class Wiki extends Extension {
$database->Execute(" $database->Execute("
INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body) INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body)
VALUES (?, ?, now(), ?, ?, ?, ?)", array($event->user->id, $_SERVER['REMOTE_ADDR'], VALUES (?, ?, now(), ?, ?, ?, ?)", array($event->user->id, $_SERVER['REMOTE_ADDR'],
$wpage->title, $wpage->rev, $wpage->locked?'Y':'N', $wpage->body)); $wpage->title, $wpage->revision, $wpage->locked?'Y':'N', $wpage->body));
} }
catch(Exception $e) { catch(Exception $e) {
throw new WikiUpdateException("Somebody else edited that page at the same time :-("); throw new WikiUpdateException("Somebody else edited that page at the same time :-(");
@ -168,13 +193,13 @@ class Wiki extends Extension {
} }
/** /**
* See if the given user is allowed to edit the given page * See if the given user is allowed to edit the given page.
* *
* @retval boolean * @param User $user
* @param WikiPage $page
* @return bool
*/ */
public static function can_edit(User $user, WikiPage $page) { public static function can_edit(User $user, WikiPage $page) {
global $config;
// admins can edit everything // admins can edit everything
if($user->is_admin()) return true; if($user->is_admin()) return true;
@ -187,6 +212,11 @@ class Wiki extends Extension {
return false; return false;
} }
/**
* @param string $title
* @param int|null $revision
* @return WikiPage
*/
private function get_page($title, $revision=-1) { private function get_page($title, $revision=-1) {
global $database; global $database;
// first try and get the actual page // first try and get the actual page

View File

@ -1,14 +1,16 @@
<?php <?php
class WikiTheme extends Themelet { class WikiTheme extends Themelet {
/* /**
* Show a page * Show a page.
* *
* $page = the shimmie page object * @param Page $page The shimmie page object
* $wiki_page = the wiki page, has ->title and ->body * @param WikiPage $wiki_page The wiki page, has ->title and ->body
* $nav_page = a wiki page object with navigation, has ->body * @param WikiPage|null $nav_page A wiki page object with navigation, has ->body
*/ */
public function display_page(Page $page, WikiPage $wiki_page, $nav_page) { // $nav_page = WikiPage or null public function display_page(Page $page, WikiPage $wiki_page, $nav_page) {
global $user;
if(is_null($nav_page)) { if(is_null($nav_page)) {
$nav_page = new WikiPage(); $nav_page = new WikiPage();
$nav_page->body = ""; $nav_page->body = "";
@ -18,7 +20,6 @@ class WikiTheme extends Themelet {
send_event($tfe); send_event($tfe);
// only the admin can edit the sidebar // only the admin can edit the sidebar
global $user;
if($user->is_admin()) { if($user->is_admin()) {
$tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar", "edit=on")."'>Edit</a>)"; $tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar", "edit=on")."'>Edit</a>)";
} }
@ -61,12 +62,13 @@ class WikiTheme extends Themelet {
} }
protected function create_display_html(WikiPage $page) { protected function create_display_html(WikiPage $page) {
global $user;
$owner = $page->get_owner(); $owner = $page->get_owner();
$tfe = new TextFormattingEvent($page->body); $tfe = new TextFormattingEvent($page->body);
send_event($tfe); send_event($tfe);
global $user;
$edit = "<table><tr>"; $edit = "<table><tr>";
$edit .= Wiki::can_edit($user, $page) ? $edit .= Wiki::can_edit($user, $page) ?
" "