/** * The init function that is called by mediawiki when loading this * SpecialPage. * * @param string $urlpar the title parameter returned by Mediawiki * which, in this case, is the URI for which we want TimeMaps */ public function execute($urlparam) { global $wgMementoIncludeNamespaces; $out = $this->getOutput(); $this->setHeaders(); if (!$urlparam) { $out->addHTML(wfMessage('timemap-welcome-message')->parse()); return; } else { // so we can use the same framework as the rest of the // MementoResource classes, we need an Article class $title = TimeMapResource::deriveTitleObject($urlparam); $article = new Article($title); $article->setContext($this->getContext()); $db = wfGetDB(DB_SLAVE); if (!$title->exists()) { throw new ErrorPageError('timemap-title', 'timemap-404-title', array($urlparam)); } if (!in_array($title->getNamespace(), $wgMementoIncludeNamespaces)) { throw new ErrorPageError('timemap-title', 'timemap-403-inaccessible', array($title)); } $page = TimeMapResource::timeMapFactory($db, $article, $urlparam); $page->alterEntity(); } }
/** * getTitle * * This function extracts the Title from the URL * * @param string $urlparam the data passed into a SpecialPage * * @return Title title object created from URL parsing */ public static function deriveTitleObject($urlparam) { if (TimeMapResource::isPivotAscending($urlparam)) { $title = preg_replace('/' . TimeMapResource::ASCENDINGURLPATTERN . '/', "", $urlparam); $title = Title::newFromText($title); } elseif (TimeMapResource::isPivotDescending($urlparam)) { $title = preg_replace('/' . TimeMapResource::DESCENDINGURLPATTERN . '/', "", $urlparam); $title = Title::newFromText($title); } else { $title = Title::newFromText($urlparam); } return $title; }