Skin.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922
  1. <?php
  2. /**
  3. * @defgroup Skins Skins
  4. */
  5. if ( ! defined( 'MEDIAWIKI' ) )
  6. die( 1 );
  7. /**
  8. * The main skin class that provide methods and properties for all other skins.
  9. * This base class is also the "Standard" skin.
  10. *
  11. * See docs/skin.txt for more information.
  12. *
  13. * @ingroup Skins
  14. */
  15. class Skin extends Linker {
  16. /**#@+
  17. * @private
  18. */
  19. var $mWatchLinkNum = 0; // Appended to end of watch link id's
  20. // How many search boxes have we made? Avoid duplicate id's.
  21. protected $searchboxes = '';
  22. /**#@-*/
  23. protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
  24. protected $skinname = 'standard' ;
  25. /** Constructor, call parent constructor */
  26. function Skin() { parent::__construct(); }
  27. /**
  28. * Fetch the set of available skins.
  29. * @return array of strings
  30. * @static
  31. */
  32. static function getSkinNames() {
  33. global $wgValidSkinNames;
  34. static $skinsInitialised = false;
  35. if ( !$skinsInitialised ) {
  36. # Get a list of available skins
  37. # Build using the regular expression '^(.*).php$'
  38. # Array keys are all lower case, array value keep the case used by filename
  39. #
  40. wfProfileIn( __METHOD__ . '-init' );
  41. global $wgStyleDirectory;
  42. $skinDir = dir( $wgStyleDirectory );
  43. # while code from www.php.net
  44. while (false !== ($file = $skinDir->read())) {
  45. // Skip non-PHP files, hidden files, and '.dep' includes
  46. $matches = array();
  47. if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
  48. $aSkin = $matches[1];
  49. $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
  50. }
  51. }
  52. $skinDir->close();
  53. $skinsInitialised = true;
  54. wfProfileOut( __METHOD__ . '-init' );
  55. }
  56. return $wgValidSkinNames;
  57. }
  58. /**
  59. * Fetch the list of usable skins in regards to $wgSkipSkins.
  60. * Useful for Special:Preferences and other places where you
  61. * only want to show skins users _can_ use.
  62. * @return array of strings
  63. */
  64. public static function getUsableSkins() {
  65. global $wgSkipSkins;
  66. $usableSkins = self::getSkinNames();
  67. foreach ( $wgSkipSkins as $skip ) {
  68. unset( $usableSkins[$skip] );
  69. }
  70. return $usableSkins;
  71. }
  72. /**
  73. * Normalize a skin preference value to a form that can be loaded.
  74. * If a skin can't be found, it will fall back to the configured
  75. * default (or the old 'Classic' skin if that's broken).
  76. * @param string $key
  77. * @return string
  78. * @static
  79. */
  80. static function normalizeKey( $key ) {
  81. global $wgDefaultSkin;
  82. $skinNames = Skin::getSkinNames();
  83. if( $key == '' ) {
  84. // Don't return the default immediately;
  85. // in a misconfiguration we need to fall back.
  86. $key = $wgDefaultSkin;
  87. }
  88. if( isset( $skinNames[$key] ) ) {
  89. return $key;
  90. }
  91. // Older versions of the software used a numeric setting
  92. // in the user preferences.
  93. $fallback = array(
  94. 0 => $wgDefaultSkin,
  95. 1 => 'nostalgia',
  96. 2 => 'cologneblue' );
  97. if( isset( $fallback[$key] ) ){
  98. $key = $fallback[$key];
  99. }
  100. if( isset( $skinNames[$key] ) ) {
  101. return $key;
  102. } else {
  103. return 'monobook';
  104. }
  105. }
  106. /**
  107. * Factory method for loading a skin of a given type
  108. * @param string $key 'monobook', 'standard', etc
  109. * @return Skin
  110. * @static
  111. */
  112. static function &newFromKey( $key ) {
  113. global $wgStyleDirectory;
  114. $key = Skin::normalizeKey( $key );
  115. $skinNames = Skin::getSkinNames();
  116. $skinName = $skinNames[$key];
  117. $className = 'Skin'.ucfirst($key);
  118. # Grab the skin class and initialise it.
  119. if ( !class_exists( $className ) ) {
  120. // Preload base classes to work around APC/PHP5 bug
  121. $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
  122. if( file_exists( $deps ) ) include_once( $deps );
  123. require_once( "{$wgStyleDirectory}/{$skinName}.php" );
  124. # Check if we got if not failback to default skin
  125. if( !class_exists( $className ) ) {
  126. # DO NOT die if the class isn't found. This breaks maintenance
  127. # scripts and can cause a user account to be unrecoverable
  128. # except by SQL manipulation if a previously valid skin name
  129. # is no longer valid.
  130. wfDebug( "Skin class does not exist: $className\n" );
  131. $className = 'SkinMonobook';
  132. require_once( "{$wgStyleDirectory}/MonoBook.php" );
  133. }
  134. }
  135. $skin = new $className;
  136. return $skin;
  137. }
  138. /** @return string path to the skin stylesheet */
  139. function getStylesheet() {
  140. return 'common/wikistandard.css';
  141. }
  142. /** @return string skin name */
  143. public function getSkinName() {
  144. return $this->skinname;
  145. }
  146. function qbSetting() {
  147. global $wgOut, $wgUser;
  148. if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
  149. $q = $wgUser->getOption( 'quickbar', 0 );
  150. return $q;
  151. }
  152. function initPage( OutputPage $out ) {
  153. global $wgFavicon, $wgAppleTouchIcon;
  154. wfProfileIn( __METHOD__ );
  155. # Generally the order of the favicon and apple-touch-icon links
  156. # should not matter, but Konqueror (3.5.9 at least) incorrectly
  157. # uses whichever one appears later in the HTML source. Make sure
  158. # apple-touch-icon is specified first to avoid this.
  159. if( false !== $wgAppleTouchIcon ) {
  160. $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
  161. }
  162. if( false !== $wgFavicon ) {
  163. $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
  164. }
  165. # OpenSearch description link
  166. $out->addLink( array(
  167. 'rel' => 'search',
  168. 'type' => 'application/opensearchdescription+xml',
  169. 'href' => wfScript( 'opensearch_desc' ),
  170. 'title' => wfMsgForContent( 'opensearch-desc' ),
  171. ));
  172. $this->addMetadataLinks($out);
  173. $this->mRevisionId = $out->mRevisionId;
  174. $this->preloadExistence();
  175. wfProfileOut( __METHOD__ );
  176. }
  177. /**
  178. * Preload the existence of three commonly-requested pages in a single query
  179. */
  180. function preloadExistence() {
  181. global $wgUser, $wgTitle;
  182. // User/talk link
  183. $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
  184. // Other tab link
  185. if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
  186. // nothing
  187. } elseif ( $wgTitle->isTalkPage() ) {
  188. $titles[] = $wgTitle->getSubjectPage();
  189. } else {
  190. $titles[] = $wgTitle->getTalkPage();
  191. }
  192. $lb = new LinkBatch( $titles );
  193. $lb->execute();
  194. }
  195. function addMetadataLinks( OutputPage $out ) {
  196. global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
  197. global $wgRightsPage, $wgRightsUrl;
  198. if( $out->isArticleRelated() ) {
  199. # note: buggy CC software only reads first "meta" link
  200. if( $wgEnableCreativeCommonsRdf ) {
  201. $out->addMetadataLink( array(
  202. 'title' => 'Creative Commons',
  203. 'type' => 'application/rdf+xml',
  204. 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
  205. }
  206. if( $wgEnableDublinCoreRdf ) {
  207. $out->addMetadataLink( array(
  208. 'title' => 'Dublin Core',
  209. 'type' => 'application/rdf+xml',
  210. 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
  211. }
  212. }
  213. $copyright = '';
  214. if( $wgRightsPage ) {
  215. $copy = Title::newFromText( $wgRightsPage );
  216. if( $copy ) {
  217. $copyright = $copy->getLocalURL();
  218. }
  219. }
  220. if( !$copyright && $wgRightsUrl ) {
  221. $copyright = $wgRightsUrl;
  222. }
  223. if( $copyright ) {
  224. $out->addLink( array(
  225. 'rel' => 'copyright',
  226. 'href' => $copyright ) );
  227. }
  228. }
  229. function setMembers(){
  230. global $wgTitle, $wgUser;
  231. $this->mTitle = $wgTitle;
  232. $this->mUser = $wgUser;
  233. $this->userpage = $wgUser->getUserPage()->getPrefixedText();
  234. $this->usercss = false;
  235. }
  236. function outputPage( OutputPage $out ) {
  237. global $wgDebugComments;
  238. wfProfileIn( __METHOD__ );
  239. $this->setMembers();
  240. $this->initPage( $out );
  241. // See self::afterContentHook() for documentation
  242. $afterContent = $this->afterContentHook();
  243. $out->out( $out->headElement( $this ) );
  244. $out->out( "\n<body" );
  245. $ops = $this->getBodyOptions();
  246. foreach ( $ops as $name => $val ) {
  247. $out->out( " $name='$val'" );
  248. }
  249. $out->out( ">\n" );
  250. if ( $wgDebugComments ) {
  251. $out->out( "<!-- Wiki debugging output:\n" .
  252. $out->mDebugtext . "-->\n" );
  253. }
  254. $out->out( $this->beforeContent() );
  255. $out->out( $out->mBodytext . "\n" );
  256. $out->out( $this->afterContent() );
  257. $out->out( $afterContent );
  258. $out->out( $this->bottomScripts() );
  259. $out->out( wfReportTime() );
  260. $out->out( "\n</body></html>" );
  261. wfProfileOut( __METHOD__ );
  262. }
  263. static function makeVariablesScript( $data ) {
  264. global $wgJsMimeType;
  265. $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
  266. foreach ( $data as $name => $value ) {
  267. $encValue = Xml::encodeJsVar( $value );
  268. $r[] = "var $name = $encValue;";
  269. }
  270. $r[] = "/*]]>*/</script>\n";
  271. return implode( "\n\t\t", $r );
  272. }
  273. /**
  274. * Make a <script> tag containing global variables
  275. * @param array $data Associative array containing one element:
  276. * skinname => the skin name
  277. * The odd calling convention is for backwards compatibility
  278. */
  279. static function makeGlobalVariablesScript( $data ) {
  280. global $wgScript, $wgStylePath, $wgUser;
  281. global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
  282. global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
  283. global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
  284. global $wgUseAjax, $wgAjaxWatch;
  285. global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
  286. global $wgRestrictionTypes, $wgLivePreview;
  287. global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
  288. $ns = $wgTitle->getNamespace();
  289. $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
  290. $separatorTransTable = $wgContLang->separatorTransformTable();
  291. $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
  292. $compactSeparatorTransTable = array(
  293. implode( "\t", array_keys( $separatorTransTable ) ),
  294. implode( "\t", $separatorTransTable ),
  295. );
  296. $digitTransTable = $wgContLang->digitTransformTable();
  297. $digitTransTable = $digitTransTable ? $digitTransTable : array();
  298. $compactDigitTransTable = array(
  299. implode( "\t", array_keys( $digitTransTable ) ),
  300. implode( "\t", $digitTransTable ),
  301. );
  302. $vars = array(
  303. 'skin' => $data['skinname'],
  304. 'stylepath' => $wgStylePath,
  305. 'wgArticlePath' => $wgArticlePath,
  306. 'wgScriptPath' => $wgScriptPath,
  307. 'wgScript' => $wgScript,
  308. 'wgVariantArticlePath' => $wgVariantArticlePath,
  309. 'wgActionPaths' => (object)$wgActionPaths,
  310. 'wgServer' => $wgServer,
  311. 'wgCanonicalNamespace' => $nsname,
  312. 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
  313. 'wgNamespaceNumber' => $wgTitle->getNamespace(),
  314. 'wgPageName' => $wgTitle->getPrefixedDBKey(),
  315. 'wgTitle' => $wgTitle->getText(),
  316. 'wgAction' => $wgRequest->getText( 'action', 'view' ),
  317. 'wgArticleId' => $wgTitle->getArticleId(),
  318. 'wgIsArticle' => $wgOut->isArticle(),
  319. 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
  320. 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
  321. 'wgUserLanguage' => $wgLang->getCode(),
  322. 'wgContentLanguage' => $wgContLang->getCode(),
  323. 'wgBreakFrames' => $wgBreakFrames,
  324. 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
  325. 'wgVersion' => $wgVersion,
  326. 'wgEnableAPI' => $wgEnableAPI,
  327. 'wgEnableWriteAPI' => $wgEnableWriteAPI,
  328. 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
  329. 'wgDigitTransformTable' => $compactDigitTransTable,
  330. );
  331. if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
  332. $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
  333. $vars['wgDBname'] = $wgDBname;
  334. $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
  335. $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
  336. }
  337. foreach( $wgRestrictionTypes as $type )
  338. $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
  339. if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
  340. $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
  341. $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
  342. $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
  343. $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
  344. }
  345. if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
  346. $msgs = (object)array();
  347. foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
  348. $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
  349. }
  350. $vars['wgAjaxWatch'] = $msgs;
  351. }
  352. wfRunHooks('MakeGlobalVariablesScript', array(&$vars));
  353. return self::makeVariablesScript( $vars );
  354. }
  355. function getHeadScripts( $allowUserJs ) {
  356. global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
  357. $vars = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
  358. $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
  359. global $wgUseSiteJs;
  360. if ($wgUseSiteJs) {
  361. $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
  362. $r[] = "<script type=\"$wgJsMimeType\" src=\"".
  363. htmlspecialchars(self::makeUrl('-',
  364. "action=raw$jsCache&gen=js&useskin=" .
  365. urlencode( $this->getSkinName() ) ) ) .
  366. "\"><!-- site js --></script>";
  367. }
  368. if( $allowUserJs && $wgUser->isLoggedIn() ) {
  369. $userpage = $wgUser->getUserPage();
  370. $userjs = htmlspecialchars( self::makeUrl(
  371. $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
  372. 'action=raw&ctype='.$wgJsMimeType));
  373. $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
  374. }
  375. return $vars . "\t\t" . implode ( "\n\t\t", $r );
  376. }
  377. /**
  378. * To make it harder for someone to slip a user a fake
  379. * user-JavaScript or user-CSS preview, a random token
  380. * is associated with the login session. If it's not
  381. * passed back with the preview request, we won't render
  382. * the code.
  383. *
  384. * @param string $action
  385. * @return bool
  386. * @private
  387. */
  388. function userCanPreview( $action ) {
  389. global $wgTitle, $wgRequest, $wgUser;
  390. if( $action != 'submit' )
  391. return false;
  392. if( !$wgRequest->wasPosted() )
  393. return false;
  394. if( !$wgTitle->userCanEditCssJsSubpage() )
  395. return false;
  396. return $wgUser->matchEditToken(
  397. $wgRequest->getVal( 'wpEditToken' ) );
  398. }
  399. /**
  400. * generated JavaScript action=raw&gen=js
  401. * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
  402. * nated together. For some bizarre reason, it does *not* return any
  403. * custom user JS from subpages. Huh?
  404. *
  405. * There's absolutely no reason to have separate Monobook/Common JSes.
  406. * Any JS that cares can just check the skin variable generated at the
  407. * top. For now Monobook.js will be maintained, but it should be consi-
  408. * dered deprecated.
  409. *
  410. * @return string
  411. */
  412. public function generateUserJs() {
  413. global $wgStylePath;
  414. wfProfileIn( __METHOD__ );
  415. $s = "/* generated javascript */\n";
  416. $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
  417. $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
  418. $s .= "\n\n/* MediaWiki:Common.js */\n";
  419. $commonJs = wfMsgForContent('common.js');
  420. if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
  421. $s .= $commonJs;
  422. }
  423. $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n";
  424. // avoid inclusion of non defined user JavaScript (with custom skins only)
  425. // by checking for default message content
  426. $msgKey = ucfirst( $this->getSkinName() ).'.js';
  427. $userJS = wfMsgForContent($msgKey);
  428. if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
  429. $s .= $userJS;
  430. }
  431. wfProfileOut( __METHOD__ );
  432. return $s;
  433. }
  434. /**
  435. * generate user stylesheet for action=raw&gen=css
  436. */
  437. public function generateUserStylesheet() {
  438. wfProfileIn( __METHOD__ );
  439. $s = "/* generated user stylesheet */\n" .
  440. $this->reallyGenerateUserStylesheet();
  441. wfProfileOut( __METHOD__ );
  442. return $s;
  443. }
  444. /**
  445. * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
  446. */
  447. protected function reallyGenerateUserStylesheet(){
  448. global $wgUser;
  449. $s = '';
  450. if (($undopt = $wgUser->getOption("underline")) < 2) {
  451. $underline = $undopt ? 'underline' : 'none';
  452. $s .= "a { text-decoration: $underline; }\n";
  453. }
  454. if( $wgUser->getOption( 'highlightbroken' ) ) {
  455. $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
  456. } else {
  457. $s .= <<<END
  458. a.new, #quickbar a.new,
  459. a.stub, #quickbar a.stub {
  460. color: inherit;
  461. }
  462. a.new:after, #quickbar a.new:after {
  463. content: "?";
  464. color: #CC2200;
  465. }
  466. a.stub:after, #quickbar a.stub:after {
  467. content: "!";
  468. color: #772233;
  469. }
  470. END;
  471. }
  472. if( $wgUser->getOption( 'justify' ) ) {
  473. $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
  474. }
  475. if( !$wgUser->getOption( 'showtoc' ) ) {
  476. $s .= "#toc { display: none; }\n";
  477. }
  478. if( !$wgUser->getOption( 'editsection' ) ) {
  479. $s .= ".editsection { display: none; }\n";
  480. }
  481. return $s;
  482. }
  483. /**
  484. * @private
  485. */
  486. function setupUserCss( OutputPage $out ) {
  487. global $wgRequest, $wgContLang, $wgUser;
  488. global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
  489. wfProfileIn( __METHOD__ );
  490. $this->setupSkinUserCss( $out );
  491. $siteargs = array(
  492. 'action' => 'raw',
  493. 'maxage' => $wgSquidMaxage,
  494. );
  495. // Add any extension CSS
  496. foreach( $out->getExtStyle() as $tag ) {
  497. $out->addStyle( $tag['href'] );
  498. }
  499. // If we use the site's dynamic CSS, throw that in, too
  500. // Per-site custom styles
  501. if( $wgUseSiteCss ) {
  502. global $wgHandheldStyle;
  503. $query = wfArrayToCGI( array(
  504. 'usemsgcache' => 'yes',
  505. 'ctype' => 'text/css',
  506. 'smaxage' => $wgSquidMaxage
  507. ) + $siteargs );
  508. # Site settings must override extension css! (bug 15025)
  509. $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
  510. $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
  511. if( $wgHandheldStyle ) {
  512. $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
  513. }
  514. $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
  515. }
  516. if( $wgUser->isLoggedIn() ) {
  517. // Ensure that logged-in users' generated CSS isn't clobbered
  518. // by anons' publicly cacheable generated CSS.
  519. $siteargs['smaxage'] = '0';
  520. $siteargs['ts'] = $wgUser->mTouched;
  521. }
  522. // Per-user styles based on preferences
  523. $siteargs['gen'] = 'css';
  524. if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
  525. $siteargs['useskin'] = $us;
  526. }
  527. $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
  528. // Per-user custom style pages
  529. if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
  530. $action = $wgRequest->getVal('action');
  531. # If we're previewing the CSS page, use it
  532. if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
  533. $previewCss = $wgRequest->getText('wpTextbox1');
  534. // @FIXME: properly escape the cdata!
  535. $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
  536. } else {
  537. $out->addStyle( self::makeUrl($this->userpage . '/' . $this->getSkinName() .'.css',
  538. 'action=raw&ctype=text/css' ) );
  539. }
  540. }
  541. wfProfileOut( __METHOD__ );
  542. }
  543. /**
  544. * Add skin specific stylesheets
  545. * @param $out OutputPage
  546. */
  547. function setupSkinUserCss( OutputPage $out ) {
  548. $out->addStyle( 'common/shared.css' );
  549. $out->addStyle( 'common/oldshared.css' );
  550. $out->addStyle( $this->getStylesheet() );
  551. $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
  552. }
  553. function getBodyOptions() {
  554. global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
  555. extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
  556. if ( 0 != $wgTitle->getNamespace() ) {
  557. $a = array( 'bgcolor' => '#ffffec' );
  558. }
  559. else $a = array( 'bgcolor' => '#FFFFFF' );
  560. if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
  561. $wgTitle->quickUserCan( 'edit' ) ) {
  562. $s = $wgTitle->getFullURL( $this->editUrlOptions() );
  563. $s = 'document.location = "' .Xml::escapeJsString( $s ) .'";';
  564. $a += array ('ondblclick' => $s);
  565. }
  566. $a['onload'] = $wgOut->getOnloadHandler();
  567. $a['class'] =
  568. 'mediawiki' .
  569. ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ).
  570. ' '.$this->getPageClasses( $wgTitle ) .
  571. ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) );
  572. return $a;
  573. }
  574. function getPageClasses( $title ) {
  575. $numeric = 'ns-'.$title->getNamespace();
  576. if( $title->getNamespace() == NS_SPECIAL ) {
  577. $type = "ns-special";
  578. } elseif( $title->isTalkPage() ) {
  579. $type = "ns-talk";
  580. } else {
  581. $type = "ns-subject";
  582. }
  583. $name = Sanitizer::escapeClass( 'page-'.$title->getPrefixedText() );
  584. return "$numeric $type $name";
  585. }
  586. /**
  587. * URL to the logo
  588. */
  589. function getLogo() {
  590. global $wgLogo;
  591. return $wgLogo;
  592. }
  593. /**
  594. * This will be called immediately after the <body> tag. Split into
  595. * two functions to make it easier to subclass.
  596. */
  597. function beforeContent() {
  598. return $this->doBeforeContent();
  599. }
  600. function doBeforeContent() {
  601. global $wgContLang;
  602. $fname = 'Skin::doBeforeContent';
  603. wfProfileIn( $fname );
  604. $s = '';
  605. $qb = $this->qbSetting();
  606. if( $langlinks = $this->otherLanguages() ) {
  607. $rows = 2;
  608. $borderhack = '';
  609. } else {
  610. $rows = 1;
  611. $langlinks = false;
  612. $borderhack = 'class="top"';
  613. }
  614. $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
  615. "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
  616. $shove = ( $qb != 0 );
  617. $left = ( $qb == 1 || $qb == 3 );
  618. if( $wgContLang->isRTL() ) $left = !$left;
  619. if( !$shove ) {
  620. $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
  621. $this->logoText() . '</td>';
  622. } elseif( $left ) {
  623. $s .= $this->getQuickbarCompensator( $rows );
  624. }
  625. $l = $wgContLang->isRTL() ? 'right' : 'left';
  626. $s .= "<td {$borderhack} align='$l' valign='top'>\n";
  627. $s .= $this->topLinks() ;
  628. $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
  629. $r = $wgContLang->isRTL() ? "left" : "right";
  630. $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
  631. $s .= $this->nameAndLogin();
  632. $s .= "\n<br />" . $this->searchForm() . "</td>";
  633. if ( $langlinks ) {
  634. $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
  635. }
  636. if ( $shove && !$left ) { # Right
  637. $s .= $this->getQuickbarCompensator( $rows );
  638. }
  639. $s .= "</tr>\n</table>\n</div>\n";
  640. $s .= "\n<div id='article'>\n";
  641. $notice = wfGetSiteNotice();
  642. if( $notice ) {
  643. $s .= "\n<div id='siteNotice'>$notice</div>\n";
  644. }
  645. $s .= $this->pageTitle();
  646. $s .= $this->pageSubtitle() ;
  647. $s .= $this->getCategories();
  648. wfProfileOut( $fname );
  649. return $s;
  650. }
  651. function getCategoryLinks() {
  652. global $wgOut, $wgTitle, $wgUseCategoryBrowser;
  653. global $wgContLang, $wgUser;
  654. if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
  655. # Separator
  656. $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
  657. // Use Unicode bidi embedding override characters,
  658. // to make sure links don't smash each other up in ugly ways.
  659. $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
  660. $embed = "<span dir='$dir'>";
  661. $pop = '</span>';
  662. $allCats = $wgOut->getCategoryLinks();
  663. $s = '';
  664. $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
  665. if ( !empty( $allCats['normal'] ) ) {
  666. $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
  667. $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
  668. $s .= '<div id="mw-normal-catlinks">' .
  669. $this->link( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
  670. . $colon . $t . '</div>';
  671. }
  672. # Hidden categories
  673. if ( isset( $allCats['hidden'] ) ) {
  674. if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
  675. $class ='mw-hidden-cats-user-shown';
  676. } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
  677. $class = 'mw-hidden-cats-ns-shown';
  678. } else {
  679. $class = 'mw-hidden-cats-hidden';
  680. }
  681. $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
  682. wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
  683. $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
  684. "</div>";
  685. }
  686. # optional 'dmoz-like' category browser. Will be shown under the list
  687. # of categories an article belong to
  688. if( $wgUseCategoryBrowser ){
  689. $s .= '<br /><hr />';
  690. # get a big array of the parents tree
  691. $parenttree = $wgTitle->getParentCategoryTree();
  692. # Skin object passed by reference cause it can not be
  693. # accessed under the method subfunction drawCategoryBrowser
  694. $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
  695. # Clean out bogus first entry and sort them
  696. unset($tempout[0]);
  697. asort($tempout);
  698. # Output one per line
  699. $s .= implode("<br />\n", $tempout);
  700. }
  701. return $s;
  702. }
  703. /** Render the array as a serie of links.
  704. * @param $tree Array: categories tree returned by Title::getParentCategoryTree
  705. * @param &skin Object: skin passed by reference
  706. * @return String separated by &gt;, terminate with "\n"
  707. */
  708. function drawCategoryBrowser( $tree, &$skin ){
  709. $return = '';
  710. foreach ($tree as $element => $parent) {
  711. if (empty($parent)) {
  712. # element start a new list
  713. $return .= "\n";
  714. } else {
  715. # grab the others elements
  716. $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
  717. }
  718. # add our current element to the list
  719. $eltitle = Title::newFromText($element);
  720. $return .= $skin->link( $eltitle, $eltitle->getText() ) ;
  721. }
  722. return $return;
  723. }
  724. function getCategories() {
  725. $catlinks=$this->getCategoryLinks();
  726. $classes = 'catlinks';
  727. if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
  728. strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
  729. $classes .= ' catlinks-allhidden';
  730. }
  731. if( !empty( $catlinks ) ){
  732. return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
  733. }
  734. }
  735. function getQuickbarCompensator( $rows = 1 ) {
  736. return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
  737. }
  738. /**
  739. * This runs a hook to allow extensions placing their stuff after content
  740. * and article metadata (e.g. categories).
  741. * Note: This function has nothing to do with afterContent().
  742. *
  743. * This hook is placed here in order to allow using the same hook for all
  744. * skins, both the SkinTemplate based ones and the older ones, which directly
  745. * use this class to get their data.
  746. *
  747. * The output of this function gets processed in SkinTemplate::outputPage() for
  748. * the SkinTemplate based skins, all other skins should directly echo it.
  749. *
  750. * Returns an empty string by default, if not changed by any hook function.
  751. */
  752. protected function afterContentHook() {
  753. $data = "";
  754. if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
  755. // adding just some spaces shouldn't toggle the output
  756. // of the whole <div/>, so we use trim() here
  757. if( trim( $data ) != '' ){
  758. // Doing this here instead of in the skins to
  759. // ensure that the div has the same ID in all
  760. // skins
  761. $data = "<div id='mw-data-after-content'>\n" .
  762. "\t$data\n" .
  763. "</div>\n";
  764. }
  765. } else {
  766. wfDebug( "Hook SkinAfterContent changed output processing.\n" );
  767. }
  768. return $data;
  769. }
  770. /**
  771. * Generate debug data HTML for displaying at the bottom of the main content
  772. * area.
  773. * @return String HTML containing debug data, if enabled (otherwise empty).
  774. */
  775. protected function generateDebugHTML() {
  776. global $wgShowDebug, $wgOut;
  777. if ( $wgShowDebug ) {
  778. $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext ) );
  779. return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
  780. $listInternals . "</li></ul>\n";
  781. }
  782. return '';
  783. }
  784. /**
  785. * This gets called shortly before the </body> tag.
  786. * @return String HTML to be put before </body>
  787. */
  788. function afterContent() {
  789. $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
  790. return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
  791. }
  792. /**
  793. * This gets called shortly before the </body> tag.
  794. * @return String HTML-wrapped JS code to be put before </body>
  795. */
  796. function bottomScripts() {
  797. global $wgJsMimeType;
  798. $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
  799. wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
  800. return $bottomScriptText;
  801. }
  802. /** @return string Retrievied from HTML text */
  803. function printSource() {
  804. global $wgTitle;
  805. $url = htmlspecialchars( $wgTitle->getFullURL() );
  806. return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
  807. }
  808. function printFooter() {
  809. return "<p>" . $this->printSource() .
  810. "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
  811. }
  812. /** overloaded by derived classes */
  813. function doAfterContent() { return "</div></div>"; }
  814. function pageTitleLinks() {
  815. global $wgOut, $wgTitle, $wgUser, $wgRequest, $wgLang;
  816. $oldid = $wgRequest->getVal( 'oldid' );
  817. $diff = $wgRequest->getVal( 'diff' );
  818. $action = $wgRequest->getText( 'action' );
  819. $s[] = $this->printableLink();
  820. $disclaimer = $this->disclaimerLink(); # may be empty
  821. if( $disclaimer ) {
  822. $s[] = $disclaimer;
  823. }
  824. $privacy = $this->privacyLink(); # may be empty too
  825. if( $privacy ) {
  826. $s[] = $privacy;
  827. }
  828. if ( $wgOut->isArticleRelated() ) {
  829. if ( $wgTitle->getNamespace() == NS_FILE ) {
  830. $name = $wgTitle->getDBkey();
  831. $image = wfFindFile( $wgTitle );
  832. if( $image ) {
  833. $link = htmlspecialchars( $image->getURL() );
  834. $style = $this->getInternalLinkAttributes( $link, $name );
  835. $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
  836. }
  837. }
  838. }
  839. if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
  840. $s[] .= $this->makeKnownLinkObj( $wgTitle,
  841. wfMsg( 'currentrev' ) );
  842. }
  843. if ( $wgUser->getNewtalk() ) {
  844. # do not show "You have new messages" text when we are viewing our
  845. # own talk page
  846. if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
  847. $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
  848. $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
  849. $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
  850. # disable caching
  851. $wgOut->setSquidMaxage(0);
  852. $wgOut->enableClientCache(false);
  853. }
  854. }
  855. $undelete = $this->getUndeleteLink();
  856. if( !empty( $undelete ) ) {
  857. $s[] = $undelete;
  858. }
  859. return $wgLang->pipeList( $s );
  860. }
  861. function getUndeleteLink() {
  862. global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
  863. if( $wgUser->isAllowed( 'deletedhistory' ) &&
  864. (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
  865. ($n = $wgTitle->isDeleted() ) )
  866. {
  867. if ( $wgUser->isAllowed( 'undelete' ) ) {
  868. $msg = 'thisisdeleted';
  869. } else {
  870. $msg = 'viewdeleted';
  871. }
  872. return wfMsg( $msg,
  873. $this->makeKnownLinkObj(
  874. SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
  875. wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
  876. }
  877. return '';
  878. }
  879. function printableLink() {
  880. global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
  881. $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
  882. $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
  883. if( $wgOut->isSyndicated() ) {
  884. foreach( $wgFeedClasses as $format => $class ) {
  885. $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
  886. $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
  887. . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
  888. }
  889. }
  890. return $wgLang->pipeList( $s );
  891. }
  892. function pageTitle() {
  893. global $wgOut;
  894. $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
  895. return $s;
  896. }
  897. function pageSubtitle() {
  898. global $wgOut;
  899. $sub = $wgOut->getSubtitle();
  900. if ( '' == $sub ) {
  901. global $wgExtraSubtitle;
  902. $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
  903. }
  904. $subpages = $this->subPageSubtitle();
  905. $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
  906. $s = "<p class='subtitle'>{$sub}</p>\n";
  907. return $s;
  908. }
  909. function subPageSubtitle() {
  910. $subpages = '';
  911. if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
  912. return $subpages;
  913. global $wgOut, $wgTitle;
  914. if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) {
  915. $ptext=$wgTitle->getPrefixedText();
  916. if(preg_match('/\//',$ptext)) {
  917. $links = explode('/',$ptext);
  918. array_pop( $links );
  919. $c = 0;
  920. $growinglink = '';
  921. $display = '';
  922. foreach($links as $link) {
  923. $growinglink .= $link;
  924. $display .= $link;
  925. $linkObj = Title::newFromText( $growinglink );
  926. if( is_object( $linkObj ) && $linkObj->exists() ){
  927. $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
  928. $c++;
  929. if ($c>1) {
  930. $subpages .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
  931. } else {
  932. $subpages .= '&lt; ';
  933. }
  934. $subpages .= $getlink;
  935. $display = '';
  936. } else {
  937. $display .= '/';
  938. }
  939. $growinglink .= '/';
  940. }
  941. }
  942. }
  943. return $subpages;
  944. }
  945. /**
  946. * Returns true if the IP should be shown in the header
  947. */
  948. function showIPinHeader() {
  949. global $wgShowIPinHeader;
  950. return $wgShowIPinHeader && session_id() != '';
  951. }
  952. function nameAndLogin() {
  953. global $wgUser, $wgTitle, $wgLang, $wgContLang;
  954. $logoutPage = $wgContLang->specialPage( 'Userlogout' );
  955. $ret = '';
  956. if ( $wgUser->isAnon() ) {
  957. if( $this->showIPinHeader() ) {
  958. $name = wfGetIP();
  959. $talkLink = $this->link( $wgUser->getTalkPage(),
  960. $wgLang->getNsText( NS_TALK ) );
  961. $ret .= "$name ($talkLink)";
  962. } else {
  963. $ret .= wfMsg( 'notloggedin' );
  964. }
  965. $returnTo = $wgTitle->getPrefixedDBkey();
  966. $query = array();
  967. if ( $logoutPage != $returnTo ) {
  968. $query['returnto'] = $returnTo;
  969. }
  970. $loginlink = $wgUser->isAllowed( 'createaccount' )
  971. ? 'nav-login-createaccount'
  972. : 'login';
  973. $ret .= "\n<br />" . $this->link(
  974. SpecialPage::getTitleFor( 'Userlogin' ),
  975. wfMsg( $loginlink ), array(), $query
  976. );
  977. } else {
  978. $returnTo = $wgTitle->getPrefixedDBkey();
  979. $talkLink = $this->link( $wgUser->getTalkPage(),
  980. $wgLang->getNsText( NS_TALK ) );
  981. $ret .= $this->link( $wgUser->getUserPage(),
  982. htmlspecialchars( $wgUser->getName() ) );
  983. $ret .= " ($talkLink)<br />";
  984. $ret .= $wgLang->pipeList( array(
  985. $this->link(
  986. SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
  987. array(), array( 'returnto' => $returnTo )
  988. ),
  989. $this->specialLink( 'preferences' ),
  990. ) );
  991. }
  992. $ret = $wgLang->pipeList( array(
  993. $ret,
  994. $this->link(
  995. Title::newFromText( wfMsgForContent( 'helppage' ) ),
  996. wfMsg( 'help' )
  997. ),
  998. ) );
  999. return $ret;
  1000. }
  1001. function getSearchLink() {
  1002. $searchPage = SpecialPage::getTitleFor( 'Search' );
  1003. return $searchPage->getLocalURL();
  1004. }
  1005. function escapeSearchLink() {
  1006. return htmlspecialchars( $this->getSearchLink() );
  1007. }
  1008. function searchForm() {
  1009. global $wgRequest, $wgUseTwoButtonsSearchForm;
  1010. $search = $wgRequest->getText( 'search' );
  1011. $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
  1012. . $this->escapeSearchLink() . "\">\n"
  1013. . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
  1014. . htmlspecialchars(substr($search,0,256)) . "\" />\n"
  1015. . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />';
  1016. if ($wgUseTwoButtonsSearchForm)
  1017. $s .= '&nbsp;<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n";
  1018. else
  1019. $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg ('powersearch-legend') . "</a>\n";
  1020. $s .= '</form>';
  1021. // Ensure unique id's for search boxes made after the first
  1022. $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
  1023. return $s;
  1024. }
  1025. function topLinks() {
  1026. global $wgOut;
  1027. $s = array(
  1028. $this->mainPageLink(),
  1029. $this->specialLink( 'recentchanges' )
  1030. );
  1031. if ( $wgOut->isArticleRelated() ) {
  1032. $s[] = $this->editThisPage();
  1033. $s[] = $this->historyLink();
  1034. }
  1035. # Many people don't like this dropdown box
  1036. #$s[] = $this->specialPagesList();
  1037. if( $this->variantLinks() ) {
  1038. $s[] = $this->variantLinks();
  1039. }
  1040. if( $this->extensionTabLinks() ) {
  1041. $s[] = $this->extensionTabLinks();
  1042. }
  1043. // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
  1044. return implode( $s, wfMsgExt( 'pipe-separator' , 'escapenoentities' ) . "\n" );
  1045. }
  1046. /**
  1047. * Compatibility for extensions adding functionality through tabs.
  1048. * Eventually these old skins should be replaced with SkinTemplate-based
  1049. * versions, sigh...
  1050. * @return string
  1051. */
  1052. function extensionTabLinks() {
  1053. $tabs = array();
  1054. $out = '';
  1055. $s = array();
  1056. wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
  1057. foreach( $tabs as $tab ) {
  1058. $s[] = Xml::element( 'a',
  1059. array( 'href' => $tab['href'] ),
  1060. $tab['text'] );
  1061. }
  1062. if( count( $s ) ) {
  1063. global $wgLang;
  1064. $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
  1065. $out .= $wgLang->pipeList( $s );
  1066. }
  1067. return $out;
  1068. }
  1069. /**
  1070. * Language/charset variant links for classic-style skins
  1071. * @return string
  1072. */
  1073. function variantLinks() {
  1074. $s = '';
  1075. /* show links to different language variants */
  1076. global $wgDisableLangConversion, $wgLang, $wgContLang, $wgTitle;
  1077. $variants = $wgContLang->getVariants();
  1078. if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
  1079. foreach( $variants as $code ) {
  1080. $varname = $wgContLang->getVariantname( $code );
  1081. if( $varname == 'disable' )
  1082. continue;
  1083. $s = $wgLang->pipeList( array( $s, '<a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>' ) );
  1084. }
  1085. }
  1086. return $s;
  1087. }
  1088. function bottomLinks() {
  1089. global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
  1090. $sep = wfMsgExt( 'pipe-separator' , 'escapenoentities' ) . "\n";
  1091. $s = '';
  1092. if ( $wgOut->isArticleRelated() ) {
  1093. $element[] = '<strong>' . $this->editThisPage() . '</strong>';
  1094. if ( $wgUser->isLoggedIn() ) {
  1095. $element[] = $this->watchThisPage();
  1096. }
  1097. $element[] = $this->talkLink();
  1098. $element[] = $this->historyLink();
  1099. $element[] = $this->whatLinksHere();
  1100. $element[] = $this->watchPageLinksLink();
  1101. if ($wgUseTrackbacks)
  1102. $element[] = $this->trackbackLink();
  1103. if ( $wgTitle->getNamespace() == NS_USER
  1104. || $wgTitle->getNamespace() == NS_USER_TALK )
  1105. {
  1106. $id=User::idFromName($wgTitle->getText());
  1107. $ip=User::isIP($wgTitle->getText());
  1108. if($id || $ip) { # both anons and non-anons have contri list
  1109. $element[] = $this->userContribsLink();
  1110. }
  1111. if( $this->showEmailUser( $id ) ) {
  1112. $element[] = $this->emailUserLink();
  1113. }
  1114. }
  1115. $s = implode( $element, $sep );
  1116. if ( $wgTitle->getArticleId() ) {
  1117. $s .= "\n<br />";
  1118. if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
  1119. if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
  1120. if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
  1121. }
  1122. $s .= "<br />\n" . $this->otherLanguages();
  1123. }
  1124. return $s;
  1125. }
  1126. function pageStats() {
  1127. global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
  1128. global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
  1129. $oldid = $wgRequest->getVal( 'oldid' );
  1130. $diff = $wgRequest->getVal( 'diff' );
  1131. if ( ! $wgOut->isArticle() ) { return ''; }
  1132. if( !$wgArticle instanceOf Article ) { return ''; }
  1133. if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
  1134. if ( 0 == $wgArticle->getID() ) { return ''; }
  1135. $s = '';
  1136. if ( !$wgDisableCounters ) {
  1137. $count = $wgLang->formatNum( $wgArticle->getCount() );
  1138. if ( $count ) {
  1139. $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
  1140. }
  1141. }
  1142. if( $wgMaxCredits != 0 ){
  1143. $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
  1144. } else {
  1145. $s .= $this->lastModified();
  1146. }
  1147. if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
  1148. $dbr = wfGetDB( DB_SLAVE );
  1149. $watchlist = $dbr->tableName( 'watchlist' );
  1150. $sql = "SELECT COUNT(*) AS n FROM $watchlist
  1151. WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
  1152. "' AND wl_namespace=" . $wgTitle->getNamespace() ;
  1153. $res = $dbr->query( $sql, 'Skin::pageStats');
  1154. $x = $dbr->fetchObject( $res );
  1155. $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
  1156. array( 'parseinline' ), $wgLang->formatNum($x->n)
  1157. );
  1158. }
  1159. return $s . ' ' . $this->getCopyright();
  1160. }
  1161. function getCopyright( $type = 'detect' ) {
  1162. global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
  1163. if ( $type == 'detect' ) {
  1164. $diff = $wgRequest->getVal( 'diff' );
  1165. $isCur = $wgArticle && $wgArticle->isCurrent();
  1166. if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
  1167. $type = 'history';
  1168. } else {
  1169. $type = 'normal';
  1170. }
  1171. }
  1172. if ( $type == 'history' ) {
  1173. $msg = 'history_copyright';
  1174. } else {
  1175. $msg = 'copyright';
  1176. }
  1177. $out = '';
  1178. if( $wgRightsPage ) {
  1179. $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
  1180. } elseif( $wgRightsUrl ) {
  1181. $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
  1182. } elseif( $wgRightsText ) {
  1183. $link = $wgRightsText;
  1184. } else {
  1185. # Give up now
  1186. return $out;
  1187. }
  1188. $out .= wfMsgForContent( $msg, $link );
  1189. return $out;
  1190. }
  1191. function getCopyrightIcon() {
  1192. global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
  1193. $out = '';
  1194. if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
  1195. $out = $wgCopyrightIcon;
  1196. } else if ( $wgRightsIcon ) {
  1197. $icon = htmlspecialchars( $wgRightsIcon );
  1198. if ( $wgRightsUrl ) {
  1199. $url = htmlspecialchars( $wgRightsUrl );
  1200. $out .= '<a href="'.$url.'">';
  1201. }
  1202. $text = htmlspecialchars( $wgRightsText );
  1203. $out .= "<img src=\"$icon\" alt='$text' />";
  1204. if ( $wgRightsUrl ) {
  1205. $out .= '</a>';
  1206. }
  1207. }
  1208. return $out;
  1209. }
  1210. function getPoweredBy() {
  1211. global $wgStylePath;
  1212. $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
  1213. $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
  1214. return $img;
  1215. }
  1216. function lastModified() {
  1217. global $wgLang, $wgArticle;
  1218. if( $this->mRevisionId ) {
  1219. $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
  1220. } else {
  1221. $timestamp = $wgArticle->getTimestamp();
  1222. }
  1223. if ( $timestamp ) {
  1224. $d = $wgLang->date( $timestamp, true );
  1225. $t = $wgLang->time( $timestamp, true );
  1226. $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
  1227. } else {
  1228. $s = '';
  1229. }
  1230. if ( wfGetLB()->getLaggedSlaveMode() ) {
  1231. $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
  1232. }
  1233. return $s;
  1234. }
  1235. function logoText( $align = '' ) {
  1236. if ( '' != $align ) { $a = " align='{$align}'"; }
  1237. else { $a = ''; }
  1238. $mp = wfMsg( 'mainpage' );
  1239. $mptitle = Title::newMainPage();
  1240. $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
  1241. $logourl = $this->getLogo();
  1242. $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
  1243. return $s;
  1244. }
  1245. /**
  1246. * show a drop-down box of special pages
  1247. */
  1248. function specialPagesList() {
  1249. global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
  1250. $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
  1251. foreach ( $pages as $name => $page ) {
  1252. $pages[$name] = $page->getDescription();
  1253. }
  1254. $go = wfMsg( 'go' );
  1255. $sp = wfMsg( 'specialpages' );
  1256. $spp = $wgContLang->specialPage( 'Specialpages' );
  1257. $s = '<form id="specialpages" method="get" ' .
  1258. 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
  1259. $s .= "<select name=\"wpDropdown\">\n";
  1260. $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
  1261. foreach ( $pages as $name => $desc ) {
  1262. $p = $wgContLang->specialPage( $name );
  1263. $s .= "<option value=\"{$p}\">{$desc}</option>\n";
  1264. }
  1265. $s .= "</select>\n";
  1266. $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
  1267. $s .= "</form>\n";
  1268. return $s;
  1269. }
  1270. function mainPageLink() {
  1271. $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
  1272. return $s;
  1273. }
  1274. function copyrightLink() {
  1275. $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
  1276. wfMsg( 'copyrightpagename' ) );
  1277. return $s;
  1278. }
  1279. private function footerLink ( $desc, $page ) {
  1280. // if the link description has been set to "-" in the default language,
  1281. if ( wfMsgForContent( $desc ) == '-') {
  1282. // then it is disabled, for all languages.
  1283. return '';
  1284. } else {
  1285. // Otherwise, we display the link for the user, described in their
  1286. // language (which may or may not be the same as the default language),
  1287. // but we make the link target be the one site-wide page.
  1288. return $this->makeKnownLink( wfMsgForContent( $page ),
  1289. wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
  1290. }
  1291. }
  1292. function privacyLink() {
  1293. return $this->footerLink( 'privacy', 'privacypage' );
  1294. }
  1295. function aboutLink() {
  1296. return $this->footerLink( 'aboutsite', 'aboutpage' );
  1297. }
  1298. function disclaimerLink() {
  1299. return $this->footerLink( 'disclaimers', 'disclaimerpage' );
  1300. }
  1301. function editThisPage() {
  1302. global $wgOut, $wgTitle;
  1303. if ( !$wgOut->isArticleRelated() ) {
  1304. $s = wfMsg( 'protectedpage' );
  1305. } else {
  1306. if( $wgTitle->quickUserCan( 'edit' ) && $wgTitle->exists() ) {
  1307. $t = wfMsg( 'editthispage' );
  1308. } elseif( $wgTitle->quickUserCan( 'create' ) && !$wgTitle->exists() ) {
  1309. $t = wfMsg( 'create-this-page' );
  1310. } else {
  1311. $t = wfMsg( 'viewsource' );
  1312. }
  1313. $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
  1314. }
  1315. return $s;
  1316. }
  1317. /**
  1318. * Return URL options for the 'edit page' link.
  1319. * This may include an 'oldid' specifier, if the current page view is such.
  1320. *
  1321. * @return string
  1322. * @private
  1323. */
  1324. function editUrlOptions() {
  1325. global $wgArticle;
  1326. if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
  1327. return "action=edit&oldid=" . intval( $this->mRevisionId );
  1328. } else {
  1329. return "action=edit";
  1330. }
  1331. }
  1332. function deleteThisPage() {
  1333. global $wgUser, $wgTitle, $wgRequest;
  1334. $diff = $wgRequest->getVal( 'diff' );
  1335. if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
  1336. $t = wfMsg( 'deletethispage' );
  1337. $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
  1338. } else {
  1339. $s = '';
  1340. }
  1341. return $s;
  1342. }
  1343. function protectThisPage() {
  1344. global $wgUser, $wgTitle, $wgRequest;
  1345. $diff = $wgRequest->getVal( 'diff' );
  1346. if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
  1347. if ( $wgTitle->isProtected() ) {
  1348. $t = wfMsg( 'unprotectthispage' );
  1349. $q = 'action=unprotect';
  1350. } else {
  1351. $t = wfMsg( 'protectthispage' );
  1352. $q = 'action=protect';
  1353. }
  1354. $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
  1355. } else {
  1356. $s = '';
  1357. }
  1358. return $s;
  1359. }
  1360. function watchThisPage() {
  1361. global $wgOut, $wgTitle;
  1362. ++$this->mWatchLinkNum;
  1363. if ( $wgOut->isArticleRelated() ) {
  1364. if ( $wgTitle->userIsWatching() ) {
  1365. $t = wfMsg( 'unwatchthispage' );
  1366. $q = 'action=unwatch';
  1367. $id = "mw-unwatch-link".$this->mWatchLinkNum;
  1368. } else {
  1369. $t = wfMsg( 'watchthispage' );
  1370. $q = 'action=watch';
  1371. $id = 'mw-watch-link'.$this->mWatchLinkNum;
  1372. }
  1373. $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
  1374. } else {
  1375. $s = wfMsg( 'notanarticle' );
  1376. }
  1377. return $s;
  1378. }
  1379. function moveThisPage() {
  1380. global $wgTitle;
  1381. if ( $wgTitle->quickUserCan( 'move' ) ) {
  1382. return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
  1383. wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
  1384. } else {
  1385. // no message if page is protected - would be redundant
  1386. return '';
  1387. }
  1388. }
  1389. function historyLink() {
  1390. global $wgTitle;
  1391. return $this->link( $wgTitle, wfMsg( 'history' ),
  1392. array( 'rel' => 'archives' ), array( 'action' => 'history' ) );
  1393. }
  1394. function whatLinksHere() {
  1395. global $wgTitle;
  1396. return $this->makeKnownLinkObj(
  1397. SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
  1398. wfMsg( 'whatlinkshere' ) );
  1399. }
  1400. function userContribsLink() {
  1401. global $wgTitle;
  1402. return $this->makeKnownLinkObj(
  1403. SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
  1404. wfMsg( 'contributions' ) );
  1405. }
  1406. function showEmailUser( $id ) {
  1407. global $wgUser;
  1408. $targetUser = User::newFromId( $id );
  1409. return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
  1410. $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
  1411. }
  1412. function emailUserLink() {
  1413. global $wgTitle;
  1414. return $this->makeKnownLinkObj(
  1415. SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
  1416. wfMsg( 'emailuser' ) );
  1417. }
  1418. function watchPageLinksLink() {
  1419. global $wgOut, $wgTitle;
  1420. if ( ! $wgOut->isArticleRelated() ) {
  1421. return '(' . wfMsg( 'notanarticle' ) . ')';
  1422. } else {
  1423. return $this->makeKnownLinkObj(
  1424. SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
  1425. wfMsg( 'recentchangeslinked' ) );
  1426. }
  1427. }
  1428. function trackbackLink() {
  1429. global $wgTitle;
  1430. return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
  1431. . wfMsg('trackbacklink') . "</a>";
  1432. }
  1433. function otherLanguages() {
  1434. global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
  1435. if ( $wgHideInterlanguageLinks ) {
  1436. return '';
  1437. }
  1438. $a = $wgOut->getLanguageLinks();
  1439. if ( 0 == count( $a ) ) {
  1440. return '';
  1441. }
  1442. $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
  1443. $first = true;
  1444. if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
  1445. foreach( $a as $l ) {
  1446. if ( ! $first ) { $s .= wfMsgExt( 'pipe-separator' , 'escapenoentities' ); }
  1447. $first = false;
  1448. $nt = Title::newFromText( $l );
  1449. $url = $nt->escapeFullURL();
  1450. $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
  1451. if ( '' == $text ) { $text = $l; }
  1452. $style = $this->getExternalLinkAttributes( $l, $text );
  1453. $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
  1454. }
  1455. if($wgContLang->isRTL()) $s .= '</span>';
  1456. return $s;
  1457. }
  1458. function talkLink() {
  1459. global $wgTitle;
  1460. if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
  1461. # No discussion links for special pages
  1462. return '';
  1463. }
  1464. $linkOptions = array();
  1465. if( $wgTitle->isTalkPage() ) {
  1466. $link = $wgTitle->getSubjectPage();
  1467. switch( $link->getNamespace() ) {
  1468. case NS_MAIN:
  1469. $text = wfMsg( 'articlepage' );
  1470. break;
  1471. case NS_USER:
  1472. $text = wfMsg( 'userpage' );
  1473. break;
  1474. case NS_PROJECT:
  1475. $text = wfMsg( 'projectpage' );
  1476. break;
  1477. case NS_FILE:
  1478. $text = wfMsg( 'imagepage' );
  1479. # Make link known if image exists, even if the desc. page doesn't.
  1480. if( wfFindFile( $link ) )
  1481. $linkOptions[] = 'known';
  1482. break;
  1483. case NS_MEDIAWIKI:
  1484. $text = wfMsg( 'mediawikipage' );
  1485. break;
  1486. case NS_TEMPLATE:
  1487. $text = wfMsg( 'templatepage' );
  1488. break;
  1489. case NS_HELP:
  1490. $text = wfMsg( 'viewhelppage' );
  1491. break;
  1492. case NS_CATEGORY:
  1493. $text = wfMsg( 'categorypage' );
  1494. break;
  1495. default:
  1496. $text = wfMsg( 'articlepage' );
  1497. }
  1498. } else {
  1499. $link = $wgTitle->getTalkPage();
  1500. $text = wfMsg( 'talkpage' );
  1501. }
  1502. $s = $this->link( $link, $text, array(), array(), $linkOptions );
  1503. return $s;
  1504. }
  1505. function commentLink() {
  1506. global $wgTitle, $wgOut;
  1507. if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
  1508. return '';
  1509. }
  1510. # __NEWSECTIONLINK___ changes behaviour here
  1511. # If it's present, the link points to this page, otherwise
  1512. # it points to the talk page
  1513. if( $wgTitle->isTalkPage() ) {
  1514. $title = $wgTitle;
  1515. } elseif( $wgOut->showNewSectionLink() ) {
  1516. $title = $wgTitle;
  1517. } else {
  1518. $title = $wgTitle->getTalkPage();
  1519. }
  1520. return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
  1521. }
  1522. /* these are used extensively in SkinTemplate, but also some other places */
  1523. static function makeMainPageUrl( $urlaction = '' ) {
  1524. $title = Title::newMainPage();
  1525. self::checkTitle( $title, '' );
  1526. return $title->getLocalURL( $urlaction );
  1527. }
  1528. static function makeSpecialUrl( $name, $urlaction = '' ) {
  1529. $title = SpecialPage::getTitleFor( $name );
  1530. return $title->getLocalURL( $urlaction );
  1531. }
  1532. static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
  1533. $title = SpecialPage::getSafeTitleFor( $name, $subpage );
  1534. return $title->getLocalURL( $urlaction );
  1535. }
  1536. static function makeI18nUrl( $name, $urlaction = '' ) {
  1537. $title = Title::newFromText( wfMsgForContent( $name ) );
  1538. self::checkTitle( $title, $name );
  1539. return $title->getLocalURL( $urlaction );
  1540. }
  1541. static function makeUrl( $name, $urlaction = '' ) {
  1542. $title = Title::newFromText( $name );
  1543. self::checkTitle( $title, $name );
  1544. return $title->getLocalURL( $urlaction );
  1545. }
  1546. # If url string starts with http, consider as external URL, else
  1547. # internal
  1548. static function makeInternalOrExternalUrl( $name ) {
  1549. if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
  1550. return $name;
  1551. } else {
  1552. return self::makeUrl( $name );
  1553. }
  1554. }
  1555. # this can be passed the NS number as defined in Language.php
  1556. static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
  1557. $title = Title::makeTitleSafe( $namespace, $name );
  1558. self::checkTitle( $title, $name );
  1559. return $title->getLocalURL( $urlaction );
  1560. }
  1561. /* these return an array with the 'href' and boolean 'exists' */
  1562. static function makeUrlDetails( $name, $urlaction = '' ) {
  1563. $title = Title::newFromText( $name );
  1564. self::checkTitle( $title, $name );
  1565. return array(
  1566. 'href' => $title->getLocalURL( $urlaction ),
  1567. 'exists' => $title->getArticleID() != 0 ? true : false
  1568. );
  1569. }
  1570. /**
  1571. * Make URL details where the article exists (or at least it's convenient to think so)
  1572. */
  1573. static function makeKnownUrlDetails( $name, $urlaction = '' ) {
  1574. $title = Title::newFromText( $name );
  1575. self::checkTitle( $title, $name );
  1576. return array(
  1577. 'href' => $title->getLocalURL( $urlaction ),
  1578. 'exists' => true
  1579. );
  1580. }
  1581. # make sure we have some title to operate on
  1582. static function checkTitle( &$title, $name ) {
  1583. if( !is_object( $title ) ) {
  1584. $title = Title::newFromText( $name );
  1585. if( !is_object( $title ) ) {
  1586. $title = Title::newFromText( '--error: link target missing--' );
  1587. }
  1588. }
  1589. }
  1590. /**
  1591. * Build an array that represents the sidebar(s), the navigation bar among them
  1592. *
  1593. * @return array
  1594. */
  1595. function buildSidebar() {
  1596. global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
  1597. global $wgLang;
  1598. wfProfileIn( __METHOD__ );
  1599. $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
  1600. if ( $wgEnableSidebarCache ) {
  1601. $cachedsidebar = $parserMemc->get( $key );
  1602. if ( $cachedsidebar ) {
  1603. wfProfileOut( __METHOD__ );
  1604. return $cachedsidebar;
  1605. }
  1606. }
  1607. $bar = array();
  1608. $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
  1609. $heading = '';
  1610. foreach ($lines as $line) {
  1611. if (strpos($line, '*') !== 0)
  1612. continue;
  1613. if (strpos($line, '**') !== 0) {
  1614. $line = trim($line, '* ');
  1615. $heading = $line;
  1616. if( !array_key_exists($heading, $bar) ) $bar[$heading] = array();
  1617. } else {
  1618. if (strpos($line, '|') !== false) { // sanity check
  1619. $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
  1620. $link = wfMsgForContent( $line[0] );
  1621. if ($link == '-')
  1622. continue;
  1623. $text = wfMsgExt($line[1], 'parsemag');
  1624. if (wfEmptyMsg($line[1], $text))
  1625. $text = $line[1];
  1626. if (wfEmptyMsg($line[0], $link))
  1627. $link = $line[0];
  1628. if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
  1629. $href = $link;
  1630. } else {
  1631. $title = Title::newFromText( $link );
  1632. if ( $title ) {
  1633. $title = $title->fixSpecialName();
  1634. $href = $title->getLocalURL();
  1635. } else {
  1636. $href = 'INVALID-TITLE';
  1637. }
  1638. }
  1639. $bar[$heading][] = array(
  1640. 'text' => $text,
  1641. 'href' => $href,
  1642. 'id' => 'n-' . strtr($line[1], ' ', '-'),
  1643. 'active' => false
  1644. );
  1645. } else { continue; }
  1646. }
  1647. }
  1648. wfRunHooks('SkinBuildSidebar', array($this, &$bar));
  1649. if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
  1650. wfProfileOut( __METHOD__ );
  1651. return $bar;
  1652. }
  1653. }