/** * Our special overridden addPage. Adds the H1 of the article content, * instead of the title itself. * * @param $title Title the Title obj which represents the article. * @param $sortkey string What key are we sorted on. * @param $pageLength integer Ignored in our implementation. * */ function addPage($title, $sortkey, $pageLength, $isRedirect = false) { global $wgContLang; $this->articleCount++; $textForm = $title->getText(); if ($isRedirect) { // In rare chances where the title will conflict with another, make // all article elements sub-arrays if (!is_array($this->articles[strtoupper($textForm[0])])) { $this->articles[strtoupper($textForm[0])] = array(); } $this->articles[strtoupper($textForm[0])] = '<span class="redirect-in-category">' . $this->getSkin()->makeKnownLinkObj($title) . '</span>'; } else { // Not a redirect, a regular article. Let's grab the h1, if // available. // Make sure we run the ArticleFromTitle hook... $article = null; wfRunHooks('ArticleFromTitle', array(&$title, &$article)); if (!$article) { $article = new Article($title); } $article->LoadContent(); preg_match('/^\\s*=(.*)=.*\\n?/', $article->getContent(), $matches); if (isset($matches[1])) { // We found a header in the content, use that as our h1 $h1 = trim($matches[1]); if (strlen($h1) == 0) { $h1 = trim($textForm); } } else { // Could not find a header, use the text form of our title $h1 = trim($textForm); } // Let's get the namespace, if any. $nsText = $title->getNsText(); if ($nsText) { // Not in default namespace, add in parenthesis. $h1 .= " ({$nsText})"; } // In rare chances where the title will conflict with another, make // all article elements sub-arrays if (!(isset($this->articles[strtoupper($h1[0])]) && is_array($this->articles[strtoupper($h1[0])]))) { $this->articles[strtoupper($h1[0])] = array(); } $this->articles[strtoupper($h1[0])][] = $this->getSkin()->makeKnownLinkObj($title, htmlentities($h1)); } }