/**
  * The category list template. Used by article pages on view and edit save.
  */
 public function categories()
 {
     wfProfileIn(__METHOD__);
     $categories = $this->request->getVal('categories', array());
     $data = array();
     // Because $out->getCategoryLinks doesn't maintain the order of the stored category data,
     // we have to build this information ourselves manually. This is essentially the same
     // code from $out->addCategoryLinks() but it results in a different data format.
     foreach ($categories as $category) {
         // Support category name or category data object
         $name = is_array($category) ? $category['name'] : $category;
         $originalName = $name;
         $title = Title::makeTitleSafe(NS_CATEGORY, $name);
         if ($title != null) {
             $this->wg->ContLang->findVariantLink($name, $title, true);
             if ($name != $originalName && array_key_exists($name, $data)) {
                 continue;
             }
             $text = $this->wg->ContLang->convertHtml($title->getText());
             $data[$name] = array('link' => Linker::link($title, $text), 'name' => $text, 'type' => CategoryHelper::getCategoryType($originalName));
         } else {
             \Wikia\Logger\WikiaLogger::instance()->warning("Unsafe category provided", ['name' => $name]);
         }
     }
     $this->response->setVal('categories', $data);
     wfProfileOut(__METHOD__);
 }