示例#1
0
 private function formatCategoryLinks($links)
 {
     $result = array();
     if (!$links) {
         return $result;
     }
     // Fetch hiddencat property
     $lb = new LinkBatch();
     $lb->setArray(array(NS_CATEGORY => $links));
     $db = $this->getDB();
     $res = $db->select(array('page', 'page_props'), array('page_title', 'pp_propname'), $lb->constructSet('page', $db), __METHOD__, array(), array('page_props' => array('LEFT JOIN', array('pp_propname' => 'hiddencat', 'pp_page = page_id'))));
     $hiddencats = array();
     foreach ($res as $row) {
         $hiddencats[$row->page_title] = isset($row->pp_propname);
     }
     foreach ($links as $link => $sortkey) {
         $entry = array();
         $entry['sortkey'] = $sortkey;
         ApiResult::setContentValue($entry, 'category', $link);
         if (!isset($hiddencats[$link])) {
             $entry['missing'] = true;
         } elseif ($hiddencats[$link]) {
             $entry['hidden'] = true;
         }
         $result[] = $entry;
     }
     return $result;
 }
示例#2
0
 /**
  * Add an array of categories, with names in the keys
  *
  * @param array $categories Mapping category name => sort key
  */
 public function addCategoryLinks(array $categories)
 {
     global $wgContLang;
     if (!is_array($categories) || count($categories) == 0) {
         return;
     }
     # Add the links to a LinkBatch
     $arr = array(NS_CATEGORY => $categories);
     $lb = new LinkBatch();
     $lb->setArray($arr);
     # Fetch existence plus the hiddencat property
     $dbr = wfGetDB(DB_SLAVE);
     $fields = array('page_id', 'page_namespace', 'page_title', 'page_len', 'page_is_redirect', 'page_latest', 'pp_value');
     if ($this->getConfig()->get('ContentHandlerUseDB')) {
         $fields[] = 'page_content_model';
     }
     $res = $dbr->select(array('page', 'page_props'), $fields, $lb->constructSet('page', $dbr), __METHOD__, array(), array('page_props' => array('LEFT JOIN', array('pp_propname' => 'hiddencat', 'pp_page = page_id'))));
     # Add the results to the link cache
     $lb->addResultToCache(LinkCache::singleton(), $res);
     # Set all the values to 'normal'.
     $categories = array_fill_keys(array_keys($categories), 'normal');
     # Mark hidden categories
     foreach ($res as $row) {
         if (isset($row->pp_value)) {
             $categories[$row->page_title] = 'hidden';
         }
     }
     # Add the remaining categories to the skin
     if (Hooks::run('OutputPageMakeCategoryLinks', array(&$this, $categories, &$this->mCategoryLinks))) {
         foreach ($categories as $category => $type) {
             $origcategory = $category;
             $title = Title::makeTitleSafe(NS_CATEGORY, $category);
             if (!$title) {
                 continue;
             }
             $wgContLang->findVariantLink($category, $title, true);
             if ($category != $origcategory && array_key_exists($category, $categories)) {
                 continue;
             }
             $text = $wgContLang->convertHtml($title->getText());
             $this->mCategories[] = $title->getText();
             $this->mCategoryLinks[$type][] = Linker::link($title, $text);
         }
     }
 }
示例#3
0
 private function formatCategoryLinks($links)
 {
     $result = [];
     if (!$links) {
         return $result;
     }
     // Fetch hiddencat property
     $lb = new LinkBatch();
     $lb->setArray([NS_CATEGORY => $links]);
     $db = $this->getDB();
     $res = $db->select(['page', 'page_props'], ['page_title', 'pp_propname'], $lb->constructSet('page', $db), __METHOD__, [], ['page_props' => ['LEFT JOIN', ['pp_propname' => 'hiddencat', 'pp_page = page_id']]]);
     $hiddencats = [];
     foreach ($res as $row) {
         $hiddencats[$row->page_title] = isset($row->pp_propname);
     }
     $linkCache = LinkCache::singleton();
     foreach ($links as $link => $sortkey) {
         $entry = [];
         $entry['sortkey'] = $sortkey;
         // array keys will cast numeric category names to ints, so cast back to string
         ApiResult::setContentValue($entry, 'category', (string) $link);
         if (!isset($hiddencats[$link])) {
             $entry['missing'] = true;
             // We already know the link doesn't exist in the database, so
             // tell LinkCache that before calling $title->isKnown().
             $title = Title::makeTitle(NS_CATEGORY, $link);
             $linkCache->addBadLinkObj($title);
             if ($title->isKnown()) {
                 $entry['known'] = true;
             }
         } elseif ($hiddencats[$link]) {
             $entry['hidden'] = true;
         }
         $result[] = $entry;
     }
     return $result;
 }
