3 * Copyright © 2004 $ThePhpWikiProgrammingTeam
5 * This file is part of PhpWiki.
7 * PhpWiki is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * PhpWiki is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * SPDX-License-Identifier: GPL-2.0-or-later
25 require_once 'lib/PageList.php';
28 * ListPages - List pages that are explicitly given as the pages argument.
30 * Mainly used to see some ratings and recommendations.
31 * But also possible to list some Categories or Users, or as generic
32 * frontend for plugin-list page lists.
34 * @author: Dan Frankowski
37 class WikiPlugin_ListPages
40 function getDescription()
42 return _("List pages that are explicitly given as the pages argument.");
45 function getDefaultArguments()
49 PageList::supportedArgs(),
50 array('pages' => false,
57 // info arg allows multiple columns
58 // info=mtime,hits,summary,version,author,locked,minor
59 // additional info args:
60 // top3recs : recommendations
61 // numbacklinks : number of backlinks (links to the given page)
62 // numpagelinks : number of forward links (links at the given page)
66 * @param string $argstr
67 * @param WikiRequest $request
68 * @param string $basepage
71 function run($dbi, $argstr, &$request, $basepage)
73 $args = $this->getArgs($argstr, $request);
76 // If the ratings table does not exist, or on dba it will break otherwise.
77 // Check if WikiTheme is_a 'wikilens'
78 if ($info == 'pagename' and is_a($GLOBALS['WikiTheme'], 'wikilens'))
81 $info = explode(',', $info);
85 if (in_array('top3recs', $info)) {
86 require_once 'lib/wikilens/Buddy.php';
87 require_once 'lib/wikilens/PageListColumns.php';
89 $active_user = $request->getUser();
90 $active_userid = $active_user->_userid;
92 // if userids is null or empty, fill it with just the active user
93 if (!isset($userids) || !is_array($userids) || !count($userids)) {
94 // TKL: moved getBuddies call inside if statement because it was
95 // causing the userids[] parameter to be ignored
96 if (is_string($active_userid)
97 and strlen($active_userid)
98 and $active_user->isSignedIn()
100 $userids = getBuddies($active_userid, $dbi);
103 // XXX: this wipes out the category caption...
104 $caption = _("You must be logged in to view ratings.");
108 // find out which users we should show ratings for
109 $allowed_users = array();
110 foreach ($userids as $userid) {
111 $user = new RatingsUser($userid);
112 if ($user->allow_view_ratings($active_user)) {
113 array_push($allowed_users, $user);
115 // PHP's silly references... (the behavior with this line commented
119 $options = array('dimension' => $dimension,
120 'users' => $allowed_users);
121 $args = array_merge($options, $args);
123 if (empty($pages) and $pages != '0')
126 if (in_array('numbacklinks', $info)) {
127 $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true);
129 if (in_array('numpagelinks', $info)) {
130 $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#"));
133 $pagelist = new PageList($info, $exclude, $args);
134 $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
135 $pagelist->addPageList($pages_array);
140 // how many back-/forwardlinks for this page
141 class _PageList_Column_ListPages_count extends _PageList_Column
143 function __construct($field, $display, $backwards = false)
145 $this->_direction = $backwards;
146 parent::__construct($field, $display, 'center');
149 function _getValue($page_handle, $revision_handle)
151 $iter = $page_handle->getLinks($this->_direction);
152 $count = $iter->count();