コード例 #1
0
ファイル: SkinTemplate.php プロジェクト: k-hasan-19/wiki
 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;
 }
コード例 #2
0
ファイル: FamilyTreeUtil.php プロジェクト: k-hasan-19/wiki
 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;
 }
コード例 #3
0
 public function propagateEdit($article, $request, &$text)
 {
     global $wgUser, $wgArticle;
     if ($this->needsPropagation()) {
         //wfDebug("propagateEdit {$article->getTitle()->getNamespace()} {$article->getTitle()->getDBkey()} {$article->mRevIdEdited}/{$article->getRevIdFetched()}\n");
         //wfDebug(" -> {$wgArticle->getTitle()->getPrefixedText()}\n");
         $this->begin();
         $res = $this->propagateEditMoveRollback($article->mRevIdEdited, $this->title->getNamespace(), $this->title->getDBkey());
         if ($res && ($wgArticle->getTitle()->getPrefixedText() == $article->getTitle()->getPrefixedText() || $wgArticle->getTitle()->getNamespace() == NS_SPECIAL && $wgArticle->getTitle()->getText() == 'Merge')) {
             // do this also for merges
             $newTitle = Title::newFromRedirect($text);
             // can't use $article->content or SD:getRedirectToTitle because they return the wrong results
             //wfDebug("propagateEdit title=".$this->title->getPrefixedText()." newTitle=" . ($newTitle == null ? '' : $newTitle->getPrefixedText()) . "\n");
             if ($newTitle != null && $newTitle->getPrefixedText() != $this->title->getPrefixedText()) {
                 // if this article is a redirect, add the new page to the users' tree(s)
                 $newTitle = StructuredData::getRedirectToTitle($newTitle, true);
                 // get final redirect; unreliable on the current title for some reason
                 $res = $this->handleRedirect($newTitle);
             }
         }
         // only update trees for the article being edited (no propagation but allow image uploads) and if it's a primary namespace
         if ($res && FamilyTreeUtil::isTreePage($article->getTitle()->getNamespace(), $article->getTitle()->getDBkey()) && ($wgArticle->getTitle()->getNamespace() == NS_SPECIAL && $wgArticle->getTitle()->getText() == 'Upload' || $wgArticle->getTitle()->getPrefixedText() == $article->getTitle()->getPrefixedText())) {
             $res = $this->updateTrees($wgUser, $article->getTitle(), $article->mRevIdEdited, $request);
         }
         //wfDebug("propagateEdit result $res\n");
         $this->end($res);
     }
 }
コード例 #4
0
ファイル: Hooks.php プロジェクト: k-hasan-19/wiki
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>&nbsp;</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
}