/** * 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, $wgUser; $this->setHeaders(); $parts = explode('/', $par); $productName = isset($parts[0]) ? $parts[0] : PonyDocsProduct::GetSelectedProduct(); $manualName = isset($parts[1]) ? $parts[1] : NULL; // Security Check $authProductGroup = PonyDocsExtension::getDerivedGroup(PonyDocsExtension::ACCESS_GROUP_PRODUCT, $productName); $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; } $product = PonyDocsProduct::GetProductByShortName($productName); $productLongName = $product->getLongName(); if (!is_null($manualName)) { $manual = PonyDocsProductManual::GetManualByShortName($productName, $manualName); $manualLongName = $manual->getLongName(); } else { $manual = NULL; } $wgOut->setPagetitle('Static Documentation Import Tool'); $h2 = "Static Documentation Import for {$productLongName}"; if (!is_null($manualName)) { $h2 .= ", {$manualLongName}"; } $wgOut->addHTML("<h2>{$h2}</h2>"); if ($this->validateProductAndManualAreStatic($product, $manual)) { if (isset($_POST['action'])) { $this->processImportForm($_POST['action'], $product, $manual); } else { $this->showImportForm($product, $manual); } } $this->showExistingVersions($product, $manual); $this->showHelpfulLinks($productName); }
/** * Handles special cases for permissions, which include: * * - Only AUTHOR group can edit/submit the manuals and versions pages. * - Only AUTHORS and EMPLOYEES can edit/submit pages in Documentation namespace. * * @param Title $title The title to test permission against. * @param User $user The user requestion the action. * @param string $action The actual action (edit, view, etc.) * @param boolean $result The result, which we store in; true=allow, false=do not. * @return boolean Return true to continue checking, false to stop checking, null to not care. */ public static function onUserCan(&$title, &$user, $action, &$result) { global $wgExtraNamespaces, $wgPonyDocsEmployeeGroup, $wgPonyDocsBaseAuthorGroup; $authProductGroup = PonyDocsExtension::getDerivedGroup(); $continueProcessing = TRUE; /** * WEB-5280 Only docteam and admin users should be able to see these pages * (Documentation:productShortName:Manuals). */ if (preg_match(PONYDOCS_PRODUCTVERSION_TITLE_REGEX, $title->__toString())) { $groups = $user->getGroups(); if (!in_array($authProductGroup, $groups) && !in_array($wgPonyDocsBaseAuthorGroup, $groups)) { $result = FALSE; $continueProcessing = FALSE; } } if (!strcmp('zipmanual', $action)) { /** * Users can only see and use "download manual as zip" link if they are a member of that product's docteam group */ $groups = $user->getGroups(); if (in_array($authProductGroup, $groups)) { $result = TRUE; $continueProcessing = FALSE; } } /** * WEB-6031 - Block access to history/diff page for non-employee **/ if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'history' || isset($_REQUEST['diff'])) { $groups = $user->getGroups(); if (!in_array($wgPonyDocsEmployeeGroup, $groups)) { $result = FALSE; $continueProcessing = FALSE; } } if (!strcmp('edit', $action) || !strcmp('submit', $action)) { $groups = $user->getGroups(); /** *WEB-5278 - Documentation:Products should be editable by docteam */ if (!strcmp(PONYDOCS_DOCUMENTATION_PRODUCTS_TITLE, $title->__toString())) { if (!in_array($wgPonyDocsBaseAuthorGroup, $groups)) { $result = FALSE; $continueProcessing = FALSE; } } elseif (preg_match(PONYDOCS_PRODUCTVERSION_TITLE_REGEX, $title->__toString()) || preg_match(PONYDOCS_PRODUCTMANUAL_TITLE_REGEX, $title->__toString())) { if (in_array($authProductGroup, $groups)) { $result = TRUE; $continueProcessing = FALSE; } } elseif ($title->getNamespace() == NS_PONYDOCS || !strcmp($title->__toString(), PONYDOCS_DOCUMENTATION_NAMESPACE_NAME)) { /** * Allow edits for employee or authors/docteam group only. */ if (in_array($authProductGroup, $groups) || in_array($wgPonyDocsEmployeeGroup, $groups)) { $result = TRUE; $continueProcessing = FALSE; } } } return $continueProcessing; }
/** * 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; }
/** * Populate toolbox link set and return. Should be based on user groups/access. Only used if MediaWiki:Sidebar is EMPTY. * * @return array */ public function generateSideBar() { global $wgArticlePath, $wgScriptPath, $wgUser, $wgPonyDocsEmployeeGroup; $authProductGroup = PonyDocsExtension::getDerivedGroup(PonyDocsExtension::ACCESS_GROUP_PRODUCT); $g = $wgUser->getAllGroups(); $sidebar = array('navigation' => array(array('text' => 'Main Page', 'href' => str_replace('$1', 'Main_Page', $wgArticlePath)), array('text' => 'Help', 'href' => str_replace('$1', 'helppage', $wgArticlePath)))); /** * Show Special pages if employee or author. */ if (in_array($authProductGroup, $g) || in_array($wgPonyDocsEmployeeGroup, $g)) { $sidebar['navigation'][] = array('text' => 'Special Pages', 'href' => str_replace('$1', 'Special:Specialpages', $wgArticlePath)); } /** * TOC List Mgmt if author. */ if (in_array($authorGroupByProduct, $g)) { $sidebar['navigation'][] = array('text' => 'TOC List Mgmt', 'href' => str_replace('$1', 'Special:TOCList', $wgArticlePath)); } //echo '<pre>'; print_r( $sidebar ); die( ); return $sidebar; }
/** * Return an array listing versions in ascending order that the current user has access to based on group membership. * - sysop/author/employee: All. * - user: All released and preview versions. * - anon: All released versions. * * Result is a mapping of version name to PonyDocsProductVersion objects. * * @FIXME: I don't think we need this? * The LoadVersions() method only loads versions from the defined list based on the user's permissions anyway. * * @static * @return array Map of PonyDocsProductVersion instances (name => object). */ public static function GetVersionsForUser($productName) { global $wgPonyDocsEmployeeGroup, $wgUser; $groups = $wgUser->getGroups(); $authProductGroup = PonyDocsExtension::getDerivedGroup(PonyDocsExtension::ACCESS_GROUP_PRODUCT, $productName); $authPreviewGroup = PonyDocsExtension::getDerivedGroup(PonyDocsExtension::ACCESS_GROUP_VERSION, $productName); if (in_array($authProductGroup, $groups) || in_array($wgPonyDocsEmployeeGroup, $groups) || PonyDocsCrawlerPassthrough::isAllowedCrawler()) { return self::$sVersionMap[$productName]; } elseif (in_array($authPreviewGroup, $groups)) { $retList = array(); foreach (self::$sVersionMap[$productName] as $pVersion) { if ($pVersion->getStatusCode() == self::STATUS_RELEASED || $pVersion->getStatusCode() == self::STATUS_PREVIEW) { $retList[] = $pVersion; } } return $retList; } else { return self::$sVersionMapReleased[$productName]; } }
/** * Update the nav URLs (toolbox) to include certain special pages for authors and bureaucrats. */ private function navURLS() { global $wgArticlePath, $wgTitle, $wgUser; $groups = $wgUser->getGroups(); $authProductGroup = PonyDocsExtension::getDerivedGroup(); if (in_array('bureaucrat', $groups) || in_array($authProductGroup, $groups)) { $this->data['nav_urls']['special_doctopics'] = array('href' => str_replace('$1', 'Special:DocTopics', $wgArticlePath), 'text' => 'Document Topics'); $this->data['nav_urls']['special_tocmgmt'] = array('href' => str_replace('$1', 'Special:TOCList', $wgArticlePath), 'text' => 'TOC Management'); $this->data['nav_urls']['documentation_manuals'] = array('href' => str_replace('$1', PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':Manuals', $wgArticlePath), 'text' => 'Manuals'); $partialUrl = SpecialDocumentLinks::getDocumentLinksArticle(); $this->data['nav_urls']['document_links'] = array('href' => str_replace('$1', 'Special:SpecialDocumentLinks?t=' . $wgTitle->getNsText() . ':' . $partialUrl, $wgArticlePath), 'text' => 'Document Links'); } }
/** * 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; }