tiki-listpages.php 16.3 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

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

rjsmelo's avatar
rjsmelo committed
15
$auto_query_args = [
16 17 18 19 20 21 22 23 24 25 26 27 28 29
				'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'
rjsmelo's avatar
rjsmelo committed
30
];
31 32

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

if (isset($_REQUEST['mapview'])
		&& $_REQUEST['mapview'] == 'y'
rjsmelo's avatar
rjsmelo committed
40 41
		&& ! isset($_REQUEST['searchmap'])
		&& ! isset($_REQUEST['searchlist'])
42
		|| isset($_REQUEST['searchmap'])
rjsmelo's avatar
rjsmelo committed
43
		&& ! isset($_REQUEST['searchlist'])
44
) {
45 46
	$smarty->assign('mapview', true);
}
47 48 49

if (isset($_REQUEST['mapview'])
			&& $_REQUEST['mapview'] == 'n'
rjsmelo's avatar
rjsmelo committed
50 51
			&& ! isset($_REQUEST['searchmap'])
			&& ! isset($_REQUEST['searchlist'])
52
			|| isset($_REQUEST['searchlist'])
rjsmelo's avatar
rjsmelo committed
53
			&& ! isset($_REQUEST['searchmap'])
54
) {
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);

rjsmelo's avatar
rjsmelo committed
73
$access->check_feature(['feature_wiki', 'feature_listPages']);
74

75
//add tablesorter sorting and filtering
76 77
$ts = Table_Check::setVars('listpages', true);
if ($ts['ajax']) {
rjsmelo's avatar
rjsmelo committed
78 79
	if (! empty($_REQUEST['categPath_ts']) || ! empty($_REQUEST['categ_ts'])) {
		if (! empty($_REQUEST['categPath_ts'])) {
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
			$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);
	}
}

rjsmelo's avatar
rjsmelo committed
95
if (! empty($multiprint_pages)) {
sylvieg's avatar
sylvieg committed
96
	$smarty->assign('print_page', 'y');
97 98 99 100
	$smarty->assign_by_ref('pages', $multiprint_pages);
	// disallow robots to index page:
	$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
	// Display the template
101
	$smarty->display('tiki-print_multi_pages.tpl');
lrargerich's avatar
lrargerich committed
102
} else {
marclaporte's avatar
marclaporte committed
103
	// This script can receive the threshold
104 105 106
	// 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
107 108
	if (isset($_REQUEST['maxRecords'])) {
		$maxRecords = $_REQUEST['maxRecords'];
109
	} else {
changi67's avatar
changi67 committed
110
		$maxRecords = $maxRecords;
111
	}
rjsmelo's avatar
rjsmelo committed
112
	if (! isset($_REQUEST['sort_mode'])) {
changi67's avatar
changi67 committed
113
		$sort_mode = $prefs['wiki_list_sortorder'] . '_' . $prefs['wiki_list_sortdirection'];
114
	} else {
115
		$sort_mode = $_REQUEST['sort_mode'];
116 117 118 119 120
	}
	$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
rjsmelo's avatar
rjsmelo committed
121
	if (! isset($_REQUEST['offset'])) {
122 123
		$offset = 0;
	} else {
124
		$offset = $_REQUEST['offset'];
125 126
	}
	$smarty->assign_by_ref('offset', $offset);
rjsmelo's avatar
rjsmelo committed
127
	if (! empty($_REQUEST['find'])) {
128
		$find = strip_tags($_REQUEST['find']);
129
	} else {
rjsmelo's avatar
rjsmelo committed
130
		if (! empty($_REQUEST['q'])) {
131
			$find = strip_tags($_REQUEST['q']);
132 133 134
		} else {
			$find = '';
		}
135 136
	}
	$smarty->assign('find', $find);
137
	$filter = '';
138 139 140

	if ($prefs['feature_multilingual'] == 'y') {
		$smarty->assign('find_lang', '');
rjsmelo's avatar
rjsmelo committed
141
		if (((! isset($_REQUEST['lang']) ) || (isset($_REQUEST['lang']) && $_REQUEST['lang'] != ''))) {
142 143 144
			$filter = setLangFilter($filter);
		}
		$smarty->assign('find_langOrphan', '');
rjsmelo's avatar
rjsmelo committed
145
		if (! empty($_REQUEST['langOrphan'])) {
146 147 148
			$filter['langOrphan'] = $_REQUEST['langOrphan'];
			$smarty->assign('find_langOrphan', $_REQUEST['langOrphan']);
		}
149
	}
150

151
	if ($prefs['feature_categories'] == 'y') {
rjsmelo's avatar
rjsmelo committed
152
		if (! empty($_REQUEST['cat_categories'])) {
153 154 155 156 157 158
			$filter['categId'] = $_REQUEST['cat_categories'];
			if (count($_REQUEST['cat_categories']) > 1) {
				unset($_REQUEST['categId']);
			} else {
				$_REQUEST['categId'] = $_REQUEST['cat_categories'][0];
			}
159
		} else {
rjsmelo's avatar
rjsmelo committed
160
			$_REQUEST['cat_categories'] = [];
161
		}
162 163

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

rjsmelo's avatar
rjsmelo committed
166
		if (! empty($_REQUEST['category'])) {
167
			$categlib = TikiLib::lib('categ');
168
			$filter['categId'] = $categlib->get_category_id($_REQUEST['category']);
169
			$smarty->assign('find_categId', $filter['categId']);
rjsmelo's avatar
rjsmelo committed
170 171
			$selectedCategories = [(int) $filter['categId']];
		} elseif (! empty($_REQUEST['categId'])) {
172 173
			$filter['categId'] = $_REQUEST['categId'];
			$smarty->assign('find_categId', $_REQUEST['categId']);
rjsmelo's avatar
rjsmelo committed
174
			$selectedCategories = [(int) $filter['categId']];
175 176
		} else {
			$smarty->assign('find_categId', '');
177
		}
178
	}
179

rjsmelo's avatar
rjsmelo committed
180
	if ((! empty($_REQUEST['page_orphans']) && $_REQUEST['page_orphans'] == 'y')
181 182
			|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'page_orphans')
	) {
183 184
		$listpages_orphans = true;
	}
