Index: trunk/extensions/Video/VideoPage.php |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | $title, |
55 | 55 | wfMsgHtml( 'video-novideo-linktext' ), |
56 | 56 | array(), |
57 | | - array( 'wpDestName' => $this->video->getName() ) |
| 57 | + array( 'wpTitle' => $this->video->getName() ) |
58 | 58 | ); |
59 | 59 | $wgOut->addHTML( wfMsgWikiHtml( 'video-novideo', $link ) ); |
60 | 60 | |
— | — | @@ -221,7 +221,10 @@ |
222 | 222 | SpecialPage::getTitleFor( 'AddVideo' ), |
223 | 223 | wfMsg( 'uploadnewversion-linktext' ), |
224 | 224 | array(), |
225 | | - array( 'wpDestName' => $this->video->getName() ) |
| 225 | + array( |
| 226 | + 'wpTitle' => $this->video->getName(), |
| 227 | + 'wpForReUpload' => 1, |
| 228 | + ) |
226 | 229 | ); |
227 | 230 | $wgOut->addHTML( "<li>{$ulink}</li>" ); |
228 | 231 | } |
Index: trunk/extensions/Video/VideoHooks.php |
— | — | @@ -90,7 +90,7 @@ |
91 | 91 | $wgOut->redirect( |
92 | 92 | // escapeFullURL() converts & to & which causes the |
93 | 93 | // destName parameter not to work correctly |
94 | | - $addTitle->getFullURL( 'destName=' . $video->getName() ) |
| 94 | + $addTitle->getFullURL( 'wpTitle=' . $video->getName() ) |
95 | 95 | ); |
96 | 96 | } |
97 | 97 | } |
Index: trunk/extensions/Video/SpecialAddVideo.php |
— | — | @@ -3,6 +3,13 @@ |
4 | 4 | class AddVideo extends SpecialPage { |
5 | 5 | |
6 | 6 | /** |
| 7 | + * New video object created when the title field is validated |
| 8 | + * |
| 9 | + * @var Video |
| 10 | + */ |
| 11 | + protected $video; |
| 12 | + |
| 13 | + /** |
7 | 14 | * Constructor -- set up the new special page |
8 | 15 | */ |
9 | 16 | public function __construct() { |
— | — | @@ -25,15 +32,14 @@ |
26 | 33 | } |
27 | 34 | |
28 | 35 | // If the user doesn't have the required 'addvideo' permission, display an error |
29 | | - if( !$wgUser->isAllowed( 'addvideo' ) ) { |
30 | | - $wgOut->permissionRequired( 'addvideo' ); |
| 36 | + if( !$this->userCanExecute( $this->getUser() ) ) { |
| 37 | + $this->displayRestrictionError(); |
31 | 38 | return; |
32 | 39 | } |
33 | 40 | |
34 | 41 | // Show a message if the database is in read-only mode |
35 | 42 | if ( wfReadOnly() ) { |
36 | | - $wgOut->readOnlyPage(); |
37 | | - return; |
| 43 | + throw new ReadOnlyError; |
38 | 44 | } |
39 | 45 | |
40 | 46 | // If user is blocked, s/he doesn't need to access this page |
— | — | @@ -42,126 +48,91 @@ |
43 | 49 | return false; |
44 | 50 | } |
45 | 51 | |
46 | | - $categories = $wgRequest->getVal( 'wpCategories' ); |
| 52 | + $this->setHeaders(); |
47 | 53 | |
48 | | - // wpDestName URL parameter is set in VideoPage.php; when viewing a |
49 | | - // video page of a video that does not yet exist, there is a link to |
50 | | - // Special:AddVideo and the wpDestName parameter will be set to the |
51 | | - // name of the video |
52 | | - $destination = $wgRequest->getVal( 'destName' ); |
53 | | - if( !$destination ) { |
54 | | - $destination = $wgRequest->getVal( 'wpDestName' ); |
| 54 | + $form = new HTMLForm( $this->getFormFields(), $this->getContext() ); |
| 55 | + $form->setIntro( wfMsgExt( 'video-addvideo-instructions', 'parse' ) ); |
| 56 | + $form->setWrapperLegend( wfMsg( 'video-addvideo-title' ) ); |
| 57 | + $form->setSubmitText( wfMsg( 'video-addvideo-button' ) ); |
| 58 | + $form->setSubmitCallback( array( $this, 'submit' ) ); |
| 59 | + |
| 60 | + if ( $this->getRequest()->getCheck( 'forReUpload' ) ) { |
| 61 | + $form->addHiddenField( 'forReUpload', true ); |
55 | 62 | } |
56 | 63 | |
57 | | - // Posted items |
58 | | - $video_code = $wgRequest->getVal( 'wpVideo' ); |
59 | | - $title = str_replace( '#', '', $wgRequest->getVal( 'wpTitle' ) ); |
| 64 | + $form->show(); |
| 65 | + } |
60 | 66 | |
61 | | - $pageTitle = wfMsg( 'video-addvideo-title' ); |
62 | | - if( $destination ) { |
63 | | - $pageTitle = wfMsg( 'video-addvideo-dest', str_replace( '_', ' ', $destination ) ); |
| 67 | + protected function getUrlAndProvider( $value ) { |
| 68 | + $url = $value; |
| 69 | + if ( !Video::isURL( $url ) ) { |
| 70 | + $url = Video::getURLfromEmbedCode( $value ); |
64 | 71 | } |
65 | 72 | |
66 | | - $wgOut->setPageTitle( $pageTitle ); |
| 73 | + return array( $url, Video::getProviderByURL( $url ) ); |
| 74 | + } |
67 | 75 | |
68 | | - if( $destination ) { |
69 | | - $title = $destination; |
| 76 | + public function validateVideoField( $value, $allData ) { |
| 77 | + list( , $provider ) = $this->getUrlAndProvider( $value ); |
| 78 | + |
| 79 | + if ( $provider == 'unknown' ) { |
| 80 | + return wfMsg( 'video-addvideo-invalidcode' ); |
70 | 81 | } |
71 | 82 | |
72 | | - $output = '<div class="add-video-container"> |
73 | | - <form name="videoadd" action="" method="post">'; |
| 83 | + return true; |
| 84 | + } |
74 | 85 | |
75 | | - $output .= '<p class="addvideo-subtitle">' . |
76 | | - wfMsgExt( 'video-addvideo-instructions', 'parse' ) . '</p>'; |
77 | | - $output .= '<table border="0" cellpadding="3" cellspacing="5">'; |
78 | | - $output .= '<tr>'; |
| 86 | + public function validateTitleField( $value, $allData ) { |
| 87 | + $video = Video::newFromName( $value ); |
79 | 88 | |
80 | | - // If we're not adding a new version of a pre-existing video, allow the |
81 | | - // user to supply the video's title, obviously... |
82 | | - if( !$destination ) { |
83 | | - $output .= '<td><label for="wpTitle">' . |
84 | | - wfMsgHtml( 'video-addvideo-title-label' ) . |
85 | | - '</label></td><td>'; |
| 89 | + if ( $video === null || !( $video instanceof Video ) ) { |
| 90 | + return wfMsg( 'badtitle' ); |
| 91 | + } |
86 | 92 | |
87 | | - $output .= Xml::element( 'input', |
88 | | - array( |
89 | | - 'type' => 'text', |
90 | | - 'name' => 'wpTitle', |
91 | | - 'size' => '30', |
92 | | - 'value' => $wgRequest->getVal( 'wpTitle' ), |
93 | | - ) |
94 | | - ); |
95 | | - $output .= '</td></tr>'; |
| 93 | + // TODO: Check to see if this is a new version |
| 94 | + if ( $video->exists() && !$this->getRequest()->getCheck( 'forReUpload' ) ) { |
| 95 | + return wfMsgHtml( 'video-addvideo-exists' ); |
96 | 96 | } |
97 | 97 | |
98 | | - $watchChecked = $wgUser->getOption( 'watchdefault' ) |
99 | | - ? ' checked="checked"' |
100 | | - : ''; |
| 98 | + $this->video = $video; |
101 | 99 | |
102 | | - $output .= '<tr> |
103 | | - <td valign="top">' . wfMsg( 'video-addvideo-embed-label' ) . '</td> |
104 | | - <td><textarea rows="5" cols="65" name="wpVideo" id="wpVideo">' . |
105 | | - $wgRequest->getVal( 'wpVideo' ) . |
106 | | - '</textarea></td> |
107 | | - </tr> |
108 | | - <tr> |
109 | | - <td></td> |
110 | | - <td> |
111 | | - <input type="checkbox" name="wpWatchthis" id="wpWatchthis"' . $watchChecked . ' value="true" /> |
112 | | - <label for="wpWatchthis">' . wfMsgHtml( 'watchthisupload' ) . '</label> |
| 100 | + return true; |
| 101 | + } |
113 | 102 | |
114 | | - </td> |
115 | | - </tr>'; |
| 103 | + public function submit( array $data ) { |
| 104 | + list( $url, $provider ) = $this->getUrlAndProvider( $data['Video'] ); |
116 | 105 | |
117 | | - $output .= '<tr> |
118 | | - <td></td> |
119 | | - <td>'; |
120 | | - $output .= Xml::element( 'input', |
121 | | - array( |
122 | | - 'type' => 'button', |
123 | | - 'value' => wfMsg( 'video-addvideo-button' ), |
124 | | - 'onclick' => 'document.videoadd.submit();', |
125 | | - ) |
126 | | - ); |
127 | | - $output .= '</td> |
128 | | - </tr> |
129 | | - </table> |
130 | | - </form> |
131 | | - </div>'; |
| 106 | + $this->video->addVideo( $url, $provider, false, $data['Watch'] ); |
132 | 107 | |
133 | | - if( $wgRequest->wasPosted() ) { |
134 | | - $video = Video::newFromName( $title ); |
| 108 | + $this->getOutput()->redirect( $this->video->getTitle()->getFullURL() ); |
135 | 109 | |
136 | | - // Page title for Video has already been taken |
137 | | - if( ( $video instanceof Video && $video->exists() ) && !$destination ) { |
138 | | - $error = '<div class="video-error">' . |
139 | | - wfMsgHtml( 'video-addvideo-exists' ) . '</div>'; |
140 | | - $wgOut->addHTML( $error ); |
141 | | - } else { |
142 | | - // Get URL based on user input |
143 | | - // It could be a straight URL to the page or the embed code |
144 | | - if ( $video->isURL( $video_code ) ) { |
145 | | - $url = $video_code; |
146 | | - } else { |
147 | | - $urlFromEmbed = $video->getURLfromEmbedCode( $video_code ); |
148 | | - if ( $video->isURL( $urlFromEmbed ) ) { |
149 | | - $url = $urlFromEmbed; |
150 | | - } |
151 | | - } |
152 | | - $provider = $video->getProviderByURL( $url ); |
153 | | - if( !$url || $provider == 'unknown' ) { |
154 | | - $error = '<div class="video-error">' . |
155 | | - wfMsg( 'video-addvideo-invalidcode' ) . '</div>'; |
156 | | - $wgOut->addHTML( $error ); |
157 | | - } else { |
158 | | - $video->addVideo( |
159 | | - $url, $provider, $categories, |
160 | | - $wgRequest->getVal( 'wpWatchthis' ) |
161 | | - ); |
162 | | - $wgOut->redirect( $video->title->getFullURL() ); |
163 | | - } |
164 | | - } |
165 | | - } |
166 | | - $wgOut->addHTML( $output ); |
| 110 | + return true; |
167 | 111 | } |
| 112 | + |
| 113 | + protected function getFormFields() { |
| 114 | + $fields = array( |
| 115 | + 'Title' => array( |
| 116 | + 'type' => 'text', |
| 117 | + 'label-message' => 'video-addvideo-title-label', |
| 118 | + 'size' => '30', |
| 119 | + 'required' => true, |
| 120 | + 'validation-callback' => array( $this, 'validateTitleField' ), |
| 121 | + ), |
| 122 | + 'Video' => array( |
| 123 | + 'type' => 'textarea', |
| 124 | + 'label-message' => 'video-addvideo-embed-label', |
| 125 | + 'rows' => '5', |
| 126 | + 'cols' => '65', |
| 127 | + 'required' => true, |
| 128 | + 'validation-callback' => array( $this, 'validateVideoField' ), |
| 129 | + ), |
| 130 | + 'Watch' => array( |
| 131 | + 'type' => 'check', |
| 132 | + 'label-message' => 'watchthisupload', |
| 133 | + 'default' => $this->getUser()->getOption( 'watchdefault' ), |
| 134 | + ), |
| 135 | + ); |
| 136 | + |
| 137 | + return $fields; |
| 138 | + } |
168 | 139 | } |
\ No newline at end of file |