r31886 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r31885‎ | r31886 | r31887 >
Date:21:56, 12 March 2008
Author:siebrand
Status:old
Tags:
Comment:
* use wfLoadExtensionMessages
* delay message loading
* split off class to seperate file
* update indentation and remove EOL whitespace
* update extension credits and add descriptionmsg
Modified paths:
  • /trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.i18n.php (modified) (history)
  • /trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.php (modified) (history)
  • /trunk/extensions/YouTubeAuthSub/YouTubeAuthSub_body.php (added) (history)
  • /trunk/extensions/YouTubeAuthSub/YouTubeAuthSub_body.php (added) (history)
  • /trunk/extensions/YouTubeAuthSub/youtubeauthsub.js (modified) (history)

Diff [purge]

Index: trunk/extensions/YouTubeAuthSub/youtubeauthsub.js
@@ -1,19 +1,22 @@
2 -
32 function checkYTASForm() {
43 var title = document.ytas_form.youtube_title.value;
54 if (title == "") {
65 alert(gYTAS_notitle);
76 return false;
87 }
9 - var desc = document.ytas_form.youtube_description.value;
10 - if (desc == "") {
11 - alert(gYTAS_nodesc);
12 - return false;
13 - }
14 - var keywords = document.ytas_form.youtube_keywords.value;
15 - if (keywords == "") {
16 - alert(gYTAS_nokeywords);
17 - return false;
18 - }
 8+
 9+ var desc = document.ytas_form.youtube_description.value;
 10+
 11+ if (desc == "") {
 12+ alert(gYTAS_nodesc);
 13+ return false;
 14+ }
 15+
 16+ var keywords = document.ytas_form.youtube_keywords.value;
 17+
 18+ if (keywords == "") {
 19+ alert(gYTAS_nokeywords);
 20+ return false;
 21+ }
1922 return true;
2023 }
Property changes on: trunk/extensions/YouTubeAuthSub/youtubeauthsub.js
___________________________________________________________________
Added: svn:eol-style
2124 + native
Index: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub_body.php
@@ -0,0 +1,241 @@
 2+<?php
 3+if (!defined('MEDIAWIKI')) {
 4+ exit;
 5+}
 6+/**
 7+ * Class provides a special page
 8+ *
 9+ * @addtogroup Extensions
 10+ */
 11+
 12+class SpecialYouTubeAuthSub extends SpecialPage {
 13+
 14+ function __construct() {
 15+ parent::__construct( 'YouTubeAuthSub' );
 16+ }
 17+
 18+ function execute( $par ) {
 19+ global $wgRequest, $wgTitle, $wgOut, $wgMemc, $wgUser;
 20+ global $wgYTAS_User, $wgYTAS_Password, $wgYTAS_DeveloperId;
 21+ global $wgYTAS_DefaultCategory, $wgYTAS_UseClientLogin, $wgYTAS_EnableLogging, $wgYTAS_UseNamespace;
 22+
 23+ wfLoadExtensionMessages( 'YouTubeAuthSub' );
 24+
 25+ $this->setHeaders();
 26+
 27+ # Check permissions
 28+ if( !$wgUser->isAllowed( 'upload' ) ) {
 29+ if( !$wgUser->isLoggedIn() ) {
 30+ $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
 31+ }
 32+ else {
 33+ $wgOut->permissionRequired( 'upload' );
 34+ }
 35+ return;
 36+ }
 37+
 38+ if ($wgRequest->getVal('status') == '200' && $wgRequest->getVal('id') != null) {
 39+ $wgOut->addHTML(wfMsg('youtubeauthsub_success', $wgRequest->getVal('id')));
 40+ $descTitle = null;
 41+ $desc = wfMsg('youtubeauthsub_summary');
 42+ //TODO: can we grab the keywords and description the user has submitted?
 43+ if ($wgYTAS_UseNamespace) {
 44+ $descTitle = Title::makeTitle(NS_YOUTUBE, $wgRequest->getVal('id'));
 45+ $a = new Article($descTitle);
 46+ if ($a->getID() == 0) {
 47+ $title = $keywords = $description = $category = "";
 48+ if ($wgRequest->getVal('metaid') != null) {
 49+ $dbr = wfGetDB(DB_SLAVE);
 50+ $row = $dbr->selectRow('ytas_meta', array('ytas_title', 'ytas_description', 'ytas_keywords', 'ytas_category'),
 51+ array("ytas_id={$wgRequest->getVal('metaid')}"));
 52+ if ($row) {
 53+ $title = $row->ytas_title;
 54+ $keywords = $row->ytas_keywords;
 55+ $description = $row->ytas_description;
 56+ $category = $row->ytas_category;
 57+ }
 58+ }
 59+ $content = "{{YoutubeVideo|{$wgRequest->getVal('id')}|{$title}|{$keywords}|{$description}|{$category}}}";
 60+ $a->insertNewArticle($content,
 61+ wfMsg('youtubeauthsub_summary'),
 62+ false,
 63+ false);
 64+ $wgOut->redirect('');
 65+ }
 66+ $wgOut->addWikiText(wfMsg('youtubeauthsub_viewpage', $descTitle->getFullText()) );
 67+ }
 68+ if ($wgYTAS_EnableLogging) {
 69+ # Add the log entry
 70+ $log = new LogPage( 'upload' );
 71+ $log->addEntry( 'upload', $descTitle, $desc );
 72+ }
 73+ }
 74+
 75+ if ($wgYTAS_UseClientLogin) {
 76+
 77+ $key = wfMemcKey('youtube', 'authsub', $wgYTAS_User);
 78+ $token = $wgMemc->get( $key );
 79+ // regenerate the token
 80+ if (!$token) {
 81+ $result = wfSpecialYouTubePost("https://www.google.com/youtube/accounts/ClientLogin?"
 82+ , "Email={$wgYTAS_User}&Passwd={$wgYTAS_Password}&service=youtube&source=wikiHow");
 83+ $YouTubeUser = "";
 84+ $lines = split("\n", $result);
 85+ foreach ($lines as $line) {
 86+ $params = split("=", $line);
 87+ switch ($params[0]) {
 88+ case "Auth":
 89+ $token = $params[1];
 90+ break;
 91+ case "YouTubeUser":
 92+ $YouTubeUser = $params[1];
 93+ break;
 94+ }
 95+ }
 96+ if (!$token) {
 97+ $wgOut->addHTML(wfMsg('youtubeauthsub_tokenerror'));
 98+ return;
 99+ }
 100+ $wgMemc->set($key, $token, time() + 3600);
 101+ }
 102+ }
 103+ else {
 104+ $token = $wgRequest->getVal('token');
 105+ if (!$token) {
 106+ $wgOut->addHTML(wfMsg('youtubeauthsub_authsubinstructions') .
 107+ "
 108+ <script type='text/javascript'>
 109+ var gYTAS_nokeywords = '" . wfMsg('youtubeauthsub_jserror_nokeywords') . "';
 110+ var gYTAS_notitle = '" . wfMsg('youtubeauthsub_jserror_notitle') . "';
 111+ </script>
 112+ <script type='text/javascript' src='/extensions/YouTubeAuthSub/youtubeauthsub.js'>
 113+ </script>
 114+ <form action='https://www.google.com/accounts/AuthSubRequest' method='POST' onsubmit='return checkYTASForm();' name='ytas_form'/>
 115+ <input type='hidden' name='next' value='{$wgTitle->getFullURL()}'/>
 116+ <input type='hidden' name='scope' value='http://gdata.youtube.com/feeds'/>
 117+ <input type='hidden' name='session' value='0'/>
 118+ <input type='hidden' name='secure' value='0'/>
 119+ <input type='submit' value='" . wfMsg('youtubeauthsub_clickhere') . "'/>"
 120+ );
 121+ return;
 122+ }
 123+ }
 124+
 125+ if ($wgRequest->wasPosted()) {
 126+ $url = "http://uploads.gdata.youtube.com/feeds/api/users/{$wgYTAS_User}/uploads";
 127+
 128+ $data = "<?xml version='1.0'?>
 129+ <entry xmlns='http://www.w3.org/2005/Atom'
 130+ xmlns:media='http://search.yahoo.com/mrss/'
 131+ xmlns:yt='http://gdata.youtube.com/schemas/2007'>
 132+ <media:group>
 133+ <media:title type='plain'>" . FeedItem::xmlEncode($wgRequest->getVal('youtube_title')) . "</media:title>
 134+ <media:description type='plain'>" . FeedItem::xmlEncode($wgRequest->getVal('youtube_description')) . "</media:description>
 135+ <media:keywords>" . FeedItem::xmlEncode($wgRequest->getVal('youtube_keywords')) . "</media:keywords>
 136+ <media:category scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>" .
 137+ FeedItem::xmlEncode($wgRequest->getVal('youtube_category')) . "</media:category>
 138+ </media:group>
 139+ </entry>
 140+ ";
 141+ $headers = array (
 142+ "X-GData-Key: key={$wgYTAS_DeveloperId}",
 143+ "Content-Type: application/atom+xml; charset=UTF-8",
 144+ "Content-Length: " . strlen($data),
 145+ );
 146+ if ($wgYTAS_UseClientLogin)
 147+ $headers[] = "Authorization: GoogleLogin auth=$token";
 148+ else
 149+ $headers[] = "Authorization: AuthSub token=$token";
 150+
 151+ $results = wfSpecialYouTubePost($url, $data, $headers);
 152+
 153+ preg_match("/<yt:token>.*<\/yt:token>/", $results, $matches);
 154+ $token = strip_tags($matches[0]);
 155+ preg_match("/'edit-media'[^>]*href='[^']*'>/", $results, $matches);
 156+ $url = preg_replace("/.*href='([^']*)'>/", "$1", $matches[0]);
 157+
 158+ if ($url == "") {
 159+ $wgOut->addHTML("Unable to extract URL, results where <pre>{$results}</pre>");
 160+ return;
 161+ }
 162+ // CAPTURE THE META INFO AND STORE IT
 163+ $meta_id = '';
 164+ $dbw = wfGetDB(DB_MASTER);
 165+ $fields = array (
 166+ 'ytas_user' => $wgUser->getID(),
 167+ 'ytas_timestamp' => $dbw->timestamp( time() ),
 168+ 'ytas_title' => $wgRequest->getVal('youtube_title'),
 169+ 'ytas_description' => $wgRequest->getVal('youtube_description'),
 170+ 'ytas_keywords' => $wgRequest->getVal('youtube_keywords'),
 171+ 'ytas_category' => $wgRequest->getVal('youtube_category')
 172+ );
 173+ $dbw->insert( 'ytas_meta', $fields, __METHOD__, array( 'IGNORE' ) );
 174+ if ( $dbw->affectedRows() ) {
 175+ $meta_id =$dbw->insertId();
 176+ }
 177+
 178+ $next_url = urlencode($wgTitle->getFullURL() . "?metaid={$meta_id}");
 179+
 180+ $wgOut->addHTML(wfMsg('youtubeauthsub_uploadhere') . "<br/><br/>
 181+ <form action='{$url}?nexturl={$next_url}' METHOD='post' enctype='multipart/form-data' name='videoupload'>
 182+ <input type='file' name='file' size='50'/>
 183+ <input type='hidden' name='token' value='{$token}'/><br/>
 184+ <input type='submit' name='submitbtn' value='" . wfMsg('youtubeauthsub_uploadbutton') . "'/>
 185+ </form>
 186+ <center>
 187+ <div id='upload_image' style='display:none;'>
 188+ " . wfMsg('youtubeauthsub_uploading') . "
 189+ <img src='/extensions/YouTubeAuthSub/upload.gif'>
 190+ </div>
 191+ </center>
 192+ ");
 193+ }
 194+ else {
 195+ $wgOut->addHTML( wfMsg('youtubeauthsub_info') .
 196+
 197+ " <script type='text/javascript'>
 198+ var gYTAS_nokeywords = '" . wfMsg('youtubeauthsub_jserror_nokeywords') . "';
 199+ var gYTAS_nodesc = '" . wfMsg('youtubeauthsub_jserror_nodesc') . "';
 200+ var gYTAS_notitle = '" . wfMsg('youtubeauthsub_jserror_notitle') . "';
 201+ </script>
 202+ <script type='text/javascript' src='/extensions/YouTubeAuthSub/youtubeauthsub.js'>
 203+ </script>
 204+ <form action='{$wgTitle->getFullURL()}' method='POST' name='ytas_form' onsubmit='return checkYTASForm();'>
 205+ <table cellpadding='100'>
 206+ ");
 207+ if (!$wgYTAS_UseClientLogin) {
 208+ $wgOut->addHTML("<input type='hidden' name='token' value='{$wgRequest->getVal('token')}'/>");
 209+ }
 210+ $wgOut->addHTML("
 211+ <tr>
 212+ <td>" . wfMsg('youtubeauthsub_title') . ":</td>
 213+ <td><input type='text' name='youtube_title' size='40'/></td>
 214+ </tr>
 215+ <tr>
 216+ <td valign='top'>" . wfMsg('youtubeauthsub_description') . ":</td>
 217+ <td><textarea cols='100' rows='4' name='youtube_description'></textarea></td>
 218+ </tr>
 219+ <tr>
 220+ <td>" . wfMsg('youtubeauthsub_keywords') . ":</td>
 221+ <td><input type='text' name='youtube_keywords' size='40'/></td>
 222+ </tr>");
 223+ if (!$wgYTAS_DefaultCategory) {
 224+ $cats = wfSpecialYouTubeGetCategories();
 225+ $wgOut->addHTML("
 226+ <tr>
 227+ <td>" . wfMsg('youtubeauthsub_category') . ":</td>
 228+ <td><select type='text' name='youtube_category'/>{$cats}</select></td>
 229+ </tr>");
 230+ }
 231+ else {
 232+ $wgOut->addHTML("<input type='hidden' name='youtube_category' value='{$wgYTAS_DefaultCategory}'/>");
 233+ }
 234+ $wgOut->addHTML("
 235+ <tr>
 236+ <td><input type='submit' value='" . wfMsg('youtubeauthsub_submit') . "'></td>
 237+ </tr>
 238+ </table>
 239+ </form>");
 240+ }
 241+ }
 242+}
Property changes on: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub_body.php
___________________________________________________________________
Added: svn:eol-style
1243 + native
Added: svn:keywords
2244 + LastChangedDate
Index: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.i18n.php
@@ -3,38 +3,44 @@
44 * Internationalisation file for YouTubeAuthSub extension.
55 *
66 * @addtogroup Extensions
7 -*/
 7+ */
88
9 -$wgYouTubeAuthSubMessages = array();
 9+$messages = array();
1010
11 -$wgYouTubeAuthSubMessages['en'] = array(
12 - 'youtubeauthsub' => 'Upload YouTube Video',
13 - 'youtubeauthsub_info' => "<img src='http://s.ytimg.com/yt/img/pixel-vfl73.gif'>
14 - To upload a video to YouTube to include on a wikiHow article, fill out the following information:",
15 - 'youtubeauthsub_title' => 'Title',
16 - 'youtubeauthsub_description' => 'Description',
17 - 'youtubeauthsub_password' => "YouTube Passsword",
18 - 'youtubeauthsub_username' => "YouTube Username",
19 - 'youtubeauthsub_keywords' => 'Keywords',
20 - 'youtubeauthsub_category' => 'Category',
21 - 'youtubeauthsub_submit' => 'Submit',
22 - 'youtubeauthsub_clickhere' => 'Click here to log in to YouTube',
23 - 'youtubeauthsub_tokenerror' => 'Error generating authorization token, try refreshing.',
24 - 'youtubeauthsub_success' => "Congratulations! Your video is uploaded. To view your video click <a href='http://www.youtube.com/watch?v=$1'>here</a>. YouTube may require some time to process your video, so it might not be ready just yet. <br/><br/>
25 -To include your video in an article on the wiki, insert the following code into an article:
26 -<code>
27 -{{&#35;ev:youtube|$1}}
28 -</code>
29 -<br/><br/>",
30 - 'youtubeauthsub_authsubinstructions' => "To upload a video, you will be required to first log in to YouTube.<br/><br/>",
31 - 'youtubeauthsub_uploadhere' => "Upload your video from here:",
32 - 'youtubeauthsub_uploadbutton' => 'Upload',
33 - 'youtubeauthsub_code' => '{{#ev:youtube|$1}}.\n\nThis video can be viewed [http://www.youtube.com/watch?v=$1 here]',
34 - 'youtubeauthsub_summary' => 'Uploading YouTube video',
35 - 'youtubeauthsub_uploading' => 'Your video is being uploaded. Please be patient.',
36 - 'youtubeauthsub_viewpage' => 'Alternatively, you can view your video [[$1|here]].',
37 - 'youtubeauthsub_jserror_nokeywords' => 'Please enter 1 or more keywords.',
38 - 'youtubeauthsub_jserror_notitle' => 'Please enter a title for the video.',
39 - 'youtubeauthsub_jserror_nodesc' => 'Please enter a description for the video.',
 11+/** English
 12+ * @author Travis Derouin
 13+ */
 14+$messages['en'] = array(
 15+ 'youtubeauthsub' => 'Upload YouTube Video',
 16+ 'youtubeauthsub-desc' => 'Allows users to [[Special:YouTubeAuthSub|upload videos]] directly to YouTube',
 17+ 'youtubeauthsub_info' => "To upload a video to YouTube to include on a page, fill out the following information:",
 18+ 'youtubeauthsub_title' => 'Title',
 19+ 'youtubeauthsub_description' => 'Description',
 20+ 'youtubeauthsub_password' => "YouTube Passsword",
 21+ 'youtubeauthsub_username' => "YouTube Username",
 22+ 'youtubeauthsub_keywords' => 'Keywords',
 23+ 'youtubeauthsub_category' => 'Category',
 24+ 'youtubeauthsub_submit' => 'Submit',
 25+ 'youtubeauthsub_clickhere' => 'Click here to log in to YouTube',
 26+ 'youtubeauthsub_tokenerror' => 'Error generating authorization token, try refreshing.',
 27+ 'youtubeauthsub_success' => "Congratulations!
 28+Your video is uploaded.
 29+To view your video click <a href='http://www.youtube.com/watch?v=$1'>here</a>.
 30+YouTube may require some time to process your video, so it might not be ready just yet.
4031
 32+To include your video in a page on the wiki, insert the following code into a page:
 33+<code>{{&#35;ev:youtube|$1}}</code>",
 34+ 'youtubeauthsub_authsubinstructions' => "To upload a video, you will be required to first log in to YouTube.",
 35+ 'youtubeauthsub_uploadhere' => "Upload your video from here:",
 36+ 'youtubeauthsub_uploadbutton' => 'Upload',
 37+ 'youtubeauthsub_code' => '{{#ev:youtube|$1}}.
 38+
 39+This video can be viewed [http://www.youtube.com/watch?v=$1 here]',
 40+ 'youtubeauthsub_summary' => 'Uploading YouTube video',
 41+ 'youtubeauthsub_uploading' => 'Your video is being uploaded.
 42+Please be patient.',
 43+ 'youtubeauthsub_viewpage' => 'Alternatively, you can view your video [[$1|here]].',
 44+ 'youtubeauthsub_jserror_nokeywords' => 'Please enter 1 or more keywords.',
 45+ 'youtubeauthsub_jserror_notitle' => 'Please enter a title for the video.',
 46+ 'youtubeauthsub_jserror_nodesc' => 'Please enter a description for the video.',
4147 );
Property changes on: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.i18n.php
___________________________________________________________________
Added: svn:eol-style
4248 + native
Index: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.php
@@ -1,10 +1,10 @@
22 <?php
33 if ( ! defined( 'MEDIAWIKI' ) )
44 die();
5 -
 5+
66 /**#@+
7 - * An extension that allows users to rate articles.
8 - *
 7+ * An extension that allows users to rate articles.
 8+ *
99 * @package MediaWiki
1010 * @subpackage Extensions
1111 *
@@ -17,76 +17,70 @@
1818
1919 $wgExtensionFunctions[] = 'wfYouTubeAuthSub';
2020
21 -require_once("SpecialPage.php");
 21+$wgYTAS_UseClientLogin = true;
2222
23 -$wgYTAS_UseClientLogin = true;
24 -
2523 # Fill out if you are using $wgUseClientLogin
26 -$wgYTAS_User = "";
27 -$wgYTAS_Password = "";
28 -$wgYTAS_DeveloperId = "";
 24+$wgYTAS_User = "x";
 25+$wgYTAS_Password = "y";
 26+$wgYTAS_DeveloperId = "z";
2927 $wgYTAS_DefaultCategory = false;
3028
31 -$wgYTAS_EnableLogging = true;
32 -$wgYTAS_UseNamespace = true;
 29+$wgYTAS_EnableLogging = true;
 30+$wgYTAS_UseNamespace = true;
3331
3432 define ( 'NS_YOUTUBE' , 20);
3533 define ( 'NS_YOUTUBE_TALK' , 21);
3634
37 -/**#@+
38 - */
39 -#$wgHooks['AfterArticleDisplayed'][] = array("wfYouTubeAuthSubForm");
40 -
4135 $wgExtensionCredits['other'][] = array(
42 - 'name' => 'YouTubeAuthSub',
43 - 'author' => 'Travis Derouin',
44 - 'description' => 'Allows users to upload videos directly to YouTube through the wiki.',
45 - 'url' => 'http://www.mediawiki.org/wiki/Extension:YouTubeAuthSub',
 36+ 'name' => 'YouTubeAuthSub',
 37+ 'version' => preg_replace('/^.* (\d\d\d\d-\d\d-\d\d) .*$/', '\1', '$LastChangedDate$'), #just the date of the last change
 38+ 'author' => 'Travis Derouin',
 39+ 'description' => 'Allows users to upload videos directly to YouTube through the wiki',
 40+ 'descriptionmsg' => 'youtubeauthsub-desc',
 41+ 'url' => 'http://www.mediawiki.org/wiki/Extension:YouTubeAuthSub',
4642 );
4743
48 -# Internationalisation file
49 -require_once( dirname(__FILE__) . '/YouTubeAuthSub.i18n.php' );
 44+$dir = dirname(__FILE__) . '/';
 45+$wgExtensionMessagesFiles['YouTubeAuthSub'] = $dir . 'YouTubeAuthSub.i18n.php';
 46+$wgAutoloadClasses['SpecialYouTubeAuthSub'] = $dir . 'YouTubeAuthSub_body.php';
 47+$wgSpecialPages['YouTubeAuthSub'] = 'SpecialYouTubeAuthSub';
5048
5149 function wfYouTubeAuthSub() {
52 - global $wgMessageCache, $wgYouTubeAuthSubMessages, $wgYTAS_UseNamespace, $wgExtraNamespaces;
53 - SpecialPage::AddPage(new SpecialPage('YouTubeAuthSub'));
54 - foreach( $wgYouTubeAuthSubMessages as $key => $value ) {
55 - $wgMessageCache->addMessages( $wgYouTubeAuthSubMessages[$key], $key );
56 - }
 50+ global $wgYTAS_UseNamespace, $wgExtraNamespaces;
5751
5852 $wgExtraNamespaces[NS_YOUTUBE] = "YouTube";
59 - $wgExtraNamespaces[NS_YOUUBE_TALK] = "YouTube_talk";
 53+ $wgExtraNamespaces[NS_YOUTUBE_TALK] = "YouTube_talk";
6054 }
6155
6256 function wfSpecialYouTubePost ($url, $content, $headers = null) {
63 -// Set the date of your post
64 -$issued=gmdate("Y-m-d\TH:i:s\Z", time());
 57+ // Set the date of your post
 58+ $issued=gmdate("Y-m-d\TH:i:s\Z", time());
6559
66 -if ($headers == null)
 60+ if ($headers == null)
6761 $headers = array( "Content-type: application/x-www-form-urlencoded" );
6862
69 -// Use curl to post to your blog.
70 -$ch = curl_init();
71 -curl_setopt($ch, CURLOPT_URL, $url);
72 -curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
73 -curl_setopt($ch, CURLOPT_TIMEOUT, 4);
74 -curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
75 -curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
76 -curl_setopt($ch, CURLOPT_VERBOSE, 1);
 63+ // Use curl to post to your blog.
 64+ $ch = curl_init();
 65+ curl_setopt($ch, CURLOPT_URL, $url);
 66+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 67+ curl_setopt($ch, CURLOPT_TIMEOUT, 4);
 68+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 69+ curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
 70+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
7771
78 -$data = curl_exec($ch);
 72+ $data = curl_exec($ch);
7973
80 -if (curl_errno($ch)) {
81 - print curl_error($ch);
82 -} else {
83 - curl_close($ch);
84 -}
 74+ if (curl_errno($ch)) {
 75+ print curl_error($ch);
 76+ }
 77+ else {
 78+ curl_close($ch);
 79+ }
8580
86 -// $data contains the result of the post...
87 -return $data;
88 -
89 -
 81+ // $data contains the result of the post...
 82+ return $data;
9083 }
 84+
9185 function wfSpecialYouTubeGetCategories() {
9286 global $wgMemc;
9387 $key = wfMemcKey('youtube', 'authsub', $wgYTAS_User);
@@ -99,9 +93,10 @@
10094 $data = curl_exec($ch);
10195 if (curl_errno($ch)) {
10296 print curl_error($ch);
103 - } else {
104 - curl_close($ch);
10597 }
 98+ else {
 99+ curl_close($ch);
 100+ }
106101 preg_match_all("/<atom:category term='([^']*)' label='([^']*)'>/", $data, $matches);
107102 $cats = "";
108103 for ($i = 0; $i < sizeof ($matches[1]) && $i < sizeof($matches[2]); $i++) {
@@ -111,228 +106,3 @@
112107 }
113108 return $cats;
114109 }
115 -
116 -function wfSpecialYouTubeAuthSub( $par )
117 -{
118 -
119 - global $wgRequest, $wgTitle, $wgOut, $wgMemc, $wgUser;
120 - global $wgYTAS_User, $wgYTAS_Password, $wgYTAS_DeveloperId;
121 - global $wgYTAS_DefaultCategory, $wgYTAS_UseClientLogin, $wgYTAS_EnableLogging, $wgYTAS_UseNamespace;
122 -
123 - $fname = "wfYouTubeAuthSub";
124 -
125 - # Check permissions
126 - if( !$wgUser->isAllowed( 'upload' ) ) {
127 - if( !$wgUser->isLoggedIn() ) {
128 - $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
129 - } else {
130 - $wgOut->permissionRequired( 'upload' );
131 - }
132 - return;
133 - }
134 -
135 - if ($wgRequest->getVal('status') == '200' && $wgRequest->getVal('id') != null) {
136 - $wgOut->addHTML(wfMsg('youtubeauthsub_success', $wgRequest->getVal('id')));
137 - $descTitle = null;
138 - $desc = wfMsg('youtubeauthsub_summary');
139 - //TODO: can we grab the keywords and description the user has submitted?
140 - if ($wgYTAS_UseNamespace) {
141 - $descTitle = Title::makeTitle(NS_YOUTUBE, $wgRequest->getVal('id'));
142 - $a = new Article($descTitle);
143 - if ($a->getID() == 0) {
144 - $title = $keywords = $description = $category = "";
145 - if ($wgRequest->getVal('metaid') != null) {
146 - $dbr = wfGetDB(DB_SLAVE);
147 - $row = $dbr->selectRow('ytas_meta', array('ytas_title', 'ytas_description', 'ytas_keywords', 'ytas_category'),
148 - array("ytas_id={$wgRequest->getVal('metaid')}"));
149 - if ($row) {
150 - $title = $row->ytas_title;
151 - $keywords = $row->ytas_keywords;
152 - $description = $row->ytas_description;
153 - $category = $row->ytas_category;
154 - }
155 - }
156 - $content = "{{YoutubeVideo|{$wgRequest->getVal('id')}|{$title}|{$keywords}|{$description}|{$category}}}";
157 - $a->insertNewArticle($content,
158 - wfMsg('youtubeauthsub_summary'),
159 - false,
160 - false);
161 - $wgOut->redirect('');
162 - }
163 - $wgOut->addWikiText(wfMsg('youtubeauthsub_viewpage', $descTitle->getFullText()) );
164 - }
165 - if ($wgYTAS_EnableLogging) {
166 - # Add the log entry
167 - $log = new LogPage( 'upload' );
168 - $log->addEntry( 'upload', $descTitle, $desc );
169 - }
170 - }
171 -
172 - if ($wgYTAS_UseClientLogin) {
173 -
174 - $key = wfMemcKey('youtube', 'authsub', $wgYTAS_User);
175 - $token = $wgMemc->get( $key );
176 - // regenerate the token
177 - if (!$token) {
178 - $result = wfSpecialYouTubePost("https://www.google.com/youtube/accounts/ClientLogin?"
179 - , "Email={$wgYTAS_User}&Passwd={$wgYTAS_Password}&service=youtube&source=wikiHow");
180 - $YouTubeUser = "";
181 - $lines = split("\n", $result);
182 - foreach ($lines as $line) {
183 - $params = split("=", $line);
184 - switch ($params[0]) {
185 - case "Auth":
186 - $token = $params[1];
187 - break;
188 - case "YouTubeUser":
189 - $YouTubeUser = $params[1];
190 - break;
191 - }
192 - }
193 - if (!$token) {
194 - $wgOut->addHTML(wfMsg('youtubeauthsub_tokenerror'));
195 - return;
196 - }
197 - $wgMemc->set($key, $token, time() + 3600);
198 - }
199 - } else {
200 - $token = $wgRequest->getVal('token');
201 - if (!$token) {
202 - $wgOut->addHTML(wfMsg('youtubeauthsub_authsubinstructions') .
203 - "
204 - <script type='text/javascript'>
205 - var gYTAS_nokeywords = '" . wfMsg('youtubeauthsub_jserror_nokeywords') . "';
206 - var gYTAS_notitle = '" . wfMsg('youtubeauthsub_jserror_notitle') . "';
207 - </script>
208 - <script type='text/javascript' src='/extensions/YouTubeAuthSub/youtubeauthsub.js'>
209 - </script>
210 - <form action='https://www.google.com/accounts/AuthSubRequest' method='POST' onsubmit='return checkYTASForm();' name='ytas_form'/>
211 - <input type='hidden' name='next' value='{$wgTitle->getFullURL()}'/>
212 - <input type='hidden' name='scope' value='http://gdata.youtube.com/feeds'/>
213 - <input type='hidden' name='session' value='0'/>
214 - <input type='hidden' name='secure' value='0'/>
215 - <input type='submit' value='" . wfMsg('youtubeauthsub_clickhere') . "'/>"
216 - );
217 - return;
218 - }
219 - }
220 -
221 - if ($wgRequest->wasPosted()) {
222 - $url = "http://uploads.gdata.youtube.com/feeds/api/users/{$wgYTAS_User}/uploads";
223 -
224 -
225 - $data = "<?xml version='1.0'?>
226 -<entry xmlns='http://www.w3.org/2005/Atom'
227 - xmlns:media='http://search.yahoo.com/mrss/'
228 - xmlns:yt='http://gdata.youtube.com/schemas/2007'>
229 - <media:group>
230 - <media:title type='plain'>" . FeedItem::xmlEncode($wgRequest->getVal('youtube_title')) . "</media:title>
231 - <media:description type='plain'>" . FeedItem::xmlEncode($wgRequest->getVal('youtube_description')) . "</media:description>
232 - <media:keywords>" . FeedItem::xmlEncode($wgRequest->getVal('youtube_keywords')) . "</media:keywords>
233 - <media:category scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>" .
234 - FeedItem::xmlEncode($wgRequest->getVal('youtube_category')) . "</media:category>
235 - </media:group>
236 -</entry>
237 -";
238 - $headers = array (
239 - "X-GData-Key: key={$wgYTAS_DeveloperId}",
240 - "Content-Type: application/atom+xml; charset=UTF-8",
241 - "Content-Length: " . strlen($data),
242 - );
243 - if ($wgYTAS_UseClientLogin)
244 - $headers[] = "Authorization: GoogleLogin auth=$token";
245 - else
246 - $headers[] = "Authorization: AuthSub token=$token";
247 -
248 - $results = wfSpecialYouTubePost($url, $data, $headers);
249 -
250 - preg_match("/<yt:token>.*<\/yt:token>/", $results, $matches);
251 - $token = strip_tags($matches[0]);
252 - preg_match("/'edit-media'[^>]*href='[^']*'>/", $results, $matches);
253 - $url = preg_replace("/.*href='([^']*)'>/", "$1", $matches[0]);
254 -
255 - if ($url == "") {
256 - $wgOut->addHTML("Unable to extract URL, results where <pre>{$results}</pre>");
257 - return;
258 - }
259 - // CAPTURE THE META INFO AND STORE IT
260 - $meta_id = '';
261 - $dbw = wfGetDB(DB_MASTER);
262 - $fields = array (
263 - 'ytas_user' => $wgUser->getID(),
264 - 'ytas_timestamp' => $dbw->timestamp( time() ),
265 - 'ytas_title' => $wgRequest->getVal('youtube_title'),
266 - 'ytas_description' => $wgRequest->getVal('youtube_description'),
267 - 'ytas_keywords' => $wgRequest->getVal('youtube_keywords'),
268 - 'ytas_category' => $wgRequest->getVal('youtube_category')
269 - );
270 - $dbw->insert( 'ytas_meta', $fields, __METHOD__, array( 'IGNORE' ) );
271 - if ( $dbw->affectedRows() ) {
272 - $meta_id =$dbw->insertId();
273 - }
274 -
275 - $next_url = urlencode($wgTitle->getFullURL() . "?metaid={$meta_id}");
276 -
277 - $wgOut->addHTML(wfMsg('youtubeauthsub_uploadhere') . "<br/><br/>
278 - <form action='{$url}?nexturl={$next_url}' METHOD='post' enctype='multipart/form-data' name='videoupload'>
279 - <input type='file' name='file' size='50'/>
280 - <input type='hidden' name='token' value='{$token}'/><br/>
281 - <input type='submit' name='submitbtn' value='" . wfMsg('youtubeauthsub_uploadbutton') . "'/>
282 - </form>
283 - <center>
284 - <div id='upload_image' style='display:none;'>
285 - " . wfMsg('youtubeauthsub_uploading') . "
286 - <img src='/extensions/YouTubeAuthSub/upload.gif'>
287 - </div>
288 - </center>
289 - ");
290 - } else {
291 - $wgOut->addHTML( wfMsg('youtubeauthsub_info') .
292 -
293 - " <script type='text/javascript'>
294 - var gYTAS_nokeywords = '" . wfMsg('youtubeauthsub_jserror_nokeywords') . "';
295 - var gYTAS_nodesc = '" . wfMsg('youtubeauthsub_jserror_nodesc') . "';
296 - var gYTAS_notitle = '" . wfMsg('youtubeauthsub_jserror_notitle') . "';
297 - </script>
298 - <script type='text/javascript' src='/extensions/YouTubeAuthSub/youtubeauthsub.js'>
299 - </script>
300 - <form action='{$wgTitle->getFullURL()}' method='POST' name='ytas_form' onsubmit='return checkYTASForm();'>
301 - <table cellpadding='100'>
302 - ");
303 - if (!$wgYTAS_UseClientLogin) {
304 - $wgOut->addHTML("<input type='hidden' name='token' value='{$wgRequest->getVal('token')}'/>");
305 - }
306 - $wgOut->addHTML("
307 - <tr>
308 - <td>" . wfMsg('youtubeauthsub_title') . ":</td>
309 - <td><input type='text' name='youtube_title' size='40'/></td>
310 - </tr>
311 - <tr>
312 - <td valign='top'>" . wfMsg('youtubeauthsub_description') . ":</td>
313 - <td><textarea cols='100' rows='4' name='youtube_description'></textarea></td>
314 - </tr>
315 - <tr>
316 - <td>" . wfMsg('youtubeauthsub_keywords') . ":</td>
317 - <td><input type='text' name='youtube_keywords' size='40'/></td>
318 - </tr>");
319 - if (!$wgYTAS_DefaultCategory) {
320 - $cats = wfSpecialYouTubeGetCategories();
321 - $wgOut->addHTML("
322 - <tr>
323 - <td>" . wfMsg('youtubeauthsub_category') . ":</td>
324 - <td><select type='text' name='youtube_category'/>{$cats}</select>
325 - </td>
326 - </tr>");
327 - } else {
328 - $wgOut->addHTML("<input type='hidden' name='youtube_category' value='{$wgYTAS_DefaultCategory}'/>");
329 - }
330 - $wgOut->addHTML("
331 - <tr>
332 - <td><input type='submit' value='" . wfMsg('youtubeauthsub_submit') . "'></td>
333 - </tr>
334 - </table>
335 - </form>");
336 - }
337 -}
338 -
339 -?>
Property changes on: trunk/extensions/YouTubeAuthSub/YouTubeAuthSub.php
___________________________________________________________________
Added: svn:eol-style
340110 + native
Added: svn:keywords
341111 + LastChangedDate

Status & tagging log