/usr/share/horde/wicked/lib/Page/StandardPage.php is in php-horde-wicked 2.0.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 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 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | <?php
/**
* Copyright 2003-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @author Jan Schneider <jan@horde.org>
* @author Tyler Colbert <tyler@colberts.us>
* @package Wicked
*/
/**
* Page class for regular pages.
*
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @author Jan Schneider <jan@horde.org>
* @author Tyler Colbert <tyler@colberts.us>
* @package Wicked
*/
class Wicked_Page_StandardPage extends Wicked_Page
{
/**
* Display modes supported by this page.
*
* @var array
*/
public $supportedModes = array(
Wicked::MODE_DISPLAY => true,
Wicked::MODE_EDIT => true,
Wicked::MODE_REMOVE => true,
Wicked::MODE_HISTORY => true,
Wicked::MODE_DIFF => true);
/**
* A Horde_Locks instance for un-/locking this page.
*
* @var Horde_Lock
*/
protected $_locks = null;
/**
* Lock information if this page is currently locked.
*
* @var array
*/
protected $_lock = null;
/**
* Constructs a standard page class to represent a wiki page.
*
* @param string $pagename The name of the page to represent.
*/
public function __construct($pagename)
{
if (is_array($pagename)) {
$this->_page = $pagename;
return;
}
$page = null;
try {
$page = $GLOBALS['wicked']->retrieveByName($pagename);
} catch (Wicked_Exception $e) {
// If we can't load $pagename, see if there's default data for it.
// Protect against directory traversion.
$pagepath = realpath(WICKED_BASE . '/data/'
. $GLOBALS['conf']['wicked']['format']);
$pagefile = realpath($pagepath . '/' . $pagename);
if ($pagefile &&
Horde_String::common($pagefile, $pagepath) == $pagepath &&
substr($pagename, 0, 1) != '.' &&
file_exists($pagefile) &&
($text = file_get_contents($pagefile))) {
try {
$GLOBALS['wicked']->newPage($pagename, $text);
try {
$page = $GLOBALS['wicked']->retrieveByName($pagename);
} catch (Wicked_Exception $e) {
$GLOBALS['notification']->push(sprintf(_("Unable to create %s"), $pagename), 'horde.error');
}
} catch (Wicked_Exception $e) {}
}
}
if ($page) {
$this->_page = $page;
} else {
if ($pagename == 'Wiki/Home') {
$GLOBALS['notification']->push(_("Unable to create Wiki/Home. The wiki is not configured."), 'horde.error');
}
$this->_page = array();
}
// Make sure 'wicked' permission exists. Set reasonable defaults if
// necessary.
$perms = $GLOBALS['injector']->getInstance('Horde_Perms');
$corePerms = $GLOBALS['injector']->getInstance('Horde_Core_Perms');
if (!$perms->exists('wicked')) {
$perm = $corePerms->newPermission('wicked');
$perm->addGuestPermission(Horde_Perms::SHOW | Horde_Perms::READ, false);
$perm->addDefaultPermission(Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT | Horde_Perms::DELETE, false);
$perms->addPermission($perm);
}
// Make sure 'wicked:pages' exists. Copy from 'wicked' if it does not
// exist.
if (!$perms->exists('wicked:pages')) {
$perm = $corePerms->newPermission('wicked:pages');
$copyFrom = $perms->getPermission('wicked');
$perm->addGuestPermission($copyFrom->getGuestPermissions(), false);
$perm->addDefaultPermission($copyFrom->getDefaultPermissions(), false);
$perm->addCreatorPermission($copyFrom->getCreatorPermissions(), false);
foreach ($copyFrom->getUserPermissions() as $user => $uperm) {
$perm->addUserPermission($user, $uperm, false);
}
foreach ($copyFrom->getGroupPermissions() as $group => $gperm) {
$perm->addGroupPermission($group, $gperm, false);
}
$perms->addPermission($perm);
}
if ($GLOBALS['conf']['lock']['driver'] != 'none') {
$this->supportedModes[Wicked::MODE_LOCKING] = $this->supportedModes[Wicked::MODE_UNLOCKING] = true;
$this->_locks = $GLOBALS['injector']->getInstance('Horde_Lock');
$locks = $this->_locks->getLocks('wicked', $pagename, Horde_Lock::TYPE_EXCLUSIVE);
if ($locks) {
$this->_lock = reset($locks);
}
}
}
/**
* Returns if the page allows a mode. Access rights and user state
* are taken into consideration.
*
* @see $supportedModes
*
* @param integer $mode The mode to check for.
*
* @return boolean True if the mode is allowed.
*/
public function allows($mode)
{
switch ($mode) {
case Wicked::MODE_EDIT:
if ($this->isLocked()) {
return Wicked::lockUser() == $this->_lock['lock_owner'];
}
break;
case Wicked::MODE_LOCKING:
if ($GLOBALS['browser']->isRobot()) {
return false;
}
if ($GLOBALS['registry']->isAdmin()) {
return true;
}
if (($this->getPermissions() & Horde_Perms::EDIT) == 0) {
return false;
}
break;
case Wicked::MODE_UNLOCKING:
if ($GLOBALS['registry']->isAdmin()) {
return true;
}
if ($this->_lock) {
return Wicked::lockUser() == $this->_lock['lock_owner'];
}
return false;
}
return parent::allows($mode);
}
/**
* @throws Wicked_Exception
*/
public function displayContents($isBlock)
{
$view = $GLOBALS['injector']->createInstance('Horde_View');
$view->text = $this->getProcessor()->transform($this->getText());
if ($isBlock) {
return $view->render('display/standard');
}
$view->showTools = true;
if ($this->allows(Wicked::MODE_EDIT) &&
!$this->isLocked(Wicked::lockUser())) {
$view->edit = Horde::widget(array(
'url' => Wicked::url('EditPage')
->add('referrer', $this->pageName()),
'title' => _("_Edit"),
'class' => 'wicked-edit',
));
}
if ($this->isLocked()) {
if ($this->allows(Wicked::MODE_UNLOCKING)) {
$view->unlock = Horde::widget(array(
'url' => $this->pageUrl(null, 'unlock')->remove('version'),
'title' => _("Un_lock"),
'class' => 'wicked-unlock',
));
}
} else {
if ($this->allows(Wicked::MODE_LOCKING)) {
$view->lock = Horde::widget(array(
'url' => $this->pageUrl(null, 'lock')->remove('version'),
'title' => _("_Lock"),
'class' => 'wicked-lock',
));
}
}
if ($this->allows(Wicked::MODE_REMOVE)) {
$params = array('referrer' => $this->pageName());
if ($this->isOld()) {
$params['version'] = $this->version();
}
$view->remove = Horde::widget(array(
'url' => Wicked::url('DeletePage')->add($params),
'title' => _("_Delete"),
'class' => 'wicked-delete',
));
}
if ($this->allows(Wicked::MODE_REMOVE) &&
!$this->isLocked(Wicked::lockUser())) {
$view->rename = Horde::widget(array(
'url' => Wicked::url('MergeOrRename')
->add('referrer', $this->pageName()),
'title' => _("_Merge/Rename")
));
}
$view->backLinks = Horde::widget(array(
'url' => Wicked::url('BackLinks')
->add('referrer', $this->pageName()),
'title' => _("_Backlinks")
));
$view->likePages = Horde::widget(array(
'url' => Wicked::url('LikePages')
->add('referrer', $this->pageName()),
'title' => _("S_imilar Pages")
));
$view->attachedFiles = Horde::widget(array(
'url' => Wicked::url('AttachedFiles')
->add('referrer', $this->pageName()),
'title' => _("Attachments")
));
if ($this->allows(Wicked::MODE_HISTORY)) {
$view->changes = Horde::widget(array(
'url' => $this->pageUrl('history.php')->remove('version'),
'title' => _("Hi_story")
));
}
if ($GLOBALS['registry']->isAdmin()) {
$permsurl = Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/admin/perms/edit.php')
->add(array(
'category' => 'wicked:pages:' . $this->pageId(),
'autocreate' => 1,
'autocreate_copy' => 'wicked',
'autocreate_guest' => Horde_Perms::SHOW | Horde_Perms::READ,
'autocreate_default' => Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT | Horde_Perms::DELETE
));
$view->perms = Horde::widget(array(
'url' => $permsurl,
'target' => '_blank',
'title' => _("Permissio_ns")
));
}
if ($histories = $GLOBALS['session']->get('wicked', 'history')) {
$view->history = Horde::widget(array(
'url' => '#',
'onclick' => 'document.location = document.display.history[document.display.history.selectedIndex].value;',
'title' => _("Ba_ck to")
));
$view->histories = array();
foreach ($histories as $history) {
if (!strlen($history)) {
continue;
}
$view->histories[(string)Wicked::url($history)] = $history;
}
}
$pageId = $GLOBALS['wicked']->getPageId($this->pageName());
$attachments = $GLOBALS['wicked']->getAttachedFiles($pageId);
if (count($attachments)) {
$view->attachments = array();
foreach ($attachments as $attachment) {
$url = $GLOBALS['registry']
->downloadUrl(
$attachment['attachment_name'],
array(
'page' => $this->pageName(),
'file' => $attachment['attachment_name'],
'version' => $attachment['attachment_version']
)
);
$icon = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_MimeViewer')
->getIcon(
Horde_Mime_Magic::filenameToMime(
$attachment['attachment_name']
)
);
$view->attachments[] = Horde::link($url)
. '<img src="' . $icon . '" width="16" height="16" alt="" /> '
. htmlspecialchars($attachment['attachment_name'])
. '</a>';
}
}
$view->downloadPlain = Wicked::url($this->pageName())
->add(array('actionID' => 'export', 'format' => 'plain'))
->link()
. _("Plain Text") . '</a>';
$view->downloadHtml = Wicked::url($this->pageName())
->add(array('actionID' => 'export', 'format' => 'html'))
->link()
. _("HTML") . '</a>';
$view->downloadLatex = Wicked::url($this->pageName())
->add(array('actionID' => 'export', 'format' => 'tex'))
->link()
. _("Latex") . '</a>';
$view->downloadRest = Wicked::url($this->pageName())
->add(array('actionID' => 'export', 'format' => 'rst'))
->link()
. _("reStructuredText") . '</a>';
return $view->render('display/standard');
}
/**
* Renders this page in History mode.
*
* @return string The content.
* @throws Wicked_Exception
*/
public function history()
{
global $injector, $page_output;
$page_output->addScriptFile('history.js');
$view = $injector->createInstance('Horde_View');
// Header.
$view->formInput = Horde_Util::formInput();
$view->name = $this->pageName();
$view->pageLink = $this->pageUrl()->link()
. htmlspecialchars($this->pageName()) . '</a>';
$view->refreshLink = $this->pageUrl('history.php')->link()
. Horde::img('reload.png', _("Reload History")) . '</a>';
if ($this->allows(Wicked::MODE_REMOVE)) {
$view->remove = Horde::img('delete.png', _("Delete Version"));
}
if ($this->allows(Wicked::MODE_EDIT) &&
!$this->isLocked(Wicked::lockUser())) {
$view->edit = Horde::img('edit.png', _("Edit Version"));
$view->restore = Horde::img('restore.png', _("Restore Version"));
}
$content = $view->render('history/header');
// First item is this page.
$view->showRestore = false;
$this->_setViewProperties($view, $this);
$content .= $view->render('history/summary');
// Now the rest of the histories.
$view->showRestore = true;
foreach ($GLOBALS['wicked']->getHistory($this->pageName()) as $page) {
$page = new Wicked_Page_StandardHistoryPage($page);
$this->_setViewProperties($view, $page);
$view->pversion = $page->version();
$content .= $view->render('history/summary');
}
// Footer.
return $content . $view->render('history/footer');
}
protected function _setViewProperties($view, $page)
{
$view->displayLink = $page->pageUrl()
->link(array(
'title' => sprintf(_("Display Version %s"), $page->version())
))
. htmlspecialchars($page->version()) . '</a>';
$text = sprintf(_("Delete Version %s"), $page->version());
$view->deleteLink = Wicked::url('DeletePage')
->add(array(
'referrer' => $page->pageName(),
'version' => $page->version()
))
->link(array('title' => $text))
. Horde::img('delete.png', $text) . '</a>';
$text = sprintf(_("Edit Version %s"), $page->version());
$view->editLink = Wicked::url('EditPage')
->add(array('referrer' => $page->pageName()))
->link(array('title' => $text))
. Horde::img('edit.png', $text) . '</a>';
$text = sprintf(_("Revert to version %s"), $page->version());
$view->restoreLink = Wicked::url('RevertPage')
->add(array(
'referrer' => $page->pageName(),
'version' => $page->version()
))
->link(array('title' => $text))
. Horde::img('restore.png', $text) . '</a>';
$view->author = $page->author();
$view->date = $page->formatVersionCreated();
$view->version = $page->version();
$view->changelog = $page->changeLog();
}
public function isLocked($owner = null)
{
if (empty($this->_lock)) {
return false;
}
if (is_null($owner)) {
return true;
}
return $owner != $this->_lock['lock_owner'];
}
/**
* @throws Wicked_Exception
*/
public function lock()
{
if ($this->_locks) {
$id = $this->_locks->setLock(Wicked::lockUser(), 'wicked', $this->pageName(), $GLOBALS['conf']['wicked']['lock']['time'] * 60, Horde_Lock::TYPE_EXCLUSIVE);
if ($id) {
$this->_lock = $this->_locks->getLockInfo($id);
} else {
throw new Wicked_Exception(_("The page is already locked."));
}
}
}
public function unlock()
{
if ($this->_locks && $this->_lock) {
$this->_locks->clearLock($this->_lock['lock_id']);
unset($this->_lock);
}
}
public function getLockRequestor()
{
$requestor = $this->_lock['lock_owner'];
if ($requestor) {
$name = $GLOBALS['injector']
->getInstance('Horde_Core_Factory_Identity')
->create($requestor)
->getValue('fullname');
if (!strlen($name)) {
$name = $requestor;
}
return $name;
}
return _("a guest");
}
public function getLockTime()
{
$time = ceil(($this->_lock['lock_expiry_timestamp'] - time()) / 60);
return sprintf(ngettext("%d minute", "%d minutes", $time), $time);
}
/**
* @throws Wicked_Exception
*/
public function updateText($newtext, $changelog)
{
$version = $this->version();
$result = $GLOBALS['wicked']->updateText($this->pageName(), $newtext,
$changelog);
$url = Wicked::url($this->pageName(), true, -1);
$new_page = $this->getPage($this->pageName());
$message = "Modified page: $url\n"
. 'New Revision: ' . $new_page->version() . "\n"
. ($changelog ? 'Change log: ' . $changelog . "\n" : '')
. "\n"
. $new_page->getDiff($version);
Wicked::mail($message,
array('Subject' => '[' . $GLOBALS['registry']->get('name')
. '] changed: ' . $this->pageName()));
$this->_page['page_text'] = $newtext;
}
public function pageID()
{
return isset($this->_page['page_id']) ? $this->_page['page_id'] : '';
}
public function pageName()
{
return isset($this->_page['page_name'])
? $this->_page['page_name']
: '';
}
public function getText()
{
return isset($this->_page['page_text'])
? $this->_page['page_text']
: '';
}
public function versionCreated()
{
return isset($this->_page['version_created'])
? $this->_page['version_created']
: '';
}
public function hits()
{
return !empty($this->_page['page_hits'])
? $this->_page['page_hits']
: 0;
}
public function changeLog()
{
return $this->_page['change_log'];
}
public function version()
{
if (isset($this->_page['page_version'])) {
return $this->_page['page_version'];
} else {
return '';
}
}
/**
* Renders this page in diff mode.
*
* @param string $version The version to diff this page against.
*/
public function diff($version)
{
$view = $GLOBALS['injector']->createInstance('Horde_View');
$view->link = $this->pageUrl()->link()
. htmlspecialchars($this->pageName())
. '</a>';
$view->version1 = $version;
$view->version2 = $this->version();
$view->diff = $this->getDiff($version, 'inline');
echo $view->render('diff/diff');
}
/**
* Produces a diff for this page.
*
* @param string $version Previous version, or null if diffing with
* `before the beginning' (empty).
* @param string $renderer The diff renderer.
*/
public function getDiff($version, $renderer = 'unified')
{
if (is_null($version)) {
$old_page_text = '';
} else {
$old_page = $this->getPage($this->pageName(), $version);
$old_page_text = $old_page->getText();
}
$diff = new Horde_Text_Diff('auto',
array(explode("\n", $old_page_text),
explode("\n", $this->getText())));
$class = 'Horde_Text_Diff_Renderer_' . Horde_String::ucfirst($renderer);
$renderer = new $class();
return $renderer->render($diff);
}
}
|