185

186
	if ($prefs['feature_listorphanPages'] == 'y') {
rjsmelo's avatar
rjsmelo committed
187
		if ((! empty($_REQUEST['page_orphans']) && $_REQUEST['page_orphans'] == 'y')
188 189
				|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'page_orphans')
		) {
190 191 192 193 194
			$filter_values['orphan'] = 'page_orphans';
		}
		$filters['orphan']['page_orphans'] = tra('Orphan pages');
	}
	if ($prefs['feature_wiki_structure'] == 'y') {
rjsmelo's avatar
rjsmelo committed
195
		if ((! empty($_REQUEST['structure_orphans']) && $_REQUEST['structure_orphans'] == 'y')
196 197
				|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'structure_orphans')
		) {
198 199
			$filter['structure_orphans'] = true;
		}
200

201
		if ($prefs['feature_listorphanStructure'] == 'y') {
rjsmelo's avatar
rjsmelo committed
202
			if ((! empty($_REQUEST['structure_orphans']) && $_REQUEST['structure_orphans'] == 'y')
203 204
					|| (isset($_REQUEST['findfilter_orphan']) && $_REQUEST['findfilter_orphan'] == 'structure_orphans')
			) {
205 206
				$filter_values['orphan'] = 'structure_orphans';
			}
207
			$filters['orphan']['structure_orphans'] = tra('Pages not in a structure');
208 209
		}
	}
210

rjsmelo's avatar
rjsmelo committed
211
	if (! empty($filters)) {
212 213 214 215 216
		$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);
	}
217 218 219

	if (isset($_REQUEST['initial'])) {
		$initial = $_REQUEST['initial'];
220 221 222
	} else {
		$initial = '';
	}
223

224
	$smarty->assign('initial', $initial);
225
	// What a checked checkbox returns is browser dependant. Don't test on the value, just presence
rjsmelo's avatar
rjsmelo committed
226
	if (isset($_REQUEST['exact_match'])) {
227 228 229 230 231
		$exact_match = true;
		$smarty->assign('exact_match', 'y');
	} else {
		$exact_match = false;
		$smarty->assign('exact_match', 'n');
changi67's avatar
changi67 committed
232
	}
233
	// Get a list of last changes to the Wiki database
