Image redirect fix back in
[lhc/web/wiklou.git] / includes / Wiki.php
1 <?php
2 /**
3 * MediaWiki is the to-be base class for this whole project
4 */
5
6 class MediaWiki {
7
8 var $params = array();
9
10 function setVal( $key, &$value ) {
11 $this->param[strtolower( $key )] = $value;
12 }
13
14 function getVal( $key, $default = "" ) {
15 $key = strtolower( $key );
16 if( isset( $this->params[$key] ) ) {
17 return $this->params[$key];
18 }
19 return $default;
20 }
21
22 function initializeArticle( &$title, $request, $action ) {
23 if( NS_MEDIA == $title->getNamespace() ) {
24 $title = Title::makeTitle( NS_IMAGE, $title->getDBkey() );
25 }
26
27 $ns = $title->getNamespace();
28
29 // Namespace might change when using redirects
30 $article = new Article( $title );
31 if( $action == 'view' && !$request->getVal( 'oldid' ) ) {
32 $rTitle = Title::newFromRedirect( $article->fetchContent() );
33 if( $rTitle ) {
34 # Reload from the page pointed to later
35 $article->mContentLoaded = false;
36 $ns = $rTitle->getNamespace();
37 $wasRedirected = true;
38 }
39 }
40
41 // Categories and images are handled by a different class
42 if( $ns == NS_IMAGE ) {
43 $b4 = $title->getPrefixedText();
44 unset( $article );
45 require_once( 'includes/ImagePage.php' );
46 $article = new ImagePage( $title );
47 if( isset( $wasRedirected ) && $request->getVal( 'redirect' ) != 'no' ) {
48 $article->mTitle = $rTitle;
49 $article->mRedirectedFrom = $b4;
50 }
51 } elseif( $ns == NS_CATEGORY ) {
52 unset( $article );
53 require_once( 'includes/CategoryPage.php' );
54 $article = new CategoryPage( $title );
55 }
56 return $article;
57 }
58
59 function performAction( $action, &$output, &$article, &$title, &$user, &$request ) {
60 switch( $action ) {
61 case 'view':
62 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
63 $article->view();
64 break;
65 case 'watch':
66 case 'unwatch':
67 case 'delete':
68 case 'revert':
69 case 'rollback':
70 case 'protect':
71 case 'unprotect':
72 case 'info':
73 case 'markpatrolled':
74 case 'validate':
75 case 'render':
76 case 'deletetrackback':
77 case 'purge':
78 $article->$action();
79 break;
80 case 'print':
81 $article->view();
82 break;
83 case 'dublincore':
84 if( !$this->getVal( 'EnableDublinCoreRdf' ) ) {
85 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
86 } else {
87 require_once( 'includes/Metadata.php' );
88 wfDublinCoreRdf( $article );
89 }
90 break;
91 case 'creativecommons':
92 if( !$this->getVal( 'EnableCreativeCommonsRdf' ) ) {
93 wfHttpError( 403, 'Forbidden', wfMsg( 'nocreativecommons' ) );
94 } else {
95 require_once( 'includes/Metadata.php' );
96 wfCreativeCommonsRdf( $article );
97 }
98 break;
99 case 'credits':
100 require_once( 'includes/Credits.php' );
101 showCreditsPage( $article );
102 break;
103 case 'submit':
104 if( !$this->getVal( 'CommandLineMode' ) && !$request->checkSessionCookie() ) {
105 # Send a cookie so anons get talk message notifications
106 User::SetupSession();
107 }
108 # Continue...
109 case 'edit':
110 $internal = $request->getVal( 'internaledit' );
111 $external = $request->getVal( 'externaledit' );
112 $section = $request->getVal( 'section' );
113 $oldid = $request->getVal( 'oldid' );
114 if( !$this->getVal( 'UseExternalEditor' ) || $action=='submit' || $internal ||
115 $section || $oldid ||( !$user->getOption( 'externaleditor' ) && !$external ) ) {
116 require_once( 'includes/EditPage.php' );
117 $editor = new EditPage( $article );
118 $editor->submit();
119 } elseif( $this->getVal( 'UseExternalEditor' ) && ( $external || $user->getOption( 'externaleditor' ) ) ) {
120 require_once( 'includes/ExternalEdit.php' );
121 $mode = $request->getVal( 'mode' );
122 $extedit = new ExternalEdit( $article, $mode );
123 $extedit->edit();
124 }
125 break;
126 case 'history':
127 if( $_SERVER['REQUEST_URI'] == $title->getInternalURL( 'action=history' ) ) {
128 $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) );
129 }
130 require_once( 'includes/PageHistory.php' );
131 $history = new PageHistory( $article );
132 $history->history();
133 break;
134 case 'raw':
135 require_once( 'includes/RawPage.php' );
136 $raw = new RawPage( $article );
137 $raw->view();
138 break;
139 default:
140 if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
141 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
142 }
143 }
144 }
145
146 }; # End of class MediaWiki
147
148 ?>
149