Index: trunk/extensions/Video/RevertVideoAction.php |
— | — | @@ -0,0 +1,123 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class RevertVideoAction extends FormAction { |
| 5 | + |
| 6 | + /** |
| 7 | + * Row from the oldvideo table for the revision to revert to |
| 8 | + * |
| 9 | + * @var ResultWrapper |
| 10 | + */ |
| 11 | + protected $oldvideo; |
| 12 | + |
| 13 | + /** |
| 14 | + * Video object defined in onSubmit() and used again in onSuccess() |
| 15 | + * |
| 16 | + * @var Video |
| 17 | + */ |
| 18 | + protected $video; |
| 19 | + |
| 20 | + /** |
| 21 | + * Return the name of the action this object responds to |
| 22 | + * @return String lowercase |
| 23 | + */ |
| 24 | + public function getName() { |
| 25 | + return 'revert'; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Get the permission required to perform this action. Often, but not always, |
| 30 | + * the same as the action name |
| 31 | + */ |
| 32 | + public function getRestriction() { |
| 33 | + return 'edit'; |
| 34 | + } |
| 35 | + |
| 36 | + protected function checkCanExecute( User $user ) { |
| 37 | + parent::checkCanExecute( $user ); |
| 38 | + |
| 39 | + $oldvideo = $this->getRequest()->getText( 'oldvideo' ); |
| 40 | + if ( strlen( $oldvideo ) < 16 ) { |
| 41 | + throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldvideo', $oldvideo ) ); |
| 42 | + } |
| 43 | + |
| 44 | + $dbr = wfGetDB( DB_READ ); |
| 45 | + $row = $dbr->selectRow( |
| 46 | + 'oldvideo', |
| 47 | + array( 'ov_url', 'ov_type', 'ov_timestamp', 'ov_url', 'ov_name' ), |
| 48 | + array( 'ov_archive_name' => urldecode( $oldvideo ) ), |
| 49 | + __METHOD__ |
| 50 | + ); |
| 51 | + if ( $row === false ) { |
| 52 | + throw new ErrorPageError( '', 'filerevert-badversion' ); |
| 53 | + } |
| 54 | + $this->oldvideo = $row; |
| 55 | + } |
| 56 | + |
| 57 | + protected function alterForm( HTMLForm $form ) { |
| 58 | + $form->setWrapperLegend( wfMsgHtml( 'video-revert-legend' ) ); |
| 59 | + $form->setSubmitText( wfMsg( 'filerevert-submit' ) ); |
| 60 | + $form->addHiddenField( 'oldvideo', $this->getRequest()->getText( 'oldvideo' ) ); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Get an HTMLForm descriptor array |
| 65 | + * @return Array |
| 66 | + */ |
| 67 | + protected function getFormFields() { |
| 68 | + $timestamp = $this->oldvideo->ov_timestamp; |
| 69 | + |
| 70 | + return array( |
| 71 | + 'intro' => array( |
| 72 | + 'type' => 'info', |
| 73 | + 'vertical-label' => true, |
| 74 | + 'raw' => true, |
| 75 | + 'default' => wfMsgExt( 'video-revert-intro', 'parse', $this->getTitle()->getText(), |
| 76 | + $this->getLang()->date( $timestamp, true ), $this->getLang()->time( $timestamp, true ), |
| 77 | + $this->oldvideo->ov_url ) |
| 78 | + ), |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Process the form on POST submission. If you return false from getFormFields(), |
| 84 | + * this will obviously never be reached. If you don't want to do anything with the |
| 85 | + * form, just return false here |
| 86 | + * @param $data Array |
| 87 | + * @return Bool|Array true for success, false for didn't-try, array of errors on failure |
| 88 | + */ |
| 89 | + public function onSubmit( $data ) { |
| 90 | + // Record upload and update metadata cache |
| 91 | + $this->video = Video::newFromName( $this->oldvideo->ov_name, $this->getContext() ); |
| 92 | + $this->video->addVideo( $this->oldvideo->ov_url, $this->oldvideo->ov_type, '' ); |
| 93 | + |
| 94 | + return true; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Do something exciting on successful processing of the form. This might be to show |
| 99 | + * a confirmation message (watch, rollback, etc) or to redirect somewhere else (edit, |
| 100 | + * protect, etc). |
| 101 | + */ |
| 102 | + public function onSuccess() { |
| 103 | + $out = $this->getOutput(); |
| 104 | + $out->setPageTitle( wfMsgHtml( 'actioncomplete' ) ); |
| 105 | + $out->setRobotPolicy( 'noindex,nofollow' ); |
| 106 | + $out->addHTML( wfMsg( 'video-revert-success' ) ); |
| 107 | + |
| 108 | + $descTitle = $this->video->getTitle(); |
| 109 | + $out->returnToMain( null, $descTitle->getPrefixedText() ); |
| 110 | + } |
| 111 | + |
| 112 | + protected function getPageTitle() { |
| 113 | + return wfMsg( 'filerevert', $this->getTitle()->getText() ); |
| 114 | + } |
| 115 | + |
| 116 | + protected function getDescription() { |
| 117 | + return wfMsg( |
| 118 | + 'filerevert-backlink', |
| 119 | + Linker::linkKnown( $this->getTitle() ) |
| 120 | + ); |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | +} |
Index: trunk/extensions/Video/VideoPage.php |
— | — | @@ -13,6 +13,16 @@ |
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
| 17 | + * Overridden to return WikiVideoPage |
| 18 | + * |
| 19 | + * @param Title $title |
| 20 | + * @return WikiVideoPage |
| 21 | + */ |
| 22 | + protected function newPage( Title $title ) { |
| 23 | + return new WikiVideoPage( $title ); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
17 | 27 | * Called on every video page view. |
18 | 28 | */ |
19 | 29 | public function view() { |
— | — | @@ -230,79 +240,6 @@ |
231 | 241 | |
232 | 242 | $wgOut->addHTML( '</ul>' ); |
233 | 243 | } |
234 | | - |
235 | | - /** |
236 | | - * Reverts a video to its earlier state |
237 | | - */ |
238 | | - function revert() { |
239 | | - global $wgOut, $wgRequest, $wgUser; |
240 | | - |
241 | | - $oldvideo = $wgRequest->getText( 'oldvideo' ); |
242 | | - if ( strlen( $oldvideo ) < 16 ) { |
243 | | - $wgOut->showUnexpectedValueError( 'oldvideo', htmlspecialchars( $oldvideo ) ); |
244 | | - return; |
245 | | - } |
246 | | - |
247 | | - // Can't do anything during DB locks |
248 | | - if ( wfReadOnly() ) { |
249 | | - $wgOut->readOnlyPage(); |
250 | | - return; |
251 | | - } |
252 | | - |
253 | | - // Must be logged in to revert videos |
254 | | - if( $wgUser->isAnon() ) { |
255 | | - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); |
256 | | - return; |
257 | | - } |
258 | | - |
259 | | - // Must be able to edit in order to revert |
260 | | - if ( !$this->mTitle->userCan( 'edit' ) ) { |
261 | | - $wgOut->readOnlyPage( $this->getContent(), true ); |
262 | | - return; |
263 | | - } |
264 | | - |
265 | | - // Must not be blocked |
266 | | - if ( $wgUser->isBlocked() ) { |
267 | | - return $this->blockedIPpage(); |
268 | | - } |
269 | | - |
270 | | - // And finally edit tokens must match in order to prevent cross-site request forgery |
271 | | - if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldvideo ) ) { |
272 | | - $wgOut->showErrorPage( 'internalerror', 'sessionfailure' ); |
273 | | - return; |
274 | | - } |
275 | | - |
276 | | - $dbr = wfGetDB( DB_MASTER ); |
277 | | - $s = $dbr->selectRow( |
278 | | - 'oldvideo', |
279 | | - array( 'ov_url', 'ov_type' ), |
280 | | - array( 'ov_archive_name' => urldecode( $oldvideo ) ), |
281 | | - __METHOD__ |
282 | | - ); |
283 | | - if ( $s !== false ) { |
284 | | - $url = $s->ov_url; |
285 | | - $type = $s->ov_type; |
286 | | - } else { |
287 | | - $wgOut->showUnexpectedValueError( 'oldvideo', htmlspecialchars( $oldvideo ) ); |
288 | | - return; |
289 | | - } |
290 | | - |
291 | | - $name = substr( $oldvideo, 15 ); |
292 | | - |
293 | | - //$oldver = wfTimestampNow() . "!{$name}"; |
294 | | - |
295 | | - // Record upload and update metadata cache |
296 | | - $video = Video::newFromName( $name, $this->getContext() ); |
297 | | - $video->addVideo( $url, $type, '' ); |
298 | | - |
299 | | - $wgOut->setPageTitle( wfMsgHtml( 'actioncomplete' ) ); |
300 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
301 | | - $wgOut->addHTML( wfMsg( 'video-revert-success' ) ); |
302 | | - |
303 | | - $descTitle = $video->getTitle(); |
304 | | - $wgOut->returnToMain( false, $descTitle->getPrefixedText() ); |
305 | | - } |
306 | | - |
307 | 244 | } |
308 | 245 | |
309 | 246 | /** |
— | — | @@ -340,15 +277,13 @@ |
341 | 278 | $rlink = $this->skin->makeKnownLinkObj( |
342 | 279 | $wgTitle, |
343 | 280 | wfMsgHtml( 'video-revert' ), |
344 | | - 'action=revert&oldvideo=' . urlencode( $video ) . |
345 | | - "&wpEditToken=$token" |
| 281 | + 'action=revert&oldvideo=' . urlencode( $video ) |
346 | 282 | ); |
347 | 283 | } else { |
348 | 284 | # Having live active links for non-logged in users |
349 | 285 | # means that bots and spiders crawling our site can |
350 | 286 | # inadvertently change content. Baaaad idea. |
351 | 287 | $rlink = wfMsgHtml( 'video-revert' ); |
352 | | - $dlink = $del; |
353 | 288 | } |
354 | 289 | } |
355 | 290 | |
Index: trunk/extensions/Video/Video.php |
— | — | @@ -82,6 +82,8 @@ |
83 | 83 | |
84 | 84 | // User Interface stuff |
85 | 85 | $wgAutoloadClasses['VideoPage'] = $dir . 'VideoPage.php'; |
| 86 | +$wgAutoloadClasses['WikiVideoPage'] = $dir . 'WikiVideoPage.php'; |
| 87 | +$wgAutoloadClasses['RevertVideoAction'] = $dir . 'RevertVideoAction.php'; |
86 | 88 | $wgAutoloadClasses['VideoHistoryList'] = $dir . 'VideoPage.php'; |
87 | 89 | $wgAutoloadClasses['CategoryWithVideoViewer'] = $dir . 'VideoPage.php'; |
88 | 90 | |
Index: trunk/extensions/Video/VideoHooks.php |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | if ( $title->getNamespace() == NS_VIDEO ) { |
86 | 86 | if( $wgRequest->getVal( 'action' ) == 'edit' ) { |
87 | 87 | $addTitle = SpecialPage::getTitleFor( 'AddVideo' ); |
88 | | - $video = Video::newFromName( $title->getText(), $article->getContext() ); |
| 88 | + $video = Video::newFromName( $title->getText(), RequestContext::getMain() ); |
89 | 89 | if( !$video->exists() ) { |
90 | 90 | global $wgOut; |
91 | 91 | $wgOut->redirect( |
Index: trunk/extensions/Video/SpecialAddVideo.php |
— | — | @@ -31,7 +31,7 @@ |
32 | 32 | public function execute( $par ) { |
33 | 33 | global $wgExtensionAssetsPath; |
34 | 34 | |
35 | | - $out = $this->getRequest(); |
| 35 | + $out = $this->getOutput(); |
36 | 36 | // Add CSS |
37 | 37 | if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) { |
38 | 38 | $out->addModuleStyles( 'ext.video' ); |
Index: trunk/extensions/Video/Video.i18n.php |
— | — | @@ -86,6 +86,8 @@ |
87 | 87 | 'video-histlegend' => 'Legend: ({{int:cur}}) = this is the current video, ({{int:video-revert}}) = revert to this old version. |
88 | 88 | <br /><i>Click on date to see the video URL on that date</i>.', |
89 | 89 | 'video-revert-success' => 'Revert to earlier version was successful.', |
| 90 | + 'video-revert-legend' => 'Revert Video', |
| 91 | + 'video-revert-intro' => "You are about to revert the video '''[[:Video:$1|$1]]''' to the [$4 version as of $3, $2].", |
90 | 92 | |
91 | 93 | 'video-category-name' => 'Videos', // name of the category where videos will be stored |
92 | 94 | |
— | — | @@ -100,6 +102,19 @@ |
101 | 103 | 'right-addvideo' => 'Add videos from external services into the site', |
102 | 104 | ); |
103 | 105 | |
| 106 | +/** Message Documentation |
| 107 | + * @author John Du Hart <john@compwhizii.net> |
| 108 | + */ |
| 109 | +$messages['qqq'] = array( |
| 110 | + 'video-revert-legend' => 'Legend of the fieldset for the revert form', |
| 111 | + 'video-revert-intro' => "Message displayed when you try to revert a version of a video. |
| 112 | +* $1 is the name of the media |
| 113 | +* $2 is a date |
| 114 | +* $3 is a hour |
| 115 | +* $4 is a URL and must follow square bracket: [$4 |
| 116 | +{{Identical|Revert}}", |
| 117 | +); |
| 118 | + |
104 | 119 | /** Finnish (Suomi) |
105 | 120 | * @author Jack Phoenix <jack@countervandalism.net> |
106 | 121 | */ |
Index: trunk/extensions/Video/WikiVideoPage.php |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class WikiVideoPage extends WikiPage { |
| 5 | + public function getActionOverrides() { |
| 6 | + return array( 'revert' => 'RevertVideoAction' ); |
| 7 | + } |
| 8 | + |
| 9 | +} |
Index: trunk/extensions/Video/providers/VimeoVideo.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | |
57 | 57 | $id = ''; |
58 | 58 | $text = strpos( $fixed_url, 'VIMEO.COM' ); |
59 | | - if( $text !=== false ) { |
| 59 | + if( $text !== false ) { |
60 | 60 | $parsed = explode( '/', $url ); |
61 | 61 | if( is_array( $parsed ) ) { |
62 | 62 | $id = array_pop( $parsed ); |