Revision [8604]

This is an old revision of PageAdminAction made by JavaWoman on 2005-05-28 17:19:34.

 

Page Administration Action

Last edited by JavaWoman:
move to two subcategories
Sat, 28 May 2005 17:19 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}}.

<?php

/**
 * Display an interface allowing Wikka administrators to perform multiple operations on Wikka pages.
 *
 * @package             Actions
 * @name                PageAdmin
 *
 * @author              {@link http://wikka.jsnx.com/DarTar Dario Taraborelli}
 * @version             0.3.1
 * @since               Wikka 1.1.X.X
 *
 * @output      A list of pages available on the current Wikka server.
 *
 * @todo        - mass-operations
 *          - handlers: rename handler
 *          - statistics: page hits
 *          - full-text page search
 *          - i18n support
 *          - CSS-driven layout
 */


// set default values as constants
define('DEFAULT_RECORDS_LIMIT', '20'); # number of records per page
define('DEFAULT_REC_LIMIT_STEP', '10'); # step for selectable records limit
define('DEFAULT_SORT_FIELD', 'time'); # sort field
define('DEFAULT_SORT_ORDER', 'desc'); # sort order, ascendant or descendant
define('DEFAULT_START', '0'); # start record
define('DEFAULT_SEARCH', ''); # keyword to restrict page search
define('DEFAULT_TAG_LENGTH', '15'); # max. length of displayed pagename
define('DEFAULT_URL_LENGTH', '18'); # max. length of displayed user host
define('DEFAULT_TERMINATOR', '~'); # symbol replacing truncated text

