Revision [9009]

This is an old revision of PageAdminAction made by JavaWoman on 2005-06-08 20:18:21.

 

Page Administration Action

Last edited by JavaWoman:
adding line numbers
Wed, 08 Jun 2005 20:18 UTC [diff]


See also:
  • Documentation: PageAdminActionInfo.

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.1.

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.  * @version             0.3.1
  11.  * @since               Wikka 1.1.X.X
  12.  *
  13.  * @output      A list of pages available on the current Wikka server.
  14.  *
  15.  * @todo        - mass-operations
  16.  *          - handlers: rename handler
  17.  *          - statistics: page hits
  18.  *          - full-text page search
  19.  *          - i18n support
  20.  *          - CSS-driven layout
  21.  */
  22.  
  23. // set default values as constants
  24. define('DEFAULT_RECORDS_LIMIT', '20'); # number of records per page
  25. define('DEFAULT_REC_LIMIT_STEP', '10'); # step for selectable records limit
  26. define('DEFAULT_SORT_FIELD', 'time'); # sort field
  27. define('DEFAULT_SORT_ORDER', 'desc'); # sort order, ascendant or descendant
  28. define('DEFAULT_START', '0'); # start record
  29. define('DEFAULT_SEARCH', ''); # keyword to restrict page search
  30. define('DEFAULT_TAG_LENGTH', '15'); # max. length of displayed pagename
  31. define('DEFAULT_URL_LENGTH', '18'); # max. length of displayed user host
  32. define('DEFAULT_TERMINATOR', '~'); # symbol replacing truncated text
  33.  
  34. // restrict access to admins
  35. if ($this->IsAdmin($this->GetUser())) {
  36.  
  37.     // perform mass-operations if required (forthcoming)
  38.     if ($_GET["action"] == "massdelete") {
  39.             echo $this->Action("massdelete");
  40.     } else if ($_GET["action"] == "massrename"){
  41.             echo $this->Action("massrename");
  42.     } else if ($_GET["action"] == "massacls"){
  43.             echo $this->Action("massacls");
  44.     } else {
  45.  
  46.         // process URL variables
  47.    
  48.         // number of records per page
  49.         $l = (!$_POST['l'])? $_GET['l'] : $_POST['l'];
  50.         if (!$_POST['l'] && !$_GET['l']) $l = DEFAULT_RECORDS_LIMIT;
  51.    
  52.         // sort field
  53.         $sort = ($_GET['sort'])? $_GET['sort'] : DEFAULT_SORT_FIELD;
  54.         // sort order
  55.         $d = ($_GET['d'])? $_GET['d'] : DEFAULT_SORT_ORDER;
  56.         // start record
  57.         $s = ($_GET['s'])? $_GET['s'] : DEFAULT_START;
  58.    
  59.         // search string
  60.         $q = (!$_POST['q'])? $_GET['q'] : $_POST['q'];
  61.                 if (!$_POST['q'] && !$_GET['q']) $q = DEFAULT_SEARCH;
  62.  
  63.         // restrict MySQL query by search string
  64.         $where = 'WHERE tag LIKE "%'.$q.'%"and latest = "Y"';
  65.  
  66.         // get total number of pages
  67.         $pages = $this->LoadSingle('SELECT count(*) as n FROM '.$this->config['table_prefix'].'pages '.$where);
  68.         $numpages = $pages['n'];
  69.  
  70.         // print page header
  71.         echo $this->Format('===== Page Administration ===== --- --- ');    
  72.    
  73.         // build pager form
  74.         echo $this->FormOpen('','','post');
  75.         $form1 = '<div style="float:left; padding:10px; border:1px dotted #AAA; background-color:#EEE; width:60%">';
  76.         $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" accesskey="a" /><br /><br />';
  77.         $form1 .= 'Show <select name="l" title="Select records-per-page limit">';
  78.  
  79.         // build drop-down menu
  80.         for ($rec=DEFAULT_REC_LIMIT_STEP; $rec < ($numpages+DEFAULT_REC_LIMIT_STEP); $rec+=DEFAULT_REC_LIMIT_STEP) {
  81.             $selected = ($l == $rec)? 'selected' : '';  
  82.             $form1 .= '<option value="'.$rec.'" '.$selected.'>'.$rec.'</option>';
  83.         }
  84.         $form1 .=  '</select> records per page <input type="submit" value="Apply" accesskey="a" /><br /><br />';
  85.        
  86.         // build pager links
  87.         if($s > 0)
  88.             $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> |  ';
  89.         if($numpages > ($s + $l))
  90.             $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>';
  91.         $form1 .= '[Records ('.$numpages.'): '.$prev.'<strong>'.($s+1).'-'.($s+$l).'</strong>'.$next.' (sorted by: <em>'.$sort.', '.$d.'</em> )]';
  92.         $form1 .= '</div>'.$this->FormClose();
  93.  
  94.         // print form and infobox
  95.         $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>';
  96.         echo $infobox;
  97.         echo $form1;
  98.  
  99.         // get page list
  100.         $pagedata = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."pages ".
  101.         $where." ORDER BY ".$sort." ".$d." limit ".$s.", ".$l);
  102.    
  103.         if ($pagedata) {
  104.    
  105.             // build table headers
  106.             $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>';
  107.             $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>';
  108.             $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>';
  109.             $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>';
  110.    
  111.             $htmlout = '<div class="pagedata" style="clear:both"><table width="100%" border="1px">'.
  112.             '  <tr>'.
  113.                 '    <th>&nbsp;</th>'.
  114.             '    <th>'.$tagheader.'</th>'.
  115.             '    <th>'.$ownerheader.'</th>'.
  116.             '    <th>'.$userheader.'</th>'.
  117.             '    <th>'.$lasteditheader.'</th>'.
  118.                 '    <th>Page Statistics</th>'.
  119.                 '    <th>Page Handlers</th>'.
  120.             '  </tr>';
  121.    
  122.             // feed table with data
  123.             foreach($pagedata as $page) {
  124.  
  125.                 // truncate long page names
  126.                 $pagename = (strlen($page['tag']) > DEFAULT_TAG_LENGTH)? substr($page['tag'], 0, DEFAULT_TAG_LENGTH).DEFAULT_TERMINATOR : $page['tag'];
  127.    
  128.                 // build handler links
  129.                 $lastedit = '<span style="font-size: .8em">'.$page['time'].'</span>';
  130.                 $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>)';
  131.                 $showpage = '<a href="'.$this->Href('',$page['tag'], '').'" title="Open '.$page['tag'].'">'.$pagename.'</a>';
  132.                 $editpage = '<a href="'.$this->Href('edit',$page['tag'], '').'" title="Edit '.$page['tag'].'">edit</a>';
  133.                 $deletepage = '<a href="'.$this->Href('delete',$page['tag'], '').'" title="Delete '.$page['tag'].'">delete</a>';
  134.                 $clonepage = '<a href="'.$this->Href('clone',$page['tag'], '').'" title="Clone '.$page['tag'].'">clone</a>';
  135.                 $aclpage = '<a href="'.$this->Href('acls',$page['tag'], '').'" title="Change ACLs for '.$page['tag'].'">acl</a>';
  136.  
  137.    
  138.                 // get page owner
  139.                 if ($page['owner']) {          
  140.                     // is the owner a registered user?
  141.                     if ($this->LoadUser($page['owner'])) {
  142.                         // does user's homepage exist?
  143.                         if ($this->ExistsPage($page['owner'])) {
  144.                             $owner = $this->Link($page['owner'],'','','','','Go to '.$page['owner'].'\'s homepage');
  145.                         } else {
  146.                             $owner = $page['owner'];
  147.                         }
  148.                     } else {
  149.                         $owner = $page['owner'];
  150.                     }  
  151.                 } else {
  152.                     // page has empty owner field: print claim link
  153.                     $owner = $this->Link($page['tag'], 'claim','(Nobody)','','','Take ownership of '.$page['tag']);
  154.                 }  
  155.                 // get last author
  156.                 if ($page['user']) {           
  157.                     // is the author a registered user?
  158.                     if ($this->LoadUser($page['user'])) {
  159.                         // does user's homepage exist?
  160.                         if ($this->ExistsPage($page['user'])) {
  161.                             $user = $this->Link($page['user'],'','','','','Go to '.$page['user'].'\'s homepage');
  162.                         } else {
  163.                             $user = $page['user'];
  164.                         }
  165.                     } else {
  166.                         // truncate long host names
  167.                         $user = (strlen($page['user']) > DEFAULT_URL_LENGTH)? substr($page['user'], 0, DEFAULT_URL_LENGTH).DEFAULT_TERMINATOR : $page['user'];
  168.                     }
  169.                 } else {
  170.                     // page has empty user field
  171.                     $user = '(Nobody)';
  172.                 }  
  173.  
  174.                 // get page hits (forthcoming)
  175.                 $hitspage = '<span style="color:#666">0</span>';               
  176.  
  177.                 // get page revisions and create revision link if needed
  178.                 $revisions = $this->LoadRevisions($page['tag']);
  179.                 $rv = count($revisions);
  180.                 $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>';
  181.  
  182.                 // get page comments and create comments link if needed
  183.                 $comments = $this->LoadComments($page['tag']);         
  184.                 $cn = count($comments);
  185.                 $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>';
  186.  
  187.                 // get page backlinks and create backlinks link
  188.                 $backlinks = $this->LoadPagesLinkingTo($page['tag']);          
  189.                 $bn = count($backlinks);
  190.                 $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>';
  191.  
  192.                 // get page referrers and create referrer link
  193.                 $referrers = $this->LoadReferrers($page['tag']);           
  194.                 $rn = count($referrers);
  195.                 $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>';
  196.  
  197.                 $htmlout .= '  <tr>'.
  198.                 '    <td><input type="checkbox" id="'.$page['id'].'" '.(($_GET['selectall'] == 1)? 'checked="checked"' : '').' title="Select '.$page['tag'].'"/></td>'.
  199.                 '    <td>'.$showpage.'</td>'.
  200.                 '    <td><center>'.$owner.'</center></td>'.
  201.                 '    <td><center>'.$user.'</center></td>'.
  202.                 '    <td><center>'.$lastedit.'</center></td>'.
  203.                 '    <td><center>'.$hitspage.'-'.$revpage.'-'.$commentspage.'-'.$backlinkpage.'-'.$refpage.'</center></td>'.
  204.                 ' <td><center> '.$editpage.' :: '.$deletepage.' :: '.$clonepage.' :: rename :: '.$aclpage.' </center></td>'.
  205.                 '  </tr>';
  206.             }
  207.    
  208.             $htmlout .= '</table></div>';
  209.             // print the table
  210.             echo $this->FormOpen('','','get');
  211.             echo $htmlout;
  212.            
  213.             // multiple-page operations (forthcoming)
  214.             echo '<br />';
  215.             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>]';
  216.             echo ' With selected: <select name="action">';
  217.             echo '<option value="" selected="selected">---</option>';
  218.             echo '<option value="massdelete">Delete</option>';
  219.             echo '<option value="massrename">Rename</option>';
  220.             echo '<option value="massacls">Change ACLs</option>';
  221.             echo '</select> <input type="submit" value="Submit" accesskey="s" />';
  222.             echo $this->FormClose();
  223.         } else {
  224.             // no records matching the search string: print error message
  225.             echo '<p><span class="error">Sorry, there are no pages matching</span> <strong>"'.$q.'"</strong></p>';
  226.         }
  227.     }
  228. } else {
  229.     // current user is not admin: show plain page index
  230.     echo $this->Action('pageindex');
  231. }
  232. ?>



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