/** * Accepts an article and performs all necessary logic to also store a redirect * @param Article $article */ public function __construct(Article $article) { $this->article = $article; if ($article->isRedirect()) { $target = $article->getRedirectTarget(); if ($target instanceof Title) { $this->redirect = F::build('Article', array($target)); } } }
public function getRedirectTarget() { $this->loadFile(); if ($this->img->isLocal()) { return parent::getRedirectTarget(); } // Foreign image page $from = $this->img->getRedirected(); $to = $this->img->getName(); if ($from == $to) { return null; } return $this->mRedirectTarget = Title::makeTitle(NS_FILE, $to); }
/** * Extract a redirect destination from a string and return an * array of Titles, or null if the text doesn't contain a valid redirect * The last element in the array is the final destination after all redirects * have been resolved (up to $wgMaxRedirects times) * * @param $text String Text with possible redirect * @return Array of Titles, with the destination last */ public static function newFromRedirectArray($text) { global $wgMaxRedirects; $title = self::newFromRedirectInternal($text); if (is_null($title)) { return null; } // recursive check to follow double redirects $recurse = $wgMaxRedirects; $titles = array($title); while (--$recurse > 0) { if ($title->isRedirect()) { $article = new Article($title, 0); $newtitle = $article->getRedirectTarget(); } else { break; } // Redirects to some special pages are not permitted if ($newtitle instanceof Title && $newtitle->isValidRedirectTarget()) { // the new title passes the checks, so make that our current title so that further recursion can be checked $title = $newtitle; $titles[] = $newtitle; } else { break; } } return $titles; }
/** * @param $title Title * * @return */ protected function _checkRedirect( $title ) { $art = new Article( $title ); $target = $art->getRedirectTarget(); if( $target ) { return $target; } else { return $title; } }
private function getRedirectName(ApiResult $result) { $res =& $result->getData(); if (isset($res['query']) && isset($res['query']['pages'])) { foreach ($this->getPageSet()->getGoodTitles() as $page_id => $oTitle) { $res['query']['pages'][$page_id]['redirectto'] = ""; if ($oTitle->isRedirect()) { $oArticle = new Article($oTitle); $oRedirTitle = $oArticle->getRedirectTarget(); if ($oRedirTitle instanceof Title) { $result->addValue(array("query", "pages", $page_id), "redirectto", Title::makeName($oRedirTitle->getNamespace(), $oRedirTitle->getDBkey())); } } } } }
private function filterRedirect($res, $title) { wfProfileIn(__METHOD__); $article = new Article($title); $this->add(array('type' => 'redirect', 'title' => $res['title'], 'url' => $title->getLocalUrl(), 'redir_title' => $article->getRedirectTarget()->getPrefixedText(), 'redir_url' => $article->getRedirectTarget()->getLocalUrl()), $res); wfProfileOut(__METHOD__); return true; }
/** * Creates a new instance of a WebService object that is stored in the * database with the specified name. * * @param string $name * The unique name of the web service i.e. article that contains the * WWSD of the web service (without the namespace). * * @return WebService * If the web service exists in the database, a new object is created * and initialized with the database values. Otherwise <null> is returned. */ public static function newFromName($name) { $t = Title::makeTitleSafe(SMW_NS_WEB_SERVICE, $name); if ($t == null) { return null; } while ($t->isRedirect()) { $article = new Article($t); $t = $article->getRedirectTarget(); if ($t == null) { return null; } } $id = $t->getArticleID(); return $id < 0 ? null : WSStorage::getDatabase()->getWS($id); }