More function level documentation
[lhc/web/wiklou.git] / skins / Standard.php
1 <?php
2 /**
3 * Standard (a.k.a. Classic) skin: old MediaWiki default skin
4 *
5 * @file
6 * @ingroup Skins
7 */
8
9 if( !defined( 'MEDIAWIKI' ) ) {
10 die( -1 );
11 }
12
13 /**
14 * @todo document
15 * @ingroup Skins
16 */
17 class SkinStandard extends SkinLegacy {
18 var $skinname = 'standard', $stylename = 'standard',
19 $template = 'StandardTemplate';
20
21 /**
22 *
23 */
24 function setupSkinUserCss( OutputPage $out ){
25 parent::setupSkinUserCss( $out );
26 $out->AddModuleStyles( 'skins.standard' );
27
28 global $wgContLang;
29 $qb = $this->qbSetting();
30 $rules = array();
31
32 if ( 2 == $qb ) { # Right
33 $rules[] = "#quickbar { position: absolute; top: 4px; right: 4px; border-left: 2px solid #000000; }";
34 $rules[] = "#article, #mw-data-after-content { margin-left: 4px; margin-right: 152px; }";
35 } elseif ( 1 == $qb || 3 == $qb ) {
36 $rules[] = "#quickbar { position: absolute; top: 4px; left: 4px; border-right: 1px solid gray; }";
37 $rules[] = "#article, #mw-data-after-content { margin-left: 152px; margin-right: 4px; }";
38 if( 3 == $qb ) {
39 $rules[] = "#quickbar { position: fixed; padding: 4px; }";
40 }
41 } elseif ( 4 == $qb ) {
42 $rules[] = "#quickbar { position: fixed; right: 0px; top: 0px; padding: 4px;}";
43 $rules[] = "#quickbar { border-right: 1px solid gray; }";
44 $rules[] = "#article, #mw-data-after-content { margin-right: 152px; margin-left: 4px; }";
45 }
46 $style = implode( "\n", $rules );
47 if ( $wgContLang->getDir() === 'rtl' ) {
48 $style = CSSJanus::transform( $style, true, false );
49 }
50 $out->addInlineStyle( $style );
51 }
52
53 }
54
55 class StandardTemplate extends LegacyTemplate {
56
57 function doAfterContent() {
58 global $wgContLang, $wgLang;
59 wfProfileIn( __METHOD__ );
60 wfProfileIn( __METHOD__ . '-1' );
61
62 $s = "\n</div><br style=\"clear:both\" />\n";
63 $s .= "\n<div id='footer'>";
64 $s .= '<table border="0" cellspacing="0"><tr>';
65
66 wfProfileOut( __METHOD__ . '-1' );
67 wfProfileIn( __METHOD__ . '-2' );
68
69 $qb = $this->getSkin()->qbSetting();
70 $shove = ( $qb != 0 );
71 $left = ( $qb == 1 || $qb == 3 );
72
73 if ( $shove && $left ) { # Left
74 $s .= $this->getQuickbarCompensator();
75 }
76 wfProfileOut( __METHOD__ . '-2' );
77 wfProfileIn( __METHOD__ . '-3' );
78 $l = $wgContLang->alignStart();
79 $s .= "<td class='bottom' align='$l' valign='top'>";
80
81 $s .= $this->bottomLinks();
82 $s .= "\n<br />" . $wgLang->pipeList( array(
83 $this->getSkin()->mainPageLink(),
84 $this->getSkin()->aboutLink(),
85 $this->getSkin()->specialLink( 'Recentchanges' ),
86 $this->searchForm() ) )
87 . '<br /><span id="pagestats">' . $this->pageStats() . '</span>';
88
89 $s .= '</td>';
90 if ( $shove && !$left ) { # Right
91 $s .= $this->getQuickbarCompensator();
92 }
93 $s .= "</tr></table>\n</div>\n</div>\n";
94
95 wfProfileOut( __METHOD__ . '-3' );
96 wfProfileIn( __METHOD__ . '-4' );
97 if ( 0 != $qb ) {
98 $s .= $this->quickBar();
99 }
100 wfProfileOut( __METHOD__ . '-4' );
101 wfProfileOut( __METHOD__ );
102 return $s;
103 }
104
105 function quickBar() {
106 global $wgOut, $wgUser, $wgRequest, $wgContLang;
107
108 wfProfileIn( __METHOD__ );
109
110 $action = $wgRequest->getText( 'action' );
111 $wpPreview = $wgRequest->getBool( 'wpPreview' );
112 $tns = $this->getSkin()->getTitle()->getNamespace();
113
114 $s = "\n<div id='quickbar'>";
115 $s .= "\n" . $this->getSkin()->logoText() . "\n<hr class='sep' />";
116
117 $sep = "\n<br />";
118
119 # Use the first heading from the Monobook sidebar as the "browse" section
120 $bar = $this->getSkin()->buildSidebar();
121 unset( $bar['SEARCH'] );
122 unset( $bar['LANGUAGES'] );
123 unset( $bar['TOOLBOX'] );
124 $browseLinks = reset( $bar );
125
126 foreach ( $browseLinks as $link ) {
127 if ( $link['text'] != '-' ) {
128 $s .= "<a href=\"{$link['href']}\">" .
129 htmlspecialchars( $link['text'] ) . '</a>' . $sep;
130 }
131 }
132
133 if( $wgUser->isLoggedIn() ) {
134 $s.= $this->getSkin()->specialLink( 'Watchlist' ) ;
135 $s .= $sep . $this->getSkin()->linkKnown(
136 SpecialPage::getTitleFor( 'Contributions' ),
137 wfMsg( 'mycontris' ),
138 array(),
139 array( 'target' => $wgUser->getName() )
140 );
141 }
142 // only show watchlist link if logged in
143 $s .= "\n<hr class='sep' />";
144 $articleExists = $this->getSkin()->getTitle()->getArticleId();
145 if ( $wgOut->isArticle() || $action == 'edit' || $action == 'history' || $wpPreview ) {
146 if( $wgOut->isArticle() ) {
147 $s .= '<strong>' . $this->editThisPage() . '</strong>';
148 } else { # backlink to the article in edit or history mode
149 if( $articleExists ){ # no backlink if no article
150 switch( $tns ) {
151 case NS_TALK:
152 case NS_USER_TALK:
153 case NS_PROJECT_TALK:
154 case NS_FILE_TALK:
155 case NS_MEDIAWIKI_TALK:
156 case NS_TEMPLATE_TALK:
157 case NS_HELP_TALK:
158 case NS_CATEGORY_TALK:
159 $text = wfMsg('viewtalkpage');
160 break;
161 case NS_MAIN:
162 $text = wfMsg( 'articlepage' );
163 break;
164 case NS_USER:
165 $text = wfMsg( 'userpage' );
166 break;
167 case NS_PROJECT:
168 $text = wfMsg( 'projectpage' );
169 break;
170 case NS_FILE:
171 $text = wfMsg( 'imagepage' );
172 break;
173 case NS_MEDIAWIKI:
174 $text = wfMsg( 'mediawikipage' );
175 break;
176 case NS_TEMPLATE:
177 $text = wfMsg( 'templatepage' );
178 break;
179 case NS_HELP:
180 $text = wfMsg( 'viewhelppage' );
181 break;
182 case NS_CATEGORY:
183 $text = wfMsg( 'categorypage' );
184 break;
185 default:
186 $text = wfMsg( 'articlepage' );
187 }
188
189 $link = $this->getSkin()->getTitle()->getText();
190 $nstext = $wgContLang->getNsText( $tns );
191 if( $nstext ) { # add namespace if necessary
192 $link = $nstext . ':' . $link;
193 }
194
195 $s .= $this->getSkin()->link(
196 Title::newFromText( $link ),
197 $text
198 );
199 } elseif( $this->getSkin()->getTitle()->getNamespace() != NS_SPECIAL ) {
200 # we just throw in a "New page" text to tell the user that he's in edit mode,
201 # and to avoid messing with the separator that is prepended to the next item
202 $s .= '<strong>' . wfMsg( 'newpage' ) . '</strong>';
203 }
204 }
205
206 # "Post a comment" link
207 if( ( $this->getSkin()->getTitle()->isTalkPage() || $wgOut->showNewSectionLink() ) && $action != 'edit' && !$wpPreview )
208 $s .= '<br />' . $this->getSkin()->link(
209 $this->getSkin()->getTitle(),
210 wfMsg( 'postcomment' ),
211 array(),
212 array(
213 'action' => 'edit',
214 'section' => 'new'
215 ),
216 array( 'known', 'noclasses' )
217 );
218
219 /*
220 watching could cause problems in edit mode:
221 if user edits article, then loads "watch this article" in background and then saves
222 article with "Watch this article" checkbox disabled, the article is transparently
223 unwatched. Therefore we do not show the "Watch this page" link in edit mode
224 */
225 if ( $wgUser->isLoggedIn() && $articleExists ) {
226 if( $action != 'edit' && $action != 'submit' ) {
227 $s .= $sep . $this->watchThisPage();
228 }
229 if ( $this->getSkin()->getTitle()->userCan( 'edit' ) )
230 $s .= $sep . $this->moveThisPage();
231 }
232 if ( $wgUser->isAllowed( 'delete' ) && $articleExists ) {
233 $s .= $sep . $this->deleteThisPage() .
234 $sep . $this->protectThisPage();
235 }
236 $s .= $sep . $this->talkLink();
237 if( $articleExists && $action != 'history' ) {
238 $s .= $sep . $this->historyLink();
239 }
240 $s .= $sep . $this->whatLinksHere();
241
242 if( $wgOut->isArticleRelated() ) {
243 $s .= $sep . $this->watchPageLinksLink();
244 }
245
246 if (
247 NS_USER == $this->getSkin()->getTitle()->getNamespace() ||
248 $this->getSkin()->getTitle()->getNamespace() == NS_USER_TALK
249 ) {
250
251 $id = User::idFromName( $this->getSkin()->getTitle()->getText() );
252 $ip = User::isIP( $this->getSkin()->getTitle()->getText() );
253
254 if( $id || $ip ){
255 $s .= $sep . $this->userContribsLink();
256 }
257 if( $this->showEmailUser( $id ) ) {
258 $s .= $sep . $this->emailUserLink();
259 }
260 }
261 $s .= "\n<br /><hr class='sep' />";
262 }
263
264 if( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
265 $s .= $this->getUploadLink() . $sep;
266 }
267
268 $s .= $this->getSkin()->specialLink( 'Specialpages' );
269
270 global $wgSiteSupportPage;
271 if( $wgSiteSupportPage ) {
272 $s .= "\n<br /><a href=\"" . htmlspecialchars( $wgSiteSupportPage ) .
273 '" class="internal">' . wfMsg( 'sitesupport' ) . '</a>';
274 }
275
276 $s .= "\n<br /></div>\n";
277 wfProfileOut( __METHOD__ );
278 return $s;
279 }
280
281 }