2 /////////////////////////////////////////////
4 Small wiki admin for ErfurtWiki using mysql
5 can delete pages, and rename pages, with the option of replacing the renamed page with a reference to the new one
6 made for The Arrow Project site.
7 Several parts of this are Arrow Specific.
8 I've commented them with ARROW in the line so people can adapt it to use outside arrow.
10 In the spirit of ErfurtWiki this page is Public Domain.
13 menno_lodder at hotmail dot com
17 //////////////////////////////////////////////
20 //ARROW some protection to ensure libraries aren't called directly
21 define('IN_ARROW', true);
23 //ARROW includes libraries and shows the admin section headers, also opens html tags upto <body>
24 require_once('header.php');
26 //ARROW if statement checks if the persion has permission
27 if(!has_perm("WIKI_ADMIN"))
29 echo("No permission");
30 include('footer.php');
33 //**************************************
34 //ARROW to use this outside of arrow, comment out the above and the footer.php include at the bottom
35 // then uncomment the following 2 methods, and set the settings variables.
36 //**************************************
38 $wikitable = "wiki"; //the table name of the table containing the wiki info (ewiki by default)
39 $wikiurl = "../wiki.php"; //the relative URL of the wiki pages to the admin page, this is used to allow linking to the wiki pages
42 These functions are untested
45 function logMsg($type, $message)
47 //log whatever you want here, or do nothing
55 $dbhost = "localhost";
59 $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die("Error - Connection to database is not established !");
60 @mysql_select_db($db, $conn) or die("Error - Can't open the database !");
68 //set the page in advance, so it can be changed by the functions below
70 if(isset($_REQUEST['page']))
72 $page = $_REQUEST['page'];
75 if(isset($_REQUEST['function']))
77 if($_REQUEST['function'] == "details")
81 else if(($_REQUEST['function'] == "rename") && isset($_REQUEST['oldname']) && isset($_REQUEST['newname']))
83 $old = $_REQUEST['oldname'];
84 $new = $_REQUEST['newname'];
86 $shadow = isset($_REQUEST['leaveshadow']);
88 $shadowtext = "not making shadow topic";
91 $shadowtext = "making shadow topic";
93 //ARROW makes a database connection to the mysql database (which is from now on the default one)
95 //check if the name already exists
96 $checkresult = mysql_query("SELECT * FROM $wikitable WHERE pagename = '".addslashes($new)."'") or die("Error check if name already exists: ".mysql_error());
97 if(!mysql_fetch_assoc($checkresult))
100 //get the last version of the old page
101 $oldresult = mysql_query("SELECT * FROM $wikitable WHERE pagename = '".addslashes($old)."' ORDER BY version DESC LIMIT 1") or die("Error check if name already exists: ".mysql_error());
103 if($oldpage = mysql_fetch_assoc($oldresult))
106 mysql_query("UPDATE $wikitable SET pagename= '".addslashes($new)."' WHERE pagename= '".addslashes($old)."'") or die("Error renaming the page: ".mysql_error());
107 echo("<b>Renamed $old to $new $shadowtext</b>,<br />");
109 //ARROW logs a message under the header "wikiadmin"
110 logMsg("wikiadmin", "Renamed $old to $new $shadowtext");
114 $shadowcontent = "This page was renamed to [$new]";
115 //this just takes the last author and meta info, cause thats rather complicated to change
116 mysql_query("INSERT INTO $wikitable (pagename, version, flags, content, author, created, lastmodified, refs, meta, hits)".
117 " VALUES ('".addslashes($old)."', '".($oldpage['version']+1)."', '".$oldpage['flags']."', '".
118 addslashes($shadowcontent)."', '".$oldpage['author']."', '".$oldpage['created']."', '".time()."', '"."\n\n".addslashes($new)."\n\n\n"."', '".
119 $oldpage['meta']."', '".$oldpage['hits']."')") or die("Error making shadow page: ".mysql_error());
124 echo("<b>Page named $old not found.</b><br />");
129 //name already exists
130 echo("<b>A page named $new already exists</b><br />");
133 //change the page to show
137 elseif(($_REQUEST['function'] == "delete") && isset($_REQUEST['page']))
139 $page = $_REQUEST['page'];
141 mysql_query("DELETE FROM $wikitable WHERE pagename = '".addslashes($page)."'") or die("Error deleting page: ".mysql_error());
143 echo("<br /><b>Deleted $page</b>");
147 echo("Unknown function or not enough parameters");
153 //no function show index
159 //show the details of a page
161 //check if a page is given
165 //select the pages with the given name, first is the most recent one
166 $pagequery = "SELECT * FROM $wikitable WHERE pagename = '".addslashes($page)."' ORDER BY version DESC";
167 $pageresult = mysql_query($pagequery) or die("Error getting page: ".mysql_error());
169 if($recentpagerow = mysql_fetch_assoc($pageresult))
171 echo("<br /><a href=\"wikiadmin.php\">Wiki Index</a>");
172 echo("<br /><h2><a target=\"blank\" href=\"$wikiurl?id=".urlencode($recentpagerow['pagename'])."\">".$recentpagerow['pagename']."</a></h2>\n");
173 echo("<b>Rename</b>\n");
174 echo("<form method=\"post\"><input type=\"text\" name=\"newname\" size=\"30\" value=\"".$recentpagerow['pagename']."\" /> \n");
175 echo("<input type=\"checkbox\" name=\"leaveshadow\" value=\"true\" checked=\"checked\" />Leave shadow page \n");
176 echo("<input value=\"Rename\" type=\"submit\" /><input type=\"hidden\" name=\"oldname\" value=\"".$recentpagerow['pagename']."\" /><input type=\"hidden\" name=\"function\" value=\"rename\" /></form>\n");
177 echo("<small>Shadow page is a page in the place of the old name, that points to the new name.</small>");
178 echo("<br /><br />\n");
179 echo("<form method=\"post\" onSubmit=\"return confirm('Are you sure you want permanently delete this page?');\">\n");
180 echo("<input value=\"Delete\" type=\"submit\" /><input type=\"hidden\" name=\"function\" value=\"delete\" />\n");
181 echo("<input type=\"hidden\" name=\"page\" value=\"".$recentpagerow['pagename']."\" />\n");
183 //put pointer back to start of results
184 mysql_data_seek($pageresult, 0);
188 echo("No page found with that title: ". $page);
194 echo("No page field found");
202 //ARROW makes a database connection to the mysql database (which is from now on the default one)
204 $pagesquery = "SELECT pagename, MAX(version) AS version, MAX(lastmodified) AS lastmodified FROM $wikitable GROUP BY pagename";
205 $pagesresult = mysql_query($pagesquery) or die("Error getting pages: ".mysql_error());
210 echo("<th>Name</th><th>view</th><th>Version</th><th>LastUpdate</th>\n");
212 while($row = mysql_fetch_assoc($pagesresult))
214 $name = $row['pagename'];
215 $time = timeString($row['lastmodified']);
216 $version = $row['version'];
219 echo("<td><a href=\"wikiadmin.php?function=details&page=".urlencode($name)."\">".htmlspecialchars($name)."</a></td>\n");
220 //ARROW ../wiki.php?id= is the base of the link to the added wiki page.
221 echo("<td><a target=\"_blank\" href=\"$wikiurl?id=".urlencode($name)."\">view</a></td>\n");
222 echo("<td>".$version."</td>\n");
223 echo("<td>".$time."</td>\n");
230 //ARROW closes all html of the header.php
231 include('footer.php');