tiki-listpages.php 20.9 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
changi67's avatar
changi67 committed
10

mose's avatar
mose committed
11
$section = 'wiki page';
12
$section_class = 'tiki_wiki_page manage';	// This will be body class instead of $section
changi67's avatar
changi67 committed
13
require_once ('tiki-setup.php');
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
$auto_query_args = array(
				'initial',
				'maxRecords',
				'sort_mode',
				'find',
				'lang',
				'langOrphan',
				'findfilter_orphan',
				'categId',
				'category',
				'page_orphans',
				'structure_orphans',
				'exact_match',
				'hits_link_to_all_languages',
				'create_new_pages_using_template_name'
);

if ($prefs['gmap_page_list'] == 'y') {
33 34 35 36
	$smarty->assign('gmapbuttons', true);
} else {
	$smarty->assign('gmapbuttons', false);
}
37 38 39 40 41 42 43 44

if (isset($_REQUEST['mapview'])
		&& $_REQUEST['mapview'] == 'y'
		&& !isset($_REQUEST['searchmap'])
		&& !isset($_REQUEST['searchlist'])
		|| isset($_REQUEST['searchmap'])
		&& !isset($_REQUEST['searchlist'])
) {
45 46
	$smarty->assign('mapview', true);
}
47 48 49 50 51 52 53 54

if (isset($_REQUEST['mapview'])
			&& $_REQUEST['mapview'] == 'n'
			&& !isset($_REQUEST['searchmap'])
			&& !isset($_REQUEST['searchlist'])
			|| isset($_REQUEST['searchlist'])
			&& !isset($_REQUEST['searchmap'])
) {
55 56
	$smarty->assign('mapview', false);
}
57 58

if ($prefs['feature_multilingual'] == 'y' && isset($_REQUEST['lang']) && isset($_REQUEST['term_srch'])) {
59
	$multilinguallib = TikiLib::lib('multilingual');
60 61
	if (isset($_REQUEST['term_srch'])) {
		$multilinguallib->storeCurrentTermSearchLanguageInSession($_REQUEST['lang']);
62
	}
63
	$smarty->assign('template_name', $_REQUEST['create_new_pages_using_template_name']);
64
}
alain_desilets's avatar
alain_desilets committed
65

66
if (isset($_REQUEST['hits_link_to_all_languages']) && $_REQUEST['hits_link_to_all_languages'] == 'On') {
67
	$all_langs = 'y';
68
} else {
alain_desilets's avatar
alain_desilets committed
69
	$all_langs = '';
70
}
alain_desilets's avatar
alain_desilets committed
71 72
$smarty->assign('all_langs', $all_langs);

changi67's avatar
changi67 committed
73
$access->check_feature(array('feature_wiki', 'feature_listPages'));
74