示例#4
0
 /**
  * Add an array of categories, with names in the keys
  */
 public function addCategoryLinks($categories)
 {
     global $wgUser, $wgContLang;
     if (!is_array($categories) || count($categories) == 0) {
         return;
     }
     # Add the links to a LinkBatch
     $arr = array(NS_CATEGORY => $categories);
     $lb = new LinkBatch();
     $lb->setArray($arr);
     # Fetch existence plus the hiddencat property
     $dbr = wfGetDB(DB_SLAVE);
     $pageTable = $dbr->tableName('page');
     $where = $lb->constructSet('page', $dbr);
     $propsTable = $dbr->tableName('page_props');
     $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, pp_value\n\t\t\tFROM {$pageTable} LEFT JOIN {$propsTable} ON pp_propname='hiddencat' AND pp_page=page_id WHERE {$where}";
     $res = $dbr->query($sql, __METHOD__);
     # Add the results to the link cache
     $lb->addResultToCache(LinkCache::singleton(), $res);
     # Set all the values to 'normal'. This can be done with array_fill_keys in PHP 5.2.0+
     $categories = array_combine(array_keys($categories), array_fill(0, count($categories), 'normal'));
     # Mark hidden categories
     foreach ($res as $row) {
         if (isset($row->pp_value)) {
             $categories[$row->page_title] = 'hidden';
         }
     }
     # Add the remaining categories to the skin
     if (wfRunHooks('OutputPageMakeCategoryLinks', array(&$this, $categories, &$this->mCategoryLinks))) {
         $sk = $wgUser->getSkin();
         foreach ($categories as $category => $type) {
             $title = Title::makeTitleSafe(NS_CATEGORY, $category);
             $text = $wgContLang->convertHtml($title->getText());
             $this->mCategoryLinks[$type][] = $sk->makeLinkObj($title, $text);
         }
     }
 }
示例#5
0
 /**
  * Make a WHERE clause from a 2-d NS/dbkey array
  *
  * @param array $arr 2-d array indexed by namespace and DB key
  * @param string $prefix Field name prefix, without the underscore
  */
 function makeWhereFrom2d(&$arr, $prefix)
 {
     $lb = new LinkBatch();
     $lb->setArray($arr);
     return $lb->constructSet($prefix, $this->mDb);
 }
示例#6
0
 /**
  * Add an array of categories, with names in the keys
  */
 function addCategoryLinks($categories)
 {
     global $wgUser, $wgContLang;
     if (!is_array($categories)) {
         return;
     }
     # Add the links to the link cache in a batch
     $arr = array(NS_CATEGORY => $categories);
     $lb = new LinkBatch();
     $lb->setArray($arr);
     $lb->execute();
     $sk =& $wgUser->getSkin();
     foreach ($categories as $category => $arbitrary) {
         $title = Title::makeTitleSafe(NS_CATEGORY, $category);
         $text = $wgContLang->convertHtml($title->getText());
         $this->mCategoryLinks[] = $sk->makeLinkObj($title, $text);
     }
 }
示例#7
0
 /**
  * Add an array of categories, with names in the keys
  *
  * @param array $categories Mapping category name => sort key
  */
 public function addCategoryLinks(array $categories)
 {
     global $wgContLang;
     if (!is_array($categories) || count($categories) == 0) {
         return;
     }
     # Add the links to a LinkBatch
     $arr = [NS_CATEGORY => $categories];
     $lb = new LinkBatch();
     $lb->setArray($arr);
     # Fetch existence plus the hiddencat property
     $dbr = wfGetDB(DB_REPLICA);
     $fields = array_merge(LinkCache::getSelectFields(), ['page_namespace', 'page_title', 'pp_value']);
     $res = $dbr->select(['page', 'page_props'], $fields, $lb->constructSet('page', $dbr), __METHOD__, [], ['page_props' => ['LEFT JOIN', ['pp_propname' => 'hiddencat', 'pp_page = page_id']]]);
     # Add the results to the link cache
     $lb->addResultToCache(LinkCache::singleton(), $res);
     # Set all the values to 'normal'.
     $categories = array_fill_keys(array_keys($categories), 'normal');
     # Mark hidden categories
     foreach ($res as $row) {
         if (isset($row->pp_value)) {
             $categories[$row->page_title] = 'hidden';
         }
     }
     # Add the remaining categories to the skin
     if (Hooks::run('OutputPageMakeCategoryLinks', [&$this, $categories, &$this->mCategoryLinks])) {
         foreach ($categories as $category => $type) {
             // array keys will cast numeric category names to ints, so cast back to string
             $category = (string) $category;
             $origcategory = $category;
             $title = Title::makeTitleSafe(NS_CATEGORY, $category);
             if (!$title) {
                 continue;
             }
             $wgContLang->findVariantLink($category, $title, true);
             if ($category != $origcategory && array_key_exists($category, $categories)) {
                 continue;
             }
             $text = $wgContLang->convertHtml($title->getText());
             $this->mCategories[] = $title->getText();
             $this->mCategoryLinks[$type][] = Linker::link($title, $text);
         }
     }
 }
 protected static function makeWhereFrom2d(&$arr, $db)
 {
     $lb = new LinkBatch();
     $lb->setArray($arr);
     return $lb->constructSet('ftr', $db);
 }
示例#9
0
 private function formatCategoryLinks($links)
 {
     $result = [];
     if (!$links) {
         return $result;
     }
     // Fetch hiddencat property
     $lb = new LinkBatch();
     $lb->setArray([NS_CATEGORY => $links]);
     $db = $this->getDB();
     $res = $db->select(['page', 'page_props'], ['page_title', 'pp_propname'], $lb->constructSet('page', $db), __METHOD__, [], ['page_props' => ['LEFT JOIN', ['pp_propname' => 'hiddencat', 'pp_page = page_id']]]);
     $hiddencats = [];
     foreach ($res as $row) {
         $hiddencats[$row->page_title] = isset($row->pp_propname);
     }
     foreach ($links as $link => $sortkey) {
         $entry = [];
         $entry['sortkey'] = $sortkey;
         // array keys will cast numeric category names to ints, so cast back to string
         ApiResult::setContentValue($entry, 'category', (string) $link);
         if (!isset($hiddencats[$link])) {
             $entry['missing'] = true;
         } elseif ($hiddencats[$link]) {
             $entry['hidden'] = true;
         }
         $result[] = $entry;
     }
     return $result;
 }