summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Coburn <btcoburn@silicodon.net>2006-12-07 08:49:06 +0100
committerBen Coburn <btcoburn@silicodon.net>2006-12-07 08:49:06 +0100
commitebf1501f6d253ef906c44bae278a2f80ffcb9f54 (patch)
tree433bac6de834b9584a965e87d39793fee0a846ac
parent5aa52fafe8be8e728c0d2c9ff12c999e80766127 (diff)
downloadrpg-ebf1501f6d253ef906c44bae278a2f80ffcb9f54.tar.gz
rpg-ebf1501f6d253ef906c44bae278a2f80ffcb9f54.tar.bz2
changelog type strings replaced with constants
Using more verbose constant names in the place of single character strings should make the code much more readable. This does not change the behavior of the changelog. darcs-hash:20061207074906-05dcb-0bdc35e7241bf14063b2b43a6ff26d8a3c307cb9.gz
-rw-r--r--inc/changelog.php16
-rw-r--r--inc/common.php14
-rw-r--r--inc/html.php6
-rw-r--r--lib/plugins/importoldchangelog/action.php10
-rw-r--r--lib/plugins/revert/admin.php2
5 files changed, 28 insertions, 20 deletions
diff --git a/inc/changelog.php b/inc/changelog.php
index 43d18f148..c985e5694 100644
--- a/inc/changelog.php
+++ b/inc/changelog.php
@@ -6,6 +6,14 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
+// Constants for known core changelog line types.
+// Use these in place of string literals for more readable code.
+define('DOKU_CHANGE_TYPE_CREATE', 'C');
+define('DOKU_CHANGE_TYPE_EDIT', 'E');
+define('DOKU_CHANGE_TYPE_MINOR_EDIT', 'e');
+define('DOKU_CHANGE_TYPE_DELETE', 'D');
+define('DOKU_CHANGE_TYPE_REVERT', 'R');
+
/**
* parses a changelog line into it's components
*
@@ -33,7 +41,7 @@ function parseChangelogLine($line) {
* @author Esther Brunner <wikidesign@gmail.com>
* @author Ben Coburn <btcoburn@silicodon.net>
*/
-function addLogEntry($date, $id, $type='E', $summary='', $extra='', $flags=null){
+function addLogEntry($date, $id, $type=DOKU_CHANGE_TYPE_EDIT, $summary='', $extra='', $flags=null){
global $conf, $INFO;
// check for special flags as keys
@@ -43,8 +51,8 @@ function addLogEntry($date, $id, $type='E', $summary='', $extra='', $flags=null)
$id = cleanid($id);
$file = wikiFN($id);
$created = @filectime($file);
- $minor = ($type==='e');
- $wasRemoved = ($type==='D');
+ $minor = ($type===DOKU_CHANGE_TYPE_MINOR_EDIT);
+ $wasRemoved = ($type===DOKU_CHANGE_TYPE_DELETE);
if(!$date) $date = time(); //use current time if none supplied
$remote = (!$flagExternalEdit)?$_SERVER['REMOTE_ADDR']:'127.0.0.1';
@@ -147,7 +155,7 @@ function _handleRecent($line,$ns,$flags){
if(isset($seen[$recent['id']])) return false;
// skip minors
- if($recent['type']==='e' && ($flags & RECENTS_SKIP_MINORS)) return false;
+ if($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT && ($flags & RECENTS_SKIP_MINORS)) return false;
// remember in seen to skip additional sights
$seen[$recent['id']] = 1;
diff --git a/inc/common.php b/inc/common.php
index 93e2df34f..60bec57a2 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -150,7 +150,7 @@ function pageinfo(){
$info['user'] = $revinfo['user'];
$info['sum'] = $revinfo['sum'];
// See also $INFO['meta']['last_change'] which is the most recent log line for page $ID.
- // Use $INFO['meta']['last_change']['type']==='e' in place of $info['minor'].
+ // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor'].
if($revinfo['user']){
$info['editor'] = $revinfo['user'];
@@ -736,7 +736,7 @@ function saveWikiText($id,$text,$summary,$minor=false){
saveOldRevision($id);
// add a changelog entry if this edit came from outside dokuwiki
if ($old>$oldRev) {
- addLogEntry($old, $id, 'E', $lang['external_edit'], '', array('ExternalEdit'=>true));
+ addLogEntry($old, $id, DOKU_CHANGE_TYPE_EDIT, $lang['external_edit'], '', array('ExternalEdit'=>true));
// remove soon to be stale instructions
$cache = new cache_instructions($id, $file);
$cache->removeCache();
@@ -773,14 +773,14 @@ function saveWikiText($id,$text,$summary,$minor=false){
// select changelog line type
$extra = '';
- $type = 'E';
+ $type = DOKU_CHANGE_TYPE_EDIT;
if ($wasReverted) {
- $type = 'R';
+ $type = DOKU_CHANGE_TYPE_REVERT;
$extra = $REV;
}
- else if ($wasCreated) { $type = 'C'; }
- else if ($wasRemoved) { $type = 'D'; }
- else if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = 'e'; } //minor edits only for logged in users
+ else if ($wasCreated) { $type = DOKU_CHANGE_TYPE_CREATE; }
+ else if ($wasRemoved) { $type = DOKU_CHANGE_TYPE_DELETE; }
+ else if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = DOKU_CHANGE_TYPE_MINOR_EDIT; } //minor edits only for logged in users
addLogEntry($newRev, $id, $type, $summary, $extra);
// send notify mails
diff --git a/inc/html.php b/inc/html.php
index dc11b17d7..672430cf1 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -469,7 +469,7 @@ function html_revisions($first=0){
print p_locale_xhtml('revisions');
print '<ul>';
if($INFO['exists'] && $first==0){
- print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']==='e') ? '<li class="minor">' : '<li>';
+ print (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
print '<div class="li">';
print $date;
@@ -493,7 +493,7 @@ function html_revisions($first=0){
$date = date($conf['dformat'],$rev);
$info = getRevisionInfo($ID,$rev,true);
- print ($info['type']==='e') ? '<li class="minor">' : '<li>';
+ print ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
print '<div class="li">';
print $date;
@@ -579,7 +579,7 @@ function html_recent($first=0){
foreach($recents as $recent){
$date = date($conf['dformat'],$recent['date']);
- print ($recent['type']==='e') ? '<li class="minor">' : '<li>';
+ print ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
print '<div class="li">';
print $date.' ';
diff --git a/lib/plugins/importoldchangelog/action.php b/lib/plugins/importoldchangelog/action.php
index 0c2601e16..8effe4ec9 100644
--- a/lib/plugins/importoldchangelog/action.php
+++ b/lib/plugins/importoldchangelog/action.php
@@ -47,10 +47,10 @@ class action_plugin_importoldchangelog extends DokuWiki_Action_Plugin {
$sum = rtrim($oldline[4], "\n");
}
// guess line type
- $type = 'E';
- if ($wasMinor) { $type = 'e'; }
- if ($sum===$lang['created']) { $type = 'C'; }
- if ($sum===$lang['deleted']) { $type = 'D'; }
+ $type = DOKU_CHANGE_TYPE_EDIT;
+ if ($wasMinor) { $type = DOKU_CHANGE_TYPE_MINOR_EDIT; }
+ if ($sum===$lang['created']) { $type = DOKU_CHANGE_TYPE_CREATE; }
+ if ($sum===$lang['deleted']) { $type = DOKU_CHANGE_TYPE_DELETE; }
// build new log line
$tmp = array();
$tmp['date'] = (int)$oldline[0];
@@ -88,7 +88,7 @@ class action_plugin_importoldchangelog extends DokuWiki_Action_Plugin {
$tmp = array();
$tmp['date'] = (int)$date;
$tmp['ip'] = '127.0.0.1'; // original ip lost
- $tmp['type'] = 'E';
+ $tmp['type'] = DOKU_CHANGE_TYPE_EDIT;
$tmp['id'] = $id;
$tmp['user'] = ''; // original user lost
$tmp['sum'] = '('.$lang['restored'].')'; // original summary lost
diff --git a/lib/plugins/revert/admin.php b/lib/plugins/revert/admin.php
index b9c196297..5c5d98ab6 100644
--- a/lib/plugins/revert/admin.php
+++ b/lib/plugins/revert/admin.php
@@ -132,7 +132,7 @@ class admin_plugin_revert extends DokuWiki_Admin_Plugin {
$cnt++;
$date = date($conf['dformat'],$recent['date']);
- echo ($recent['type']==='e') ? '<li class="minor">' : '<li>';
+ echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
echo '<div class="li">';
echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';