r99378 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99377‎ | r99378 | r99379 >
Date:21:16, 9 October 2011
Author:johnduhart
Status:deferred
Tags:
Comment:
Changes to use an IContextSource instead of global variables
Moved the revert action code to an Action class so it actually works in 1.18
Fix to VimeoVideo
Modified paths:
  • /trunk/extensions/Video/RevertVideoAction.php (added) (history)
  • /trunk/extensions/Video/SpecialAddVideo.php (modified) (history)
  • /trunk/extensions/Video/Video.i18n.php (modified) (history)
  • /trunk/extensions/Video/Video.php (modified) (history)
  • /trunk/extensions/Video/VideoHooks.php (modified) (history)
  • /trunk/extensions/Video/VideoPage.php (modified) (history)
  • /trunk/extensions/Video/WikiVideoPage.php (added) (history)
  • /trunk/extensions/Video/providers/VimeoVideo.php (modified) (history)

Diff [purge]

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 @@
1414 }
1515
1616 /**
 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+ /**
1727 * Called on every video page view.
1828 */
1929 public function view() {
@@ -230,79 +240,6 @@
231241
232242 $wgOut->addHTML( '</ul>' );
233243 }
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 -
307244 }
308245
309246 /**
@@ -340,15 +277,13 @@
341278 $rlink = $this->skin->makeKnownLinkObj(
342279 $wgTitle,
343280 wfMsgHtml( 'video-revert' ),
344 - 'action=revert&oldvideo=' . urlencode( $video ) .
345 - "&wpEditToken=$token"
 281+ 'action=revert&oldvideo=' . urlencode( $video )
346282 );
347283 } else {
348284 # Having live active links for non-logged in users
349285 # means that bots and spiders crawling our site can
350286 # inadvertently change content. Baaaad idea.
351287 $rlink = wfMsgHtml( 'video-revert' );
352 - $dlink = $del;
353288 }
354289 }
355290
Index: trunk/extensions/Video/Video.php
@@ -82,6 +82,8 @@
8383
8484 // User Interface stuff
8585 $wgAutoloadClasses['VideoPage'] = $dir . 'VideoPage.php';
 86+$wgAutoloadClasses['WikiVideoPage'] = $dir . 'WikiVideoPage.php';
 87+$wgAutoloadClasses['RevertVideoAction'] = $dir . 'RevertVideoAction.php';
8688 $wgAutoloadClasses['VideoHistoryList'] = $dir . 'VideoPage.php';
8789 $wgAutoloadClasses['CategoryWithVideoViewer'] = $dir . 'VideoPage.php';
8890
Index: trunk/extensions/Video/VideoHooks.php
@@ -84,7 +84,7 @@
8585 if ( $title->getNamespace() == NS_VIDEO ) {
8686 if( $wgRequest->getVal( 'action' ) == 'edit' ) {
8787 $addTitle = SpecialPage::getTitleFor( 'AddVideo' );
88 - $video = Video::newFromName( $title->getText(), $article->getContext() );
 88+ $video = Video::newFromName( $title->getText(), RequestContext::getMain() );
8989 if( !$video->exists() ) {
9090 global $wgOut;
9191 $wgOut->redirect(
Index: trunk/extensions/Video/SpecialAddVideo.php
@@ -31,7 +31,7 @@
3232 public function execute( $par ) {
3333 global $wgExtensionAssetsPath;
3434
35 - $out = $this->getRequest();
 35+ $out = $this->getOutput();
3636 // Add CSS
3737 if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
3838 $out->addModuleStyles( 'ext.video' );
Index: trunk/extensions/Video/Video.i18n.php
@@ -86,6 +86,8 @@
8787 'video-histlegend' => 'Legend: ({{int:cur}}) = this is the current video, ({{int:video-revert}}) = revert to this old version.
8888 <br /><i>Click on date to see the video URL on that date</i>.',
8989 '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].",
9092
9193 'video-category-name' => 'Videos', // name of the category where videos will be stored
9294
@@ -100,6 +102,19 @@
101103 'right-addvideo' => 'Add videos from external services into the site',
102104 );
103105
 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+
104119 /** Finnish (Suomi)
105120 * @author Jack Phoenix <jack@countervandalism.net>
106121 */
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 @@
5656
5757 $id = '';
5858 $text = strpos( $fixed_url, 'VIMEO.COM' );
59 - if( $text !=== false ) {
 59+ if( $text !== false ) {
6060 $parsed = explode( '/', $url );
6161 if( is_array( $parsed ) ) {
6262 $id = array_pop( $parsed );

Follow-up revisions

RevisionCommit summaryAuthorDate
r99398svn:eol-style nativeialex14:03, 10 October 2011

Status & tagging log