// restrict access to admins
if ($this->IsAdmin($this->GetUser())) {

    // perform mass-operations if required (forthcoming)
    if ($_GET["action"] == "massdelete") {
            echo $this->Action("massdelete");
    } else if ($_GET["action"] == "massrename"){
            echo $this->Action("massrename");
    } else if ($_GET["action"] == "massacls"){
            echo $this->Action("massacls");
    } else {

        // process URL variables
   
        // number of records per page
        $l = (!$_POST['l'])? $_GET['l'] : $_POST['l'];
        if (!$_POST['l'] && !$_GET['l']) $l = DEFAULT_RECORDS_LIMIT;
   
        // sort field
        $sort = ($_GET['sort'])? $_GET['sort'] : DEFAULT_SORT_FIELD;
        // sort order
        $d = ($_GET['d'])? $_GET['d'] : DEFAULT_SORT_ORDER;
        // start record
        $s = ($_GET['s'])? $_GET['s'] : DEFAULT_START;
   
        // search string
        $q = (!$_POST['q'])? $_GET['q'] : $_POST['q'];
                if (!$_POST['q'] && !$_GET['q']) $q = DEFAULT_SEARCH;

        // restrict MySQL query by search string
        $where = 'WHERE tag LIKE "%'.$q.'%"and latest = "Y"';

        // get total number of pages
        $pages = $this->LoadSingle('SELECT count(*) as n FROM '.$this->config['table_prefix'].'pages '.$where);
        $numpages = $pages['n'];

        // print page header
        echo $this->Format('===== Page Administration ===== --- --- ');    
   
        // build pager form
        echo $this->FormOpen('','','post');
        $form1 = '<div style="float:left; padding:10px; border:1px dotted #AAA; background-color:#EEE; width:60%">';
        $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 />';
        $form1 .= 'Show <select name="l" title="Select records-per-page limit">';

        // build drop-down menu
        for ($rec=DEFAULT_REC_LIMIT_STEP; $rec < ($numpages+DEFAULT_REC_LIMIT_STEP); $rec+=DEFAULT_REC_LIMIT_STEP) {
            $selected = ($l == $rec)? 'selected' : '';  
            $form1 .= '<option value="'.$rec.'" '.$selected.'>'.$rec.'</option>';
        }
        $form1 .=  '</select> records per page <input type="submit" value="Apply" accesskey="a" /><br /><br />';
       
        // build pager links
        if($s > 0)
            $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> |  ';
        if($numpages > ($s + $l))
            $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>';
        $form1 .= '[Records ('.$numpages.'): '.$prev.'<strong>'.($s+1).'-'.($s+$l).'</strong>'.$next.' (sorted by: <em>'.$sort.', '.$d.'</em> )]';
        $form1 .= '</div>'.$this->FormClose();

        // print form and infobox
        $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>';
        echo $infobox;
        echo $form1;

        // get page list
        $pagedata = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."pages ".
        $where." ORDER BY ".$sort." ".$d." limit ".$s.", ".$l);
   
        if ($pagedata) {
   
            // build table headers
            $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>';
            $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>';
            $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>';
            $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>';
   
            $htmlout = '<div class="pagedata" style="clear:both"><table width="100%" border="1px">'.
            '  <tr>'.
                '    <th>&nbsp;</th>'.
            '    <th>'.$tagheader.'</th>'.
            '    <th>'.$ownerheader.'</th>'.
            '    <th>'.$userheader.'</th>'.
            '    <th>'.$lasteditheader.'</th>'.
                '    <th>Page Statistics</th>'.
                '    <th>Page Handlers</th>'.
            '  </tr>';
   
            // feed table with data
            foreach($pagedata as $page) {

                // truncate long page names
                $pagename = (strlen($page['tag']) > DEFAULT_TAG_LENGTH)? substr($page['tag'], 0, DEFAULT_TAG_LENGTH).DEFAULT_TERMINATOR : $page['tag'];
   
                // build handler links
                $lastedit = '<span style="font-size: .8em">'.$page['time'].'</span>';
                $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>)';
                $showpage = '<a href="'.$this->Href('',$page['tag'], '').'" title="Open '.$page['tag'].'">'.$pagename.'</a>';
                $editpage = '<a href="'.$this->Href('edit',$page['tag'], '').'" title="Edit '.$page['tag'].'">edit</a>';
                $deletepage = '<a href="'.$this->Href('delete',$page['tag'], '').'" title="Delete '.$page['tag'].'">delete</a>';
                $clonepage = '<a href="'.$this->Href('clone',$page['tag'], '').'" title="Clone '.$page['tag'].'">clone</a>';
                $aclpage = '<a href="'.$this->Href('acls',$page['tag'], '').'" title="Change ACLs for '.$page['tag'].'">acl</a>';

   
                // get page owner
                if ($page['owner']) {          
                    // is the owner a registered user?
                    if ($this->LoadUser($page['owner'])) {
                        // does user's homepage exist?
                        if ($this->ExistsPage($page['owner'])) {
                            $owner = $this->Link($page['owner'],'','','','','Go to '.$page['owner'].'\'s homepage');
                        } else {
                            $owner = $page['owner'];
                        }
                    } else {
                        $owner = $page['owner'];
                    }  
                } else {
                    // page has empty owner field: print claim link
                    $owner = $this->Link($page['tag'], 'claim','(Nobody)','','','Take ownership of '.$page['tag']);
                }  
                // get last author
                if ($page['user']) {           
                    // is the author a registered user?
                    if ($this->LoadUser($page['user'])) {
                        // does user's homepage exist?
                        if ($this->ExistsPage($page['user'])) {
                            $user = $this->Link($page['user'],'','','','','Go to '.$page['user'].'\'s homepage');
                        } else {
                            $user = $page['user'];
                        }
                    } else {
                        // truncate long host names
                        $user = (strlen($page['user']) > DEFAULT_URL_LENGTH)? substr($page['user'], 0, DEFAULT_URL_LENGTH).DEFAULT_TERMINATOR : $page['user'];
                    }
                } else {
                    // page has empty user field
                    $user = '(Nobody)';
                }  

                // get page hits (forthcoming)
                $hitspage = '<span style="color:#666">0</span>';               

                // get page revisions and create revision link if needed
                $revisions = $this->LoadRevisions($page['tag']);
                $rv = count($revisions);
                $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>';

                // get page comments and create comments link if needed
                $comments = $this->LoadComments($page['tag']);         
                $cn = count($comments);
                $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>';

                // get page backlinks and create backlinks link
                $backlinks = $this->LoadPagesLinkingTo($page['tag']);          
                $bn = count($backlinks);
                $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>';

                // get page referrers and create referrer link
                $referrers = $this->LoadReferrers($page['tag']);           
                $rn = count($referrers);
                $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>';

                $htmlout .= '  <tr>'.
                '    <td><input type="checkbox" id="'.$page['id'].'" '.(($_GET['selectall'] == 1)? 'checked="checked"' : '').' title="Select '.$page['tag'].'"/></td>'.
                '    <td>'.$showpage.'</td>'.
                '    <td><center>'.$owner.'</center></td>'.
                '    <td><center>'.$user.'</center></td>'.
                '    <td><center>'.$lastedit.'</center></td>'.
                '    <td><center>'.$hitspage.'-'.$revpage.'-'.$commentspage.'-'.$backlinkpage.'-'.$refpage.'</center></td>'.
                ' <td><center> '.$editpage.' :: '.$deletepage.' :: '.$clonepage.' :: rename :: '.$aclpage.' </center></td>'.
                '  </tr>';
            }
   
            $htmlout .= '</table></div>';
            // print the table
            echo $this->FormOpen('','','get');
            echo $htmlout;
           
            // multiple-page operations (forthcoming)
            echo '<br />';
            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>]';
            echo ' With selected: <select name="action">';
            echo '<option value="" selected="selected">---</option>';
            echo '<option value="massdelete">Delete</option>';
            echo '<option value="massrename">Rename</option>';
            echo '<option value="massacls">Change ACLs</option>';
            echo '</select> <input type="submit" value="Submit" accesskey="s" />';
            echo $this->FormClose();
        } else {
            // no records matching the search string: print error message
            echo '<p><span class="error">Sorry, there are no pages matching</span> <strong>"'.$q.'"</strong></p>';
        }
    }
} else {
    // current user is not admin: show plain page index
    echo $this->Action('pageindex');
}
?>



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