Permalink
Browse files

Get rid of the idea of an implicit page owner. Instead, add a list of…

… all people who have edited the page as possibilities to add quickly. Cleanup the MyReviews page a little bit to break down the big uber-function
  • Loading branch information...
1 parent 6f71993 commit da65db06bc1b6bb42d029e1b346a55fbbeb6fb85 @Whiteknight committed May 2, 2010
Showing with 97 additions and 27 deletions.
  1. +39 −22 MyReviews_body.php
  2. +57 −5 PageOwner_body.php
  3. +1 −0 PageReviews.php
View
61 MyReviews_body.php
@@ -188,35 +188,36 @@ function execute($par) {
}
}
- # Show the basic main page
- function showMainPage() {
- global $wgRequest, $wgOut;
-
+ function showViewerAdditions()
+ {
+ global $wgOut;
if ($this->viewer) {
$html = <<<EOT
-<form action="" method="POST">
- <input type="hidden" name="postbackmode" value="impersonateuser"/>
- <b>Choose user to view: </b>
- <input type="text" name="username"/>
- <input type="submit" name="submit" value="View"/>
-</form>
+<div style="float: right;">
+ <form action="" method="POST">
+ <input type="hidden" name="postbackmode" value="impersonateuser"/>
+ <b>Choose user to view: </b>
+ <input type="text" name="username"/>
+ <input type="submit" name="submit" value="View"/>
+ </form>
+</div>
EOT;
$wgOut->addHTML($html);
}
+ }
-
- $dbr = wfGetDB(DB_SLAVE);
-
- // Reviews this user has given
+ # Reviews this user has given
+ function reviewsIGave($userid) {
$selectquery =<<<EOSQL
SELECT
review_score.display_as, page.page_namespace, page.page_title, review.*
FROM
review_score INNER JOIN (
review INNER JOIN page ON review.page_id = page.page_id
) ON review.review_score_id = review_score.id
- WHERE user_id = '{$this->userID}';
+ WHERE user_id = '{$userid}';
EOSQL;
+ $dbr = wfGetDB(DB_SLAVE);
$given = $dbr->query($selectquery);
$givenReviews = "";
if($dbr->numRows($given) == 0) {
@@ -244,9 +245,15 @@ function showMainPage() {
</div>
EOT;
}
+ return $givenReviews;
+ }
- // Reviews given to this user
- $selectquery =<<<EOSQL
+ # Reviews given to this user
+ function reviewsIReceive($userid) {
+ # Explanation of this SQL: We want to get page/review information (along
+ # with the displayable name of the review) for all pages that this user
+ # owns
+ $selectquery = <<<EOSQL
SELECT
page.page_namespace, page.page_title, review_score.display_as, review.*
FROM (
@@ -255,13 +262,12 @@ function showMainPage() {
) INNER JOIN page
ON review.page_id = page.page_id
WHERE review.page_id IN (
- SELECT page_id FROM page_owner WHERE user_id = '{$this->userID}'
- UNION
- SELECT rev_page FROM revision
- WHERE rev_parent_id = 0 AND rev_user = '{$this->userID}'
- GROUP BY rev_page
+ SELECT page_id
+ FROM page_owner
+ WHERE user_id = '{$this->userID}'
);
EOSQL;
+ $dbr = wfGetDB(DB_SLAVE);
$taken = $dbr->query($selectquery);
$takenReviews = "";
if($dbr->numRows($taken) == 0) {
@@ -284,7 +290,18 @@ function showMainPage() {
</div>
EOT;
}
+ return $takenReviews;
+ }
+
+ # Show the basic main page
+ function showMainPage() {
+ global $wgRequest, $wgOut;
+
+ $this->showViewerAdditions();
+ $givenReviews = $this->reviewsIGave($this->userID);
+ $takenReviews = $this->reviewsIReceive($this->userID);
+ # TODO: Show a list of all pages I own
$html = <<<EOT
<h2 style="clear:both;">{$this->username}'s Reviews</h2>
<table style="width: 100%;" cellspacing="5" cellpadding="5">
View
62 PageOwner_body.php
@@ -68,9 +68,14 @@ function handlePostBack() {
$userid = User::idFromName($username);
$this->handleAddUser($pagename, $pageid, $username, $userid);
} else {
+ $method = $wgRequest->getText("par_method");
$username = $wgRequest->getText("par_username");
$userid = User::idFromName($username);
- $this->handleRemoveUser($pagename, $pageid, $username, $userid);
+ if ($method == "remove") {
+ $this->handleRemoveUser($pagename, $pageid, $username, $userid);
+ } else if ($method == "assign") {
+ $this->handleAddUser($pagename, $pageid, $username, $userid);
+ }
}
$href = Title::newFromText("Special:PageOwner/$pagename")->getFullURL();
$wgOut->addHTML("<br><a href=\"$href\">Back</a>");
@@ -124,7 +129,7 @@ function showMainSpecialPage($par)
$currentowners = "";
if($dbr->numRows($given) == 0) {
- $currentowners = "<p>No Owners</p>";
+ $currentowners = "<p>No owners</p>";
}
while($row = $dbr->fetchObject($given)) {
$username = $row->user_name;
@@ -140,6 +145,41 @@ function showMainSpecialPage($par)
EOT;
}
+ # Now, get a list of all page editors to make a list of possible people
+ # to assign to this page.
+ # Break down this sql statement: We want a list of all users who have
+ # made edits to this page, but we want to exclude any users who are
+ # already listed as owners of the page
+ $selectquery = <<<EOSQL
+SELECT DISTINCT rev_user
+ FROM revision
+ WHERE rev_page = '{$pageid}'
+ AND rev_user NOT IN (
+ SELECT user.user_id
+ FROM user, page_owner
+ WHERE page_owner.page_id = '{$pageid}'
+ AND user.user_id = page_owner.user_id
+ );
+EOSQL;
+ $res = $dbr->query($selectquery);
+ $possibleowners = "";
+ while ($row = $dbr->fetchObject($res)) {
+ if ($row->rev_user == 0) {
+ continue;
+ }
+ $username = User::newFromId($row->rev_user)->getName();
+ $userpage = Title::newFromText("User:$username");
+ $userhref = $userpage->getFullURL();
+ $talkhref = $userpage->getTalkPage()->getFullURL();
+ $possibleowners .= <<<EOT
+ <p>
+ [<a href="javascript: assignimplicituser('{$username}')" style="font-size: 80%;">Assign</a>]
+ &mdash;
+ <a href="{$userhref}">{$username}</a> (<a href="{$talkhref}">Talk</a>)<br/>
+</p>
+EOT;
+ }
+
$href = Title::newFromText("Special:PageOwner")->getFullURL();
$pagehref = Title::newFromText($par)->getFullURL();
$this->setHeaders();
@@ -148,15 +188,26 @@ function showMainSpecialPage($par)
function removeuser(user) {
username = document.getElementById("par_username");
username.value = user;
- document.removepeople.submit();
+ method = document.getElementById("par_method");
+ method.value = "remove";
+ document.changepeople.submit();
+ }
+
+ function assignimplicituser(user) {
+ username = document.getElementById("par_username");
+ username.value = user;
+ method = document.getElementById("par_method");
+ method.value = "assign";
+ document.changepeople.submit();
}
</script>
<table style="width: 100%;" cellspacing="5" cellpadding="5">
<tr>
<td id="PeerReview-PageOwner-owners" valign="top">
<h3>Current Page Owners</h3>
- <form name="removepeople" action="{$href}" method="POST">
+ <form name="changepeople" action="{$href}" method="POST">
{$currentowners}
+ <input type="hidden" name="par_method" id="par_method" value="remove">
<input type="hidden" name="par_pagename" value="{$par}"/>
<input type="hidden" name="par_username" id="par_username" value=""/>
</form>
@@ -166,9 +217,10 @@ function removeuser(user) {
<hr>
<h3>Add New Owners</h3>
<form action="$href" method="POST">
- New owner: <input type="textbox" name="newowner"/>
+ New owner: <input type="textbox" name="newowner" id="par_newowner"/>
<input type="hidden" name="par_pagename" value="{$par}"/>
<input type="submit" name="submit" value="Add"/>
+ {$possibleowners}
</form>
</td>
</tr>
View
1 PageReviews.php
@@ -73,6 +73,7 @@ function handlePostBack() {
'comment' => $wgRequest->getVal('reviewable-comment'
));
$dbw->insert('review', $toInsert);
+
$extraClass = "PeerReview-PageReviews-success";
$response = <<<EOT
<h2>Success!</h2>

0 comments on commit da65db0

Please sign in to comment.