示例#1
0
/**
 * constructor
 */
function wfSpecialGotoPageOld()
{
    global $wgOut, $wgRequest, $wgUser;
    $error = '';
    $titleList = '';
    $addPersonFamily = false;
    $title = null;
    $namespace = $wgRequest->getVal('namespace');
    $titleText = $wgRequest->getVal('pagetitle');
    if ($namespace == 'person') {
        $addPersonFamily = true;
        $titleText = wrConstructName($wgRequest->getVal('personGiven'), $wgRequest->getVal('personSurname'));
        if ($titleText) {
            $title = Title::newFromText($titleText, NS_PERSON);
        }
    } else {
        if ($namespace == 'family') {
            $addPersonFamily = true;
            $husbandText = wrConstructName($wgRequest->getVal('husbandGiven'), $wgRequest->getVal('husbandSurname'));
            $wifeText = wrConstructName($wgRequest->getVal('wifeGiven'), $wgRequest->getVal('wifeSurname'));
            $titleText = '';
            if ($husbandText && $wifeText) {
                $titleText = $husbandText . ' and ' . $wifeText;
            } else {
                if ($husbandText) {
                    $titleText = $husbandText . ' and Unknown';
                } else {
                    if ($wifeText) {
                        $titleText = 'Unknown and ' . $wifeText;
                    }
                }
            }
            if ($titleText) {
                $title = Title::newFromText($titleText, NS_FAMILY);
            }
        } else {
            if ($titleText) {
                $title = Title::newFromText($titleText, $namespace);
                if (is_null($title)) {
                    $error = wfmsg('invalidtitle');
                } else {
                    if ($wgRequest->getVal('add') && ($title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK)) {
                        // user must exist if we're adding a page for them
                        $pos = strpos($title->getText(), '/');
                        if ($pos !== false) {
                            $userName = substr($title->getText(), 0, $pos);
                        } else {
                            $userName = $title->getText();
                        }
                        if (!User::isIP($userName) && User::idFromName($userName) == 0) {
                            $error = 'User does not exist.  Is the name spelled correctly?';
                            $title = null;
                        }
                    }
                }
            }
        }
    }
    if ($title) {
        if ($wgRequest->getVal('goto')) {
            if ($title->getNamespace() == NS_SPECIAL || $title->exists()) {
                $wgOut->redirect($title->getFullURL());
                return;
            } else {
                $error = 'Title not found.';
                $skin = $wgUser->getSkin();
                $n = 0;
                $moreLink = false;
                $dbr =& wfGetDB(DB_SLAVE);
                $res = $dbr->select('page', array('page_title', 'page_namespace', 'page_is_redirect'), 'page_namespace=' . $title->getNamespace() . ' and page_title like "' . $title->getDBkey() . '%"', 'wfSpecialGotoPageOld', array('LIMIT' => 31, 'ORDER BY' => 'page_title'));
                while ($row = $dbr->fetchObject($res)) {
                    if ($n == 30) {
                        $moreLink = true;
                        break;
                    }
                    if (!$titleList) {
                        $titleList = '<h2>Titles starting with ' . $titleText . '</h2><table style="background: inherit;" border="0" width="100%">';
                    }
                    $t = Title::makeTitle($row->page_namespace, $row->page_title);
                    if ($t) {
                        $link = ($row->page_is_redirect ? '<div class="allpagesredirect">' : '') . $skin->makeKnownLinkObj($t, htmlspecialchars($t->getPrefixedText())) . ($row->page_is_redirect ? '</div>' : '');
                    } else {
                        $link = '[[' . htmlspecialchars($row->page_title) . ']]';
                    }
                    if ($n % 3 == 0) {
                        $titleList .= '<tr>';
                    }
                    $titleList .= "<td>{$link}</td>";
                    $n++;
                    if ($n % 3 == 0) {
                        $titleList .= '</tr>';
                    }
                }
                $dbr->freeResult($res);
                if ($n % 3 != 0) {
                    $titleList .= '</tr>';
                }
                if ($titleList) {
                    $titleList .= '</table>';
                    $error .= " All pages starting with {$titleText} are listed below.";
                }
                if ($moreLink) {
                    $t = Title::makeTitle(NS_SPECIAL, 'Allpages');
                    $titleList .= '<p>More not shown (' . $skin->makeKnownLinkObj($t, 'show all', "from={$title->getText()}&namespace={$title->getNamespace()}") . ')</p>';
                }
            }
        } else {
            if ($wgRequest->getVal('add')) {
                // PERSON and FAMILY pages must have a unique id
                if (($title->getNamespace() == NS_PERSON || $title->getNamespace() == NS_FAMILY) && !StructuredData::titleStringHasId($title->getText())) {
                    // standardize name case and append a unique id
                    $title = StructuredData::appendUniqueId(Title::newFromText((string) StructuredData::standardizeNameCase($title->getText()), $title->getNamespace()));
                }
                if ($title != null) {
                    $wgOut->redirect($title->getFullURL('action=edit'));
                }
                return;
            }
        }
    }
    // set up page
    $wgOut->setPagetitle('Go to / Add page');
    $wgOut->setArticleRelated(false);
    $wgOut->setRobotpolicy('noindex,nofollow');
    if ($error) {
        $wgOut->addHTML("<p><font color=red>{$error}</font></p>");
    }
    $wgOut->addHTML("<center>" . getGotoPageForm($namespace, $titleText) . "</center>");
    if (!$addPersonFamily) {
        if ($titleList) {
            $wgOut->addHTML($titleList);
        } else {
            $wgOut->addWikiText("\n\n" . wfmsg('gotopageend'));
        }
    }
}
示例#2
0
 public static function constructFamilyTitle($husbandGivenname, $husbandSurname, $wifeGivenname, $wifeSurname)
 {
     // construct name and append id
     $husbandName = StructuredData::constructName($husbandGivenname, $husbandSurname);
     $wifeName = StructuredData::constructName($wifeGivenname, $wifeSurname);
     $titleText = StructuredData::constructFamilyName($husbandName, $wifeName);
     if ($titleText) {
         return StructuredData::appendUniqueId(Title::newFromText($titleText, NS_FAMILY));
     } else {
         return null;
     }
 }
