Revision [10134]

This is an old revision of PageAdminAction made by JavaWoman on 2005-07-19 16:15:49.

 

Page Administration Action

Last edited by JavaWoman:
new version, various related changes
Tue, 19 Jul 2005 16:15 UTC [diff]


See also:

This is the development page for the Page Administration action.

This action, inspired by the UserAdmin action, is meant to allow Wikka Administrators to manage pages and perform several maintenance operations.
It displays the standard PageIndex to non-admins.
 



Sample output

Page Administration



Page Statistics:
  • hits
  • revisions
  • comments
  • backlinks
  • referrers
Search page by name:

Show records per page

[Records (471): 1-10 | 11-20 (sorted by: time, desc )]
  Page Name Owner Last Author Last Edit Page Statistics Page Handlers
InitializeSessi~
FreekNL
FreekNL
2005-01-31 21:58:56 (-)
0-1-0-0-0
edit :: delete :: clone :: rename :: acl
GmBowen
GmBowen
GmBowen
2005-01-31 19:54:17 (-)
0-125-8-41-45
edit :: delete :: clone :: rename :: acl
SandBox
(Public)
ip076155.niehs.nih~
2005-01-31 18:59:42 (-)
0-544-6-13-44
edit :: delete :: clone :: rename :: acl
TheLounge
JsnX
JavaWoman
2005-01-31 16:39:53 (*)
0-31-7-5-26
edit :: delete :: clone :: rename :: acl
HandleCsvData
NilsLindenberg
NilsLindenberg
2005-01-31 15:25:17 (*)
0-5-0-3-0
edit :: delete :: clone :: rename :: acl
PageAdminAction
DarTar
DarTar
2005-01-31 14:43:34 (*)
0-11-1-1-0
edit :: delete :: clone :: rename :: acl
WikkaBlog2
GmBowen
GmBowen
2005-01-31 14:38:24 (*)
0-8-9-3-1
edit :: delete :: clone :: rename :: acl
IanHayhurst
IanHayhurst
IanHayhurst
2005-01-31 14:01:54 (-)
0-3-0-0-0
edit :: delete :: clone :: rename :: acl
FlexibleWikka
DarTar
DarTar
2005-01-31 11:31:31 (*)
0-14-4-7-20
edit :: delete :: clone :: rename :: acl
CodeContributio~
(Public)
DarTar
2005-01-31 11:29:49 (*)
0-79-3-8-12
edit :: delete :: clone :: rename :: acl

[Check all | Uncheck all] With selected:


Current Version


Last available version is 0.3.2.

Features:

Bugfixes and modifications:

To Do


To do:

The code