changi67's avatar
changi67 committed
75 76 77 78 79 80 81
/* mass-remove:
the checkboxes are sent as the array $_REQUEST["checked[]"], values are the wiki-PageNames,
e.g. $_REQUEST["checked"][3]="HomePage"
$_REQUEST["submit_mult"] holds the value of the "with selected do..."-option list
we look if any page's checkbox is on and if remove_pages is selected.
then we check permission to delete pages.
if so, we call histlib's method remove_all_versions for all the checked pages.
82
*/
83
if (!empty($_REQUEST['submit_mult']) && isset($_REQUEST['checked'])) {
sylvieg's avatar
sylvieg committed
84
	$action = $_REQUEST['submit_mult'];
85
	check_ticket('list-pages');
86
	Perms::bulk(array( 'type' => 'wiki page' ), 'object', $_REQUEST['checked']);
87

changi67's avatar
changi67 committed
88
	switch ($action) {
89 90
		case 'remove_pages':
			// Now check permissions to remove the selected pages
changi67's avatar
changi67 committed
91
			$access->check_permission('tiki_p_remove');
92
			$access->check_authenticity(tr('Are you sure you want to remove the %0 selected pages?', count($_REQUEST['checked'])));
93 94
			foreach ($_REQUEST['checked'] as $check)
				$tikilib->remove_all_versions($check);
95
			break;
96

changi67's avatar
changi67 committed
97 98
		case 'print_pages':
			$access->check_feature('feature_wiki_multiprint');
99
			foreach ($_REQUEST['checked'] as $check) {
100 101
				$access->check_page_exists($check);
				// Now check permissions to access this page
102
				$perms = Perms::get(array( 'type' => 'wiki page', 'object' => $check ));
103
				if (! $perms->view ) {
104
					$access->display_error($check, tra('You do not have permission to view this page.'), '403');
105
				}
106
				$access->check_authenticity(tr('Are you sure you want to print the %0 selected pages?', count($_REQUEST['checked'])));
107 108
				$page_info = $tikilib->get_page_info($check);
				$page_info['parsed'] = $tikilib->parse_data($page_info['data']);
sylvieg's avatar
sylvieg committed
109
				$page_info['h'] = 1;
110
				$multiprint_pages[] = $page_info;
111
			}
112
			break;
113

killianebel's avatar
killianebel committed
114 115
		case 'export_pdf':
			$access->check_feature('feature_wiki_multiprint');
116
			foreach ($_REQUEST['checked'] as $check) {
killianebel's avatar
killianebel committed
117 118
				$access->check_page_exists($check);
				// Now check permissions to access this page
119
				$perms = Perms::get(array( 'type' => 'wiki page', 'object' => $check ));
killianebel's avatar
killianebel committed
120
				if (! $perms->view ) {
121
					$access->display_error($check, tra('You do not have permission to view this page.'), '403');
killianebel's avatar
killianebel committed
122 123 124 125 126
				}

				$multiprint_pages[] = $check;
			}

127
			header('Location: tiki-print_multi_pages.php?display=pdf&printpages=' . urlencode(serialize($multiprint_pages)));
killianebel's avatar
killianebel committed
128 129
			die;

130
		case 'unlock_pages':
changi67's avatar
changi67 committed
131
			$access->check_feature('feature_wiki_usrlock');
132
			$access->check_authenticity(tr('Are you sure you want to unlock the %0 selected pages?', count($_REQUEST['checked'])));
lphuberdeau's avatar
lphuberdeau committed
133
			$wikilib = TikiLib::lib('wiki');
134
			foreach ($_REQUEST['checked'] as $check) {
135
				$info = $tikilib->get_page_info($check);
136 137 138 139 140 141
				if ($info['flag'] == 'L'
						&& (
							$globalperms->admin_wiki == 'y'
							|| ($user && ($user == $info['lockedby']) || (!$info['lockedby'] && $user == $info['user']))
						)
				) {
142
					$wikilib->unlock_page($check);
changi67's avatar
changi67 committed
143
				}
144
			}
145
			break;
changi67's avatar
changi67 committed
146

147
		case 'lock_pages':
changi67's avatar
changi67 committed
148
			$access->check_feature('feature_wiki_usrlock');
149
			$access->check_authenticity(tr('Are you sure you want to lock the %0 selected pages?', count($_REQUEST['checked'])));
lphuberdeau's avatar
lphuberdeau committed
150
			$wikilib = TikiLib::lib('wiki');
151
			foreach ($_REQUEST['checked'] as $check) {
152
				$info = $tikilib->get_page_info($check);
153
				$perms = Perms::get(array( 'type' => 'wiki page', 'object' => $check ));
154
				if ( $info['flag'] != 'L' && ( $globalperms->admin_wiki == 'y' || $perms->lock ) ) {
155
					$wikilib->lock_page($check);
changi67's avatar
changi67 committed
156
				}
157
			}
158
			break;
changi67's avatar
changi67 committed
159 160

		case 'zip':
161
			if ($globalperms->admin == 'y') {
162
				$access->check_authenticity(tr('Are you sure you want to download a zip of the %0 selected pages?', count($_REQUEST['checked'])));
changi67's avatar
changi67 committed
163
				include_once ('lib/wiki/xmllib.php');
164
				$xmllib = new XmlLib;
changi67's avatar
changi67 committed
165 166 167 168 169 170 171 172
				$zipFile = 'dump/xml.zip';
				$config['debug'] = false;
				if ($xmllib->export_pages($_REQUEST['checked'], null, $zipFile, $config)) {
					if (!$config['debug']) {
						header("location: $zipFile");
						die;
					}
				} else {
173
					Feedback::error(['mes' => $xmllib->get_error()]);
174 175
				}
			}
176
			break;
177

178 179 180
		case 'title':
			if ($tiki_p_admin == 'y') {
				$access->check_authenticity(tr('Are you sure you want to modify the %0 pages?', count($_REQUEST['checked'])).' '.tr('No history will be created.'));
181
				foreach ($_REQUEST['checked'] as $check) {
182
					$info = $tikilib->get_page_info($check);
183
					$info['data'] = "!$check\r\n" . $info['data'];
184 185 186 187
					$table = $tikilib->table('tiki_pages');
					$table->update(array('data' => $info['data']), array('page_id' => $info['page_id']));
				}
			}
188
			break;
189
	}
190
}
191