/**
 * Create family tree page
 *
 * @param unknown_type $args user, name, ns, title
 * @return FTE_SUCCESS, FTE_INVALID_ARG, FTE_NOT_LOGGED_IN, FTE_NOT_AUTHORIZED, FTE_NOT_FOUND, FTE_DUP_KEY, FTE_DB_ERROR
 */
function wfCreateFamilyTreePage($args)
{
    global $wgUser, $wgAjaxCachePolicy, $wrBotUserID, $wgArticle, $wgTitle;
    // set cache policy
    $wgAjaxCachePolicy->setPolicy(0);
    $status = FTE_SUCCESS;
    $ns = '';
    $titleString = '';
    $revid = 0;
    $xml = simplexml_load_string($args);
    $userName = (string) $xml['user'];
    $treeName = (string) $xml['name'];
    $ns = (int) $xml['ns'];
    $titleString = (string) $xml['title'];
    $text = (string) $xml;
    if (!$userName || !$treeName || !$titleString || !($ns == NS_PERSON || $ns == NS_FAMILY)) {
        $status = FTE_INVALID_ARG;
    } else {
        if (!$wgUser->isLoggedIn()) {
            $status = FTE_NOT_LOGGED_IN;
        } else {
            if ($userName != $wgUser->getName() || $wgUser->isBlocked() || wfReadOnly()) {
                $status = FTE_NOT_AUTHORIZED;
            }
        }
    }
    if ($status == FTE_SUCCESS) {
        // get tree id
        $treeId = 0;
        $status = ftGetTreeId($userName, $treeName, $treeId);
        if ($status == FTE_SUCCESS && !$treeId) {
            $status = FTE_NOT_FOUND;
        }
    }
    if ($status == FTE_SUCCESS) {
        $dbw =& wfGetDB(DB_MASTER);
        $dbw->ignoreErrors(true);
        $dbw->begin();
        $title = Title::newFromText($titleString, $ns);
        if ($title == null) {
            $status = FTE_INVALID_ARG;
        } else {
            if (!StructuredData::titleStringHasId($titleString)) {
                $title = StructuredData::appendUniqueId($title, $dbw);
            }
            $article = new Article($title, 0);
            if ($article->exists()) {
                $status = FTE_DUP_KEY;
            }
        }
        if ($status == FTE_SUCCESS) {
            // set the global article and title to this, so that propagation works ok
            $wgArticle = $article;
            $wgTitle = $article->getTitle();
            // NOTE: This doesn't execute the code in FamilyTreePropagator to update familytree_page and add page to tree, but we don't want that to be called
            // because we add the page to the tree below
            if (!$article->doEdit($text, 'creating initial family tree', EDIT_NEW)) {
                $status = FTE_WIKI_ERROR;
            } else {
                $revid = $article->mRevIdEdited;
            }
        }
        // add the page to the tree
        if ($status == FTE_SUCCESS) {
            if (!FamilyTreeUtil::addPage($dbw, $wgUser, $treeId, $title, $revid, 0)) {
                $status = FTE_DB_ERROR;
            }
        }
        // watch the page
        if ($status == FTE_SUCCESS) {
            StructuredData::addWatch($wgUser, $article, true);
        }
        if ($status == FTE_SUCCESS) {
            $dbw->commit();
        } else {
            $dbw->rollback();
        }
    }
    // return status
    $titleString = StructuredData::escapeXml($title->getText());
    return "<create status=\"{$status}\" ns=\"{$ns}\" title=\"{$titleString}\" latest=\"{$revid}\"></create>";
}
示例#4
0
 function doSubmit()
 {
     global $wgOut, $wgUser, $wgRequest;
     $fname = "MovePageForm::doSubmit";
     if ($wgUser->pingLimiter('move')) {
         $wgOut->rateLimited();
         return;
     }
     # Variables beginning with 'o' for old article 'n' for new article
     // WERELATE - default ns on new title to ns on old title
     $ot = Title::newFromText($this->oldTitle);
     $nt = Title::newFromText($this->newTitle, $ot->getNamespace());
     // WERELATE - added: PERSON and FAMILY pages must have a unique id
     if ($nt && ($nt->getNamespace() == NS_PERSON || $nt->getNamespace() == NS_FAMILY) && !StructuredData::titleStringHasId($nt->getText())) {
         $nt = StructuredData::appendUniqueId($nt);
     }
     # Delete to make way if requested
     // WERELATE: added title parm and $nt condition
     if ($nt && $wgUser->isAllowed('delete', $nt) && $this->deleteAndMove) {
         $article = new Article($nt);
         // This may output an error message and exit
         $article->doDelete(wfMsgForContent('delete_and_move_reason'));
     }
     # don't allow moving to pages with # in
     if (!$nt || $nt->getFragment() != '') {
         $this->showForm('badtitletext');
         return;
     }
     $error = $ot->moveTo($nt, true, $this->reason);
     if ($error !== true) {
         $this->showForm($error);
         return;
     }
     wfRunHooks('SpecialMovepageAfterMove', array(&$this, &$ot, &$nt));
     # Move the talk page if relevant, if it exists, and if we've been told to
     $ott = $ot->getTalkPage();
     if ($ott->exists()) {
         if ($wgRequest->getVal('wpMovetalk') == 1 && !$ot->isTalkPage() && !$nt->isTalkPage()) {
             $ntt = $nt->getTalkPage();
             # Attempt the move
             $error = $ott->moveTo($ntt, true, $this->reason);
             if ($error === true) {
                 $talkmoved = 1;
                 wfRunHooks('SpecialMovepageAfterMove', array(&$this, &$ott, &$ntt));
             } else {
                 $talkmoved = $error;
             }
         } else {
             # Stay silent on the subject of talk.
             $talkmoved = '';
         }
     } else {
         $talkmoved = 'notalkpage';
     }
     # Give back result to user.
     $titleObj = Title::makeTitle(NS_SPECIAL, 'Movepage');
     $success = $titleObj->getFullURL('action=success&oldtitle=' . wfUrlencode($ot->getPrefixedText()) . '&newtitle=' . wfUrlencode($nt->getPrefixedText()) . '&talkmoved=' . $talkmoved);
     $wgOut->redirect($success);
 }