Save the code below as actions/pageadmin.php and use it as {{pageadmin}}.

  1. <?php
  2.  
  3. /**
  4.  * Display an interface allowing Wikka administrators to perform multiple operations on Wikka pages.
  5.  *
  6.  * @package     Actions
  7.  * @name        PageAdmin
  8.  *
  9.  * @author      {@link http://wikka.jsnx.com/DarTar Dario Taraborelli}
  10.  * @author      {@link http://wikka.jsnx.com/JavaWoman JavaWoman} (using getCount(); minor tweaks)
  11.  * @version     0.3.2
  12.  * @since       Wikka 1.1.X.X
  13.  *
  14.  * @output      A list of pages available on the current Wikka server.
  15.  *
  16.  * @todo    - mass-operations
  17.  *          - handlers: rename handler
  18.  *          - statistics: page hits
  19.  *          - full-text page search
  20.  *          - i18n support
  21.  *          - CSS-driven layout
  22.  */
  23.  
  24. // set default values as constants
  25. define('DEFAULT_RECORDS_LIMIT', '20'); # number of records per page
  26. define('DEFAULT_REC_LIMIT_STEP', '10'); # step for selectable records limit
  27. define('DEFAULT_SORT_FIELD', 'time'); # sort field
  28. define('DEFAULT_SORT_ORDER', 'desc'); # sort order, ascendant or descendant
  29. define('DEFAULT_START', '0'); # start record
  30. define('DEFAULT_SEARCH', ''); # keyword to restrict page search
  31. define('DEFAULT_TAG_LENGTH', '15'); # max. length of displayed pagename
  32. define('DEFAULT_URL_LENGTH', '18'); # max. length of displayed user host
  33. #define('DEFAULT_TERMINATOR', '~'); # symbol replacing truncated text
  34. define('DEFAULT_TERMINATOR', '&#8230;'); # standard symbol replacing truncated text (ellipsis) JW 2005-07-19
  35.  
  36. // restrict access to admins
  37. if ($this->IsAdmin($this->GetUser()))
  38. {
  39.     // perform mass-operations if required (forthcoming)
  40.     if (isset($_GET['action']))
  41.     {
  42.         if ($_GET['action'] == 'massdelete')
  43.         {
  44.             echo $this->Action('massdelete');
  45.         }
  46.         elseif ($_GET['action'] == 'massrename')
  47.         {
  48.             echo $this->Action('massrename');
  49.         }
  50.         elseif ($_GET['action'] == 'massacls')
  51.         {
  52.             echo $this->Action('massacls');
  53.         }
  54.     }
  55.     else
  56.     {
  57.         // process URL variables
  58.         # JW 2005-07-19 some modifications to avoid notices but these are still not actually secure
  59.  
  60.         // number of records per page
  61.         #$l = (!$_POST['l']) ? $_GET['l'] : $_POST['l'];
  62.         #if (!$_POST['l'] && !$_GET['l']) $l = DEFAULT_RECORDS_LIMIT;
  63.         if (isset($_POST['l']))
  64.             $l = $_POST['l'];
  65.         elseif (isset($_GET['l']))
  66.             $l = $_GET['l'];
  67.         else
  68.             $l = DEFAULT_RECORDS_LIMIT;
  69.  
  70.         // sort field
  71.         #$sort = ($_GET['sort']) ? $_GET['sort'] : DEFAULT_SORT_FIELD;
  72.         $sort = (isset($_GET['sort'])) ? $_GET['sort'] : DEFAULT_SORT_FIELD;
  73.         // sort order
  74.         #$d = ($_GET['d']) ? $_GET['d'] : DEFAULT_SORT_ORDER;
  75.         $d = (isset($_GET['d'])) ? $_GET['d'] : DEFAULT_SORT_ORDER;
  76.         // start record
  77.         #$s = ($_GET['s']) ? $_GET['s'] : DEFAULT_START;
  78.         $s = (isset($_GET['s'])) ? $_GET['s'] : DEFAULT_START;
  79.  
  80.         // search string
  81.         #$q = (!$_POST['q']) ? $_GET['q'] : $_POST['q'];
  82.         #if (!$_POST['q'] && !$_GET['q']) $q = DEFAULT_SEARCH;
  83.         if (isset($_POST['q']))
  84.             $q = $_POST['q'];
  85.         elseif (isset($_GET['q']))
  86.             $q = $_GET['q'];
  87.         else
  88.             $q = DEFAULT_SEARCH;
  89.  
  90.         // select all   added JW 2005-07-19
  91.         $checked = '';
  92.         if (isset($_GET['selectall']))
  93.         {
  94.             $checked = (1 == $_GET['selectall']) ? ' checked="checked"' : '';
  95.         }
  96.  
  97.         // restrict MySQL query by search string     modified JW 2005-07-19
  98.         #$where = 'WHERE tag LIKE "%'.$q.'%"and latest = "Y"';
  99.         #$where = "`tag` LIKE '%".$q."%' AND `latest` = 'Y'";
  100.         $where = ('' == $q) ? "`latest` = 'Y'" : "`tag` LIKE '%".$q."%' AND `latest` = 'Y'";
  101.         // get total number of pages
  102.         #$pages = $this->LoadSingle('SELECT count(*) as n FROM '.$this->config['table_prefix'].'pages '.$where);
  103.         #$numpages = $pages['n'];
  104.         $numpages = $this->getCount('pages',$where);
  105.  
  106.         // print page header
  107.         echo $this->Format('===== Page Administration ===== --- --- ');
  108.  
  109.         // build pager form     JW 2005-07-19 accesskey removed (causes more problems than it solves)
  110.         echo $this->FormOpen('','','post');
  111.         $form1 = '<div style="float:left; padding:10px; border:1px dotted #AAA; background-color:#EEE; width:60%">';
  112.         $form1 .= 'Search page by name: <input type ="text" name="q" title="Enter a search string" size="20" maxlength="50" value="'.$q.'"/><input type="submit" value="Submit" /><br /><br />';
  113.         $form1 .= 'Show <select name="l" title="Select records-per-page limit">';
  114.  
  115.         // build drop-down menu     JW 2005-07-19 accesskey removed (causes more problems than it solves)
  116.         for ($rec=DEFAULT_REC_LIMIT_STEP; $rec < ($numpages+DEFAULT_REC_LIMIT_STEP); $rec+=DEFAULT_REC_LIMIT_STEP) {
  117.             $selected = ($l == $rec)? 'selected' : '';
  118.             $form1 .= '<option value="'.$rec.'" '.$selected.'>'.$rec.'</option>';
  119.         }
  120.         $form1 .=  '</select> records per page <input type="submit" value="Apply" /><br /><br />';
  121.  
  122.         // build pager links
  123.         $prev = '';     # JW 2005-07-19
  124.         $next = '';     # JW 2005-07-19
  125.         if ($s > 0)
  126.             $prev = '<a href="' .$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.($s-$l)).'&q='.$q.'" title="Show records from '.($s-$l+1).' to '.$s.'">'.($s-$l+1).'-'.$s.'</a> |  ';
  127.         if ($numpages > ($s + $l))
  128.             $next = ' | <a href="'.$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.($s+$l)).'&q='.$q.'" title="Show records from '.($s+$l+1).' to '.($s+2*$l).'">'.($s+$l+1).'-'.($s+2*$l).'</a>';
  129.         $form1 .= '[Records ('.$numpages.'): '.$prev.'<strong>'.($s+1).'-'.($s+$l).'</strong>'.$next.' (sorted by: <em>'.$sort.', '.$d.'</em> )]';
  130.         $form1 .= '</div>'.$this->FormClose();
  131.  
  132.         // print form and infobox
  133.         $infobox = '<div style="float:right; margin-bottom: 20px;padding:10px; border:1px dotted #AAA; background-color:#EEE; width:30%"><strong>Page Statistics:</strong><br /><ul style="list-style-type: none"><li><span style="color: #666">hits</a></li><li><span style="color: #CC0000">revisions</a></li><li><span style="color:#00CC00">comments</span></li><li><span style="color: #0000CC">backlinks</span></li><li><span style="color: #000000">referrers</span></li></ul></div>';
  134.         echo $infobox;
  135.         echo $form1;
  136.  
  137.         // get page list     modified JW 2005-07-19
  138.         $pagedata = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."pages WHERE ".
  139.         $where." ORDER BY ".$sort." ".$d." LIMIT ".$s.", ".$l);
  140.  
  141.         if ($pagedata)
  142.         {
  143.             // build table headers
  144.             $tagheader = '<a href="'.$this->Href('','', (($sort == 'tag' && $d == 'asc')? 'l='.$l.'&sort=tag&d=desc&q='.$q : 'l='.$l.'&sort=tag&d=asc&q='.$q)).'" title="Sort by page name">Page Name</a>';
  145.             $ownerheader = '<a href="'.$this->Href('','', (($sort == 'owner' && $d == 'asc')? 'l='.$l.'&sort=owner&d=desc&q='.$q : 'l='.$l.'&sort=owner&d=asc&q='.$q)).'" title="Sort by page owner">Owner</a>';
  146.             $userheader = '<a href="'.$this->Href('','', (($sort == 'user' && $d == 'asc')? 'l='.$l.'&sort=user&d=desc&q='.$q : 'l='.$l.'&sort=user&d=asc&q='.$q)).'" title="Sort by author name">Last Author</a>';
  147.             $lasteditheader = '<a href="'.$this->Href('','', (($sort == 'time' && $d == 'desc')? 'l='.$l.'&sort=time&d=asc&q='.$q : 'l='.$l.'&sort=time&d=desc&q='.$q)).'" title="Sort by edit time">Last Edit</a>';
  148.  
  149.             $htmlout = '<div class="pagedata" style="clear:both"><table width="100%" border="1px">'.
  150.             '  <tr>'.
  151.             '    <th>&nbsp;</th>'.
  152.             '    <th>'.$tagheader.'</th>'.
  153.             '    <th>'.$ownerheader.'</th>'.
  154.             '    <th>'.$userheader.'</th>'.
  155.             '    <th>'.$lasteditheader.'</th>'.
  156.             '    <th>Page Statistics</th>'.
  157.             '    <th>Page Handlers</th>'.
  158.             '  </tr>';
  159.  
  160.             // feed table with data
  161.             foreach($pagedata as $page)
  162.             {
  163.                 // truncate long page names
  164.                 $pagename = (strlen($page['tag']) > DEFAULT_TAG_LENGTH) ? substr($page['tag'], 0, DEFAULT_TAG_LENGTH).DEFAULT_TERMINATOR : $page['tag'];
  165.  
  166.                 // build handler links
  167.                 $lastedit = '<span style="font-size: .8em">'.$page['time'].'</span>';
  168.                 $lastedit .= ($page['note'])? ' (<a href="'.$this->Href('history', $page['tag'], '').'" title="Last edit: '.$page['note'].'">*</a>)' : ' (<a href="'.$this->Href('history', $page['tag'], '').'" title="Display '.$page['tag'].'\'s history">-</a>)';
  169.                 #$showpage = '<a href="'.$this->Href('',$page['tag'], '').'" title="Open '.$page['tag'].'">'.$pagename.'</a>';
  170.                 # modified JW 2005-07-19 there should really only be a title if the name is truncated
  171.                 if ($pagename != $page['tag'])
  172.                 {
  173.                     $showpage = '<a href="'.$this->Href('',$page['tag'], '').'" title="'.$page['tag'].'">'.$pagename.'</a>';
  174.                 }
  175.                 else
  176.                 {
  177.                     $showpage = '<a href="'.$this->Href('',$page['tag'], '').'">'.$pagename.'</a>';
  178.                 }
  179.                 $editpage = '<a href="'.$this->Href('edit',$page['tag'], '').'" title="Edit '.$page['tag'].'">edit</a>';
  180.                 $deletepage = '<a href="'.$this->Href('delete',$page['tag'], '').'" title="Delete '.$page['tag'].'">delete</a>';
  181.                 $clonepage = '<a href="'.$this->Href('clone',$page['tag'], '').'" title="Clone '.$page['tag'].'">clone</a>';
  182.                 $aclpage = '<a href="'.$this->Href('acls',$page['tag'], '').'" title="Change ACLs for '.$page['tag'].'">acl</a>';
  183.  
  184.                 // get page owner
  185.                 if ($page['owner'])
  186.                 {
  187.                     // is the owner a registered user?
  188.                     if ($this->LoadUser($page['owner']))
  189.                     {
  190.                         // does user's homepage exist?
  191.                         if ($this->ExistsPage($page['owner']))
  192.                         {
  193.                             $owner = $this->Link($page['owner'],'','','','','Go to '.$page['owner'].'\'s homepage');
  194.                         }
  195.                         else
  196.                         {
  197.                             $owner = $page['owner'];
  198.                         }
  199.                     }
  200.                     else
  201.                     {
  202.                         $owner = $page['owner'];
  203.                     }
  204.                 }
  205.                 else
  206.                 {
  207.                     // page has empty owner field: print claim link
  208.                     $owner = $this->Link($page['tag'], 'claim','(Nobody)','','','Take ownership of '.$page['tag']);
  209.                 }
  210.                 // get last author
  211.                 if ($page['user'])
  212.                 {
  213.                     // is the author a registered user?
  214.                     if ($this->LoadUser($page['user']))
  215.                     {
  216.                         // does user's homepage exist?
  217.                         if ($this->ExistsPage($page['user']))
  218.                         {
  219.                             $user = $this->Link($page['user'],'','','','','Go to '.$page['user'].'\'s homepage');
  220.                         }
  221.                         else
  222.                         {
  223.                             $user = $page['user'];
  224.                         }
  225.                     }
  226.                     else
  227.                     {
  228.                         // truncate long host names
  229.                         $user = (strlen($page['user']) > DEFAULT_URL_LENGTH) ? substr($page['user'], 0, DEFAULT_URL_LENGTH).DEFAULT_TERMINATOR : $page['user'];
  230.                         # added  JW 2005-07-19
  231.                         if ($user != $page['user'])
  232.                         {
  233.                             $user = '<span title="'.$page['user'].'">'.$user.'</span>';
  234.                         }
  235.                     }
  236.                 }
  237.                 else
  238.                 {
  239.                     // page has empty user field
  240.                     $user = '(Nobody)';
  241.                 }
  242.  
  243.                 // get counts   - JW 2005-07-19
  244.                 $whereTag       = "`tag` = '".$page['tag']."'";
  245.                 $wherePageTag   = "`page_tag` = '".$page['tag']."'";
  246.                 $whereToTag     = "`to_tag` = '".$page['tag']."'";
  247.                 $hn = 0;
  248.                 $rv = $this->getCount('pages',$whereTag);
  249.                 $cn = $this->getCount('comments',$wherePageTag);
  250.                 $bn = $this->getCount('links',$whereToTag);
  251.                 $rn = $this->getCount('referrers',$wherePageTag);
  252.  
  253.                 // get page hits (forthcoming)
  254.                 $hitspage = ($hn > 0) ? '<a style="color:#666" href="'.$this->Href('hits',$page['tag'], '').'" title="Hits of '.$page['tag'].' ('.$hn.')">'.$hn.'</a>' : '<span style="color:#666">0</span>';
  255.  
  256.                 // get page revisions and create revision link if needed
  257.                 $revpage = ($rv > 0) ? '<a style="color:#CC0000" href="'.$this->Href('revisions',$page['tag'], '').'" title="Revisions of '.$page['tag'].' ('.$rv.')">'.$rv.'</a>' : '<span style="color:#CC0000">0</span>';
  258.  
  259.                 // get page comments and create comments link if needed
  260.                 $commentspage = ($cn > 0) ? '<a style="color:#00CC00" href="'.$this->Href('',$page['tag'], 'show_comments=1#comments').'" title="Comments for '.$page['tag'].' ('.$cn.')">'.$cn.'</a>' : '<span style="color:#00CC00">0</span>';
  261.  
  262.                 // get page backlinks and create backlinks link
  263.                 $backlinkpage = ($bn > 0) ? '<a style="color:#0000CC" href="'.$this->Href('backlinks',$page['tag'], '').'" title="Pages linking to '.$page['tag'].' ('.$bn.')">'.$bn.'</a>' : '<span style="color:#0000CC">0</span>';
  264.  
  265.                 // get page referrers and create referrer link
  266.                 $refpage = ($rn > 0) ? '<a style="color:#000000" href="'.$this->Href('referrers',$page['tag'], '').'" title="External sites linking to '.$page['tag'].' ('.$rn.')">'.$rn.'</a>' : '<span style="color:#000000">0</span>';
  267.  
  268.                 $htmlout .= '  <tr>'.
  269.                 #'    <td><input type="checkbox" id="'.$page['id'].'" '.(($_GET['selectall'] == 1)? 'checked="checked"' : '').' title="Select '.$page['tag'].'"/></td>'.
  270.                 '    <td><input type="checkbox" id="'.$page['id'].'"'.$checked.' title="Select '.$page['tag'].'"/></td>'.   # modified JW 2005-07-19
  271.                 '    <td>'.$showpage.'</td>'.
  272.                 '    <td><center>'.$owner.'</center></td>'.
  273.                 '    <td><center>'.$user.'</center></td>'.
  274.                 '    <td><center>'.$lastedit.'</center></td>'.
  275.                 '    <td><center>'.$hitspage.'-'.$revpage.'-'.$commentspage.'-'.$backlinkpage.'-'.$refpage.'</center></td>'.
  276.                 '    <td><center> '.$editpage.' :: '.$deletepage.' :: '.$clonepage.' :: rename :: '.$aclpage.' </center></td>'.
  277.                 '  </tr>';
  278.             }
  279.  
  280.             $htmlout .= '</table></div>';
  281.             // print the table
  282.             echo $this->FormOpen('','','get');
  283.             echo $htmlout;
  284.  
  285.             // multiple-page operations (forthcoming)       JW 2005-07-19 accesskey removed (causes more problems than it solves)
  286.             echo '<br />';
  287.             echo '[<a href="'.$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.$s.'&q='.$q.'&selectall=1').'" title="Check all results">Check all</a> | <a href="'.$this->Href('','','l='.$l.'&sort='.$sort.'&d='.$d.'&s='.$s.'&q='.$q.'&selectall=0').'" title="Uncheck all results">Uncheck all</a>]';
  288.             echo ' With selected: <select name="action">';
  289.             echo '<option value="" selected="selected">---</option>';
  290.             echo '<option value="massdelete">Delete</option>';
  291.             echo '<option value="massrename">Rename</option>';
  292.             echo '<option value="massacls">Change ACLs</option>';
  293.             echo '</select> <input type="submit" value="Submit" />';
  294.             echo $this->FormClose();
  295.         }
  296.         else
  297.         {
  298.             // no records matching the search string: print error message
  299.             echo '<p><span class="error">Sorry, there are no pages matching</span> <strong>"'.$q.'"</strong></p>';
  300.         }
  301.     }
  302. }
  303. else
  304. {
  305.     // current user is not admin: show plain page index
  306.     echo $this->Action('pageindex');
  307. }
  308. ?>


Code adapted to take advantage of WikkaCountingRecords getCount(), making the beta operational again; also various other tweaks - see Bugfixes and modifications list above and comments in the code. Version bumped up from 0.3.1 to 0.3.2 (since there's no functional change and the todo list is as undone as it was). --JavaWoman


CategoryDevelopmentActions CategoryDevelopmentAdmin
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki