function wfConnectDoc(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision) { if (!$article || !$text) { return true; } if ($article->getID() == 0) { return true; } //first check to see if there's a [[Doc:foo]] in the article $count = preg_match_all('@\\[\\[Doc:([^\\]]*)\\]\\]@i', $text, $matches, PREG_SET_ORDER); if ($count) { $doc_array = array(); //cycle through and clean up the samples, check for multiples, etc. foreach ($matches as $match) { $doc = preg_replace('@ @', '-', $match[1]); //check for multiple $sample_array = explode(',', $doc); foreach ($sample_array as $doc) { $doc_array[] = $doc; } } //update that link table foreach ($doc_array as $doc) { DocViewer::updateLinkTable($article, $doc); } //make sure we didn't lose any $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('dv_links', 'dvl_doc', array('dvl_page' => $article->getID()), __METHOD__); foreach ($res as $row) { if (!in_array($row->dvl_doc, $doc_array)) { //no longer on the page; remove it DocViewer::updateLinkTable($article, $row->dvl_doc, false); } } } else { //nothing in the article? //remove anything in the link table if there are mentions DocViewer::updateLinkTable($article, '', false); } return true; }
protected function generateBody() { return DocViewer::displayContainer('', true); }
private function displayHtml() { global $IP, $wgTitle, $wgOut, $wgRequest; $isMainPage = $wgTitle->getText() == wfMsg('mainpage'); $isSample = class_exists('DocViewer') && $wgTitle->getText() == 'DocViewer'; $action = $wgRequest->getVal('action', 'view'); $pageExists = $wgTitle->exists(); $article = ""; if (!$isMainPage) { // get the html for the article since it's already been generated $article = $wgOut->getHTML(); } $wgOut->clearHTML(); // handle search and i10l pages here require_once "{$IP}/extensions/wikihow/mobile/MobileHtmlBuilder.class.php"; if ($isMainPage) { // The main page doesn't need any content $article = 'Main-Page'; $m = new MobileMainPageBuilder(); } elseif ($isSample) { $sample_title = DocViewer::getPageTitle(); $title = Title::newFromText($sample_title); $article = 'Sample'; $m = new MobileSampleBuilder(); echo $m->createByHtml($title, $article); return; } elseif ($action == 'view-languages') { $m = new MobileViewLanguagesBuilder(); } elseif (!$pageExists) { $article = '404 page'; $m = new Mobile404Builder(); } else { // article page $m = new MobileArticleBuilder(); } $wgOut->setArticleBodyOnly(true); wfRunHooks('JustBeforeOutputHTML', array(&$this)); echo $m->createByHtml($wgTitle, $article); }
/** * EXECUTE **/ function execute($par = '') { global $wgOut, $wgRequest, $wgHooks, $wgCanonical, $wgSquidMaxage; $sample = preg_replace('@-@', ' ', $par); wfLoadExtensionMessages('DocViewer'); //no side bar $wgHooks['ShowSideBar'][] = array('DocViewer::removeSideBarCallback'); //no head section $wgHooks['ShowHeadSection'][] = array('DocViewer::removeHeadSectionCallback'); //make a custom canonical url self::$wgSampleURL = wfExpandUrl(self::$wgSampleURL . $par); $wgHooks['GetFullURL'][] = array('DocViewer::getCanonicalUrl'); //page title $page_title = $this->getPageTitle($par); $wgOut->setHTMLTitle(wfMsg('pagetitle', $page_title)); //the guts $wgOut->addCSScode('dvc'); // css path defined in extensions/min/groupConfig.php $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('docviewer.js'), 'extensions/wikihow/docviewer', false)); $html = self::displayContainer($par, false); if (!$html) { //nothin' $wgOut->setStatusCode(404); $html = '<p>' . wfMsg('dv-no-doc-err') . '</p>'; } else { //http cache headers $wgOut->setSquidMaxage($wgSquidMaxage); //meta tags $wgOut->addMeta('description', "Use our sample '{$page_title}.' Read it or download it for free. Free help from wikiHow."); $wgOut->addMeta('keywords', $sample . ', ' . wfMsg('sample_meta_keywords_default')); $wgOut->setRobotPolicy('index,follow'); } $wgOut->addHTML($html); }