/** * Show existing versions and remove form * * @global OutputPage $wgOut * @param PonyDocsProduct $product * @param mixed $manual PonyDocsManual or NULL */ private function showExistingVersions($product, $manual) { global $wgOut; $productName = $product->getShortName(); if (!is_null($manual)) { $manualName = $manual->getShortName(); } // Display existing versions $wgOut->addHTML('<h3>Existing Content</h3>'); if (is_null($manual)) { $existingVersions = $product->getStaticVersionNames(); } else { $existingVersions = $manual->getStaticVersionNames(); } if (count($existingVersions) > 0) { $wgOut->addHTML('<script type="text/javascript">function verify_delete() {return confirm("Are you sure?");}</script>'); $wgOut->addHTML('<table>'); $wgOut->addHTML('<tr><th>Version</th><th></th></tr>'); foreach ($existingVersions as $versionName) { $wgOut->addHTML("<tr>\n" . "<td>{$versionName}</td>\n" . "<td>\n" . '<form method="POST" onsubmit="return verify_delete()">' . "\n" . '<input type="submit" name="action" value="remove"/>' . "\n" . '<input type="hidden" name="product" value="' . $productName . '"/>' . "\n" . '<input type="hidden" name="version" value="' . $versionName . '"/>' . "\n"); if (!is_null($manual)) { $wgOut->addHTML('<input type="hidden" name="manual" value="' . $manualName . '"/>' . "\n"); } $wgOut->addHTML("</form>\n</td>\n</tr>\n"); } $wgOut->addHTML('</tr></table>'); } else { $wgOut->addHTML('<p>No existing version defined.</p>'); } }
/** * This loads the list of products. * * @param boolean $reload * * @return array */ public static function LoadProducts($reload = FALSE) { $dbr = wfGetDB(DB_SLAVE); /** * If we have content in our list, just return that unless $reload is true. */ if (sizeof(self::$sProductList) && !$reload) { return self::$sProductList; } self::$sProductList = array(); // Use 0 as the last parameter to enforce getting latest revision of this article. $article = new Article(Title::newFromText(PONYDOCS_DOCUMENTATION_PRODUCTS_TITLE), 0); $content = $article->getContent(); if (!$article->exists()) { // There is no products file found -- just return. return array(); } /** * The content of this topic should be of this form: * {{#product:shortName|Long Product Name|description|parent}}{{#product:anotherProduct|... */ // explode on the closing tag to get an array of products $tags = explode('}}', $content); foreach ($tags as $tag) { $tag = trim($tag); if (strpos($tag, '{{#product:') === 0) { // Remove the opening tag and prefix $product = str_replace('{{#product:', '', $tag); $parameters = explode('|', $product); $parameters = array_map('trim', $parameters); // Pad out array to avoid notices $parameters = array_pad($parameters, 5, ''); // Set static flag if defined as static $static = FALSE; if (strpos($parameters[0], PONYDOCS_PRODUCT_STATIC_PREFIX) === 0) { $parameters[0] = substr($parameters[0], strlen(PONYDOCS_PRODUCT_STATIC_PREFIX)); $static = TRUE; } // Allow admins to omit optional parameters foreach (array(1, 2, 3) as $index) { if (!array_key_exists($index, $parameters)) { $parameters[$index] = ''; } } // Avoid wedging the product page with a fatal error if shortName is omitted by some crazy nihilist if (isset($parameters[0]) && $parameters[0] != '') { $pProduct = new PonyDocsProduct($parameters[0], $parameters[1], $parameters[2], $parameters[3], $parameters[4]); $pProduct->setStatic($static); self::$sDefinedProductList[$pProduct->getShortName()] = $pProduct; self::$sProductList[$parameters[0]] = $pProduct; // Handle child products if (isset($parameters[3]) && $parameters[3] != '') { self::$sParentChildMap[$parameters[3]][] = $parameters[0]; } // Handle product categories if (isset($parameters[4]) && $parameters[4] != '') { $categories = explode(',', $parameters[4]); foreach ($categories as $category) { self::$sCategoryMap[$category][$parameters[0]] = $pProduct; } } else { self::$sCategoryMap[PONYDOCS_NO_CATEGORY][$parameters[0]] = $pProduct; } } } } return self::$sProductList; }