234
	//  $listpages_orphans must not be initialized here because it can already have received a value from another script
rjsmelo's avatar
rjsmelo committed
235
	if (! isset($listpages_orphans)) {
sylvieg's avatar
sylvieg committed
236 237
		$listpages_orphans = false;
	}
238 239 240 241 242 243 244 245 246 247 248 249
	$listpages = $tikilib->list_pages(
		$offset,
		$maxRecords,
		$sort_mode,
		$find,
		$initial,
		$exact_match,
		false,
		true,
		$listpages_orphans,
		$filter
	);
250

251
	possibly_look_for_page_aliases($find);
252 253
	// Only show the 'Actions' column if the user can do at least one action on one of the listed pages
	$show_actions = 'n';
rjsmelo's avatar
rjsmelo committed
254
	$actions_perms = ['tiki_p_edit', 'tiki_p_wiki_view_history', 'tiki_p_assign_perm_wiki_page', 'tiki_p_remove'];
255 256
	foreach ($actions_perms as $p) {
		foreach ($listpages['data'] as $i) {
changi67's avatar
changi67 committed
257
			if ($i['perms'][$p] == 'y') {
258 259 260 261 262
				$show_actions = 'y';
				break 2;
			}
		}
	}
263

264
	$smarty->assign('show_actions', $show_actions);
265
	// If there're more records then assign next_offset
266
	$cant_pages = ceil($listpages['cant'] / $maxRecords);
267 268
	$smarty->assign_by_ref('cant_pages', $cant_pages);
	$smarty->assign('actual_page', 1 + ($offset / $maxRecords));
rjsmelo's avatar
rjsmelo committed
269
	if ($listpages['cant'] > ($offset + $maxRecords)) {
270
		$smarty->assign('next_offset', $offset + $maxRecords);
rjsmelo's avatar
rjsmelo committed
271
	} else {
272
		$smarty->assign('next_offset', -1);
rjsmelo's avatar
rjsmelo committed
273
	}
274

275
	// If offset is > 0 then prev_offset
rjsmelo's avatar
rjsmelo committed
276
	if ($offset > 0) {
277
		$smarty->assign('prev_offset', $offset - $maxRecords);
rjsmelo's avatar
rjsmelo committed
278
	} else {
279
		$smarty->assign('prev_offset', -1);
rjsmelo's avatar
rjsmelo committed
280
	}
281

282
	if ($prefs['feature_categories'] == 'y') {
283
		$categlib = TikiLib::lib('categ');
284
		$categories = $categlib->getCategories();
285
		$smarty->assign('notable', 'y');
286
		$smarty->assign('cat_tree', $categlib->generate_cat_tree($categories, true, $selectedCategories));
287 288
		$smarty->assign_by_ref('categories', $categories);
	}
289

290
	if ($prefs['feature_multilingual'] == 'y') {
rjsmelo's avatar
rjsmelo committed
291
		$languages = [];
292 293
		$langLib = TikiLib::lib('language');
		$languages = $langLib->list_languages(false, 'y');
changi67's avatar
changi67 committed
294
		$smarty->assign_by_ref('languages', $languages);
295
	}
296

297
	if ($prefs['gmap_page_list'] == 'y') {
298 299
		// Generate Google map plugin data
		global $gmapobjectarray;
rjsmelo's avatar
rjsmelo committed
300
		$gmapobjectarray = [];
301
		foreach ($listpages['data'] as $p) {
rjsmelo's avatar
rjsmelo committed
302
			$gmapobjectarray[] = ['type' => 'wiki page',
303 304 305
				'id' => $p['pageName'],
				'title' => $p['pageName'],
				'href' => 'tiki-index.php?page=' . urlencode($p['pageName']),
rjsmelo's avatar
rjsmelo committed
306
			];
307 308
		}
	}
309

310 311 312 313 314 315 316 317
	foreach ($listpages['data'] as & $p) {
		if ($userlib->object_has_one_permission($p['pageName'], 'wiki page')) {
			$p['perms_active'] = 'y';
		} else {
			$p['perms_active'] = 'n';
		}
	}

318
	$smarty->assign_by_ref('listpages', $listpages['data']);
319
	$smarty->assign_by_ref('cant', $listpages['cant']);
320
	ask_ticket('list-pages');