192
//add tablesorter sorting and filtering
193 194
$ts = Table_Check::setVars('listpages', true);
if ($ts['ajax']) {
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	if (!empty($_REQUEST['categPath_ts']) || !empty($_REQUEST['categ_ts'])) {
		if (!empty($_REQUEST['categPath_ts'])) {
			$req = $_REQUEST['categPath_ts'];
		} else {
			$req = $_REQUEST['categ_ts'];
		}
		$pos = strrpos($req, '::');
		if ($pos !== false) {
			$catname = substr($req, $pos + 2);
		} else {
			$catname = $req;
		}
		$categlib = TikiLib::lib('categ');
		$_REQUEST['categId'] = $categlib->get_category_id($catname);
	}
}

changi67's avatar
changi67 committed
212
if (!empty($multiprint_pages)) {
sylvieg's avatar
sylvieg committed
213
	$smarty->assign('print_page', 'y');
214 215 216 217
	$smarty->assign_by_ref('pages', $multiprint_pages);
	// disallow robots to index page:
	$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
	// Display the template
218
	$smarty->display('tiki-print_multi_pages.tpl');
lrargerich's avatar
lrargerich committed
219
} else {
marclaporte's avatar
typo  
marclaporte committed
220
	// This script can receive the threshold
221 222 223
	// for the information as the number of
	// days to get in the log 1,3,4,etc
	// it will default to 1 recovering information for today
sylvieg's avatar
sylvieg committed
224 225
	if (isset($_REQUEST['maxRecords'])) {
		$maxRecords = $_REQUEST['maxRecords'];
226
	} else {
changi67's avatar
changi67 committed
227
		$maxRecords = $maxRecords;
228
	}
229
	if (!isset($_REQUEST['sort_mode'])) {
changi67's avatar
changi67 committed
230
		$sort_mode = $prefs['wiki_list_sortorder'] . '_' . $prefs['wiki_list_sortdirection'];
231
	} else {
232
		$sort_mode = $_REQUEST['sort_mode'];
233 234 235 236 237
	}
	$smarty->assign_by_ref('sort_mode', $sort_mode);
	// If offset is set use it if not then use offset =0
	// use the maxRecords php variable to set the limit
	// if sortMode is not set then use lastModif_desc
238
	if (!isset($_REQUEST['offset'])) {
239 240
		$offset = 0;
	} else {
241
		$offset = $_REQUEST['offset'];
242 243
	}
	$smarty->assign_by_ref('offset', $offset);
244 245
	if (!empty($_REQUEST['find'])) {
		$find = strip_tags($_REQUEST['find']);
246
	} else {
247 248
		if (!empty($_REQUEST['q'])) {
			$find = strip_tags($_REQUEST['q']);
249 250 251
		} else {
			$find = '';
		}
252 253
	}
	$smarty->assign('find', $find);
254
	$filter = '';
255 256 257 258 259 260 261 262 263 264 265

	if ($prefs['feature_multilingual'] == 'y') {
		$smarty->assign('find_lang', '');
		if (((!isset($_REQUEST['lang']) ) || (isset($_REQUEST['lang']) && $_REQUEST['lang'] != ''))) {
			$filter = setLangFilter($filter);
		}
		$smarty->assign('find_langOrphan', '');
		if (!empty($_REQUEST['langOrphan'])) {
			$filter['langOrphan'] = $_REQUEST['langOrphan'];
			$smarty->assign('find_langOrphan', $_REQUEST['langOrphan']);
		}
266
	}
267

268 269 270 271 272 273 274 275
	if ($prefs['feature_categories'] == 'y') {
		if (!empty($_REQUEST['cat_categories'])) {
			$filter['categId'] = $_REQUEST['cat_categories'];
			if (count($_REQUEST['cat_categories']) > 1) {
				unset($_REQUEST['categId']);
			} else {
				$_REQUEST['categId'] = $_REQUEST['cat_categories'][0];
			}
276 277
		} else {
			$_REQUEST['cat_categories'] = array();
278
		}
279 280

		$selectedCategories = $_REQUEST['cat_categories'];
281
		$smarty->assign('findSelectedCategoriesNumber', count($_REQUEST['cat_categories']));
282

283
		if (!empty($_REQUEST['category'])) {
284
			$categlib = TikiLib::lib('categ');
285
			$filter['categId'] = $categlib->get_category_id($_REQUEST['category']);
286
			$smarty->assign('find_categId', $filter['categId']);
287
			$selectedCategories = array((int) $filter['categId']);
288 289 290
		} elseif (!empty($_REQUEST['categId'])) {
			$filter['categId'] = $_REQUEST['categId'];
			$smarty->assign('find_categId', $_REQUEST['categId']);
291
			$selectedCategories = array((int) $filter['categId']);
292 293
		} else {
			$smarty->assign('find_categId', '');
294
		}
295

296
	}
297

298 299 300
	if ((!empty($_REQUEST['page_orphans']) && $_REQUEST['page_orphans'] == 'y')
			|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'page_orphans')
	) {
301 302
		$listpages_orphans = true;
	}
303

304
	if ($prefs['feature_listorphanPages'] == 'y') {
305 306 307
		if ((!empty($_REQUEST['page_orphans']) && $_REQUEST['page_orphans'] == 'y')
				|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'page_orphans')
		) {
308 309 310 311 312
			$filter_values['orphan'] = 'page_orphans';
		}
		$filters['orphan']['page_orphans'] = tra('Orphan pages');
	}
	if ($prefs['feature_wiki_structure'] == 'y') {
313 314 315
		if ((!empty($_REQUEST['structure_orphans']) && $_REQUEST['structure_orphans'] == 'y')
				|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'structure_orphans')
		) {
316 317
			$filter['structure_orphans'] = true;
		}
318

319
		if ($prefs['feature_listorphanStructure'] == 'y') {
320 321 322
			if ((!empty($_REQUEST['structure_orphans']) && $_REQUEST['structure_orphans'] == 'y')
					|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'structure_orphans')
			) {
323 324
				$filter_values['orphan'] = 'structure_orphans';
			}
325
			$filters['orphan']['structure_orphans'] = tra('Pages not in a structure');
326 327
		}
	}
328

329 330 331 332 333 334
	if (!empty($filters)) {
		$filter_names['orphan'] = tra('Type');
		$smarty->assign_by_ref('filters', $filters);
		$smarty->assign_by_ref('filter_names', $filter_names);
		$smarty->assign_by_ref('filter_values', $filter_values);
	}
335 336 337

	if (isset($_REQUEST['initial'])) {
		$initial = $_REQUEST['initial'];
338 339 340
	} else {
		$initial = '';
	}
341

342
	$smarty->assign('initial', $initial);
343 344
	// What a checked checkbox returns is browser dependant. Don't test on the value, just presence
	if (isset($_REQUEST['exact_match']) ) {
345 346 347 348 349
		$exact_match = true;
		$smarty->assign('exact_match', 'y');
	} else {
		$exact_match = false;
		$smarty->assign('exact_match', 'n');
changi67's avatar
changi67 committed
350
	}
351
	// Get a list of last changes to the Wiki database
352
	//  $listpages_orphans must not be initialized here because it can already have received a value from another script
sylvieg's avatar
sylvieg committed
353 354 355
	if (!isset($listpages_orphans)) {
		$listpages_orphans = false;
	}
356 357 358 359 360 361 362 363 364 365 366 367
	$listpages = $tikilib->list_pages(
		$offset,
		$maxRecords,
		$sort_mode,
		$find,
		$initial,
		$exact_match,
		false,
		true,
		$listpages_orphans,
		$filter
	);
