Example #1
0
 /**
  * The init function that is called by mediawiki when loading this
  * SpecialPage.
  *
  * @param string $urlparam the title parameter returned by Mediawiki
  *				which, in this case, is the page for which we want
  *              to perform datetime negotiation
  */
 public function execute($urlparam)
 {
     global $wgMementoIncludeNamespaces;
     $out = $this->getOutput();
     $this->setHeaders();
     if (!$urlparam) {
         $out->addHTML(wfMessage('timegate-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 = Title::newFromText($urlparam);
         $article = new Article($title);
         $article->setContext($this->getContext());
         $db = wfGetDB(DB_SLAVE);
         if (!$title->exists()) {
             throw new ErrorPageError('timegate-title', 'timegate-404-title', array($urlparam));
         }
         if (!in_array($title->getNamespace(), $wgMementoIncludeNamespaces)) {
             throw new ErrorPageError('timegate-title', 'timegate-403-inaccessible', array($title));
         }
         $page = new TimeGateResourceFrom302TimeNegotiation($db, $article);
         $page->alterHeaders();
     }
 }
Example #2
0
 /**
  * Create an Article object of the appropriate class for the given page.
  *
  * @param Title $title
  * @param IContextSource $context
  * @return Article
  */
 public static function newFromTitle($title, IContextSource $context)
 {
     if (NS_MEDIA == $title->getNamespace()) {
         // FIXME: where should this go?
         $title = Title::makeTitle(NS_FILE, $title->getDBkey());
     }
     $page = null;
     Hooks::run('ArticleFromTitle', array(&$title, &$page, $context));
     if (!$page) {
         switch ($title->getNamespace()) {
             case NS_FILE:
                 $page = new ImagePage($title);
                 break;
             case NS_CATEGORY:
                 $page = new CategoryPage($title);
                 break;
             default:
                 $page = new Article($title);
         }
     }
     $page->setContext($context);
     return $page;
 }