Revision [17576]

This is an old revision of GmBowenAdminPageControlTool made by GmBowen on 2007-10-01 17:13:02.

 


Simple Admin Control Panel

For various reasons, administrators might need to remove content from the wiki in a (semi)permanent fashion (this is more and more true as legal culpability for offensive statements, etc. is extended....and because of this an administrator may not want to completely remove the content (so the "owner" is still identifiable), but make it so that it at least appears to no longer exist). Below is code for what is essentially a simple administrator control panel (appearing under the footer) that allows the administrator to "Hide a page" (it changes the "Y" to an "H" in the _pages database table (if the ACLS table for "Read" is set to null then only the administrator can re-create the page....at least that's how it tested out on my server), "Erase the History" of a page, or "Delete a Page". It provides a small table under the footer with these features in it at the bottom of the page. An action is included at the bottom of this page that will allow the admin to list the hidden pages and restore them if desired.
http://gmbtst.msvu.ca/wikitest/adminpanel.jpg
All the changes must be implemented for the features to work.

Hide Page Code


Whenever the "Hide Page" button is clicked it changes the field "latest" for that page from "Y" to "H" and it therefore does not appear. If the ACLS permissions are set to null before "Hide Page" is clicked then only the admin can re-create the page.

1. The following code must be saved as hidepage.php and the file placed in the actions directory
<? // code developed by GMBowen to "hide" a given page (by changing "latest" to "H" in _pages table)
if ($this->IsAdmin())
{
    echo '<table><tr><td><form action="" method="post">
    <input type="submit" name="hidepage" value="Hide Page"></td></table></form>'
;
    echo "<small>* To <strong>hide</strong> page, <strong>set</strong> ACLS ''Read'' to <strong><i>null</i></strong> & click on Hide button above...</small><BR>";
    echo "<small>* Note that unless the ACLS is set to null, then anybody with Read permission can re-create the page.</small>";
}
if ($_POST['hidepage'] && $this->IsAdmin())
{
$thispage=$this->GetPageTag();
//$sql = "DELETE FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='N'";
$sql = "UPDATE ".$this->config['table_prefix']."pages SET latest='H' WHERE tag='$thispage' AND latest='Y'";
mysql_query($sql) or die("Unable to process query: " . mysql_error());
 $url = $this->config['base_url'];
     $this->redirect($url."HomePage");
} ?>

2. The database table (wakka?)_pages must be changed. The field "latest" must be edited so that rather than being enum('Y', 'N') it now reads enum('Y', 'N', 'H')

Erase History Code

Sometimes it can be useful for the administrator to erase the history of a page.

Perhaps add code so there is one history page that shows "Previous history of this page removed by Administrator"?? --Mike

The following code must be saved as adminerasehistory.php and the file placed in the actions directory....
<?
// code developed by GMBowen & JGoguen to allow admins to erase history on a given page
if ($this->IsAdmin())
{
    echo '<table><tr><td><form action="" method="post">
    <input type="submit" name="erasehistory" value="Erase History"></td></table> <br /></form>'
;
}
if ($_POST['erasehistory'] && $this->IsAdmin())
{
$thispage=$this->GetPageTag();
$sql = "DELETE FROM ".$this->config["table_prefix"]."pages WHERE tag='$thispage' AND latest='N'";
mysql_query($sql) or die("Unable to process query: " . mysql_error());
}
elseif ($_POST['erasehistory'] && !$this->IsAdmin())
{
echo "<i>History can only be erased by an administrator.</i>";
}
?>

Modification of footer.php code

The following code was added at the end of the footer.php file (just after the last "?>")......it includes code to "delete" a page. (And I know this is easy to do just on the URL line....but I use frames (Ya, I know, bad idea) and so sometimes the URL bar isn't visible....and that's deliberate eh?....so this addition solves the problem for me.)

<? if ($this->IsAdmin())
{
echo "<table border=1><tr><td width=250>";
include("hidepage.php");
echo "</p></td><td valign=top>";
include("adminerasehistory.php");
?>
</td><td valign=top>
[<A HREF="<? echo $this->GetConfigValue("base_url").$this->GetPageTag()."/delete"; ?>"><strong>Delete Page</strong></A>]</td></tr></table>
<? } ?>


<? if ($this->IsAdmin())
{
echo "<table border=1><tr><td width=250>";
include($this->config['action_path']."/hidepage.php");
echo "</p></td><td valign=top>";
include($this->config['action_path']."/adminerasehistory.php");
?>
</td><td valign=top>
[<A HREF="<? echo $this->GetConfigValue("base_url").$this->GetPageTag()."/delete"; ?>"><strong>Delete Page</strong></A>]</td></tr></table>
<? } ?>


View Hidden Pages Action

This action is designed to work in conjunction with the Simple Admin Control Panel. It allows an administrator to view a list of pages which have been hidden, and restore them if desired. Use it by placing {{hiddenpages.php}} on a page.

save this code as the file hiddenpages.php in the actions directory...
<?
// code developed by GMBowen for administrators to view a list of hidden pages and restore them if desired

if ($this->IsAdmin())
{
  $unhide=$_REQUEST['unhide'];
  $unhidename=$_REQUEST['unhidename'];

$this->query("UPDATE ".$this->config['table_prefix']."pages SET latest = 'Y' WHERE tag='$unhidename' AND latest = 'H' ");

$thislink = $this->config["base_url"].$this->MiniHref($method, $tag);

$counta = "0";
$query = "SELECT tag,owner,latest,time FROM ".$this->config['table_prefix']."pages WHERE latest = 'H' ORDER BY id asc";
$result = mysql_query($query);

echo "<BR><TABLE width='650' border='1'>";
echo "<TH COLSPAN=5>The current hidden pages are.....</TH>";
?>
   <TR>
      <TD>
         <P>&nbsp;</P>
      </TD>
      <TD>
         <P>Page Name</P>
      </TD>
      <TD>
         <P>Page Owner</P>
      </TD>
      <TD>
         <P>Time Hidden</P>
      </TD>
      <TD>
         <P>Un-Hide??</P>
      </TD>
   </TR>
<?
while($row=mysql_fetch_array($result)) {
        $count = ($count + 1);
        echo "<TR BGCOLOR='#DDDDDD'><TD valign='top' ALIGN='center'>&nbsp;".$count."&nbsp;</TD>";
        echo "<TD valign='top' ALIGN='left'>&nbsp;".$row['tag']."&nbsp;</TD>";
        echo "<TD valign='top' ALIGN='left'>&nbsp;".$row['owner']."&nbsp;</TD>";
        echo "<TD ALIGN='left'>&nbsp;".$row['time']."&nbsp;</TD>";
        $unhidepagelnk = $thislink.'&unhide=yes'.'&unhidename='.$row['tag'];
        echo "<TD ALIGN='left'><a href=\"$unhidepagelnk\">&nbsp Restore?</a></TD></TR>";
    }
echo "</table>";
}
else
{
echo "<em>In order to list hidden pages you need to be a designated administrator.</em>";
}
?>


CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki