Merge lp:~yoboy-leguesh/ubuntu-fr-doc/mediaplus into lp:ubuntu-fr-doc

Proposed by YoBoY
Status: Merged
Merged at revision: 112
Proposed branch: lp:~yoboy-leguesh/ubuntu-fr-doc/mediaplus
Merge into: lp:ubuntu-fr-doc
Diff against target: 276 lines (+242/-0)
6 files modified
lib/plugins/mediaplus/action.php (+196/-0)
lib/plugins/mediaplus/conf/default.php (+7/-0)
lib/plugins/mediaplus/conf/metadata.php (+10/-0)
lib/plugins/mediaplus/lang/en/lang.php (+11/-0)
lib/plugins/mediaplus/lang/fr/lang.php (+11/-0)
lib/plugins/mediaplus/plugin.info.txt (+7/-0)
To merge this branch: bzr merge lp:~yoboy-leguesh/ubuntu-fr-doc/mediaplus
Reviewer Review Type Date Requested Status
Ubuntu-fr-webteam Pending
Review via email: mp+98978@code.launchpad.net

Description of the change

Ajout d'un mécanisme de pagination dans le média manager

Le mediamanager affiche par defaut toutes les images d'un dossier ce qui fait énormément d'images dans certains dossier et le rend inexploitable. L'ajout d'un système de pagination permet de n'afficher que 25 images à la fois (configurable).

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'lib/plugins/mediaplus'
2=== added file 'lib/plugins/mediaplus/action.php'
3--- lib/plugins/mediaplus/action.php 1970-01-01 00:00:00 +0000
4+++ lib/plugins/mediaplus/action.php 2012-03-23 07:23:19 +0000
5@@ -0,0 +1,196 @@
6+<?php
7+/**
8+ * Action Plugin Prototype
9+ *
10+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
11+ * @author Philippe Cortez <dokuwiki@yoboy.fr>
12+ */
13+// must be run within Dokuwiki
14+if(!defined('DOKU_INC')) die();
15+if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
16+require_once(DOKU_PLUGIN.'action.php');
17+
18+/**
19+ * All DokuWiki plugins to interfere with the event system
20+ * need to inherit from this class
21+ */
22+class action_plugin_mediaplus extends Dokuwiki_Action_Plugin {
23+
24+ /**
25+ * Registers a callback function for a given event
26+ */
27+ function register(&$controller) {
28+ $controller->register_hook('MEDIAMANAGER_CONTENT_OUTPUT', 'BEFORE', $this, handle_mediaplus, array());
29+ }
30+
31+ function handle_mediaplus(&$event, $param) {
32+ global $IMG;
33+ global $AUTH;
34+ global $INUSE;
35+ global $NS;
36+ global $JUMPTO;
37+
38+ $data = $event->data;
39+ $do = $data['do'];
40+ if($do == 'filesinuse'){
41+ media_filesinuse($INUSE,$IMG);
42+ }elseif($do == 'filelist'){
43+ $this->_mediaplus_filelist($NS,$AUTH,$JUMPTO);
44+ }elseif($do == 'searchlist'){
45+ media_searchlist($_REQUEST['q'],$NS,$AUTH);
46+ }else{
47+ msg('Unknown action '.hsc($do),-1);
48+ }
49+ $event->preventDefault();
50+ }
51+
52+ /**
53+ * List all files in a given Media namespace
54+ */
55+ function _mediaplus_filelist($ns,$auth=null,$jump='', $sort=false){
56+ global $conf;
57+ global $lang;
58+ $ns = cleanID($ns);
59+ $bypages = $this->getConf('bypages');
60+
61+ if($_REQUEST['page']) $page = $_REQUEST['page'];
62+ else $page = 1;
63+
64+ // check auth our self if not given (needed for ajax calls)
65+ if(is_null($auth)) $auth = auth_quickaclcheck("$ns:*");
66+
67+ echo '<h1 id="media__ns">:'.hsc($ns).'</h1>'.NL;
68+
69+ if($auth < AUTH_READ){
70+ // FIXME: print permission warning here instead?
71+ echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
72+ }else{
73+ media_uploadform($ns, $auth);
74+
75+ $dir = utf8_encodeFN(str_replace(':','/',$ns));
76+ $data = array();
77+ search($data,$conf['mediadir'],'search_media',
78+ array('showmsg'=>true,'depth'=>1),$dir,1,$sort);
79+
80+ if(!count($data)){
81+ echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
82+ }else {
83+ if ($jump != '') {
84+ // go to the page where the item is
85+ $idkey = array_search($jump, $data);
86+ $page = (int)($idkey/$bypages +1);
87+ $jump = (int)($idkey%$bypages);
88+ }
89+ $pagemax = (int)(count($data)/$bypages +1);
90+ $link = DOKU_BASE.'lib/exe/mediamanager.php?ns='.$ns.'&page=';
91+ if ($page > $pagemax) $page = $pagemax;
92+ $data = array_slice($data, ($page-1)*$bypages, $bypages);
93+
94+ if ($pagemax > 1) echo $this->_mediaplus_pagination($page, $pagemax, $link);
95+ foreach($data as $item){
96+ $this->_mediaplus_printfile($item,$auth,$jump);
97+ }
98+ if ($pagemax > 1) echo $this->_mediaplus_pagination($page, $pagemax, $link);
99+ }
100+ }
101+ media_searchform($ns);
102+ }
103+
104+
105+ function _mediaplus_pagination($page, $pagemax, $link) {
106+ $paginate = '<div class="pagination">'.NL;
107+ if ($page > 1) $paginate .= '<a href="'.$link.($page-1).'" class="pagination">< '.$this->getLang('previous').'</a> '.NL;
108+ if ($page == 1 ) $paginate .= '<b>1</b> '.NL;
109+ else $paginate .= '<a href="'.$link.'1" class="pagination">1</a> '.NL;
110+ $min = ($page-4 > 1 ? $page -4 : 2);
111+ $max = ($page + 4 < $pagemax ? $page +4 : $pagemax-1);
112+ if($min > 2) $paginate .= "… ";
113+ for($i=$min; $i<=$max; $i++) {
114+ if($i == $page) $paginate .= '<b>'.$i.'</b> '.NL;
115+ else $paginate .= '<a href="'.$link.$i.'" class="pagination">'.$i.'</a> '.NL;
116+ }
117+ if ($max < $pagemax-1) $paginate .= '… '.NL;
118+ if ($page == $pagemax) $paginate .= '<b>'.$pagemax.'</b> '.NL;
119+ else $paginate .= '<a href="'.$link.$pagemax.'">'.$pagemax.'</a> '.NL;
120+ if ($page < $pagemax) $paginate .= '<a href="'.$link.($page+1).'">'.$this->getLang('next').' ></a>'.NL;
121+ $paginate .= ' <span class="itemsinfo">('.$this->getConf('bypages').' '.$this->getLang('items per pages').')</span>'.NL.'</div>'.NL;
122+ return $paginate;
123+ }
124+
125+ /**
126+ * Formats and prints one file in the list
127+ */
128+ function _mediaplus_printfile($item,$auth,$jump,$display_namespace=false){
129+ global $lang;
130+ global $conf;
131+
132+ // Prepare zebra coloring
133+ // I always wanted to use this variable name :-D
134+ static $twibble = 1;
135+ $twibble *= -1;
136+ $zebra = ($twibble == -1) ? 'odd' : 'even';
137+
138+ // Automatically jump to recent action
139+ if($jump == $item['id']) {
140+ $jump = ' id="scroll__here" ';
141+ }else{
142+ $jump = '';
143+ }
144+
145+ // Prepare fileicons
146+ list($ext,$mime,$dl) = mimetype($item['file'],false);
147+ $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
148+ $class = 'select mediafile mf_'.$class;
149+
150+ // Prepare filename
151+ $file = utf8_decodeFN($item['file']);
152+
153+ // Prepare info
154+ $info = '';
155+ if($item['isimg']){
156+ $info .= (int) $item['meta']->getField('File.Width');
157+ $info .= '&#215;';
158+ $info .= (int) $item['meta']->getField('File.Height');
159+ $info .= ' ';
160+ }
161+ $info .= '<i>'.dformat($item['mtime']).'</i>';
162+ $info .= ' ';
163+ $info .= filesize_h($item['size']);
164+
165+ // output
166+ echo '<div class="'.$zebra.'"'.$jump.' title="'.hsc($item['id']).'">'.NL;
167+ if (!$display_namespace) {
168+ echo '<a name="h_:'.$item['id'].'" class="'.$class.'">'.hsc($file).'</a> ';
169+ } else {
170+ echo '<a name="h_:'.$item['id'].'" class="'.$class.'">'.hsc($item['id']).'</a><br/>';
171+ }
172+ echo '<span class="info">('.$info.')</span>'.NL;
173+
174+ // view button
175+ $link = ml($item['id'],'',true);
176+ echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/magnifier.png" '.
177+ 'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
178+
179+ // mediamanager button
180+ /* $link = wl('',array('do'=>'media','image'=>$item['id'],'ns'=>getNS($item['id'])));
181+ echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/mediamanager.png" '.
182+ 'alt="'.$lang['btn_media'].'" title="'.$lang['btn_media'].'" class="btn" /></a>';*/
183+
184+ // delete button
185+ if($item['writable'] && $auth >= AUTH_DELETE){
186+ $link = DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']).
187+ '&amp;sectok='.getSecurityToken();
188+ echo ' <a href="'.$link.'" class="btn_media_delete" title="'.$item['id'].'">'.
189+ '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
190+ 'title="'.$lang['btn_delete'].'" class="btn" /></a>';
191+ }
192+
193+ echo '<div class="example" id="ex_'.str_replace(':','_',$item['id']).'">';
194+ echo $lang['mediausage'].' <code>{{:'.$item['id'].'}}</code>';
195+ echo '</div>';
196+ if($item['isimg']) media_printimgdetail($item);
197+ echo '<div class="clearer"></div>'.NL;
198+ echo '</div>'.NL;
199+ }
200+
201+}
202
203=== added directory 'lib/plugins/mediaplus/conf'
204=== added file 'lib/plugins/mediaplus/conf/default.php'
205--- lib/plugins/mediaplus/conf/default.php 1970-01-01 00:00:00 +0000
206+++ lib/plugins/mediaplus/conf/default.php 2012-03-23 07:23:19 +0000
207@@ -0,0 +1,7 @@
208+<?php
209+/**
210+ * Options for the Mediaplus Plugin
211+ */
212+$conf['bypages'] = 25; // Number of files displayed by pages
213+
214+//Setup VIM: ex: et ts=2 :
215
216=== added file 'lib/plugins/mediaplus/conf/metadata.php'
217--- lib/plugins/mediaplus/conf/metadata.php 1970-01-01 00:00:00 +0000
218+++ lib/plugins/mediaplus/conf/metadata.php 2012-03-23 07:23:19 +0000
219@@ -0,0 +1,10 @@
220+<?php
221+/**
222+ * Metadata for configuration manager plugin
223+ * Additions for the mediaplus plugin
224+ *
225+ */
226+
227+$meta['bypages'] = array('numeric');
228+
229+//Setup VIM: ex: et ts=2 :
230
231=== added directory 'lib/plugins/mediaplus/lang'
232=== added directory 'lib/plugins/mediaplus/lang/en'
233=== added file 'lib/plugins/mediaplus/lang/en/lang.php'
234--- lib/plugins/mediaplus/lang/en/lang.php 1970-01-01 00:00:00 +0000
235+++ lib/plugins/mediaplus/lang/en/lang.php 2012-03-23 07:23:19 +0000
236@@ -0,0 +1,11 @@
237+<?php
238+/**
239+ * English language file
240+ *
241+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
242+ */
243+
244+// custom language strings for the plugin
245+$lang['previous'] = 'Previous';
246+$lang['next'] = 'Next';
247+$lang['items per pages'] = 'items per pages';
248
249=== added directory 'lib/plugins/mediaplus/lang/fr'
250=== added file 'lib/plugins/mediaplus/lang/fr/lang.php'
251--- lib/plugins/mediaplus/lang/fr/lang.php 1970-01-01 00:00:00 +0000
252+++ lib/plugins/mediaplus/lang/fr/lang.php 2012-03-23 07:23:19 +0000
253@@ -0,0 +1,11 @@
254+<?php
255+/**
256+ * French language file
257+ *
258+ * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
259+ */
260+
261+// custom language strings for the plugin
262+$lang['previous'] = 'Précédent';
263+$lang['next'] = 'Suivant';
264+$lang['items per pages'] = 'éléments par pages';
265
266=== added file 'lib/plugins/mediaplus/plugin.info.txt'
267--- lib/plugins/mediaplus/plugin.info.txt 1970-01-01 00:00:00 +0000
268+++ lib/plugins/mediaplus/plugin.info.txt 2012-03-23 07:23:19 +0000
269@@ -0,0 +1,7 @@
270+base mediaplus
271+author me
272+email dokuwiki@chimeric.de
273+date 2011-03-20
274+name mediaplus plugin
275+desc replace media manager
276+url http://dokuwiki.org/plugin:tag

Subscribers

People subscribed via source and target branches

to all changes: