/** * AJAX method to fetch manuals for a specified product and version * * @param $ver string The string representation of the version to retrieve * manuals for. * @returns string JSON representation of the manuals */ public static function ajaxFetchManuals($product, $ver) { PonyDocsProductVersion::LoadVersionsForProduct($product); PonyDocsProductVersion::SetSelectedVersion($product, $ver); $manuals = PonyDocsProductManual::LoadManualsForProduct($product, TRUE); $result = array(); foreach ($manuals as $manual) { if (!$manual->isStatic()) { $result[] = array("shortname" => $manual->getShortName(), "longname" => $manual->getLongName()); } } $result = json_encode($result); return $result; }
/** * Hook function which * - Sets the version correctly when editing a topic * - Redirects to the first topic in a manual if the user requested a bare manual URL * - Redirect to the landing page when there are no available versions */ public function onArticleFromTitleQuickLookup(&$title, &$article) { global $wgScriptPath; if (preg_match('/&action=edit/', $_SERVER['PATH_INFO'])) { // Check referrer and see if we're coming from a doc page. // If so, we're editing it, so we should force the version // to be from the referrer. if (preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/(\\w+)\\/((latest|[\\w\\.]*)\\/)?(\\w+)\\/?/i', $_SERVER['HTTP_REFERER'], $match)) { $targetProduct = $match[1]; $targetVersion = $match[3]; if ($targetVersion == "latest") { PonyDocsProductVersion::SetSelectedVersion($targetProduct, PonyDocsProductVersion::GetLatestReleasedVersion($targetProduct)->getVersionName()); } else { PonyDocsProductVersion::SetSelectedVersion($targetProduct, $targetVersion); } } } // Match a URL like /Documentation/PRODUCT if (preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+)$/i', $_SERVER['PATH_INFO'], $match)) { $targetProduct = $match[1]; $version = PonyDocsProductVersion::GetVersions($targetProduct, TRUE); //check for product not found if (empty($version)) { PonyDocsExtension::redirectToLandingPage(); return true; } } // Matches a URL like /Documentation/PRODUCT/VERSION/MANUAL // TODO: Should match PONYDOCS_PRODUCTMANUAL_LEGALCHARS instead of \w at the end if (preg_match('/^' . str_replace("/", "\\/", $wgScriptPath) . '\\/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . '\\/([' . PONYDOCS_PRODUCT_LEGALCHARS . ']+)\\/([' . PONYDOCS_PRODUCTVERSION_LEGALCHARS . ']+)\\/(\\w+)\\/?$/i', $_SERVER['PATH_INFO'], $match)) { $targetProduct = $match[1]; $targetVersion = $match[2]; $targetManual = $match[3]; $p = PonyDocsProduct::GetProductByShortName($targetProduct); if (!$p instanceof PonyDocsProduct) { $wgHooks['BeforePageDisplay'][] = "PonyDocsExtension::handle404"; return false; } // User wants to find first topic in a requested manual. // Load up versions PonyDocsProductVersion::LoadVersionsForProduct($targetProduct); // Determine version if ($targetVersion == '') { // No version specified, use the user's selected version $ver = PonyDocsProductVersion::GetVersionByName($targetProduct, PonyDocsProductVersion::GetSelectedVersion($targetProduct)); } else { if (strtolower($targetVersion) == "latest") { // User wants the latest version. $ver = PonyDocsProductVersion::GetLatestReleasedVersion($targetProduct); } else { // Okay, they want to get a version by a specific name $ver = PonyDocsProductVersion::GetVersionByName($targetProduct, $targetVersion); } } if (!$ver) { if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$wgScriptPath}/" . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME); } header('Location: ' . $wgScriptPath . '/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME); die; } // Okay, the version is valid, let's set the user's version. PonyDocsProductVersion::SetSelectedVersion($targetProduct, $ver->getVersionName()); PonyDocsProductManual::LoadManualsForProduct($targetProduct); $manual = PonyDocsProductManual::GetManualByShortName($targetProduct, $targetManual); if (!$manual) { // Rewrite to Main documentation if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to {$wgScriptPath}/" . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME); } header('Location: ' . $wgScriptPath . '/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME); die; } elseif (!$manual->isStatic()) { // Get the TOC out of here! heehee $toc = new PonyDocsTOC($manual, $ver, $p); list($toc, $prev, $next, $start) = $toc->loadContent(); //Added empty check for WEB-10038 if (empty($toc)) { PonyDocsExtension::redirectToLandingPage(); return FALSE; } foreach ($toc as $entry) { if (isset($entry['link']) && $entry['link'] != "") { // We found the first article in the manual with a link. // Redirect to it. if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . ":" . __LINE__ . "] redirecting to " . $entry['link']); } header("Location: " . $entry['link']); die; } } //Replace die with a warning log and redirect error_log("WARNING [" . __METHOD__ . ":" . __LINE__ . "] redirecting to " . PonyDocsExtension::getDefaultUrl()); PonyDocsExtension::redirectToLandingPage(); return FALSE; } } return TRUE; }
/** * This returns the list of available manuals (active ones) in a more useful way for templates. It is an associative array * where the key is the short name of the manual and the value is the display/long name. * * @return array */ public function getManualsForProduct($product) { PonyDocsProductVersion::LoadVersionsForProduct($product); // Dependency PonyDocsProductVersion::getSelectedVersion($product); $manuals = PonyDocsProductManual::LoadManualsForProduct($product); // Dependency $out = array(); foreach ($manuals as $m) { $out[$m->getShortName()] = $m->getLongName(); } return $out; }
function execute() { global $action, $IP, $wgArticlePath, $wgContLang, $wgExtraNamespaces, $wgRequest, $wgRevision, $wgTitle, $wgUser; PonyDocsProduct::LoadProducts(); $this->data['selectedProduct'] = PonyDocsProduct::GetSelectedProduct(); PonyDocsProductVersion::LoadVersionsForProduct($this->data['selectedProduct']); PonyDocsProductManual::LoadManualsForProduct($this->data['selectedProduct']); $ponydocs = PonyDocsWiki::getInstance($this->data['selectedProduct']); $this->data['products'] = $ponydocs->getProductsForTemplate(); $this->data['versions'] = $ponydocs->getVersionsForProduct($this->data['selectedProduct']); $this->data['namespaces'] = $wgExtraNamespaces; $this->data['selectedVersion'] = PonyDocsProductVersion::GetSelectedVersion($this->data['selectedProduct']); $this->data['pVersion'] = PonyDocsProductVersion::GetVersionByName($this->data['selectedProduct'], $this->data['selectedVersion']); if (PONYDOCS_DEBUG) { error_log("DEBUG [" . __METHOD__ . "] selected product/version is set to " . $this->data['selectedProduct'] . "/" . $this->data['selectedVersion']); } $this->data['versionurl'] = $this->data['wgScript'] . '?title=' . $this->data['thispage'] . '&action=changeversion'; $this->skin = $this->data['skin']; // TODO remove this, and replace elsewhere (template files mostly) with $this->skin $skin = $this->data['skin']; if ($this->skin->getTitle()) { $this->data['canonicalURI'] = $this->skin->getTitle()->getFullURL(); } $action = $wgRequest->getText('action'); // Suppress warnings to prevent notices about missing indexes in $this->data wfSuppressWarnings(); /** * When displaying a page we output header.php, then a sub-template, and then footer.php. The namespace * which we are in determines the sub-template, which is named 'ns<Namespace>'. It defaults to our * nsDefault.php template. */ $this->data['namespace'] = $wgContLang->getNsText($wgTitle->getNamespace()); $idx = $this->data['namespace'] ? "NS:{$this->data['namespace']}" : 'T:' . $wgTitle->__toString(); if (!isset($this->_methodMappings[$idx])) { $idx = 0; } $inDocumentation = FALSE; if ($this->data['namespace'] == PONYDOCS_DOCUMENTATION_NAMESPACE_NAME || $wgTitle->__toString() == PONYDOCS_DOCUMENTATION_NAMESPACE_NAME || preg_match('/^' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':/', $wgTitle->__toString())) { $inDocumentation = TRUE; $this->prepareDocumentation(); } $this->data['versions'] = $ponydocs->getVersionsForProduct($this->data['selectedProduct']); $this->html('headelement'); ?> <script type="text/javascript"> function AjaxChangeProduct_callback( o ) { document.getElementById( 'docsProductSelect' ).disabled = true; var s = new String( o.responseText ); document.getElementById( 'docsProductSelect' ).disabled = false; window.location.href = s; } function AjaxChangeProduct() { var productIndex = document.getElementById( 'docsProductSelect' ).selectedIndex; var product = document.getElementById( 'docsProductSelect' )[productIndex].value; var title = '<?php Xml::escapeJsString($this->data['thispage']); ?> '; sajax_do_call( 'efPonyDocsAjaxChangeProduct', [product,title], AjaxChangeProduct_callback ); } function AjaxChangeVersion_callback( o ) { document.getElementById( 'docsVersionSelect' ).disabled = true; var s = new String( o.responseText ); document.getElementById( 'docsVersionSelect' ).disabled = false; window.location.href = s; } function AjaxChangeVersion() { var productIndex = document.getElementById( 'docsProductSelect' ).selectedIndex; var product = document.getElementById( 'docsProductSelect' )[productIndex].value; var versionIndex = document.getElementById( 'docsVersionSelect' ).selectedIndex; var version = document.getElementById( 'docsVersionSelect' )[versionIndex].value; var title = '<?php Xml::escapeJsString($this->data['thispage']); ?> '; sajax_do_call( 'efPonyDocsAjaxChangeVersion', [product,version,title], AjaxChangeVersion_callback ); } function changeManual(){ var url = $( "#docsManualSelect" ).val(); if ( url != "" ){ window.location.href = url; } } </script> <div id="globalWrapper"> <div id="column-content"> <div id="content" <?php $this->html("specialpageattributes"); ?> > <a id="top"></a> <?php if ($this->data['sitenotice']) { ?> <div id="siteNotice"><?php $this->html('sitenotice'); ?> </div> <?php } ?> <?php if (!$inDocumentation) { ?> <h1 id="firstHeading" class="firstHeading"><?php $this->html('title'); ?> </h1> <?php } ?> <div id="bodyContent"> <h3 id="siteSub"><?php $this->msg('tagline'); ?> </h3> <div id="contentSub"<?php $this->html('userlangattributes'); ?> ><?php $this->html('subtitle'); ?> </div> <?php if ($this->data['undelete']) { ?> <div id="contentSub2"><?php $this->html('undelete'); ?> </div> <?php } if ($this->data['newtalk']) { ?> <div class="usermessage"><?php $this->html('newtalk'); ?> </div> <?php } if ($this->data['showjumplinks']) { ?> <div id="jump-to-nav"> <?php $this->msg('jumpto'); ?> <a href="#column-one"><?php $this->msg('jumptonavigation'); ?> </a>, <a href="#searchInput"><?php $this->msg('jumptosearch'); ?> </a> </div> <?php } // Version group message, if any if ($this->data['versionGroupMessage'] !== null) { ?> <div class="affectedVersions <?php echo implode(" ", $this->data['versionclasses']); ?> "> <p class="bannerVersion"> <?php echo $this->data['versionGroupMessage']; ?> </p> </div> <?php } ?> <!-- start content --> <?php $this->html('bodytext'); if ($this->data['catlinks']) { $this->html('catlinks'); } ?> <!-- end content --> <?php if ($this->data['dataAfterContent']) { $this->html('dataAfterContent'); } ?> <div class="visualClear"></div> </div> </div> </div> <div id="column-one"<?php $this->html('userlangattributes'); ?> > <div id="p-cactions" class="portlet"> <h5><?php $this->msg('views'); ?> </h5> <div class="pBody"> <ul><?php foreach ($this->data['content_actions'] as $key => $tab) { echo ' <li id="' . Sanitizer::escapeId("ca-{$key}") . '"'; if ($tab['class']) { echo ' class="' . htmlspecialchars($tab['class']) . '"'; } echo '><a href="' . htmlspecialchars($tab['href']) . '"'; # We don't want to give the watch tab an accesskey if the # page is being edited, because that conflicts with the # accesskey on the watch checkbox. We also don't want to # give the edit tab an accesskey, because that's fairly su- # perfluous and conflicts with an accesskey (Ctrl-E) often # used for editing in Safari. if (in_array($action, array('edit', 'submit')) && in_array($key, array('edit', 'watch', 'unwatch'))) { echo $skin->tooltip("ca-{$key}"); } else { echo Xml::expandAttributes($skin->tooltipAndAccesskeyAttribs("ca-{$key}")); } echo '>' . htmlspecialchars($tab['text']) . '</a></li>'; } ?> </ul> </div> </div> <div class="portlet" id="p-personal"> <h5><?php $this->msg('personaltools'); ?> </h5> <div class="pBody"> <ul<?php $this->html('userlangattributes'); ?> > <?php foreach ($this->data['personal_urls'] as $key => $item) { ?> <li id="<?php echo Sanitizer::escapeId("pt-{$key}"); ?> " <?php if ($item['active']) { ?> class="active" <?php } ?> > <a href="<?php echo htmlspecialchars($item['href']); ?> " <?php echo Xml::expandAttributes($skin->tooltipAndAccesskeyAttribs('pt-' . $key)); if (!empty($item['class'])) { ?> class="<?php echo htmlspecialchars($item['class']); ?> " <?php } ?> > <?php echo htmlspecialchars($item['text']); ?> </a> </li> <?php } ?> </ul> </div> </div> <div class="portlet" id="p-logo"> <a style="background-image: url(<?php $this->text('logopath'); ?> );" href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href']); ?> " <?php echo Xml::expandAttributes($skin->tooltipAndAccesskeyAttribs('p-logo')); ?> ></a><br /> </div> <script type="<?php $this->text('jsmimetype'); ?> "> if ( window.isMSIE55 ) { fixalpha(); } </script> <div id="p-documentation" class="portlet"> <h5>documentation</h5> <div id="documentationBody" class="pBody"> <?php if (!count($this->data['products'])) { ?> <p>No products defined.</p> <?php } else { ?> <div class="product"> <label for='docsProductSelect' class="navlabels">Product: </label><br /> <select id="docsProductSelect" name="selectedProduct" onChange="AjaxChangeProduct();"> <?php $this->hierarchicalProductSelect(); ?> </select> </div> <?php $versions = PonyDocsProductVersion::GetVersions($this->data['selectedProduct'], TRUE); if (!count($versions)) { ?> <p>No Product Versions Defined.</p> <?php } else { $manuals = PonyDocsProductManual::GetDefinedManuals($this->data['selectedProduct'], TRUE); if (!count($manuals)) { ?> <p>The product manual you requested is not defined, you are not logged in, or you do not have the correct permissions to view this content.</p> <?php } else { ?> <p> <div class="productVersion"> <?php // do quick manip $found = FALSE; for ($i = count($this->data['versions']) - 1; $i >= 0; $i--) { $this->data['versions'][$i]['label'] = $this->data['versions'][$i]['name']; if (!$found && $this->data['versions'][$i]['status'] == "released") { $this->data['versions'][$i]['label'] .= " (latest release)"; $found = TRUE; } } ?> <label for='docsVersionSelect' class="navlabels">Product version: </label><br /> <select id="docsVersionSelect" name="selectedVersion" onChange="AjaxChangeVersion();"> <?php foreach ($this->data['versions'] as $idx => $data) { echo '<option value="' . $data['name'] . '" '; if (!strcmp($data['name'], $this->data['selectedVersion'])) { echo 'selected'; } echo '>' . $data['label'] . '</option>'; } ?> </select> </div> <div class="productManual"> <label for="docsManualSelect" class="navlabels">Select manual: </label><br /> <select id="docsManualSelect" name="selectedManual" onChange="changeManual();"> <?php $navData = PonyDocsExtension::fetchNavDataForVersion($this->data['selectedProduct'], $this->data['selectedVersion']); print "<option value=''>Pick One...</option>"; //loop through nav array and look for current URL foreach ($navData as $manual) { $selected = ""; if (!strcmp($this->data['manualname'], $manual['longName'])) { $selected = " selected "; } print "<option value='" . $manual['firstUrl'] . "' {$selected}>"; print $manual['longName']; print "<!-- categories: {$manual['categories']} -->"; print '</option>'; } ?> </select> </div> </p> <p> <?php if (sizeof($this->data['manualtoc'])) { ?> <p> <a href="<?php echo str_replace('$1', '', $wgArticlePath); ?> index.php?title=<?php echo $wgTitle->__toString(); ?> &action=pdfbook">Pdf Version</a> </p> <?php $inUL = FALSE; $listid = ""; foreach ($this->data['manualtoc'] as $idx => $data) { if (0 == $data['level']) { if ($inUL) { echo '</ul></div>'; $inUL = FALSE; } $listid = "list" . $idx; echo '<div class="wikiSidebarBox collapsible">'; echo '<h3>' . $data['text'] . '</h3>'; echo '<ul>'; $inUL = TRUE; } elseif (1 == $data['level']) { if ($data['current']) { echo '<li class="expanded">' . $data['text'] . '</li>'; } else { echo '<li><a href="' . wfUrlencode($data['link']) . '">' . $data['text'] . '</a></li>'; } } else { if ($data['current']) { echo '<li class="expanded" style="margin-left: 13px;">' . $data['text'] . '</li>'; } else { echo '<li style="margin-left: 13px;"><a href="' . wfUrlencode($data['link']) . '">' . $data['text'] . '</a></li>'; } } } if ($inUL) { echo '</ul></div>'; } } ?> </p> <?php } } } ?> </div> </div> <?php $sidebar = $this->data['sidebar']; if (!isset($sidebar['SEARCH'])) { $sidebar['SEARCH'] = TRUE; } if (!isset($sidebar['TOOLBOX'])) { $sidebar['TOOLBOX'] = TRUE; } if (!isset($sidebar['LANGUAGES'])) { $sidebar['LANGUAGES'] = TRUE; } foreach ($sidebar as $boxName => $cont) { if ($boxName == 'SEARCH') { $this->searchBox(); } elseif ($boxName == 'TOOLBOX') { $this->toolbox(); } elseif ($boxName == 'LANGUAGES') { $this->languageBox(); } else { $this->customBox($boxName, $cont); } } ?> </div><!-- end of the left (by default at least) column --> <div class="visualClear"></div> <div id="footer"<?php $this->html('userlangattributes'); ?> > <?php if ($this->data['poweredbyico']) { ?> <div id="f-poweredbyico"><?php $this->html('poweredbyico'); ?> </div> <?php } if ($this->data['copyrightico']) { ?> <div id="f-copyrightico"><?php $this->html('copyrightico'); ?> </div> <?php } // Generate additional footer links $footerlinks = array('lastmod', 'viewcount', 'numberofwatchingusers', 'credits', 'copyright', 'privacy', 'about', 'disclaimer', 'tagline'); $validFooterLinks = array(); foreach ($footerlinks as $aLink) { if (isset($this->data[$aLink]) && $this->data[$aLink]) { $validFooterLinks[] = $aLink; } } if (count($validFooterLinks) > 0) { ?> <ul id="f-list"> <?php foreach ($validFooterLinks as $aLink) { if (isset($this->data[$aLink]) && $this->data[$aLink]) { ?> <li id="<?php echo $aLink; ?> "><?php $this->html($aLink); ?> </li> <?php } } ?> </ul> <?php } ?> </div> </div> <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?> <?php $this->html('reporttime'); ?> <?php if ($this->data['debug']) { ?> <!-- Debug output: <?php $this->text('debug'); ?> --> <?php } ?> </body> </html> <?php wfRestoreWarnings(); }