Revision [10135]
This is an old revision of PageAdminAction made by JavaWoman on 2005-07-19 16:23:27.
Page Administration Action
Last edited by JavaWoman:
new version (test no longer broken), various related changes
Tue, 19 Jul 2005 16:23 UTC [diff]
new version (test no longer broken), various related changes
Tue, 19 Jul 2005 16:23 UTC [diff]
See also:
- Are you an administrator of this site ?
Give it a PageAdminTest try
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
Current Version
Last available version is 0.3.2.
Features:
- displays a pageable, sortable and searchable list of pages;
- displays detailed and clickable page statistics (revisions, comments, backlinks, referrers)
- generates links to different handlers with titles;
- shortens long pagenames and hostnames;
- shows last edit notes (if available);
- adds 'claim' links to pages with no owner;
- shows plain-text username in owner/lastauthor fields if user has no homepage;
- supports a bunch of configurable options (including max. length of displayed pagename, max. length of hostname, symbol for truncated text).
- The standard symbol for truncated text is of course the ellipsis (... or rather …) - why not use that? --JavaWoman
- Made ellipsis the default in version 0.3.2 --JW
Bugfixes and modifications:
- added constant section;
- added titles to different form elements;
- added configurable hostname and pagename length limit;
- fixed problem with search keyword not read by pager;
- added submit buttons after menus;
- fixed invalid markup resulting in green text on the whole page.
- using getCount() to retrieve the various counts --JW
- various changes to prevent NOTICEs --JW
- removed accesskey attributes (cause more problems than they solve) --JW
- various other minor tweaks --JW
To Do
- Code optimization;
- Mass-operations (mass-page deletion, mass-page rename, mass-page ACLs etc.);
- Handlers: add rename handler;
- Page statistics: add page hits;
- CSS-driven layout;
- Can I advocate for a "Page Hide/Unhide" option here?....H instead of Y or N for most recent works well. In some communities, particularly where there might be legal/administrative follow-ups to what was posted, it is quite useful to be able to "keep" the contents of the page in the database, but make them inaccessible to the wiki users. --GmBowen
- Mike, as you can see this interface does not add any specific handler or page feature which is not already supported by Wikka: it is just a hub for existing handlers (the multiple-page operations will require new handlers, though). So if you want to propose something like a 'hide/unhide' handler, I suggest you open a dedicated page. -- DarTar
- To be more precise, this action does include two forthcoming features (rename handler, page hits) but only as placeholders. The development of each of these functionalities should be take place elsewhere, not on this page. -- DarTar
- There might as well be a placeholer for a future "hide" or "lock" handler then. :) We certainly need something like that - see comments.--JavaWoman.
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}
- * @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} (using getCount(); minor tweaks)
- * @version 0.3.2
- * @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_TERMINATOR', '~'); # symbol replacing truncated text
- define('DEFAULT_TERMINATOR', '…'); # standard symbol replacing truncated text (ellipsis) JW 2005-07-19
- // restrict access to admins
- if ($this->IsAdmin($this->GetUser()))
- {
- // perform mass-operations if required (forthcoming)
- {
- if ($_GET['action'] == 'massdelete')
- {
- echo $this->Action('massdelete');
- }
- elseif ($_GET['action'] == 'massrename')
- {
- echo $this->Action('massrename');
- }
- elseif ($_GET['action'] == 'massacls')
- {
- echo $this->Action('massacls');
- }
- }
- else
- {
- // process URL variables
- # JW 2005-07-19 some modifications to avoid notices but these are still not actually secure
- // number of records per page
- #$l = (!$_POST['l']) ? $_GET['l'] : $_POST['l'];
- #if (!$_POST['l'] && !$_GET['l']) $l = DEFAULT_RECORDS_LIMIT;
- $l = $_POST['l'];
- $l = $_GET['l'];
- else
- $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;
- $q = $_POST['q'];
- $q = $_GET['q'];
- else
- $q = DEFAULT_SEARCH;
- // select all added JW 2005-07-19
- $checked = '';
- {
- $checked = (1 == $_GET['selectall']) ? ' checked="checked"' : '';
- }
- // restrict MySQL query by search string modified JW 2005-07-19
- #$where = 'WHERE tag LIKE "%'.$q.'%"and latest = "Y"';
- #$where = "`tag` LIKE '%".$q."%' AND `latest` = 'Y'";
- $where = ('' == $q) ? "`latest` = 'Y'" : "`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'];
- $numpages = $this->getCount('pages',$where);
- // print page header
- echo $this->Format('===== Page Administration ===== --- --- ');
- // build pager form JW 2005-07-19 accesskey removed (causes more problems than it solves)
- 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" /><br /><br />';
- $form1 .= 'Show <select name="l" title="Select records-per-page limit">';
- // build drop-down menu JW 2005-07-19 accesskey removed (causes more problems than it solves)
- 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" /><br /><br />';
- // build pager links
- $prev = ''; # JW 2005-07-19
- $next = ''; # JW 2005-07-19
- 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 modified JW 2005-07-19
- $pagedata = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."pages WHERE ".
- $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> </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
- // 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>';
- # modified JW 2005-07-19 there should really only be a title if the name is truncated
- if ($pagename != $page['tag'])
- {
- $showpage = '<a href="'.$this->Href('',$page['tag'], '').'" title="'.$page['tag'].'">'.$pagename.'</a>';
- }
- else
- {
- $showpage = '<a href="'.$this->Href('',$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']))
- {
- }
- else
- {
- $owner = $page['owner'];
- }
- }
- else
- {
- $owner = $page['owner'];
- }
- }
- else
- {
- // page has empty owner field: print claim link
- }
- // 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']))
- {
- }
- else
- {
- $user = $page['user'];
- }
- }
- else
- {
- // truncate long host names
- # added JW 2005-07-19
- if ($user != $page['user'])
- {
- $user = '<span title="'.$page['user'].'">'.$user.'</span>';
- }
- }
- }
- else
- {
- // page has empty user field
- $user = '(Nobody)';
- }
- // get counts - JW 2005-07-19
- $whereTag = "`tag` = '".$page['tag']."'";
- $wherePageTag = "`page_tag` = '".$page['tag']."'";
- $whereToTag = "`to_tag` = '".$page['tag']."'";
- $hn = 0;
- $rv = $this->getCount('pages',$whereTag);
- $cn = $this->getCount('comments',$wherePageTag);
- $bn = $this->getCount('links',$whereToTag);
- $rn = $this->getCount('referrers',$wherePageTag);
- // get page hits (forthcoming)
- $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>';
- // get page revisions and create revision link if needed
- $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
- $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
- $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
- $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><input type="checkbox" id="'.$page['id'].'"'.$checked.' title="Select '.$page['tag'].'"/></td>'. # modified JW 2005-07-19
- ' <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) JW 2005-07-19 accesskey removed (causes more problems than it solves)
- 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" />';
- 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');
- }
- ?>
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