368

369
	possibly_look_for_page_aliases($find);
370 371 372
	// Only show the 'Actions' column if the user can do at least one action on one of the listed pages
	$show_actions = 'n';
	$actions_perms = array('tiki_p_edit', 'tiki_p_wiki_view_history', 'tiki_p_assign_perm_wiki_page', 'tiki_p_remove');
373 374
	foreach ($actions_perms as $p) {
		foreach ($listpages['data'] as $i) {
changi67's avatar
changi67 committed
375
			if ($i['perms'][$p] == 'y') {
376 377 378 379 380
				$show_actions = 'y';
				break 2;
			}
		}
	}
381

382
	$smarty->assign('show_actions', $show_actions);
383
	// If there're more records then assign next_offset
384
	$cant_pages = ceil($listpages['cant'] / $maxRecords);
385 386
	$smarty->assign_by_ref('cant_pages', $cant_pages);
	$smarty->assign('actual_page', 1 + ($offset / $maxRecords));
387 388 389 390 391
	if ($listpages['cant'] > ($offset + $maxRecords))
		$smarty->assign('next_offset', $offset + $maxRecords);
	else
		$smarty->assign('next_offset', -1);

392
	// If offset is > 0 then prev_offset
393 394 395 396 397
	if ($offset > 0)
		$smarty->assign('prev_offset', $offset - $maxRecords);
	else
		$smarty->assign('prev_offset', -1);

398
	if ($prefs['feature_categories'] == 'y') {
399
		$categlib = TikiLib::lib('categ');
400
		$categories = $categlib->getCategories();
401
		$smarty->assign('notable', 'y');
402
		$smarty->assign('cat_tree', $categlib->generate_cat_tree($categories, true, $selectedCategories));
403 404
		$smarty->assign_by_ref('categories', $categories);
	}
405

406
	if ($prefs['feature_multilingual'] == 'y') {
changi67's avatar
changi67 committed
407
		$languages = array();
408 409
		$langLib = TikiLib::lib('language');
		$languages = $langLib->list_languages(false, 'y');
changi67's avatar
changi67 committed
410
		$smarty->assign_by_ref('languages', $languages);
411
	}
412

413
	if ($prefs['gmap_page_list'] == 'y') {
414 415 416
		// Generate Google map plugin data
		global $gmapobjectarray;
		$gmapobjectarray = array();
417
		foreach ($listpages['data'] as $p) {
418
			$gmapobjectarray[] = array('type' => 'wiki page',
419 420 421
				'id' => $p['pageName'],
				'title' => $p['pageName'],
				'href' => 'tiki-index.php?page=' . urlencode($p['pageName']),
422 423 424
			);
		}
	}
425

426 427 428 429 430 431 432 433
	foreach ($listpages['data'] as & $p) {
		if ($userlib->object_has_one_permission($p['pageName'], 'wiki page')) {
			$p['perms_active'] = 'y';
		} else {
			$p['perms_active'] = 'n';
		}
	}

434
	$smarty->assign_by_ref('listpages', $listpages['data']);
435
	$smarty->assign_by_ref('cant', $listpages['cant']);
436
	ask_ticket('list-pages');
437 438 439
	include_once ('tiki-section_options.php');
	// disallow robots to index page:
	$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
440 441

	// Exact match and single result, go to page directly
442
	if ( count($listpages['data']) == 1 && !$ts['ajax']) {
443 444
		$result = reset($listpages['data']);
		if ( TikiLib::strtolower($find) == TikiLib::strtolower($result['pageName']) ) {
lphuberdeau's avatar
lphuberdeau committed
445
			$wikilib = TikiLib::lib('wiki');
446
			header('Location: ' . $wikilib->sefurl($result['pageName'], '', $all_langs));
447 448 449 450
			exit;
		}
	}

