Example #1
0
	/**
	 * If this page is a redirect, get its target
	 *
	 * The target will be fetched from the redirect table if possible.
	 * If this page doesn't have an entry there, call insertRedirect()
	 * @return Title|mixed object, or null if this page is not a redirect
	 */
	public function getRedirectTarget() {
		if ( !$this->mTitle->isRedirect() ) {
			return null;
		}

		if ( $this->mRedirectTarget !== null ) {
			return $this->mRedirectTarget;
		}

		// Query the redirect table
		$dbr = wfGetDB( DB_SLAVE );
		$row = $dbr->selectRow( 'redirect',
			array( 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ),
			array( 'rd_from' => $this->getId() ),
			__METHOD__
		);

		// rd_fragment and rd_interwiki were added later, populate them if empty
		if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
			return $this->mRedirectTarget = Title::makeTitle(
				$row->rd_namespace, $row->rd_title,
				$row->rd_fragment, $row->rd_interwiki );
		}

		// This page doesn't have an entry in the redirect table
		return $this->mRedirectTarget = $this->insertRedirect();
	}
 /**
  * Function to follow redirects
  *
  * @param $title Title
  * @return Title|null null if the page is an interwiki redirect
  */
 public static function followRedirect(Title $title)
 {
     if (!$title->isRedirect()) {
         return $title;
     }
     $wikipage = WikiPage::factory($title);
     $target = $wikipage->followRedirect();
     if ($target instanceof Title) {
         return $target;
     } else {
         return null;
         // Interwiki redirect
     }
 }
Example #3
0
 /**
  * Build message object for a subtitle containing a backlink to a page
  *
  * @param Title $title Title to link to
  * @param array $query Array of additional parameters to include in the link
  * @return Message
  * @since 1.25
  */
 public static function buildBacklinkSubtitle(Title $title, $query = array())
 {
     if ($title->isRedirect()) {
         $query['redirect'] = 'no';
     }
     return wfMessage('backlinksubtitle')->rawParams(Linker::link($title, null, array(), $query));
 }
Example #4
0
 /**
  * Add a subtitle containing a backlink to a page
  *
  * @param Title $title Title to link to
  */
 public function addBacklinkSubtitle(Title $title)
 {
     $query = array();
     if ($title->isRedirect()) {
         $query['redirect'] = 'no';
     }
     $this->addSubtitle($this->msg('backlinksubtitle')->rawParams(Linker::link($title, null, array(), $query)));
 }
Example #5
0
File: Linker.php Project: paladox/2
 /**
  * Return the CSS colour of a known link
  *
  * @param Title $t
  * @param int $threshold User defined threshold
  * @return string CSS class
  */
 public static function getLinkColour($t, $threshold)
 {
     $colour = '';
     if ($t->isRedirect()) {
         # Page is a redirect
         $colour = 'mw-redirect';
     } elseif ($threshold > 0 && $t->isContentPage() && $t->exists() && $t->getLength() < $threshold) {
         # Page is a stub
         $colour = 'stub';
     }
     return $colour;
 }
 /**
  * Check if page is the main page after follow redirect when followRedirects is true.
  *
  * @param Title $title Title object to check
  * @return boolean
  */
 protected function isMainPage($title)
 {
     if ($title->isRedirect() && $this->followRedirects) {
         $wp = $this->makeWikiPage($title);
         $target = $wp->getRedirectTarget();
         if ($target) {
             return $target->isMainPage();
         }
     }
     return $title->isMainPage();
 }
Example #7
0
 /**
  * Return the CSS colour of a known link
  *
  * @param Title $t
  * @param integer $threshold user defined threshold
  * @return string CSS class
  */
 function getLinkColour($t, $threshold)
 {
     $colour = '';
     if ($t->isRedirect()) {
         # Page is a redirect
         $colour = 'mw-redirect';
     } elseif ($threshold > 0 && $t->exists() && $t->getLength() < $threshold && MWNamespace::isContent($t->getNamespace())) {
         # Page is a stub
         $colour = 'stub';
     }
     return $colour;
 }