Пример #1
0
/**
 * Our primary setup function simply handles URL rewrites for aliasing (per spec) and calls our PonyDocsWiki singleton instance
 * to ensure it runs the data retrieval functions for versions and manuals and the like. 
 */
function efPonyDocsSetup()
{
    global $wgPonyDocs, $wgScriptPath, $wgArticlePath;
    // force mediawiki to start session for anonymous traffic
    if (session_id() == '') {
        wfSetupSession();
        if (PONYDOCS_DEBUG) {
            error_log("DEBUG [" . __METHOD__ . "] started session");
        }
    }
    // Set selected product from URL
    if (preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/((index.php\\?title=)|)' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '[\\/|:]{1}([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+)[\\/|:]?/i', $_SERVER['PATH_INFO'], $match)) {
        PonyDocsProduct::SetSelectedProduct($match[3]);
    }
    // Set selected version from URL
    // - every time from /-separated title URLs
    // - only when no selected version already set from :-separated title
    $currentVersion = PonyDocsProductVersion::GetSelectedVersion(PonyDocsProduct::GetSelectedProduct(), FALSE);
    if (preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/((index.php\\?title=)|)' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+)\\/([' . PONYDOCS_PRODUCTVERSION_LEGALCHARS . ']+)/i', $_SERVER['PATH_INFO'], $match) || preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/((index.php\\?title=)|)' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+)\\/[' . PONYDOCS_PRODUCTMANUAL_LEGALCHARS . ']+TOC([' . PONYDOCS_PRODUCTVERSION_LEGALCHARS . ']+)/i', $_SERVER['PATH_INFO'], $match) || !isset($currentVersion) && preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/((index.php\\?title=)|)' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+):[' . PONYDOCS_PRODUCTMANUAL_LEGALCHARS . ']+TOC([' . PONYDOCS_PRODUCTVERSION_LEGALCHARS . ']+)/i', $_SERVER['PATH_INFO'], $match) || !isset($currentVersion) && preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/((index.php\\?title=)|)' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+):[' . PONYDOCS_PRODUCTMANUAL_LEGALCHARS . ']+:[^:]+:([' . PONYDOCS_PRODUCTVERSION_LEGALCHARS . ']+)/i', $_SERVER['PATH_INFO'], $match)) {
        $result = PonyDocsProductVersion::SetSelectedVersion($match[3], $match[4]);
        if (is_null($result)) {
            // this version isn't available to this user; go away
            $defaultRedirect = PonyDocsExtension::getDefaultUrl();
            if (PONYDOCS_DEBUG) {
                error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$defaultRedirect}");
            }
            header("Location: " . $defaultRedirect);
            exit;
        }
    }
    PonyDocsWiki::getInstance(PonyDocsProduct::GetSelectedProduct());
}
Пример #2
0
/**
 * This is called when a version change occurs in the select box.  It should update the version
 * only;  to update the page the Ajax function in JS should then refresh by using history.go(0)
 * or something along those lines, otherwise the content may reflect the old version selection.
 * 
 * @param string $version New version tag to set as current.  Should be some checking.
 * @param string $title The current title that the person resides in, if any.
 * @param boolean $force Force the change, no matter if a doc is in the same version or not
 * @return AjaxResponse
 */
function efPonyDocsAjaxChangeVersion($product, $version, $title, $force = false)
{
    global $wgArticlePath;
    $dbr = wfGetDB(DB_SLAVE);
    PonyDocsProduct::SetSelectedProduct($product);
    PonyDocsProductVersion::SetSelectedVersion($product, $version);
    $response = new AjaxResponse();
    if ($force) {
        // This is coming from the search page.  let's not do any title look up,
        // and instead just pass back the same url.
        $leadingSlash = "/";
        if (substr($title, 0, 1) == "/") {
            $leadingSlash = "";
        }
        $response->addText($leadingSlash . $title);
        // Need to make the url non-relative
        return $response;
    }
    $defaultTitle = PONYDOCS_DOCUMENTATION_NAMESPACE_NAME;
    if (preg_match('/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':(.*):(.*):(.*):(.*)/i', $title, $match)) {
        $res = $dbr->select('categorylinks', 'cl_from', array("cl_to = 'V:" . $dbr->strencode($product . ":" . $version) . "'", 'cl_type = "page"', "cl_sortkey LIKE '" . $dbr->strencode(strtoupper($product . ':' . $match[2] . ':' . $match[3])) . ":%'"), __METHOD__);
        if ($res->numRows()) {
            $response->addText(str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '/' . $product . '/' . $version . '/' . $match[2] . '/' . $match[3], $wgArticlePath));
            if (PONYDOCS_DEBUG) {
                error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect rule 1");
            }
        } else {
            // same manual/topic doesn't exist for newly selected version, redirect to default
            $response->addText(str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '/' . $product . '/' . $version, $wgArticlePath));
            if (PONYDOCS_DEBUG) {
                error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect rule 2");
            }
        }
    } elseif (preg_match('/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':(.*):(Manuals|Versions)/i', $title, $match)) {
        // this is a manuals or versions page
        $add_text = str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':' . $product . ':' . $match[2], $wgArticlePath);
        /// FIXME we probably need to clear objectcache for this [product]:Manuals page, or even better, do not cache it(?)
        $response->addText($add_text);
        if (PONYDOCS_DEBUG) {
            error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect rule 3");
        }
    } elseif (preg_match('/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/(.*)\\/(.*)\\/(.*)\\/(.*)/i', $title, $match)) {
        /**
         * Just swap out the source version tag ($match[2]) with the selected version in the output URL.
         */
        $response->addText(str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '/' . $product . '/' . $version . '/' . $match[3] . '/' . $match[4], $wgArticlePath));
        if (PONYDOCS_DEBUG) {
            error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect rule 4");
        }
    } elseif (preg_match('/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/(.*)\\/(.*)\\/(.*)/i', $title, $match)) {
        //Redirection for WEB-10264
        $response->addText(str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '/' . $product . '/' . $version . '/' . $match[3], $wgArticlePath));
        if (PONYDOCS_DEBUG) {
            error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect rule to switch versions on a static manual");
        }
    } else {
        $add_text = str_replace('$1', $defaultTitle . '/' . $product . '/' . $version, $wgArticlePath);
        $response->addText($add_text);
        if (PONYDOCS_DEBUG) {
            error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect rule 5");
        }
    }
    if (PONYDOCS_DEBUG) {
        error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] ajax redirect result " . print_r($response, true));
    }
    return $response;
}