451
	if ($ts['enabled'] && !$ts['ajax']) {
452 453 454 455 456 457 458 459 460 461 462 463 464
		//create dropdown lists for category name and path filters
		$cnames = array();
		$cpaths = array();
		if (isset($categories) && count($categories) > 0) {
			foreach($categories as $c) {
				$cnames[] = $c['name'];
				$cpaths[] = $c['categpath'];
			}
		}
		//set language dropdown showing only languages that pages are actually in
		if (isset($languages) && count($languages) > 0) {
			$pagelangs = array_unique($tikilib->table('tiki_pages')->fetchColumn('lang', array()));
			$pagelangs = array_flip($pagelangs);
465 466 467
			$langLib = TikiLib::lib('language');
			$langLib->getLanguages();
			$temp_langs = array_intersect_key($langmapping, $pagelangs);
468 469
			if (count($temp_langs) > 0) {
				foreach ($temp_langs as $short => $long) {
470
					$ts_langs[$short . '|' . $long[0]] = $long[0];
471 472 473 474
				}
			} else {
				$ts_langs = array();
			}
475 476 477
		} else {
			$ts_langs = array();
		}
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
		//workaround to set initial sort order until this can be done in tablesorter using sortList with selectors
		$cols = [
			//pref => sort_mode
			'id' => 'page_id',
			'name' => 'pageName',
			'hits' => 'hits',
			'lastmodif' => 'lastModif',
			'comment' => 'comment',
			'creator' => 'creator',
			'user' => 'user',
			'lastver' => 'version',
			'status' => 'flag',
			'versions' => 'version',
			'links' => 'links',
			'backlinks' => 'backlinks',
			'size' => 'page_size',
		];
		///replicate column filtering from tiki-listpages_content.tpl for the relevant columns
		foreach($cols as $pref => $fieldname) {
			$prefstr = 'wiki_list_' . $pref;
			if ($prefs[$prefstr] !== 'y') {
				unset($cols[$pref]);
			}
		}
		$cols = array_values($cols);
		///add checkbox column
		$remperm = Perms::get()->remove;
		if ($remperm || $prefs['feature_wiki_multiprint'] === 'y') {
			array_unshift($cols, 'checkbox');
		}
		if (strpos($sort_mode, '_desc') !== false) {
			$pos = strlen($sort_mode) - 5;
			$sortdir = 1;
		} elseif(strpos($sort_mode, '_asc') !== false) {
			$pos = strlen($sort_mode) - 4;
			$sortdir = 0;
		}
		///set sort column
		$sort = substr($sort_mode, 0, $pos);
		$sortcol = array_search($sort, $cols);

519
		$settings = array(
520
			'id' => $ts['tableid'],
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
			'total' 	=> $listpages['cant'],
			'vars'	=> array(
				'show_actions' => $show_actions,
			),
			'columns'	=> array(
				'#language'	=> array(
					'filter' => array(
						'options' => $ts_langs,
					),
				),
				'#categories'	=> array(
					'filter' => array(
						'options' => $cnames,
					),
				),
				'#catpaths'	=> array(
					'filter' => array(
						'options' => $cpaths,
					),
				),
			),
		);
543 544 545 546 547

		if ($sortcol !== false) {
			$settings['sorts']['sortlist']['col'] = $sortcol;
			$settings['sorts']['sortlist']['dir'] = $sortdir;
		}
548 549 550
		Table_Factory::build('TikiListpages', $settings);
	}

changi67's avatar
changi67 committed
551
	if ($access->is_serializable_request()) {
552
		if (isset($_REQUEST['listonly']) && ($prefs['feature_jquery'] == 'y' && $prefs['feature_jquery_autocomplete'] == 'y')) {
553
			$pages = array();
554 555 556 557 558 559 560
			foreach ($listpages['data'] as $page) {
				if (isset($_REQUEST['nonamespace'])) {
					$pages[] = TikiLib::lib('wiki')->get_without_namespace($page['pageName']);
				} else {
					$pages[] = $page['pageName'];
				}
			}	
changi67's avatar
changi67 committed
561
			$access->output_serialized($pages);
562 563
		} else {
			$pages = array();
lphuberdeau's avatar
lphuberdeau committed
564
			$wikilib = TikiLib::lib('wiki');
565
			foreach ($listpages['data'] as $page) {
566 567 568 569 570 571 572 573 574 575 576
				$pages[] = array(
						'page_id' => $page['page_id'],
						'page_name' => $page['pageName'],
						'url' => $wikilib->sefurl($page['pageName']), 'version' => $page['version'],
						'description' => $page['description'],
						'last_modif' => date('Y-m-d H:i:s', $page['lastModif']),
						'last_author' => $page['user'],
						'creator' => $page['creator'],
						'creation_date' => date('Y-m-d H:i:s', $page['created']),
						'lang' => $page['lang'],
				);
577 578
			}
			require_once 'lib/ointegratelib.php';
changi67's avatar
changi67 committed
579 580
			$response = OIntegrate_Response::create(array('list' => $pages), '1.0');
			$response->addTemplate('smarty', 'tikiwiki', 'files/templates/listpages/smarty-tikiwiki-1.0-shortlist.txt');
581
			$response->schemaDocumentation = 'http://dev.tiki.org/WebserviceListpages';
582 583
			$response->send();
		}
584 585
	} else {
		// Display the template
586
		if ($ts['ajax']) {
587 588 589 590 591
			$smarty->display($listpages_orphans ? 'tiki-orphan_pages.tpl' : 'tiki-listpages.tpl');
		} else {
			$smarty->assign('mid', ($listpages_orphans ? 'tiki-orphan_pages.tpl' : 'tiki-listpages.tpl'));
			$smarty->display('tiki.tpl');
		}
592
	}
