MediaWiki
REL1_24
|
00001 <?php 00030 class MediaWikiPageLinkRenderer implements PageLinkRenderer { 00034 protected $formatter; 00035 00039 protected $baseUrl; 00040 00052 public function __construct( TitleFormatter $formatter, $baseUrl = null ) { 00053 if ( $baseUrl === null ) { 00054 $baseUrl = $GLOBALS['wgArticlePath']; 00055 } 00056 00057 $this->formatter = $formatter; 00058 $this->baseUrl = $baseUrl; 00059 } 00060 00069 public function getPageUrl( TitleValue $page, $params = array() ) { 00070 //TODO: move the code from Linker::linkUrl here! 00071 //The below is just a rough estimation! 00072 00073 $name = $this->formatter->getPrefixedText( $page ); 00074 $name = str_replace( ' ', '_', $name ); 00075 $name = wfUrlencode( $name ); 00076 00077 $url = $this->baseUrl . $name; 00078 00079 if ( $params ) { 00080 $separator = ( strpos( $url, '?' ) ) ? '&' : '?'; 00081 $url .= $separator . wfArrayToCgi( $params ); 00082 } 00083 00084 $fragment = $page->getFragment(); 00085 if ( $fragment !== '' ) { 00086 $url = $url . '#' . wfUrlencode( $fragment ); 00087 } 00088 00089 return $url; 00090 } 00091 00100 public function renderHtmlLink( TitleValue $page, $text = null ) { 00101 if ( $text === null ) { 00102 $text = $this->formatter->getFullText( $page ); 00103 } 00104 00105 // TODO: move the logic implemented by Linker here, 00106 // using $this->formatter and $this->baseUrl, and 00107 // re-implement Linker to use a HtmlPageLinkRenderer. 00108 $title = Title::newFromTitleValue( $page ); 00109 $link = Linker::link( $title, htmlspecialchars( $text ) ); 00110 00111 return $link; 00112 } 00113 00122 public function renderWikitextLink( TitleValue $page, $text = null ) { 00123 if ( $text === null ) { 00124 $text = $this->formatter->getFullText( $page ); 00125 } 00126 00127 $name = $this->formatter->getFullText( $page ); 00128 00129 return '[[:' . $name . '|' . wfEscapeWikiText( $text ) . ']]'; 00130 } 00131 }