/** * This is called upon loading the special page. It should write output to the page with $wgOut. * @param string $par the URL path following the special page name */ public function execute($par) { global $wgOut, $wgArticlePath; $dbr = wfGetDB(DB_SLAVE); $this->setHeaders(); /** * We need to select ALL pages of the form: * Documentation:<productShortName>:<manualShortName>TOC* * We should group these by manual and then by descending version order. The simplest way is by assuming that every TOC * page is linked to at least one version (category) and thus has an entry in the categorylinks table. So to do this we * must run this query for each manual type, which involes getting the list of manuals defined. */ $out = array(); // Added for WEB-10802, looking for product name passed in // e.g. /Special:TOCList/Splunk $parts = explode('/', $par); if (isset($parts[0]) && is_string($parts[0]) and $parts[0] != '') { $productName = $parts[0]; } else { $productName = PonyDocsProduct::GetSelectedProduct(); } $manuals = PonyDocsProductManual::GetDefinedManuals($productName); $allowed_versions = array(); $product = PonyDocsProduct::GetProductByShortName($productName); $wgOut->setPagetitle('Table of Contents Management'); if ($product) { $wgOut->addHTML('<h2>Table of Contents Management Pages for ' . $product->getLongName() . '</h2>'); foreach (PonyDocsProductVersion::GetVersions($productName) as $v) { $allowed_versions[] = $v->getVersionName(); } foreach ($manuals as $pMan) { $res = $dbr->select(array('categorylinks', 'page'), array('page_title', 'GROUP_CONCAT( cl_to separator "|") categories'), array('cl_from = page_id', 'page_namespace = "' . NS_PONYDOCS . '"', "page_title LIKE '" . $dbr->strencode("{$productName}:" . $pMan->getShortName()) . "TOC%'", 'cl_to LIKE "V:%:%"', 'cl_type = "page"'), __METHOD__, array('GROUP BY' => 'page_title')); while ($row = $dbr->fetchObject($res)) { $versions = array(); $categories = explode('|', $row->categories); foreach ($categories as $category) { $categoryParts = explode(':', $category); if (in_array($categoryParts[2], $allowed_versions)) { $versions[] = $categoryParts[2]; } } if (sizeof($versions)) { $wgOut->addHTML('<a href="' . str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ":{$row->page_title}", $wgArticlePath) . '">' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ":{$row->page_title}" . '</a> - Versions: ' . implode(' | ', $versions) . '<br />'); } } } $html = '<h2>Other Useful Management Pages</h2>' . '<a href="' . str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':' . $productName . PONYDOCS_PRODUCTVERSION_SUFFIX, $wgArticlePath) . '">Version Management</a> - Define and update available ' . $productName . ' versions.<br />' . '<a href="' . str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':' . $productName . PONYDOCS_PRODUCTMANUAL_SUFFIX, $wgArticlePath) . '">Manuals Management</a> - Define the list of available manuals for the Documentation namespace.' . '<br/><br/>'; $wgOut->addHTML($html); } else { $wgOut->addHTML("<h2>Table of Contents Management Page</h2>Error: Product {$productName} does not exist."); } }
/** * When an article is fully saved, we want to update the doclinks for that * article in our doclinks table. Only if it's in the documentation * namepsace, however. * * @param WikiPage $article * @param User $user * @param string $text * @param string $summary * @param boolean $minor * @param boolean $watch * @param $sectionanchor * @param integer $flags * @param Revision $revision * @param Status $status * @param integer $baseRevId * * @deprecated Replace with PageContentSaveComplete hook * */ public static function onArticleSaveComplete(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { $title = $article->getTitle(); $realArticle = Article::newFromWikiPage($article, RequestContext::getMain()); // Update doc links PonyDocsExtension::updateOrDeleteDocLinks("update", $realArticle, $text); if (!preg_match('/^' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':/i', $title->__toString(), $matches)) { return TRUE; } // Okay, article is in doc namespace // Now we need to remove any pdf books for this topic. // Since the person is editing the article, it's safe to say that the // version and manual can be fetched from the classes and not do any // manipulation on the article itself. $productName = PonyDocsProduct::GetSelectedProduct(); $product = PonyDocsProduct::GetProductByShortName($productName); $version = PonyDocsProductVersion::GetSelectedVersion($productName); $manual = PonyDocsProductManual::GetCurrentManual($productName, $title); if ($manual != null) { // Then we are in the documentation namespace, but we're not part of // manual. // Clear any PDF for this manual PonyDocsPdfBook::removeCachedFile($productName, $manual->getShortName(), $version); } // Clear all TOC cache entries for each version. // Dangerous. Only set the flag if you know that you should be skipping this processing. // Currently used for branch/inherit. if ($manual && !PonyDocsExtension::isSpeedProcessingEnabled()) { // Clear any TOC cache entries this article may be related to. $topic = new PonyDocsTopic($realArticle); $manVersionList = $topic->getProductVersions(); foreach ($manVersionList as $version) { PonyDocsTOC::clearTOCCache($manual, $version, $product); PonyDocsProductVersion::clearNAVCache($version); } } PonyDocsExtension::clearArticleCategoryCache($realArticle); // if this is product versions or manuals page, clear navigation cache if (preg_match(PONYDOCS_PRODUCTVERSION_TITLE_REGEX, $title->__toString(), $matches) || preg_match(PONYDOCS_PRODUCTMANUAL_TITLE_REGEX, $title->__toString(), $matches)) { // reload to get updated version list PonyDocsProductVersion::LoadVersionsForProduct($productName, true); $prodVersionList = PonyDocsProductVersion::GetVersions($productName); foreach ($prodVersionList as $version) { PonyDocsProductVersion::clearNAVCache($version); } } return true; }
/** * Branches a topic from a source title to a target title. * * @param $topicTitle string The name of the internal topic. * @param $version PonyDocsVersion The target Version * @param $tocSection The TOC section this title resides in. * @param $tocTitle The toc title that references this topic. * @param $deleteExisting boolean Should we purge any existing conflicts? * @param $split Should we create a new page? * @returns boolean */ static function branchTopic($topicTitle, $version, $tocSection, $tocTitle, $deleteExisting, $split) { // Clear any hooks so no weirdness gets called after we create the // branch $wgHooks['ArticleSave'] = array(); if (!preg_match('/^' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':([^:]*):([^:]*):(.*):([^:]*)$/', $topicTitle, $match)) { throw new Exception("Invalid Title to Branch From"); } $productName = $match[1]; $manualName = $match[2]; $title = $match[3]; // Get the PonyDocsProduct and PonyDocsProductManual $product = PonyDocsProduct::GetProductByShortName($productName); $manual = PonyDocsProductManual::GetManualByShortName($productName, $manualName); // Get conflicts. $conflicts = self::getConflicts($product, $topicTitle, $version); if (!empty($conflicts)) { if ($deleteExisting && !$split) { // We want to purge each conflicting title completely. foreach ($conflicts as $conflict) { $article = new Article(Title::newFromText($conflict)); if (!$article->exists()) { // Article doesn't exist. Should never occur, but if it doesn't, no big deal since it was a conflict. continue; } if ($conflict == $topicTitle) { // Then the conflict is same as source material, do nothing. continue; } else { // Do actual delete. $article->doDelete("Requested purge of conficting article when branching topic " . $topicTitle . " with version: " . $version->getVersionName(), false); } } } elseif (!$split) { // Ruh oh, there's conflicts and we didn't want to purge or split. Cancel out. throw new Exception("When calling branchTitle, there were conflicts and purge was not requested and we're not splitting."); } } // Load existing article to branch from $existingArticle = PonyDocsArticleFactory::getArticleByTitle($topicTitle); if (!$existingArticle->exists()) { // No such title exists in the system throw new Exception("Invalid Title to Branch From. Target Article does not exist:" . $topicTitle); } $title = PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':' . $product->getShortName() . ':' . $manual->getShortName() . ':' . $title . ':' . $version->getVersionName(); $newArticle = PonyDocsArticleFactory::getArticleByTitle($title); if ($newArticle->exists()) { throw new Exception("Article already exists:" . $title); } // Copy content $existingContent = $existingArticle->getContent(); $newContent = $existingContent; // Build the versions which will go into the new array. $newVersions = array(); // Text representation of the versions $newVersions[] = $version->getVersionName(); if ($split) { // We need to get all versions from PonyDocsVersion $rawVersions = PonyDocsProductVersion::GetVersions($productName); $existingVersions = array(); foreach ($rawVersions as $rawVersion) { $existingVersions[] = $rawVersion->getVersionName(); } // $existingVersions is now an array of version names in incremental order $versionIndex = array_search($version->getVersionName(), $existingVersions); // versionIndex is the index where our target version is // we will use this to determine what versions need to be brought over. preg_match_all("/\\[\\[Category:V:([^\\]]*):([^\\]]*)\\]\\]/", $existingContent, $matches); foreach ($matches[2] as $match) { $index = array_search($match, $existingVersions); if ($index > $versionIndex) { $newVersions[] = $match; } } } // $newVersions contains all the versions that need to be pulled from the existing Content and put into the new content. // So let's now remove it form the original content foreach ($newVersions as $tempVersion) { $existingContent = preg_replace("/\\[\\[Category:V:" . $productName . ":" . $tempVersion . "\\]\\]/", "", $existingContent); } // Now let's do the edit on the original content. // Set version and manual $existingArticle->doEdit($existingContent, "Removed versions from existing article when branching Topic " . $topicTitle, EDIT_UPDATE); // Clear categories tags from new article content $newContent = preg_replace("/\\[\\[Category:V:([^\\]]*)]]/", "", $newContent); // add new category tags to new content foreach ($newVersions as $version) { $newContent .= "[[Category:V:" . $productName . ":" . $version . "]]"; } $newContent .= "\n"; // doEdit on new article $newArticle->doEdit($newContent, "Created new topic from branched topic " . $topicTitle, EDIT_NEW); return $title; }
/** * This is called upon loading the special page. It should write output to * the page with $wgOut */ public function execute() { global $wgOut, $wgArticlePath, $wgScriptPath, $wgUser; global $wgRequest; global $wgDBprefix; $currentProduct = ''; $currentVersion = ''; $collapseAll = FALSE; $dbr = wfGetDB(DB_SLAVE); // Set headers and title of the page, get value of "t" from GET/POST $this->setHeaders(); $title = $wgRequest->getVal('t'); if (empty($title)) { $wgOut->setPagetitle("Documentation Linkage"); $wgOut->addHTML('No topic specified.'); return; } $wgOut->setPagetitle("Documentation Linkage For " . $title); // Parse "t" (the title we're looking for inbound links to) // Find titles for all inherited versions, etc. $titlePieces = explode(':', $title); $plainTitle = $title; // Create a new Title from text, such as what one would find in a link. Decodes any HTML entities in the text. $title = Title::newFromText($title); $toUrls = array(); // Do PonyDocs-specific stuff (loop through all inherited versions) if ($titlePieces[0] == PONYDOCS_DOCUMENTATION_NAMESPACE_NAME) { // Get all the versions in the product $versions = PonyDocsProductVersion::LoadVersionsForProduct($titlePieces[1], true); if (empty($versions)) { error_log('WARNING [PonyDocs] [' . __CLASS__ . '] Unable to find product versions for this topic: ' . $title); } $currentProduct = $titlePieces[1]; $currentVersion = $titlePieces[4]; // Get the latest released version of this product $latestVersionObj = PonyDocsProductVersion::GetLatestReleasedVersion($titlePieces[1]); if (is_object($latestVersionObj)) { $latestVersion = $latestVersionObj->getVersionName(); } else { error_log('WARNING [PonyDocs] [' . __CLASS__ . '] Unable to find latest released version of ' . $titlePieces[1]); } // Generate a title without the version so we can dynamically generate a list of titles with all inherited versions $titleNoVersion = $titlePieces[0] . ":" . $titlePieces[1] . ":" . $titlePieces[2] . ":" . $titlePieces[3]; // Search the database for matching to_links for each inherited version if (is_array($versions)) { foreach ($versions as $ver) { // Add this URL to array of URLs to search db for $toUrls[] = PonyDocsExtension::translateTopicTitleForDocLinks($titleNoVersion, NULL, $ver); // Compare this version with latest version. If they're the same, add the URL with "latest" too. $thisVersion = $ver->getVersionName(); if ($thisVersion == $latestVersion) { $titleLatestVersion = $titlePieces[0] . ':' . $titlePieces[1] . ':' . $titlePieces[2] . ':' . $titlePieces[3] . ':latest'; $toUrls[] = PonyDocsExtension::translateTopicTitleForDocLinks($titleLatestVersion); } } } else { error_log('WARNING [PonyDocs] [' . __CLASS__ . '] Unable to find versions for ' . $title); } } else { // Do generic mediawiki stuff for non-PonyDocs namespaces $collapseAll = TRUE; $toUrls[] = PonyDocsExtension::translateTopicTitleForDocLinks($title); } // Query the database for the list of toUrls we've collated if (!empty($toUrls)) { foreach ($toUrls as &$toUrl) { $toUrl = $dbr->strencode($toUrl); } $inUrls = "'" . implode("','", $toUrls) . "'"; $query = "SELECT * FROM " . $wgDBprefix . "ponydocs_doclinks WHERE to_link IN ({$inUrls})"; $results = $dbr->query($query); } // Create array of links, sorted by product and version $links = array(); // Loop through results and save into handy dandy links array if (!empty($results)) { foreach ($results as $result) { $fromProduct = ''; $fromVersion = ''; $displayUrl = ''; if (strpos($result->from_link, PONYDOCS_DOCUMENTATION_NAMESPACE_NAME) !== false) { // If this is a PonyDocs style links, with slashes, // save product, version, display URL accordingly. $pieces = explode('/', $result->from_link); $fromProduct = $pieces[1]; $fromVersion = $pieces[2]; $displayUrl = $result->from_link; } else { // If this is a generic mediawiki style link, with colons (or not), // set product to the namespace, and remove namespace // from the display URL. Leave version blank. if (strpos($result->from_link, ':') !== false) { $pieces = explode(':', $result->from_link); $fromProduct = $pieces[0]; // The "product" will be the namespace $displayUrl = $pieces[1]; // So the namespace doesn't show in every URL } else { // it's possible to have a link with no colons $fromProduct = 'Other'; // No namespace, so the "product" will be the string "Other" $displayUrl = $result->from_link; } $fromVersion = 'None'; // No concept of versions outside of PonyDocs } // Put all this stuff in an array that we can use to generate HTML $links[$fromProduct][$fromVersion][] = array('from_link' => $result->from_link, 'to_link' => $result->to_link, 'display_url' => $displayUrl); } } // Make HTML go! ob_start(); ?> <div class="doclinks"> <h2>Inbound links to <?php echo $plainTitle; ?> from other topics.</h2> <?php // If there are no links, display a message saying as much if (empty($links)) { ?> <p>No links to <?php echo $plainTitle; ?> (and its inherited versions) from other topics.</p> <?php } else { // Display all links, ordered by product then version foreach ($links as $fromProduct => $fromVersions) { // If this is a PonyDocs Product if (PonyDocsProduct::IsProduct($fromProduct)) { // Get versions for this product, so we can display the versions in the correct order PonyDocsProductVersion::LoadVersionsForProduct($fromProduct, true); $fromProductVersions = PonyDocsProductVersion::GetVersions($fromProduct); // If there are no valid versions for this product/user, then skip the product name header. if (!count($fromProductVersions)) { continue; } ?> <h2><?php echo $fromProduct; ?> </h2> <?php foreach ($fromProductVersions as $fromProductVersionObj) { $fromProductVersionName = $fromProductVersionObj->getVersionName(); // If there are doclinks from this version, print them if (array_key_exists($fromProductVersionName, $fromVersions)) { // Expand containers of incoming links from the current Product and Version // Expand containers of incoming links from other Products // But don't expand any containers if this is not a PonyDocs product $selected = ''; if (($currentProduct != $fromProduct || $currentVersion == $fromProductVersionName) && !$collapseAll) { $selected = 'selected'; } ?> <h3 class="doclinks-collapsible <?php print $selected; ?> "> <?php echo $fromProduct . ' ' . $fromProductVersionName; ?> </h3> <ul> <?php foreach ($fromVersions[$fromProductVersionName] as $linkAry) { ?> <li> <a href="<?php echo str_replace('$1', $linkAry['from_link'], $wgArticlePath); ?> "> <?php echo $linkAry['display_url']; ?> </a> </li> <?php } ?> </ul> <?php } } } else { ?> <h2><?php echo $fromProduct; ?> </h2> <h3 class="doclinks-collapsible selected">Latest</h3> <?php // This is not a PonyDocs product, don't worry about sorting foreach ($fromVersions as $fromVersion => $fromVersionData) { ?> <ul> <?php foreach ($fromVersionData as $linkAry) { ?> <li> <a href="<?php echo str_replace('$1', $linkAry['from_link'], $wgArticlePath); ?> "> <?php echo $linkAry['display_url']; ?> </a> </li> <?php } ?> </ul> <?php } } } } ?> </div> <?php $htmlContent = ob_get_contents(); ob_end_clean(); $wgOut->addHTML($htmlContent); return true; }
/** * This is called upon loading the special page. It should write output to the page with $wgOut. */ public function execute() { global $wgOut, $wgArticlePath, $wgScriptPath; global $wgUser; $dbr = wfGetDB(DB_SLAVE); $this->setHeaders(); $wgOut->setPagetitle('Documentation Rename Version'); $forceProduct = PonyDocsProduct::GetSelectedProduct(); $ponydocs = PonyDocsWiki::getInstance($forceProduct); $products = $ponydocs->getProductsForTemplate(); // Security Check $authProductGroup = PonyDocsExtension::getDerivedGroup(PonyDocsExtension::ACCESS_GROUP_PRODUCT, $forceProduct); $groups = $wgUser->getGroups(); if (!in_array($authProductGroup, $groups)) { $wgOut->addHTML('<p>Sorry, but you do not have permission to access this Special page.</p>'); return; } ob_start(); // Grab all versions available for product // We need to get all versions from PonyDocsProductVersion $versions = PonyDocsProductVersion::GetVersions($forceProduct); ?> <input type="hidden" id="force_product" value="<?php echo $forceProduct; ?> " /> <div id="renameversion"> <a name="top"></a> <div class="versionselect"> <h1>Rename Version Console</h1> Select product, source version, and target version. You will be able to approve the list of manuals to rename before you launch the process. <h2>Choose a Product</h2> <?php if (!count($products)) { print "<p>No products defined.</p>"; } else { ?> <div class="product"> <select id="docsProductSelect1" name="selectedProduct" onChange="AjaxChangeProduct1();"> <?php foreach ($products as $idx => $data) { echo '<option value="' . $data['name'] . '" '; if (!strcmp($data['name'], $forceProduct)) { echo 'selected'; } echo '>' . $data['label'] . '</option>'; } ?> </select> </div> <script language="javascript"> function AjaxChangeProduct1_callback( o ) { document.getElementById( 'docsProductSelect1' ).disabled = true; var s = new String( o.responseText ); document.getElementById( 'docsProductSelect1' ).disabled = false; window.location.href = s; } function AjaxChangeProduct1() { var productIndex = document.getElementById( 'docsProductSelect1' ).selectedIndex; var product = document.getElementById( 'docsProductSelect1' )[productIndex].value; var title = '<?php echo $_SERVER['REQUEST_URI']; ?> '; // TODO fix this title var force = true; sajax_do_call( 'efPonyDocsAjaxChangeProduct', [product, title, force], AjaxChangeProduct1_callback, true); } </script> <?php } ?> <h2>Choose a Source Version</h2> <select name="version" id="versionselect_sourceversion"> <?php foreach ($versions as $version) { ?> <option value="<?php echo $version->getVersionName(); ?> "> <?php echo $version->getVersionName() . " - " . $version->getVersionStatus(); ?> </option> <?php } ?> </select> <h2>Choose a Target Version</h2> <select name="version" id="versionselect_targetversion"> <?php foreach ($versions as $version) { ?> <option value="<?php echo $version->getVersionName(); ?> "> <?php echo $version->getVersionName() . " - " . $version->getVersionStatus(); ?> </option> <?php } ?> </select> <div> <input type="button" id="versionselect_submit" value="Fetch Manuals" /> </div> </div> <div class="submitrequest" style="display: none;"> <div id="manuallist"></div> <input type="button" id="renameversion_submit" value="Rename Version" /> <div id="progressconsole"></div> </div> <div class="completed" style="display: none;"> <p class="summary"> <strong>Source Version:</strong> <span class="sourceversion"></span> <strong>Target Version:</strong> <span class="targetversion"></span> </p> <h2>Process Complete</h2> The following is the log of the processed job. Look it over for any potential issues that may have occurred during the Rename Version job. <div> <div class="logconsole" style="font-family: monospace; font-size: 10px;"></div> </div> </div> </div> <?php $buffer = ob_get_clean(); $wgOut->addHTML($buffer); return TRUE; }
/** * This returns the list of available versions for template output in a more useful way for templates. It is a simple list * with each element being an associative array containing two keys: name and status. * * @FIXME: If a version has NO defined manuals (i.e. no TOC pages for a manual tagged to it) it should be REMOVED from this * list. * * @return array */ public function getVersionsForProduct($productName) { $dbr = wfGetDB(DB_SLAVE); $version = PonyDocsProductVersion::GetVersions($productName); $validVersions = $out = array(); /** * This should give us one row per version which has 1 or more TOCs tagged to it. So basically, if its not in this list * it should not be displayed. */ $res = PonyDocsCategoryLinks::getTOCCountsByProductVersion($productName); while ($row = $dbr->fetchObject($res)) { $validVersions[] = $row->cl_to; } foreach ($version as $v) { /** * Only add it to our available list if its in our list of valid versions. * NOTE disabled for now */ //if( in_array( 'V:' . $v->getVersionName( ), $validVersions )) $out[] = array('name' => $v->getVersionName(), 'status' => $v->getVersionStatus()); } return $out; }
/** * This is a callback for usort() which compares two versions to determine which is earlier. * It is passed two PonyDocsProductVersion instances and returns * -1 if $vA is earlier than $vB, 0 if they are the same, and 1 if $vB is earlier than $vA. * You can then use usort( $versionList, _ponydocs_versionCmp )and $versionList will come back sorted. * * @param PonyDocsProductVersion $vA First version to compare. * @param PonyDocsProductVersion $vB Second version to compare. * @return integer */ function PonyDocs_ProductVersionCmp(PonyDocsProductVersion $vA, PonyDocsProductVersion $vB) { $versions = PonyDocsProductVersion::GetVersions($vA->getProductName()); $indexA = array_search($vA, $versions); $indexB = array_search($vB, $versions); if ($indexA == $indexB) { return 0; } return $indexA < $indexB ? -1 : 1; }
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(); }
/** * This is called upon loading the special page. It should write output to the page with $wgOut. */ public function execute() { global $wgOut, $wgArticlePath, $wgScriptPath; global $wgUser; $dbr = wfGetDB(DB_SLAVE); $this->setHeaders(); $wgOut->setPagetitle('Documentation Branch And Inheritance'); // if title is set we have our product and manual, else take selected product if (isset($_GET['titleName'])) { if (!preg_match('/' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':(.*):(.*):(.*):(.*)/', $_GET['titleName'], $match)) { throw new Exception("Invalid Title to Branch From"); } $forceProduct = $match[1]; $forceManual = $match[2]; } else { $forceProduct = PonyDocsProduct::GetSelectedProduct(); $ponydocs = PonyDocsWiki::getInstance($forceProduct); $products = $ponydocs->getProductsForTemplate(); } // Security Check $authProductGroup = PonyDocsExtension::getDerivedGroup(PonyDocsExtension::ACCESS_GROUP_PRODUCT, $forceProduct); $groups = $wgUser->getGroups(); if (!in_array($authProductGroup, $groups)) { $wgOut->addHTML("<p>Sorry, but you do not have permission to access this Special page.</p>"); return; } // Static product check if (PonyDocsProduct::GetProductByShortName($forceProduct)->isStatic()) { $wgOut->addHTML("<p>Sorry, but you cannot branch/inherit a static product.</p>"); return; } ob_start(); // Grab all versions available for product // We need to get all versions from PonyDocsProductVersion $versions = PonyDocsProductVersion::GetVersions($forceProduct); if (isset($_GET['titleName'])) { ?> <input type="hidden" id="force_titleName" value="<?php echo $_GET['titleName']; ?> " /> <input type="hidden" id="force_sourceVersion" value="<?php echo PonyDocsProductVersion::GetVersionByName($forceProduct, PonyDocsProductVersion::GetSelectedVersion($forceProduct))->getVersionName(); ?> " /> <input type="hidden" id="force_manual" value="<?php echo $forceManual; ?> " /> <?php } ?> <input type="hidden" id="force_product" value="<?php echo $forceProduct; ?> " /> <div id="docbranchinherit"> <a name="top"></a> <div class="versionselect"> <h1>Branch and Inheritance Console</h1> Begin by selecting your product, source version material and a target version below. You will then be presented with additional screens to specify branch and inherit behavior. <?php if (isset($_GET['titleName'])) { ?> <p> Requested Operation on Single Topic: <strong><?php echo $_GET['titleName']; ?> </strong> </p> <?php } ?> <h2>Choose a Product</h2> <?php if (isset($_GET['titleName'])) { ?> You have selected a product: <?php echo $forceProduct; ?> <?php } else { if (!count($products)) { print "<p>No products defined.</p>"; } else { ?> <div class="product"> <select id="docsProductSelect1" name="selectedProduct" onChange="AjaxChangeProduct1();"> <?php foreach ($products as $idx => $data) { echo '<option value="' . $data['name'] . '" '; if (!strcmp($data['name'], $forceProduct)) { echo 'selected'; } echo '>' . $data['label'] . '</option>'; } ?> </select> </div> <script language="javascript"> function AjaxChangeProduct1_callback( o ) { document.getElementById('docsProductSelect1').disabled = true; var s = new String( o.responseText ); document.getElementById('docsProductSelect1').disabled = false; window.location.href = s; } function AjaxChangeProduct1( ) { var productIndex = document.getElementById('docsProductSelect1').selectedIndex; var product = document.getElementById('docsProductSelect1')[productIndex].value; var title = '<?php echo $_SERVER['REQUEST_URI']; ?> '; // TODO fix this title var force = true; sajax_do_call( 'efPonyDocsAjaxChangeProduct', [product,title,force], AjaxChangeProduct1_callback,true); } </script> <?php } } ?> <h2>Choose a Source Version</h2> <?php // Determine if topic was set, if so, we should fetch version from currently selected version. if (isset($_GET['titleName'])) { $version = PonyDocsProductVersion::GetVersionByName($forceProduct, PonyDocsProductVersion::GetSelectedVersion($forceProduct)); ?> You have selected a topic. We are using the version you are currently browsing: <?php echo $version->getVersionName(); ?> <?php } else { ?> <select name="version" id="versionselect_sourceversion"> <?php foreach ($versions as $version) { ?> <option value="<?php echo $version->getVersionName(); ?> "><?php echo $version->getVersionName() . " - " . $version->getVersionStatus(); ?> </option> <?php } ?> </select> <?php } ?> <h2>Choose a Target Version</h2> <select name="version" id="versionselect_targetversion"> <?php foreach ($versions as $version) { ?> <option value="<?php echo $version->getVersionName(); ?> "><?php echo $version->getVersionName() . " - " . $version->getVersionStatus(); ?> </option> <?php } ?> </select> <p> <input type="button" id="versionselect_submit" value="Continue to Manuals" /> </p> </div> <div class="manualselect" style="display: none;"> <?php if (isset($_GET['titleName'])) { ?> <p> Requested Operation on Single Topic: <strong><?php echo $_GET['titleName']; ?> </strong> </p> <?php } ?> <p class="summary"> <strong>Source Version:</strong> <span class="sourceversion"></span> <strong>Target Version:</strong> <span class="targetversion"></span> </p> <h1>Choose Manuals To Branch/Inherit From</h1> <div id="manualselect_manuals"> </div> <h1>Choose Default Action For Topics</h1> <input type="radio" selected="selected" name="manualselect_action" value="ignore" id="manualselect_action_ignore"><label for="manualselect_action_ignore">Ignore - Do Nothing</label><br /> <input type="radio" name="manualselect_action" value="inherit" id="manualselect_action_inherit"><label for="manualselect_action_inherit">Inherit - Add Target Version to Existing Topic</label><br /> <input type="radio" name="manualselect_action" value="branch" id="manualselect_action_branch"><label for="manualselect_action_branch">Branch - Create a copy of existing topic with Target Version</label><br /> <br /> <input type="button" id="manualselect_submit" value="Continue to Topics" /> </div> <div class="topicactions" style="display: none;"> <?php if (isset($_GET['titleName'])) { ?> <p> Requested Operation on Single Topic: <strong><?php echo $_GET['titleName']; ?> </strong> </p> <?php } ?> <p class="summary"> <strong>Source Version:</strong> <span class="sourceversion"></span> <strong>Target Version:</strong> <span class="targetversion"></span> </p> <h1>Specify Topic Actions</h1> <div class="container"> </div> <br /> <br /> <input type="button" id="topicactions_submit" value="Process Request" /> <div id="progressconsole"></div> </div> <div class="completed" style="display: none;"> <p class="summary"> <strong>Source Version:</strong> <span class="sourceversion"></span> <strong>Target Version:</strong> <span class="targetversion"></span> </p> <h2>Process Complete</h2> The following is the log of the processed job. Look it over for any potential issues that may have occurred during the branch/inherit job. <div> <div class="logconsole" style="font-family: monospace; font-size: 10px;"> </div> </div> </div> </div> <?php $buffer = ob_get_clean(); $wgOut->addHTML($buffer); return true; }