593
}
594

595 596 597 598
/**
 * @param $filter
 * @return mixed
 */
599 600
function setLangFilter($filter)
{
601 602 603 604
	global $prefs;
	$multilinguallib = TikiLib::lib('multilingual');
	$smarty = TikiLib::lib('smarty');

605
	$lang = $multilinguallib->currentPageSearchLanguage();
606 607 608
	if (isset($_REQUEST['listonly']) && $prefs['feature_jquery_autocomplete'] == 'y' && strlen($lang) > 2) {
		$lang = substr($lang, 0, 2);		// for autocomplete - use only language filter, not culture as well
	}
609 610 611 612
	// Without this condition, default listing is empty and language filter shows any language
	if ($lang == 'en-us') {
		$lang = 'en';
	}
changi67's avatar
changi67 committed
613
	$filter['lang'] = $lang;
614
	$smarty->assign('find_lang', $lang);
changi67's avatar
changi67 committed
615
	return $filter;
616
}
617

618 619 620
/**
 * @param $query
 */
621 622
function possibly_look_for_page_aliases($query)
{
623 624
	global $prefs;
	$smarty = TikiLib::lib('smarty');
625

626 627 628 629
	$lang = NULL;
	if (isset($_REQUEST['lang'])) {
		$lang = $_REQUEST['lang'];
	}
630

changi67's avatar
changi67 committed
631
	if ($prefs['feature_wiki_pagealias'] == 'y' && $query) {
632
		$semanticlib = TikiLib::lib('semantic');
633
		$aliases = $semanticlib->getAliasContaining($query, false, $lang);
changi67's avatar
changi67 committed
634
		$smarty->assign('aliases', $aliases);
635
	} else {
changi67's avatar
changi67 committed
636
		$smarty->assign('aliases', null);
637
	}
638

sylvieg's avatar
sylvieg committed
639
	if (!empty($aliases) > 0) {
640 641 642 643
		$smarty->assign('aliases_were_found', 'y');
	} else {
		$smarty->assign('aliases_were_found', 'n');
	}
644

645
	$alias_found = 'n';
sylvieg's avatar
sylvieg committed
646
	if (!empty($aliases)) {
647
		foreach ($aliases as $an_alias_info) {
sylvieg's avatar
sylvieg committed
648 649 650
			if ($an_alias_info['toPage'] == $query) {
				$alias_found = 'y';
			}
651 652 653
		}
	}
	$smarty->assign('alias_found', $alias_found);
654 655 656 657

	set_category_for_new_page_creation();
}

658 659
function set_category_for_new_page_creation()
{
660 661
	global $prefs;
	$smarty = TikiLib::lib('smarty');
662 663

	$create_page_with_categId = '';
664
	if (isset($_REQUEST['create_page_with_search_category'])) {
665 666 667 668 669
		if ($prefs['feature_categories'] == 'y' && !empty($_REQUEST['categId'])) {
			$create_page_with_categId = $_REQUEST['categId'];
		}
	}
	$smarty->assign('create_page_with_categId', $create_page_with_categId);
670
}