rjsmelo's avatar
rjsmelo committed
321
	include_once('tiki-section_options.php');
322 323
	// disallow robots to index page:
	$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
324 325

	// Exact match and single result, go to page directly
rjsmelo's avatar
rjsmelo committed
326
	if (count($listpages['data']) == 1 && ! $ts['ajax']) {
327
		$result = reset($listpages['data']);
rjsmelo's avatar
rjsmelo committed
328
		if (TikiLib::strtolower($find) == TikiLib::strtolower($result['pageName'])) {
lphuberdeau's avatar
lphuberdeau committed
329
			$wikilib = TikiLib::lib('wiki');
330
			header('Location: ' . $wikilib->sefurl($result['pageName'], '', $all_langs));
331 332 333 334
			exit;
		}
	}

rjsmelo's avatar
rjsmelo committed
335
	if ($ts['enabled'] && ! $ts['ajax']) {
336
		//create dropdown lists for category name and path filters
rjsmelo's avatar
rjsmelo committed
337 338
		$cnames = [];
		$cpaths = [];
339
		if (isset($categories) && count($categories) > 0) {
rjsmelo's avatar
rjsmelo committed
340
			foreach ($categories as $c) {
341 342 343 344 345 346
				$cnames[] = $c['name'];
				$cpaths[] = $c['categpath'];
			}
		}
		//set language dropdown showing only languages that pages are actually in
		if (isset($languages) && count($languages) > 0) {
rjsmelo's avatar
rjsmelo committed
347
			$pagelangs = array_unique($tikilib->table('tiki_pages')->fetchColumn('lang', []));
348
			$pagelangs = array_flip($pagelangs);
349 350 351
			$langLib = TikiLib::lib('language');
			$langLib->getLanguages();
			$temp_langs = array_intersect_key($langmapping, $pagelangs);
352 353
			if (count($temp_langs) > 0) {
				foreach ($temp_langs as $short => $long) {
354
					$ts_langs[$short . '|' . $long[0]] = $long[0];
355 356
				}
			} else {
rjsmelo's avatar
rjsmelo committed
357
				$ts_langs = [];
358
			}
359
		} else {
rjsmelo's avatar
rjsmelo committed
360
			$ts_langs = [];
361
		}
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
		//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
rjsmelo's avatar
rjsmelo committed
380
		foreach ($cols as $pref => $fieldname) {
381 382 383 384 385 386 387 388 389 390 391 392 393 394
			$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;
rjsmelo's avatar
rjsmelo committed
395
		} elseif (strpos($sort_mode, '_asc') !== false) {
396 397 398 399 400 401 402
			$pos = strlen($sort_mode) - 4;
			$sortdir = 0;
		}
		///set sort column
		$sort = substr($sort_mode, 0, $pos);
		$sortcol = array_search($sort, $cols);

rjsmelo's avatar
rjsmelo committed
403
		$settings = [
404
			'id' => $ts['tableid'],
405
			'total' 	=> $listpages['cant'],
rjsmelo's avatar
rjsmelo committed
406
			'vars'	=> [
407
				'show_actions' => $show_actions,
rjsmelo's avatar
rjsmelo committed
408 409 410 411
			],
			'columns'	=> [
				'#language'	=> [
					'filter' => [
412
						'options' => $ts_langs,
rjsmelo's avatar
rjsmelo committed
413 414 415 416
					],
				],
				'#categories'	=> [
					'filter' => [
417
						'options' => $cnames,
rjsmelo's avatar
rjsmelo committed
418 419 420 421
					],
				],
				'#catpaths'	=> [
					'filter' => [
422
						'options' => $cpaths,
rjsmelo's avatar
rjsmelo committed
423 424 425 426
					],
				],
			],
		];
427 428 429 430 431

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

changi67's avatar
changi67 committed
435
	if ($access->is_serializable_request()) {
436
		if (isset($_REQUEST['listonly']) && ($prefs['feature_jquery'] == 'y' && $prefs['feature_jquery_autocomplete'] == 'y')) {
rjsmelo's avatar
rjsmelo committed
437
			$pages = [];
438 439 440 441 442 443
			foreach ($listpages['data'] as $page) {
				if (isset($_REQUEST['nonamespace'])) {
					$pages[] = TikiLib::lib('wiki')->get_without_namespace($page['pageName']);
				} else {
					$pages[] = $page['pageName'];
				}
rjsmelo's avatar
rjsmelo committed
444
			}
changi67's avatar
changi67 committed
445
			$access->output_serialized($pages);
446
		} else {
rjsmelo's avatar
rjsmelo committed
447
			$pages = [];
lphuberdeau's avatar
lphuberdeau committed
448
			$wikilib = TikiLib::lib('wiki');
449
			foreach ($listpages['data'] as $page) {
rjsmelo's avatar
rjsmelo committed
450
				$pages[] = [
451 452 453 454 455 456 457 458 459
						'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'],
rjsmelo's avatar
rjsmelo committed
460
				];
461 462
			}
			require_once 'lib/ointegratelib.php';
rjsmelo's avatar
rjsmelo committed
463
			$response = OIntegrate_Response::create(['list' => $pages], '1.0');
464
			$response->addTemplate('smarty', 'tikiwiki', 'templates/smarty-tikiwiki-1.0-shortlist.txt');
465
			$response->schemaDocumentation = 'http://dev.tiki.org/WebserviceListpages';
466 467
			$response->send();
		}
468 469
	} else {
		// Display the template
470
		if ($ts['ajax']) {
471 472 473 474 475
			$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');
		}
476
	}
