/** * There's something wrong with this file, not enough to reject it * totally but we require manual intervention to save it for real. * Stash it away, then present a form asking to confirm or cancel. * * @param string $warning as HTML * @access private */ function uploadWarning($warning) { global $wgOut; global $wgUseCopyrightUpload; $this->mSessionKey = $this->stashSession(); if (!$this->mSessionKey) { # Couldn't save file; an error has been displayed so let's go. return; } $wgOut->addHTML("<h2>" . wfMsgHtml('uploadwarning') . "</h2>\n"); $wgOut->addHTML("<ul class='warning'>{$warning}</ul><br />\n"); $save = wfMsgHtml('savefile'); $reupload = wfMsgHtml('reupload'); $iw = wfMsgWikiHtml('ignorewarning'); $reup = wfMsgWikiHtml('reuploaddesc'); $titleObj = Title::makeTitle(NS_SPECIAL, 'Upload'); // WERELATE: added target and id $query = 'action=submit'; if ($this->mTarget) { $query .= '&target=' . urlencode($this->mTarget) . '&id=' . urlencode($this->mId); } $action = $titleObj->escapeLocalURL($query); if ($wgUseCopyrightUpload) { $copyright = "\n\t<input type='hidden' name='wpUploadCopyStatus' value=\"" . htmlspecialchars($this->mUploadCopyStatus) . "\" />\n\t<input type='hidden' name='wpUploadSource' value=\"" . htmlspecialchars($this->mUploadSource) . "\" />\n\t"; } else { $copyright = ""; } // WERELATE - added back-button instructions; added four fields; added id='wpUpload' to wpUpload button; removed reupload; added $people and $families; added checkboxes // metadata fields and tree checkboxes are ignored in a re-upload situation $people = $this->toForm($this->mPeople, 'person', NS_PERSON, false); $families = $this->toForm($this->mFamilies, 'family', NS_FAMILY, false); //!!! remove this code dependency before sharing require_once "extensions/familytree/FamilyTreeUtil.php"; global $wgUser, $wgRequest; $allTrees = FamilyTreeUtil::getFamilyTrees($wgUser->getName()); $checkedTreeIds = FamilyTreeUtil::readTreeCheckboxes($allTrees, $wgRequest); $treecheckboxeshtml = FamilyTreeUtil::generateHiddenTreeCheckboxes($allTrees, $checkedTreeIds); $wgOut->addHTML("<p><b>Press the \"back button\" on your browser to choose a different file, or</b></p>"); $wgOut->addHTML("\n\t<form id='uploadwarning' method='post' enctype='multipart/form-data' action='{$action}'>\n\t\t<input type='hidden' name='wpIgnoreWarning' value='1' />\n\t\t<input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars($this->mSessionKey) . "\" />\n\t\t<input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars($this->mUploadDescription) . "\" />\n\t\t<input type='hidden' name='wrDate' value=\"" . htmlspecialchars($this->mDate) . "\" />\n\t\t<input type='hidden' name='wrPlace' value=\"" . htmlspecialchars($this->mPlace) . "\" />\n\t\t{$people}\n\t\t{$families}\n\t\t{$treecheckboxeshtml}\n\t\t<input type='hidden' name='wrCopyright' value=\"" . htmlspecialchars($this->mCopyright) . "\" />\n\t\t<input type='hidden' name='wpLicense' value=\"" . htmlspecialchars($this->mLicense) . "\" />\n\t\t<input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars($this->mDestFile) . "\" />\n\t\t<input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars(intval($this->mWatchthis)) . "\" />\n\t{$copyright}\n\t<table border='0'>\n\t\t<tr>\n\t\t\t<tr>\n\t\t\t\t<td align='right'>\n\t\t\t\t\t<input tabindex='2' type='submit' id='wpUpload' name='wpUpload' value=\"{$save}\" />\n\t\t\t\t</td>\n\t\t\t\t<td align='left'>{$iw}</td>\n\t\t\t</tr>\n\t\t</tr>\n\t</table></form>\n"); }
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 }