function formatResult($skin, $result) { global $wgUser, $wgLang, $mvImageArchive, $mvgScriptPath, $wgRequest; #make sure the first letter is upper case (makeTitle() should do that) //$result->title = strtoupper($result->title[0]) . substr($result->title, 1); //$img_url = $mvImageArchive . $result->title . '?size=icon&time=0:00:00'; //$img_url = MV_StreamImage::getStreamImageURL($result->stream_id, '0:00:00', 'icon', true); //$img_html = '<img src="'.$img_url . '" width="80" height="60">'; //$title = Title::makeTitle( MV_NS_SITTING, $result->title ); //$spec_list = Title::makeTitle(MV_NS_SPECIAL, "Special:Mv_List_Streams"); $stream_id = $wgRequest->getVal('stream_id'); $stream_name = MV_Stream::getStreamNameFromId($stream_id); //$stream_name = 'New'; $title = Title::newFromText($stream_name, MV_NS_STREAM); $text = $result->title; $form = '<form method="post" action="' . $title->getEditURL() . '">'; $form .= '<input type="hidden" name="mv_action" value="add_existing_stream_file"></input>'; $form .= '<input type="hidden" name="sf_new' . '[stream_id]" value="' . $stream_id . '"></input>'; $form .= '<input type="hidden" name="sf_new' . '[id]" value="' . $result->id . '"></input>'; //$form.='<input type="hidden" name="sf_new'.'[duration]" value="'.$result->duration.'"></input>'; //$form.='<input type="hidden" name="sf_new'.'[base_offset]" value="'.$result->base_offset.'"></input>'; //$form.='<input type="hidden" name="sf_new'.'[path]" value="'.$text.'"></input>'; //$form.='<input type="hidden" name="sf_new'.'[file_desc_mesg]" value="'.$result->file_desc_mesg.'"></input>'; $form .= '<input type="submit" name="submit" value="Add"></input>'; $form .= '</form>'; $rlink = $text . $form; return $rlink; }
function getStreamImageURL($stream_id, $req_time = null, $req_size = null, $directLink = false) { global $wgScript, $mvWebImgLoc, $mvLocalImgLoc, $mvExternalImages; //check global external image prefrence: $req_size_out = $req_size != null ? '&size=' . $req_size : ''; if ($mvExternalImages) { global $mvExternalImgServerPath; //try to get the stream_name for external requests: $sn = MV_Stream::getStreamNameFromId($stream_id); return $mvExternalImgServerPath . '?action=ajax&rs=mv_frame_server&stream_name=' . $sn . '&t=' . $req_time . $req_size_out; } //by default return a non-direct link so that javascript can modify the url to get new images if (!$directLink) { return $wgScript . '?action=ajax&rs=mv_frame_server&stream_id=' . $stream_id . '&t=' . $req_time . $req_size_out; } $req_time = MV_StreamImage::procRequestTime($stream_id, $req_time); if ($req_time == false) { return MV_StreamImage::getMissingImageURL($req_size); } //print "got req time: $req_time<br />"; //first check if the file exist if (is_file(MV_StreamImage::getLocalImagePath($stream_id, $req_time, $req_size))) { if ($req_size == null) { $s = ''; $ext = 'jpg'; //default type is jpg } else { list($im_width, $im_height, $ext) = MV_StreamImage::getSizeType($req_size); $s = '_' . $im_width . 'x' . $im_height; } return $mvWebImgLoc . '/' . MV_StreamImage::getRelativeImagePath($stream_id) . '/' . $req_time . $s . '.' . $ext; } else { //throw 'error finding image'; return MV_StreamImage::getMissingImageURL($req_size); } }
function processUpload() { global $wgUser, $wgOut, $wgFileExtensions, $wgScriptPath; $details = null; $value = null; global $mvMediaFilesTable, $mvStreamFilesTable, $wgRequest; $stream_id = $wgRequest->getVal('stream_id'); $file_desc_msg = $wgRequest->getVal('file_desc_msg'); $newStream = MV_Stream::newStreamByID($stream_id); $files = $newStream->getFileList(); $doAdd = true; foreach ($files as $sf) { if ($sf->file_desc_msg == $file_desc_msg) { $doAdd = false; } } if (!$doAdd) { $value = 99; } else { $value = $this->internalProcessUpload($details); } switch ($value) { case self::SUCCESS: $html = 'File has been uploaded successfully<br/>'; $file = '' . $this->mLocalFile->getPath(); if (file_exists($file)) { $f = fopen($file, "rb"); $header = fread($f, 512); $page['serial'] = substr($header, 14, 4); $page['segments'] = ord($header[26]); $page['rate'] = ord($header[27 + $page['segments'] + 15]); $page['rate'] = $page['rate'] << 8 | ord($header[27 + $page['segments'] + 14]); $page['rate'] = $page['rate'] << 8 | ord($header[27 + $page['segments'] + 13]); $page['rate'] = $page['rate'] << 8 | ord($header[27 + $page['segments'] + 12]); fseek($f, -6000, SEEK_END); $end = fread($f, 6000); $tail = strstr($end, "OggS"); if ($tail) { $serial = substr($tail, 14, 4); if ($serial == $page['serial']) { $duration = 103; $granulepos = ord($tail[6]); $granulepos = $granulepos | ord($tail[7]) << 8; $granulepos = $granulepos | ord($tail[8]) << 16; $granulepos = $granulepos | ord($tail[9]) << 24; $granulepos = $granulepos | ord($tail[10]) << 32; $granulepos = $granulepos | ord($tail[11]) << 40; $granulepos = $granulepos | ord($tail[12]) << 48; $granulepos = $granulepos | ord($tail[13]) << 56; $duration = $granulepos / $page['rate']; } } fclose($f); } $dbr =& wfGetDB(DB_WRITE); $text = '' . $wgScriptPath . '/images/' . $this->mLocalFile->getUrlRel(); if ($duration === null) { $duration = 0; } if ($dbr->insert($mvMediaFilesTable, array('path' => $text, 'duration' => $duration, 'file_desc_msg' => $file_desc_msg), __METHOD__)) { $result = $dbr->query("SELECT LAST_INSERT_ID() AS id"); $row = $dbr->fetchObject($result); $id = $row->id; if ($dbr->insert($mvStreamFilesTable, array('file_id' => $id, 'stream_id' => $stream_id), __METHOD__)) { $stream_name = MV_Stream::getStreamNameFromId($stream_id); $title = Title::newFromText($stream_name, MV_NS_STREAM); $wgOut->redirect($title->getLocalURL("action=edit")); } else { $html .= 'Inserting file path into DB failed, Please notify the Administrator immediately'; } } else { $html .= 'Inserting file path into DB failed, Please notify the Administrator immediately'; } /* if ($dbr->insert($mvStreamFilesTable, array('stream_id'=>$stream_id))) { $result = $dbr->query("SELECT LAST_INSERT_ID()"); $row = $dbr->fetchObject($result); if ($duration===null)$duration=0; if ($dbr->insert($mvMediaFilesTable, array('id'=>$row->id,'path'=>$text,'duration'=>$duration))) { //$html .='<input type="button" name="Close" value="Close" Onclick="window.opener.document.getElementById(\'path\').value=\''.$wgScriptPath.'/images/'.$this->mLocalFile->getUrlRel().'\'; window.opener.document.getElementById(\'duration\').value='.floor($duration).'; window.close()"></input>' ; $stream_name = MV_Stream::getStreamNameFromId($stream_id); $title = Title::newFromText( $stream_name, MV_NS_STREAM ); $wgOut->redirect($title->getLocalURL("action=edit")); } else { $html .= 'Inserting file path into DB failed, Please notify the Administrator immediately'; } } else { $html .= 'Inserting file path into DB failed, Please notify the Administrator immediately'; } */ $wgOut->addHTML($html); break; case self::BEFORE_PROCESSING: break; case self::LARGE_FILE_SERVER: $this->mainUploadForm(wfMsgHtml('largefileserver')); break; case self::EMPTY_FILE: $this->mainUploadForm(wfMsgHtml('emptyfile')); break; case self::MIN_LENGHT_PARTNAME: $this->mainUploadForm(wfMsgHtml('minlength1')); break; case self::ILLEGAL_FILENAME: $filtered = $details['filtered']; $this->uploadError(wfMsgWikiHtml('illegalfilename', htmlspecialchars($filtered))); break; case self::PROTECTED_PAGE: $this->uploadError(wfMsgWikiHtml('protectedpage')); break; case self::OVERWRITE_EXISTING_FILE: $errorText = $details['overwrite']; $overwrite = new WikiError($wgOut->parse($errorText)); $this->uploadError($overwrite->toString()); break; case self::FILETYPE_MISSING: $this->uploadError(wfMsgExt('filetype-missing', array('parseinline'))); break; case self::FILETYPE_BADTYPE: $finalExt = $details['finalExt']; $this->uploadError(wfMsgExt('filetype-banned-type', array('parseinline'), htmlspecialchars($finalExt), implode(wfMsgExt('comma-separator', array('escapenoentities')), $wgFileExtensions))); break; case self::VERIFICATION_ERROR: $veri = $details['veri']; $this->uploadError($veri->toString()); break; case self::UPLOAD_VERIFICATION_ERROR: $error = $details['error']; $this->uploadError($error); break; case self::UPLOAD_WARNING: $warning = $details['warning']; $this->uploadWarning($warning); break; case self::INTERNAL_ERROR: $internal = $details['internal']; $this->showError($internal); break; case 99: $this->mainUploadForm('Type ' . $file_desc_msg . ' already exists'); break; default: throw new MWException(__METHOD__ . ": Unknown value `{$value}`"); } }
function onEdit(&$mvd_pages_cache, $mvd_id) { // force update local mvd_page_cache from db: $mvd_pages_cache[$mvd_id] = MV_Index::getMVDbyId($mvd_id); $stream_name = MV_Stream::getStreamNameFromId($this->mvd_pages[$mvd_id]->stream_id); $streamTitle = Title::newFromText($stream_name, MV_NS_STREAM); // clear the cache for the parent stream page: // print "clear parent stream: " . $streamTitle ."\n"; Article::onArticleEdit($streamTitle); }
/** * global MV_Stream server * @@todo cache this function */ function mvGetMVStream($stream_init) { global $MVStreams; // wfDebug('mv get stream: ' .$stream_name . "\n"); if (is_object($stream_init)) { $stream_init = get_object_vars($stream_init); } elseif (is_string($stream_init)) { // if a string is passed in assume its the stream name: $stream_init = array('name' => $stream_init); } if (isset($stream_init['name'])) { $stream_name = $stream_init['name']; } elseif (isset($stream_init['id'])) { $stream_name = MV_Stream::getStreamNameFromId($stream_init['id']); } else { die('missing stream id or name' . $stream_init); } // @@todo cache in memcache) if (!isset($MVStreams[$stream_name])) { $MVStreams[$stream_name] = new MV_Stream($stream_init); $MVStreams[$stream_name]->db_load_stream(); } return $MVStreams[$stream_name]; }
function edit($textbox1_override = null) { global $wgOut, $wgUser, $wgRequest; $fname = 'MV_EditPage::edit'; wfProfileIn($fname); wfDebug("{$fname}: enter\n"); // this is not an article $wgOut->setArticleFlag(false); $this->importFormData($wgRequest); if ($textbox1_override) { $this->textbox1 = $textbox1_override; } $this->firsttime = false; if ($this->live) { $this->livePreview(); wfProfileOut($fname); return; } $permErrors = $this->mTitle->getUserPermissionsErrors('edit', $wgUser); if (!$this->mTitle->exists()) { $permErrors += array_diff($this->mTitle->getUserPermissionsErrors('create', $wgUser), $permErrors); } # Ignore some permissions errors. $remove = array(); foreach ($permErrors as $error) { if ($this->preview || $this->diff && ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext')) { // Don't worry about blocks when previewing/diffing $remove[] = $error; } if ($error[0] == 'readonlytext') { if ($this->edit) { $this->formtype = 'preview'; } elseif ($this->save || $this->preview || $this->diff) { $remove[] = $error; } } } # array_diff returns elements in $permErrors that are not in $remove. $permErrors = array_diff($permErrors, $remove); if (!empty($permErrors)) { wfDebug("{$fname}: User can't edit\n"); // limt rows for ajax: $non_ajax_rows = $wgUser->getIntOption('rows'); $wgUser->setOption('rows', 5); $sk = $wgUser->getSkin(); $cancel = '<a href="javascript:mv_disp_mvd(\'' . $this->mTitle->getDBkey() . '\',\'' . $this->mvd_id . '\');">' . wfMsgExt('cancel', array('parseinline')) . '</a>'; // get the stream parent: $mvd = MV_Index::getMVDbyId($this->mvd_id); $stream_name = MV_Stream::getStreamNameFromId($mvd->stream_id); $lTitle = SpecialPage::getTitleFor('Userlogin'); $loginLink = $lTitle->getFullURL('returnto=' . MWNamespace::getCanonicalName(MV_NS_STREAM) . ':' . $stream_name); $wgOut->addHTML(wfMsg('mv_user_cant_edit', $loginLink, $cancel)); $wgOut->readOnlyPage($this->mArticle->getContent(), true, $permErrors); $wgUser->setOption('rows', $non_ajax_rows); wfProfileOut($fname); return; } else { if ($this->save) { $this->formtype = 'save'; } elseif ($this->preview) { $this->formtype = 'preview'; } elseif ($this->diff) { $this->formtype = 'diff'; } else { # First time through $this->firsttime = true; if ($this->previewOnOpen()) { $this->formtype = 'preview'; } else { $this->extractMetaDataFromArticle(); $this->formtype = 'initial'; } } } wfProfileIn("{$fname}-business-end"); $this->isConflict = false; // css / js subpages of user pages get a special treatment $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage(); $this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage(); /* Notice that we can't use isDeleted, because it returns true if article is ever deleted * no matter it's current state */ $this->deletedSinceEdit = false; if ($this->edittime != '') { /* Note that we rely on logging table, which hasn't been always there, * but that doesn't matter, because this only applies to brand new * deletes. This is done on every preview and save request. Move it further down * to only perform it on saves */ if ($this->mTitle->isDeleted()) { $this->lastDelete = $this->getLastDelete(); if (!is_null($this->lastDelete)) { $deletetime = $this->lastDelete->log_timestamp; if ($deletetime - $this->starttime > 0) { $this->deletedSinceEdit = true; } } } } # Show applicable editing introductions if ($this->formtype == 'initial' || $this->firsttime) { $this->showIntro(); } if ($this->mTitle->isTalkPage()) { $wgOut->addWikiMsg('talkpagetext'); } # Attempt submission here. This will check for edit conflicts, # and redundantly check for locked database, blocked IPs, etc. # that edit() already checked just in case someone tries to sneak # in the back door with a hand-edited submission URL. // set up commit transaction // $dbw = wfGetDB( DB_MASTER ); // $dbw->begin(); if ('save' == $this->formtype) { if (!$this->attemptSave()) { wfProfileOut("{$fname}-business-end"); wfProfileOut($fname); return; } } // $dbw->commit(); # First time through: get contents, set time for conflict # checking, etc. if ('initial' == $this->formtype || $this->firsttime) { if ($this->initialiseForm() === false) { $this->noSuchSectionPage(); wfProfileOut("{$fname}-business-end"); wfProfileOut($fname); return; } if (!$this->mTitle->getArticleId()) { wfRunHooks('EditFormPreloadText', array(&$this->textbox1, &$this->mTitle)); } } $this->showEditForm(); wfProfileOut("{$fname}-business-end"); wfProfileOut($fname); }