477
}
478

479 480 481 482
/**
 * @param $filter
 * @return mixed
 */
483 484
function setLangFilter($filter)
{
485 486 487 488
	global $prefs;
	$multilinguallib = TikiLib::lib('multilingual');
	$smarty = TikiLib::lib('smarty');

489
	$lang = $multilinguallib->currentPageSearchLanguage();
490 491 492
	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
	}
493 494 495 496
	// Without this condition, default listing is empty and language filter shows any language
	if ($lang == 'en-us') {
		$lang = 'en';
	}
changi67's avatar
changi67 committed
497
	$filter['lang'] = $lang;
498
	$smarty->assign('find_lang', $lang);
changi67's avatar
changi67 committed
499
	return $filter;
500
}
501

502 503 504
/**
 * @param $query
 */
505 506
function possibly_look_for_page_aliases($query)
{
507 508
	global $prefs;
	$smarty = TikiLib::lib('smarty');
509

rjsmelo's avatar
rjsmelo committed
510
	$lang = null;
511 512 513
	if (isset($_REQUEST['lang'])) {
		$lang = $_REQUEST['lang'];
	}
514

changi67's avatar
changi67 committed
515
	if ($prefs['feature_wiki_pagealias'] == 'y' && $query) {
516
		$semanticlib = TikiLib::lib('semantic');
517
		$aliases = $semanticlib->getAliasContaining($query, false, $lang);
changi67's avatar
changi67 committed
518
		$smarty->assign('aliases', $aliases);
519
	} else {
changi67's avatar
changi67 committed
520
		$smarty->assign('aliases', null);
521
	}
522

rjsmelo's avatar
rjsmelo committed
523
	if (! empty($aliases) > 0) {
524 525 526 527
		$smarty->assign('aliases_were_found', 'y');
	} else {
		$smarty->assign('aliases_were_found', 'n');
	}
528

529
	$alias_found = 'n';
rjsmelo's avatar
rjsmelo committed
530
	if (! empty($aliases)) {
531
		foreach ($aliases as $an_alias_info) {
sylvieg's avatar
sylvieg committed
532 533 534
			if ($an_alias_info['toPage'] == $query) {
				$alias_found = 'y';
			}
535 536 537
		}
	}
	$smarty->assign('alias_found', $alias_found);
538 539 540 541

	set_category_for_new_page_creation();
}

542 543
function set_category_for_new_page_creation()
{
544 545
	global $prefs;
	$smarty = TikiLib::lib('smarty');
546 547

	$create_page_with_categId = '';
548
	if (isset($_REQUEST['create_page_with_search_category'])) {
rjsmelo's avatar
rjsmelo committed
549
		if ($prefs['feature_categories'] == 'y' && ! empty($_REQUEST['categId'])) {
550 551 552 553
			$create_page_with_categId = $_REQUEST['categId'];
		}
	}
	$smarty->assign('create_page_with_categId', $create_page_with_categId);
554
}