+ header( "Content-Length: $size", true );
+ }
+
+ /**
+ * Static callback for the HTMLForm in showUploads, to process
+ * Note the stash has to be recreated since this is being called in a static context.
+ * This works, because there really is only one stash per logged-in user, despite appearances.
+ *
+ * @return Status
+ */
+ public static function tryClearStashedUploads( $formData ) {
+ if ( isset( $formData['Clear'] ) ) {
+ $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash();
+ wfDebug( "stash has: " . print_r( $stash->listFiles(), true ) );
+ if ( ! $stash->clear() ) {
+ return Status::newFatal( 'uploadstash-errclear' );
+ }
+ }
+ return Status::newGood();
+ }
+
+ /**
+ * Default action when we don't have a subpage -- just show links to the uploads we have,
+ * Also show a button to clear stashed files
+ * @param Status : $status - the result of processRequest
+ */
+ private function showUploads( $status = null ) {
+ global $wgOut;
+ if ( $status === null ) {
+ $status = Status::newGood();
+ }
+
+ // sets the title, etc.
+ $this->setHeaders();
+ $this->outputHeader();
+
+ // create the form, which will also be used to execute a callback to process incoming form data
+ // this design is extremely dubious, but supposedly HTMLForm is our standard now?
+
+ $form = new HTMLForm( array(
+ 'Clear' => array(
+ 'type' => 'hidden',
+ 'default' => true,
+ 'name' => 'clear',
+ )
+ ), 'clearStashedUploads' );
+ $form->setSubmitCallback( array( __CLASS__ , 'tryClearStashedUploads' ) );
+ $form->setTitle( $this->getTitle() );
+ $form->setSubmitText( wfMsg( 'uploadstash-clear' ) );
+
+ $form->prepareForm();
+ $formResult = $form->tryAuthorizedSubmit();
+
+ // show the files + form, if there are any, or just say there are none
+ $refreshHtml = Html::element( 'a',
+ array( 'href' => $this->getTitle()->getLocalURL() ),
+ wfMsg( 'uploadstash-refresh' ) );
+ $files = $this->stash->listFiles();
+ if ( $files && count( $files ) ) {
+ sort( $files );
+ $fileListItemsHtml = '';
+ foreach ( $files as $file ) {
+ // TODO: Use Linker::link or even construct the list in plain wikitext
+ $fileListItemsHtml .= Html::rawElement( 'li', array(),
+ Html::element( 'a', array( 'href' =>
+ $this->getTitle( "file/$file" )->getLocalURL() ), $file )
+ );
+ }
+ $wgOut->addHtml( Html::rawElement( 'ul', array(), $fileListItemsHtml ) );
+ $form->displayForm( $formResult );
+ $wgOut->addHtml( Html::rawElement( 'p', array(), $refreshHtml ) );
+ } else {
+ $wgOut->addHtml( Html::rawElement( 'p', array(),
+ Html::element( 'span', array(), wfMsg( 'uploadstash-nofiles' ) )
+ . ' '
+ . $refreshHtml
+ ) );
+ }
+
+ return true;