Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * This loads the list of manuals BASED ON whether each manual defined has a TOC defined for the
  * currently selected version or not.
  *
  * @param boolean $reload
  * @return array
  */
 public static function LoadManualsForProduct($productName, $reload = false)
 {
     $dbr = wfGetDB(DB_SLAVE);
     /**
      * If we have content in our list, just return that unless $reload is true.
      */
     if (isset(self::$sManualList[$productName]) && sizeof(self::$sManualList[$productName]) && !$reload) {
         return self::$sManualList[$productName];
     }
     self::$sManualList[$productName] = array();
     self::$sCategoryMap[$productName] = array();
     // Use 0 as the last parameter to enforce getting latest revision of this article.
     $article = new Article(Title::newFromText(PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':' . $productName . PONYDOCS_PRODUCTMANUAL_SUFFIX), 0);
     $content = $article->getContent();
     if (!$article->exists()) {
         /**
          * There is no manuals file found -- just return.
          */
         return array();
     }
     /**
      * The content of this topic should be of this form:
      * {{#manual:shortName|longName}}
      * ...
      * 
      * There is a user defined parser hook which converts this into useful output when viewing as well.
      * 
      * Then query categorylinks to only add the manual if it is for the selected product and has a tagged TOC file with the selected version.
      * Otherwise, skip it!
      */
     // Explode on the closing tag to get an array of manual tags
     $tags = explode('}}', $content);
     foreach ($tags as $tag) {
         $tag = trim($tag);
         if (strpos($tag, '{{#manual:') === 0) {
             // Remove the opening tag and prefix
             $manual = str_replace('{{#manual:', '', $tag);
             $parameters = explode('|', $manual);
             $parameters = array_map('trim', $parameters);
             // Pad out array to avoid notices
             $parameters = array_pad($parameters, 3, '');
             // 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;
             }
             $pManual = new PonyDocsProductManual($productName, $parameters[0], $parameters[1], $parameters[2], $static);
             self::$sDefinedManualList[$productName][strtolower($pManual->getShortName())] = $pManual;
             // If the Manual is static or there is a TOC for this Product/Manual/Version, add to sManualList
             if (!$static) {
                 $res = PonyDocsCategoryLinks::getTOCByProductManualVersion($productName, $pManual->getShortName(), PonyDocsProductVersion::GetSelectedVersion($productName));
                 if (!$res->numRows()) {
                     continue;
                 }
             }
             // Handle Manual Categories
             if (isset($parameters[2]) && $parameters[2] != '') {
                 $categories = explode(',', $parameters[2]);
                 foreach ($categories as $category) {
                     self::$sCategoryMap[$productName][$category][$pManual->getShortName()] = $pManual;
                 }
             } else {
                 self::$sCategoryMap[$productName][PONYDOCS_NO_CATEGORY][$pManual->getShortName()] = $pManual;
             }
             self::$sManualList[$productName][strtolower($pManual->getShortName())] = $pManual;
         }
     }
     return self::$sManualList[$productName];
 }