Index: trunk/extensions/ExternalPages/ExternalPages.alias.php |
— | — | @@ -2,7 +2,8 @@ |
3 | 3 | /** |
4 | 4 | * Aliases for Special:ExternalPages |
5 | 5 | * |
6 | | - * @addtogroup Extensions |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
7 | 8 | */ |
8 | 9 | |
9 | 10 | $aliases = array(); |
Index: trunk/extensions/ExternalPages/ExternalPages_body.php |
— | — | @@ -5,76 +5,73 @@ |
6 | 6 | exit( 1 ); |
7 | 7 | } |
8 | 8 | |
9 | | -$base = dirname( __FILE__ ); |
10 | | - |
11 | 9 | /** |
12 | 10 | * Special page allows retrieval and display of pages from remote WMF sites |
13 | 11 | * with year, lang and project specifable |
14 | 12 | */ |
15 | 13 | class ExternalPages extends SpecialPage { |
16 | 14 | |
17 | | - private $mYear = ''; |
18 | | - private $mLang = ''; |
19 | | - private $mProject = ''; |
20 | | - private $mPage = false; |
21 | | - private $mPageURL = ''; |
22 | | - private $mPageText = false; |
23 | | - private $mFromCache = false; |
| 15 | + private $mYear = ''; |
| 16 | + private $mLang = ''; |
| 17 | + private $mProject = ''; |
| 18 | + private $mPage = false; |
| 19 | + private $mPageURL = ''; |
| 20 | + private $mPageText = false; |
| 21 | + private $mFromCache = false; |
24 | 22 | |
25 | 23 | // adjust these as needed to change cache expiry |
26 | 24 | const EP_SMAXAGE = 600; |
27 | 25 | const EP_MAXAGE = 600; |
28 | 26 | const EP_MEMCACHE_EXP = 600; |
29 | 27 | |
30 | | - function __construct() { |
31 | | - SpecialPage::SpecialPage( 'ExternalPages' ); |
| 28 | + public function __construct() { |
| 29 | + parent::__construct( 'ExternalPages' ); |
32 | 30 | wfLoadExtensionMessages( 'ExternalPages' ); |
33 | | - } |
34 | | - /* |
35 | | - * entry point (retrieve parsed page, convert rel links to full |
36 | | - * urls that direct to the remote site |
37 | | - * $par would be the subpage. we don't need it |
38 | | - */ |
39 | | - function execute( $par ) { |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Entry point (retrieve parsed page, convert rel links to full |
| 35 | + * URLs that direct to the remote site |
| 36 | + * $par would be the subpage. we don't need it |
| 37 | + */ |
| 38 | + public function execute( $par ) { |
40 | 39 | global $wgUser, $wgRequest; |
41 | | - |
| 40 | + |
42 | 41 | wfLoadExtensionMessages( 'ExternalPages' ); |
43 | 42 | $this->setHeaders(); |
44 | | - if ( ! $this->parseParams() ) { |
| 43 | + |
| 44 | + if ( !$this->parseParams() ) { |
45 | 45 | return( false ); |
46 | 46 | } |
47 | | - if ( ! $this->userCanExecute( $wgUser ) ) { |
| 47 | + if ( !$this->userCanExecute( $wgUser ) ) { |
48 | 48 | $this->displayRestrictionError(); |
49 | 49 | return( false ); |
50 | 50 | } |
51 | | - |
| 51 | + |
52 | 52 | $this->constructURL(); |
53 | 53 | $this->retrieveExternalPage(); |
54 | | - |
55 | | - } |
56 | | - |
57 | | - /* |
58 | | - * process parameters of the request |
59 | | - */ |
60 | | - private function parseParams() { |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Process parameters of the request |
| 58 | + */ |
| 59 | + private function parseParams() { |
61 | 60 | global $wgRequest, $wgServer; |
62 | | - |
63 | | - if (!$wgRequest->getVal( 'EPyear') ) { |
64 | | - $this->mYear=false; |
65 | | - } |
66 | | - else { |
| 61 | + |
| 62 | + if ( !$wgRequest->getVal( 'EPyear' ) ) { |
| 63 | + $this->mYear = false; |
| 64 | + } else { |
67 | 65 | $this->mYear = $wgRequest->getInt( 'EPyear' ); |
68 | 66 | // if this code is still being used 50 years from now, replace it :-P |
69 | | - if (! (( $this->mYear > 2000 ) && ( $this->mYear < 2050 ))) { |
| 67 | + if (! ( ( $this->mYear > 2000 ) && ( $this->mYear < 2050 ) ) ) { |
70 | 68 | ExternalPagesErrors::showError( 'externalpages-bad-year' ); |
71 | 69 | return( false ); |
72 | 70 | } |
73 | 71 | } |
74 | | - |
| 72 | + |
75 | 73 | if ( !$wgRequest->getVal( 'EPlanguage' ) ) { |
76 | | - $this->mLang=false; |
77 | | - } |
78 | | - else { |
| 74 | + $this->mLang = false; |
| 75 | + } else { |
79 | 76 | $this->mLang = $wgRequest->getVal( 'EPlanguage' ); |
80 | 77 | $knownLanguages = Language::getLanguageNames( false ); |
81 | 78 | if ( !array_key_exists( $this->mLang, $knownLanguages ) ) { |
— | — | @@ -86,47 +83,46 @@ |
87 | 84 | if ( !$wgRequest->getVal( 'EPproject' ) ) { |
88 | 85 | ExternalPagesErrors::showError( 'externalpages-no-project' ); |
89 | 86 | return( false ); |
90 | | - } |
91 | | - else { |
| 87 | + } else { |
92 | 88 | $this->mProject = $wgRequest->getVal( 'EPproject' ); |
93 | | - // for initial fundraiser rollout, just allow pages from one project. this |
94 | | - // can be generalized later |
| 89 | + // for initial fundraiser rollout, just allow pages from one project. |
| 90 | + // This can be generalized later |
95 | 91 | if ( 'wikimediafoundation.org' != $this->mProject ) { |
96 | 92 | ExternalPagesErrors::showError( 'externalpages-bad-project' ); |
97 | | - return(false); |
| 93 | + return( false ); |
98 | 94 | } |
99 | 95 | } |
100 | 96 | |
101 | 97 | if ( !$wgRequest->getVal( 'EPpage' ) ) { |
102 | 98 | ExternalPagesErrors::showError( 'externalpages-no-page' ); |
103 | | - return(false); |
| 99 | + return( false ); |
104 | 100 | } |
105 | 101 | $this->mPage = $wgRequest->getVal( 'EPpage' ); |
106 | 102 | // strictly speaking this may behave differently on the local wiki, oh well |
107 | | - if ( ! Title::newFromText( $this->mPage ) ) { |
| 103 | + if ( !Title::newFromText( $this->mPage ) ) { |
108 | 104 | ExternalPagesErrors::showError( 'externalpages-bad-page' ); |
109 | | - return(false); |
| 105 | + return( false ); |
110 | 106 | } |
111 | 107 | return( true ); |
112 | | - } |
| 108 | + } |
113 | 109 | |
114 | | - private function constructURL() { |
115 | | - $url = "http://" . $this->mProject . "/w/api.php?action=parse&page="; |
116 | | - $title = ( $this->mYear ? $this->mYear."/" : "" ) . $this->mPage; |
117 | | - $title .= $this->mLang ? "/".$this->mLang : "" ; |
| 110 | + private function constructURL() { |
| 111 | + $url = 'http://' . $this->mProject . '/w/api.php?action=parse&page='; |
| 112 | + $title = ( $this->mYear ? $this->mYear . '/' : '' ) . $this->mPage; |
| 113 | + $title .= $this->mLang ? '/' . $this->mLang : ''; |
118 | 114 | $title = urlencode( $title ); |
119 | 115 | $url = $url . $title . '&format=php'; |
120 | 116 | $this->mPageURL = $url; |
121 | | - } |
| 117 | + } |
122 | 118 | |
123 | | - public function cacheHeaders() { |
| 119 | + public function cacheHeaders() { |
124 | 120 | global $wgRequest; |
125 | 121 | |
126 | 122 | $smaxage = self::EP_SMAXAGE; |
127 | 123 | $maxage = self::EP_MAXAGE; |
128 | 124 | |
129 | 125 | $public = ( session_id() == '' ); |
130 | | - |
| 126 | + |
131 | 127 | if ( $public ) { |
132 | 128 | $wgRequest->response()->header( "Cache-Control: public, s-maxage=$smaxage, max-age=$maxage" ); |
133 | 129 | } else { |
— | — | @@ -135,100 +131,97 @@ |
136 | 132 | $time = time() + self::EP_MAXAGE; |
137 | 133 | $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', $time ) . ' GMT' ); |
138 | 134 | return( true ); |
139 | | - } |
| 135 | + } |
140 | 136 | |
141 | | - private function getCacheKey( $string ) { |
| 137 | + private function getCacheKey( $string ) { |
142 | 138 | return( wfMemcKey( 'externalpages', $string ) ); |
143 | | - } |
| 139 | + } |
144 | 140 | |
145 | | - private function getPageFromCache() { |
| 141 | + private function getPageFromCache() { |
146 | 142 | global $wgMemc; |
147 | | - |
| 143 | + |
148 | 144 | wfProfileIn( __METHOD__ ); |
149 | 145 | |
150 | | - if ( ! $this->mPageURL ) { |
| 146 | + if ( !$this->mPageURL ) { |
151 | 147 | $this->constructURL(); |
152 | 148 | } |
153 | 149 | |
154 | 150 | $this->mPageText = $wgMemc->get( $this->getCacheKey( $this->mPageURL ) ); |
155 | | - if ( ! $this->mPageText ) { |
| 151 | + if ( !$this->mPageText ) { |
156 | 152 | wfDebugLog( 'ExternalPages', "Remote Page Text: cache miss for {$this->mPageURL} " ); |
157 | 153 | wfProfileOut( __METHOD__ ); |
158 | 154 | return( false ); |
159 | 155 | } |
160 | 156 | wfProfileOut( __METHOD__ ); |
161 | 157 | return( true ); |
162 | | - } |
| 158 | + } |
163 | 159 | |
164 | | - private function savePageToCache() { |
| 160 | + private function savePageToCache() { |
165 | 161 | global $wgMemc; |
166 | 162 | |
167 | 163 | wfDebugLog( 'ExternalPages', "Saving text {$this->mPageURL} to cache." ); |
168 | 164 | $wgMemc->set( $this->getCacheKey( $this->mPageURL ), $this->mPageText, self::EP_MEMCACHE_EXP ); |
169 | | - } |
| 165 | + } |
170 | 166 | |
171 | | - private function retrieveExternalPage() { |
| 167 | + private function retrieveExternalPage() { |
172 | 168 | global $wgOut, $wgRequest, $wgHooks; |
173 | | - |
174 | | - if ( ! $this->mPageURL ) { |
| 169 | + |
| 170 | + if ( !$this->mPageURL ) { |
175 | 171 | $this->constructURL(); |
176 | 172 | } |
177 | 173 | |
178 | 174 | // try from cache first |
179 | 175 | $this->getPageFromCache(); |
180 | 176 | |
181 | | - if ( ! $this->mPageText ) { |
| 177 | + if ( !$this->mPageText ) { |
182 | 178 | $serializedText = Http::get( $this->mPageURL ); |
183 | 179 | |
184 | 180 | if ( empty( $serializedText ) ) { |
185 | 181 | ExternalPagesErrors::showError( 'externalpages-bad-url' ); |
186 | | - return(false); |
187 | | - } |
188 | | - else { |
| 182 | + return( false ); |
| 183 | + } else { |
189 | 184 | $text = unserialize( $serializedText ); |
190 | 185 | } |
191 | 186 | |
192 | 187 | if ( isset( $text['parse'] ) && ( isset( $text['parse']['text'] ) ) ) { |
193 | 188 | $this->mPageText = $text['parse']['text']['*']; |
194 | | - $absurl = '<a href="http://'.$this->mProject."/"; |
| 189 | + $absurl = '<a href="http://' . $this->mProject . '/'; |
195 | 190 | $this->mPageText = str_replace( '<a href="https://www.mediawiki.org/', $absurl, $this->mPageText ); |
196 | 191 | } |
197 | 192 | $this->savePageToCache(); |
198 | | - } |
199 | | - else { |
| 193 | + } else { |
200 | 194 | wfDebugLog( 'ExternalPages', "Retrieved {$this->mPageURL} from cache." ); |
201 | 195 | } |
202 | 196 | |
203 | 197 | if ( $this->mPageText ) { |
204 | 198 | $wgHooks['CacheHeadersAfterSet'][] = array( $this, 'cacheHeaders' ); |
205 | 199 | $wgOut->addHTML( $this->mPageText ); |
206 | | - } |
207 | | - else { |
| 200 | + } else { |
208 | 201 | ExternalPagesErrors::showError( 'externalpages-bad-url-data' ); |
209 | 202 | return( false ); |
210 | 203 | } |
211 | 204 | return; |
212 | | - } |
| 205 | + } |
213 | 206 | } |
214 | 207 | |
215 | | -/* |
216 | | - * error handler for some formatting of error messages |
| 208 | +/** |
| 209 | + * Error handler for some formatting of error messages |
217 | 210 | */ |
218 | 211 | class ExternalPagesErrors { |
219 | 212 | |
220 | | - static function showError( $errorText='externalpages-error-generic', $phpErrorText=false ) { |
| 213 | + static function showError( $errorText = 'externalpages-error-generic', $phpErrorText = false ) { |
221 | 214 | global $wgOut; |
222 | | - |
| 215 | + |
223 | 216 | $args = func_get_args(); |
224 | 217 | |
225 | 218 | array_shift( $args ); |
226 | | - $msg = wfMsg( $errorText, $args ); |
| 219 | + $msg = wfMsg( $errorText, $args ); |
227 | 220 | |
228 | | - $wgOut->addWikiText( "<div class=\"errorbox\" style=\"float:none;\">" . |
229 | | - $msg . |
230 | | - "</div>" ); |
| 221 | + $wgOut->addWikiText( |
| 222 | + '<div class="errorbox" style="float:none;">' . |
| 223 | + $msg . |
| 224 | + '</div>' |
| 225 | + ); |
231 | 226 | } |
232 | 227 | |
233 | | -} |
234 | | - |
235 | | -?> |
| 228 | +} |
\ No newline at end of file |
Index: trunk/extensions/ExternalPages/ExternalPages.i18n.php |
— | — | @@ -1,24 +1,28 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Internationalizations for extension ExternalPages. |
| 4 | + * Internationalizations for ExternalPages extension. |
5 | 5 | * |
6 | | - * @addtogroup Extensions |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
7 | 8 | */ |
8 | 9 | |
9 | 10 | $messages = array(); |
10 | 11 | |
| 12 | +/** English |
| 13 | + * @author Ariel Glenn |
| 14 | + */ |
11 | 15 | $messages['en'] = array( |
12 | | - 'externalpages' => 'External Pages', |
13 | | - 'externalpages-desc' => 'Retrieves and displays pages from remote WMF sites', |
14 | | - 'externalpages-bad-year' => 'Bad year specified', |
15 | | - 'externalpages-bad-language' => 'Bad language specified', |
16 | | - 'externalpages-bad-project' => 'Bad project specified', |
17 | | - 'externalpages-no-project' => 'No project specified', |
18 | | - 'externalpages-bad-page' => 'Bad page specified', |
19 | | - 'externalpages-no-page' => 'No page specified', |
20 | | - 'externalpages-error-generic' => 'Error encountered', |
21 | | - 'externalpages-bad-url' => 'Failed to retrieve URL', |
22 | | - 'externalpages-bad-url-data' => 'Failed to retrieve page contents', |
| 16 | + 'externalpages' => 'External Pages', |
| 17 | + 'externalpages-desc' => 'Retrieves and displays pages from remote WMF sites', |
| 18 | + 'externalpages-bad-year' => 'Bad year specified', |
| 19 | + 'externalpages-bad-language' => 'Bad language specified', |
| 20 | + 'externalpages-bad-project' => 'Bad project specified', |
| 21 | + 'externalpages-no-project' => 'No project specified', |
| 22 | + 'externalpages-bad-page' => 'Bad page specified', |
| 23 | + 'externalpages-no-page' => 'No page specified', |
| 24 | + 'externalpages-error-generic' => 'Error encountered', |
| 25 | + 'externalpages-bad-url' => 'Failed to retrieve URL', |
| 26 | + 'externalpages-bad-url-data' => 'Failed to retrieve page contents', |
23 | 27 | ); |
24 | 28 | |
25 | 29 | /** Message documentation (Message documentation) |
Index: trunk/extensions/ExternalPages/SpecialExternalPages.php |
— | — | @@ -1,12 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * A Special Page extension to retrieve and display a page |
5 | | - * from a specified external WMF site, with optional year, |
6 | | - * project |
7 | | - * and language parameters |
| 5 | + * from a specified external WMF site, with optional year, |
| 6 | + * project and language parameters |
8 | 7 | * |
9 | | - * @addtogroup Extensions |
10 | | - * |
| 8 | + * @file |
| 9 | + * @ingroup Extensions |
| 10 | + * @version 0.1 |
11 | 11 | * @author Ariel Glenn <ariel@wikimedia.org> |
12 | 12 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later |
13 | 13 | */ |
— | — | @@ -14,11 +14,12 @@ |
15 | 15 | if ( !defined( 'MEDIAWIKI' ) ) { |
16 | 16 | echo <<<EOT |
17 | 17 | To install the ExternalPages extension, put the following line in LocalSettings.php: |
18 | | -require_once( "\$IP/extensions/SpecialExternalPages.php" ); |
| 18 | +require_once( "\$IP/extensions/ExternalPages/SpecialExternalPages.php" ); |
19 | 19 | EOT; |
20 | | - exit(1); |
| 20 | + exit( 1 ); |
21 | 21 | } |
22 | 22 | |
| 23 | +// Extension credits that will show up on Special:Version |
23 | 24 | $wgExtensionCredits['specialpage'][] = array( |
24 | 25 | 'name' => 'ExternalPages', |
25 | 26 | 'version' => '0.1', |
— | — | @@ -29,7 +30,6 @@ |
30 | 31 | ); |
31 | 32 | |
32 | 33 | $dir = dirname( __FILE__ ) . '/'; |
33 | | - |
34 | 34 | $wgExtensionMessagesFiles['ExternalPages'] = $dir . 'ExternalPages.i18n.php'; |
35 | 35 | $wgExtensionAliasesFiles['ExternalPages'] = $dir . 'ExternalPages.alias.php'; |
36 | 36 | |
— | — | @@ -42,11 +42,9 @@ |
43 | 43 | function externalPagesLocalizedPageName( &$specialPageArray, $code ) { |
44 | 44 | wfLoadExtensionMessages( 'ExternalPages' ); |
45 | 45 | $text = wfMsg( 'externalpages' ); |
46 | | - |
| 46 | + |
47 | 47 | # Convert from title in text form to DBKey and put it into the alias array: |
48 | 48 | $title = Title::newFromText( $text ); |
49 | 49 | $specialPageArray['ExternalPages'][] = $title->getDBKey(); |
50 | 50 | return true; |
51 | | -} |
52 | | - |
53 | | -?> |
| 51 | +} |
\ No newline at end of file |