示例#5
0
/**
 * Reserve index numbers
 *
 * @param unknown_type $args XML: <reserve><page namespace="" title=""/>...</reserve> => <reserve><page namespace="" title="" titleix=""/>...</reserve>
 * @return GE_SUCCESS, GE_INVALID_ARG, GE_NOT_LOGGED_IN, GE_NOT_AUTHORIZED, GE_DB_ERROR
 */
function wfReserveIndexNumbers($args)
{
    global $wgUser, $wgAjaxCachePolicy, $wrBotUserID;
    // set cache policy
    $wgAjaxCachePolicy->setPolicy(0);
    $status = GE_SUCCESS;
    $result = '';
    if (!$wgUser->isLoggedIn()) {
        $status = GE_NOT_LOGGED_IN;
    } else {
        if (wfReadOnly() || $wgUser->getID() != $wrBotUserID) {
            $status = GE_NOT_AUTHORIZED;
        } else {
            $xml = simplexml_load_string($args);
            $dbw =& wfGetDB(DB_MASTER);
            $dbw->ignoreErrors(true);
            $dbw->begin();
            foreach ($xml->page as $page) {
                $ns = (int) $page['namespace'];
                $titleString = (string) $page['title'];
                $title = Title::newFromText($titleString, $ns);
                if (!$title) {
                    //wfDebug("wfReserve error $ns $titleString\n");
                    $status = GE_INVALID_ARG;
                    $result = '';
                    break;
                }
                $titleId = StructuredData::appendUniqueId($title, $dbw);
                if ($titleId == null) {
                    //wfDebug("wfReserve iderror $ns $titleString\n");
                    $status = GE_DB_ERROR;
                    $result = '';
                    break;
                }
                $titleString = StructuredData::escapeXml($titleString);
                $result .= "<page namespace=\"{$ns}\" title=\"{$titleString}\" titleix=\"" . StructuredData::escapeXml($titleId->getText()) . '"/>';
            }
            if ($status == GE_SUCCESS) {
                $dbw->commit();
            } else {
                $dbw->rollback();
            }
        }
    }
    // return status
    return "<reserve status=\"{$status}\">" . $result . '</reserve>';
}