]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/ListPages.php
function run: @return mixed
[SourceForge/phpwiki.git] / lib / plugin / ListPages.php
1 <?php
2
3 /*
4  * Copyright 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 require_once 'lib/PageList.php';
24
25 /**
26  * ListPages - List pages that are explicitly given as the pages argument.
27  *
28  * Mainly used to see some ratings and recommendations.
29  * But also possible to list some Categories or Users, or as generic
30  * frontend for plugin-list page lists.
31  *
32  * @author: Dan Frankowski
33  */
34 class WikiPlugin_ListPages
35     extends WikiPlugin
36 {
37     function getDescription()
38     {
39         return _("List pages that are explicitly given as the pages argument.");
40     }
41
42     function getDefaultArguments()
43     {
44         return array_merge
45         (
46             PageList::supportedArgs(),
47             array('pages' => false,
48                 //'exclude'  => false,
49                 'info' => 'pagename',
50                 'dimension' => 0,
51             ));
52     }
53
54     // info arg allows multiple columns
55     // info=mtime,hits,summary,version,author,locked,minor
56     // additional info args:
57     //   top3recs      : recommendations
58     //   numbacklinks  : number of backlinks (links to the given page)
59     //   numpagelinks  : number of forward links (links at the given page)
60
61     /**
62      * @param WikiDB $dbi
63      * @param string $argstr
64      * @param WikiRequest $request
65      * @param string $basepage
66      * @return mixed
67      */
68     function run($dbi, $argstr, &$request, $basepage)
69     {
70         $args = $this->getArgs($argstr, $request);
71
72         extract($args);
73         // If the ratings table does not exist, or on dba it will break otherwise.
74         // Check if WikiTheme isa 'wikilens'
75         if ($info == 'pagename' and isa($GLOBALS['WikiTheme'], 'wikilens'))
76             $info .= ",top3recs";
77         if ($info)
78             $info = explode(',', $info);
79         else
80             $info = array();
81
82         if (in_array('top3recs', $info)) {
83             require_once 'lib/wikilens/Buddy.php';
84             require_once 'lib/wikilens/PageListColumns.php';
85
86             $active_user = $request->getUser();
87             $active_userid = $active_user->_userid;
88
89             // if userids is null or empty, fill it with just the active user
90             if (!isset($userids) || !is_array($userids) || !count($userids)) {
91                 // TKL: moved getBuddies call inside if statement because it was
92                 // causing the userids[] parameter to be ignored
93                 if (is_string($active_userid)
94                     and strlen($active_userid)
95                         and $active_user->isSignedIn()
96                 ) {
97                     $userids = getBuddies($active_userid, $dbi);
98                 } else {
99                     $userids = array();
100                     // XXX: this wipes out the category caption...
101                     $caption = _("You must be logged in to view ratings.");
102                 }
103             }
104
105             // find out which users we should show ratings for
106             $allowed_users = array();
107             foreach ($userids as $userid) {
108                 $user = new RatingsUser($userid);
109                 if ($user->allow_view_ratings($active_user)) {
110                     array_push($allowed_users, $user);
111                 }
112                 // PHP's silly references... (the behavior with this line commented
113                 // out is... odd)
114                 unset($user);
115             }
116             $options = array('dimension' => $dimension,
117                 'users' => $allowed_users);
118             $args = array_merge($options, $args);
119         }
120         if (empty($pages) and $pages != '0')
121             return '';
122
123         if (in_array('numbacklinks', $info)) {
124             $args['types']['numbacklinks'] = new _PageList_Column_ListPages_count('numbacklinks', _("#"), true);
125         }
126         if (in_array('numpagelinks', $info)) {
127             $args['types']['numpagelinks'] = new _PageList_Column_ListPages_count('numpagelinks', _("#"));
128         }
129
130         $pagelist = new PageList($info, $exclude, $args);
131         $pages_array = is_string($pages) ? explodePageList($pages) : (is_array($pages) ? $pages : array());
132         $pagelist->addPageList($pages_array);
133         return $pagelist;
134     }
135 }
136
137 // how many back-/forwardlinks for this page
138 class _PageList_Column_ListPages_count extends _PageList_Column
139 {
140     function _PageList_Column_ListPages_count($field, $display, $backwards = false)
141     {
142         $this->_direction = $backwards;
143         return $this->_PageList_Column($field, $display, 'center');
144     }
145
146     function _getValue($page, &$revision_handle)
147     {
148         $iter = $page->getLinks($this->_direction);
149         $count = $iter->count();
150         return $count;
151     }
152 }
153
154 // Local Variables:
155 // mode: php
156 // tab-width: 8
157 // c-basic-offset: 4
158 // c-hanging-comment-ender-p: nil
159 // indent-tabs-mode: nil
160 // End: