function getTrees() { if ($this->trees == null) { $this->trees = array(); if ($this->mUser->isLoggedIn() && FamilyTreeUtil::isTreePage($this->mTitle->getNamespace(), $this->mTitle->getDBkey())) { $this->trees = FamilyTreeUtil::getOwnerTrees($this->mUser, $this->mTitle, true); } } return $this->trees; }
public static function generateTreeCheckboxes($user, $title, $editPage, $allTrees = null, $treeOwnerIds = null) { global $wgRequest, $wgUser; $result = ''; $cnt = 0; // $editPage is true also for adding a page in Special:Search // title may be null for image upload or adding a page in Special:Search if ($title == null || FamilyTreeUtil::isTreePage($title->getNamespace(), $title->getDBkey())) { $isNew = $title == null || $title->getArticleID() == 0; if (!is_array($allTrees)) { $allTrees = FamilyTreeUtil::getFamilyTrees($user->getName()); } if (count($allTrees) > 0) { if ($editPage && $wgRequest->wasPosted()) { $checkedTrees = FamilyTreeUtil::readTreeCheckboxes($allTrees, $wgRequest); } else { if (is_array($treeOwnerIds)) { $checkedTrees = $treeOwnerIds; } else { $checkedTrees = $title == null ? array() : FamilyTreeUtil::getOwnerTrees($user, $title, false); } // if we're creating the page and the user has just one tree and no tree is checked if ($editPage && $isNew && count($allTrees) == 1 && count($checkedTrees) == 0) { $checkedTrees[] = $allTrees[0]['id']; } } // if no trees checked, check the default tree(s) if (count($checkedTrees) == 0 && !$wgRequest->wasPosted() && !($isNew && $wgUser->getIntOption('watchcreations') === 0 || !$isNew && $wgUser->getIntOption('watchdefault') === 0)) { foreach ($allTrees as $tree) { if ($tree['checked']) { $checkedTrees[] = $tree['id']; } } } foreach ($allTrees as $tree) { $cnt++; $class = ''; if ($editPage && !$wgRequest->wasPosted() && ($title == null || $title->getArticleID() == 0)) { if ($cnt == 1 && count($checkedTrees) == 0) { $class = ' treeCheckbox'; // defaultTreeCheckbox"'; } else { $class = ' treeCheckbox'; } } $result .= " <input type=\"checkbox\" class=\"treeCheck{$class}\"" . ' name="' . htmlspecialchars(FamilyTreeUtil::toInputName($tree['name'])) . '"' . (in_array($tree['id'], $checkedTrees) ? " checked='checked'" : "") . "/> " . htmlspecialchars($tree['name']) . ($editPage ? '' : "<br/>\n"); } } } if ($editPage && $cnt) { $result = wfMsg('addtotreecheckbox') . $result; } return $result; }
private function updateTrees($user, $title, $revId, $request) { //wfDebug("updateTrees " . $title->getPrefixedText() . " " . $revId . "\n"); $allTrees = FamilyTreeUtil::getFamilyTrees($user->getName()); $treeOwnerIds = FamilyTreeUtil::getOwnerTrees($user, $title, false); $checkedTreeIds = FamilyTreeUtil::readTreeCheckboxes($allTrees, $request); return FamilyTreeUtil::updateTrees($this->db, $title, $revId, $allTrees, $treeOwnerIds, $checkedTreeIds, true, false); }
function wrDoContentActions($action, $article) { global $wgUser, $wgOut, $wgRequest; if ($action != 'treeUpdate' && $action != 'treeUpdateConfirm') { return true; // handle by another content action handler } if ($wgUser->isAnon()) { $wgOut->showErrorPage('treenologintitle', 'treenologintext'); return false; } if (!FamilyTreeUtil::isTreePage($article->getTitle()->getNamespace(), $article->getTitle()->getDBkey())) { $wgOut->showErrorPage('treenonamespacetitle', 'treenonamespacetext'); return false; } if (wfReadOnly()) { $wgOut->readOnlyPage(); return false; } $allTrees = FamilyTreeUtil::getFamilyTrees($wgUser->getName()); $treeOwnerIds = FamilyTreeUtil::getOwnerTrees($wgUser, $article->getTitle(), false); $checkedTreeIds = FamilyTreeUtil::readTreeCheckboxes($allTrees, $wgRequest); $ancGenerations = $wgRequest->getVal('ancestorgenerations'); $includeAncestorChildren = $wgRequest->getCheck('includeancestorchildren'); $descGenerations = $wgRequest->getVal('descendantgenerations'); $wgOut->setRobotpolicy('noindex,nofollow'); if ($action == 'treeUpdateConfirm' && ($ancGenerations == 0 && $descGenerations == 0 || count($checkedTreeIds) > 0)) { $dbw =& wfGetDB(DB_MASTER); $result = FamilyTreeUtil::updateTrees($dbw, $article->getTitle(), $article->getRevIdFetched(), $allTrees, $treeOwnerIds, $checkedTreeIds); if ($result) { $dbw->commit(); } else { $dbw->rollback(); } if ($ancGenerations > 0 || $descGenerations > 0) { $job = new AddTreePagesJob(array('trees' => join(',', $checkedTreeIds), 'user' => $wgUser->getName(), 'title' => $article->getTitle()->getPrefixedText(), 'ancGenerations' => $ancGenerations, 'includeAncestorChildren' => $includeAncestorChildren, 'descGenerations' => $descGenerations)); $job->insert(); $treesUpdatedMsg = 'treesupdatedtextdeferred'; } else { $treesUpdatedMsg = 'treesupdatedtext'; } $wgOut->setPagetitle(wfMsg('treesupdatedtitle')); $wgOut->addWikiText(wfMsg($treesUpdatedMsg)); $wgOut->returnToMain(true, $article->getTitle()->getPrefixedText()); } else { if (count($allTrees) == 0) { $wgOut->showErrorPage('treenonetitle', 'treenonetext'); } else { // show form $wgOut->setPagetitle(wfMsg('treeupdatetitle')); if ($action == 'treeUpdateConfirm') { $wgOut->addHTML('<font color="red">Please check the box next to the tree(s) you want to add the pages to.</font>'); } $wgOut->addWikiText('==Trees=='); $wgOut->addWikiText(wfMsg('treeupdatetext')); // TODO show form $action = $article->getTitle()->escapeLocalURL('action=treeUpdateConfirm'); $wgOut->addHTML(<<<END <form id="treeUpdate" method="post" action="{$action}" enctype="multipart/form-data"> END ); $wgOut->addHTML(FamilyTreeUtil::generateTreeCheckboxes($wgUser, $article->getTitle(), false, $allTrees, $treeOwnerIds)); if ($article->getTitle()->getNamespace() == NS_PERSON || $article->getTitle()->getNamespace() == NS_FAMILY) { $wgOut->addWikiText('==Include relatives=='); $wgOut->addWikiText(":'''''Warning''': including relatives can add potentially many people to your tree and to your watchlist.''"); $wgOut->addWikiText(':Add the following relatives to the checked trees.'); $options = array(); for ($i = 0; $i <= 20; $i++) { $options["{$i}"] = $i; } $ancGenerations = StructuredData::addSelectToHtml(0, 'ancestorgenerations', $options, 0); $options = array(); for ($i = 0; $i <= 5; $i++) { $options["{$i}"] = $i; } $descGenerations = StructuredData::addSelectToHtml(0, 'descendantgenerations', $options, 0); $wgOut->addHTML(<<<END <dl><dd>Include ancestors for {$ancGenerations} generations \t<dl><dd><input type="checkbox" name="includeancestorchildren"/>Also include ancestors' children</dd></dl></dd> <dd> </dd> <dd>Include descendants for {$descGenerations} generations</dd> </dl> END ); } $updateButton = array('id' => 'wrTreeUpdate', 'name' => 'wrTreeUpdate', 'type' => 'submit', 'value' => wfMsg('treeupdatebutton'), 'title' => wfMsg('treeupdatebuttontip')); $wgOut->addHTML(wfElement('input', $updateButton, '')); $wgOut->addHTML("</form>\n"); } } return false; // stop processing }