r91093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91092‎ | r91093 | r91094 >
Date:18:24, 29 June 2011
Author:krinkle
Status:ok
Tags:
Comment:
Rename WikiLove API classes and filenames per convention
(Follows up r91032, r87294)
(I know "WikiLove API" makes more sense..)
Modified paths:
  • /trunk/extensions/WikiLove/ApiWikiLove.php (added) (history)
  • /trunk/extensions/WikiLove/ApiWikiLoveImageLog.php (added) (history)
  • /trunk/extensions/WikiLove/WikiLove.api.php (deleted) (history)
  • /trunk/extensions/WikiLove/WikiLove.php (modified) (history)
  • /trunk/extensions/WikiLove/WikiLoveImageLog.api.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.api.php
@@ -1,179 +0,0 @@
2 -<?php
3 -class WikiLoveApi extends ApiBase {
4 - public function execute() {
5 - global $wgRequest, $wgWikiLoveLogging, $wgParser;
6 -
7 - $params = $this->extractRequestParams();
8 -
9 - $title = Title::newFromText( $params['title'] );
10 - if ( is_null( $title ) ) {
11 - $this->dieUsageMsg( array( 'invaliduser', $params['title'] ) );
12 - }
13 -
14 - $talk = WikiLoveHooks::getUserTalkPage( $title );
15 - if ( is_null( $talk ) ) {
16 - $this->dieUsageMsg( array( 'invaliduser', $params['title'] ) );
17 - }
18 -
19 - if ( $wgWikiLoveLogging ) {
20 - $this->saveInDb( $talk, $params['subject'], $params['message'], $params['type'], isset( $params['email'] ) ? 1 : 0 );
21 - }
22 -
23 - // not using section => 'new' here, as we like to give our own edit summary
24 - $api = new ApiMain( new FauxRequest( array(
25 - 'action' => 'edit',
26 - 'title' => $talk->getFullText(),
27 - // need to do this, as Article::replaceSection fails for non-existing pages
28 - 'appendtext' => ( $talk->exists() ? "\n\n" : '' ) . wfMsgForContent( 'newsectionheaderdefaultlevel', $params['subject'] )
29 - . "\n\n" . $params['text'],
30 - 'token' => $params['token'],
31 - 'summary' => wfMsgForContent( 'wikilove-summary', $wgParser->stripSectionName( $params['subject'] ) ),
32 - 'notminor' => true,
33 - ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
34 -
35 - $api->execute();
36 -
37 - if ( isset( $params['email'] ) ) {
38 - $this->emailUser( $talk, $params['subject'], $params['email'], $params['token'] );
39 - }
40 -
41 - $this->getResult()->addValue( 'redirect', 'pageName', $talk->getPrefixedDBkey() );
42 - $this->getResult()->addValue( 'redirect', 'fragment', Title::escapeFragmentForURL( $params['subject'] ) );
43 - // note that we cannot use Title::makeTitle here as it doesn't sanitize the fragment
44 - }
45 -
46 - /**
47 - * @param $talk Title
48 - * @param $subject
49 - * @param $message
50 - * @param $type
51 - * @param $email
52 - * @return void
53 - */
54 - private function saveInDb( $talk, $subject, $message, $type, $email ) {
55 - global $wgUser;
56 - $dbw = wfGetDB( DB_MASTER );
57 - $receiver = User::newFromName( $talk->getSubjectPage()->getBaseText() );
58 - if ( $receiver === false || $receiver->isAnon() ) {
59 - $this->setWarning( 'Not logging anonymous recipients' );
60 - return;
61 - }
62 -
63 - $values = array(
64 - 'wll_timestamp' => $dbw->timestamp(),
65 - 'wll_sender' => $wgUser->getId(),
66 - 'wll_sender_editcount' => $wgUser->getEditCount(),
67 - 'wll_sender_registration' => $wgUser->getRegistration(),
68 - 'wll_receiver' => $receiver->getId(),
69 - 'wll_receiver_editcount' => $receiver->getEditCount(),
70 - 'wll_receiver_registration' => $receiver->getRegistration(),
71 - 'wll_type' => $type,
72 - 'wll_subject' => $subject,
73 - 'wll_message' => $message,
74 - 'wll_email' => $email,
75 - );
76 -
77 - try{
78 - $dbw->insert( 'wikilove_log', $values, __METHOD__ );
79 - } catch( DBQueryError $dbqe ) {
80 - $this->setWarning( 'Action was not logged' );
81 - }
82 - }
83 -
84 - /**
85 - * @param $talk Title
86 - * @param $subject string
87 - * @param $text string
88 - * @param $token string
89 - */
90 - private function emailUser( $talk, $subject, $text, $token ) {
91 - global $wgRequest;
92 - $api = new ApiMain( new FauxRequest( array(
93 - 'action' => 'emailuser',
94 - 'target' => User::newFromName( $talk->getSubjectPage()->getBaseText() )->getName(),
95 - 'subject' => $subject,
96 - 'text' => $text,
97 - 'token' => $token,
98 - ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
99 - try{
100 - $api->execute();
101 - } catch( DBQueryError $dbqe ) {
102 - $this->setWarning( 'E-mail was not sent' );
103 - }
104 - }
105 -
106 - public function getAllowedParams() {
107 - return array(
108 - 'title' => array(
109 - ApiBase::PARAM_TYPE => 'string',
110 - ApiBase::PARAM_REQUIRED => true,
111 - ),
112 - 'text' => array(
113 - ApiBase::PARAM_TYPE => 'string',
114 - ApiBase::PARAM_REQUIRED => true,
115 - ),
116 - 'message' => array(
117 - ApiBase::PARAM_TYPE => 'string',
118 - ),
119 - 'token' => array(
120 - ApiBase::PARAM_TYPE => 'string',
121 - ApiBase::PARAM_REQUIRED => true,
122 - ),
123 - 'subject' => array(
124 - ApiBase::PARAM_TYPE => 'string',
125 - ApiBase::PARAM_REQUIRED => true,
126 - ),
127 - 'type' => array(
128 - ApiBase::PARAM_TYPE => 'string',
129 - ),
130 - 'email' => array(
131 - ApiBase::PARAM_TYPE => 'string',
132 - ),
133 - );
134 - }
135 -
136 - public function getParamDescription() {
137 - return array(
138 - 'title' => 'Title of the user or user talk page to send WikiLove to',
139 - 'text' => 'Raw wikitext to add in the new section',
140 - 'message' => 'Actual message the user has entered, for logging purposes',
141 - 'token' => 'Edit token. You can get one of these through prop=info',
142 - 'subject' => 'Subject header of the new section',
143 - 'email' => 'Content of the optional e-mail message to send to the user',
144 - 'type' => array( 'Type of WikiLove (for statistics); this corresponds with a type',
145 - 'selected in the left menu, and optionally a subtype after that',
146 - '(e.g. "barnstar-normal" or "kitten")',
147 - ),
148 - );
149 - }
150 -
151 - public function getDescription() {
152 - return array(
153 - 'Give WikiLove to another user.',
154 - "WikiLove is a positive message posted to a user's talk page through a",
155 - 'convenient interface with preset or locally defined templates. This action',
156 - 'adds the specified wikitext to a certain talk page. For statistical purposes,',
157 - 'the type and other data are logged.',
158 - );
159 - }
160 -
161 - public function getPossibleErrors() {
162 - return array_merge( parent::getPossibleErrors(), array(
163 - array( 'invalidtitle', 'title' ),
164 - array(
165 - 'code' => 'nologging',
166 - 'info' => 'Warning: action was not logged!'
167 - ),
168 - ) );
169 - }
170 -
171 - public function getExamples() {
172 - return array(
173 - 'api.php?action=wikilove&title=User:Dummy&text=Love&subject=Hi&token=%2B\\',
174 - );
175 - }
176 -
177 - public function getVersion() {
178 - return __CLASS__ . ': $Id$';
179 - }
180 -}
Index: trunk/extensions/WikiLove/WikiLoveImageLog.api.php
@@ -1,64 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * This API is for logging each time a user attempts to use a custom image via the Make your own
6 - * feature. This is basically just to see if users can grok the concept. Once usage analysis is
7 - * complete, this API can be deleted.
8 - */
9 -class WikiLoveImageLogApi extends ApiBase {
10 - public function execute() {
11 - global $wgRequest, $wgWikiLoveLogging, $wgParser;
12 -
13 - $params = $this->extractRequestParams();
14 -
15 - if ( $wgWikiLoveLogging ) {
16 - $this->saveInDb( $params['image'], $params['success'] );
17 - }
18 - }
19 -
20 - /**
21 - * @param $user User ID
22 - * @param $image string
23 - * @param $success integer
24 - */
25 - private function saveInDb( $image, $success ) {
26 - global $wgUser;
27 - $dbw = wfGetDB( DB_MASTER );
28 -
29 - $values = array(
30 - 'wlil_timestamp' => $dbw->timestamp(),
31 - 'wlil_user_id' => $wgUser->getId(),
32 - 'wlil_image' => $image,
33 - 'wlil_success' => $success,
34 - );
35 -
36 - try{
37 - $dbw->insert( 'wikilove_image_log', $values, __METHOD__ );
38 - } catch( DBQueryError $dbqe ) {
39 - $this->setWarning( 'Action was not logged' );
40 - }
41 - }
42 -
43 - public function getDescription() {
44 - return array(
45 - 'This API is for logging each time a user attempts to use a custom image via WikiLove.',
46 - );
47 - }
48 -
49 - public function getAllowedParams() {
50 - return array(
51 - 'image' => array(
52 - ApiBase::PARAM_TYPE => 'string',
53 - ApiBase::PARAM_REQUIRED => true,
54 - ),
55 - 'success' => array(
56 - ApiBase::PARAM_TYPE => 'integer',
57 - ApiBase::PARAM_REQUIRED => true,
58 - )
59 - );
60 - }
61 -
62 - public function getVersion() {
63 - return __CLASS__ . ': $Id$';
64 - }
65 -}
Index: trunk/extensions/WikiLove/WikiLove.php
@@ -55,8 +55,8 @@
5656 $dir = dirname( __FILE__ ) . '/';
5757
5858 // add autoload classes
59 -$wgAutoloadClasses['WikiLoveApi'] = $dir . 'WikiLove.api.php';
60 -$wgAutoloadClasses['WikiLoveImageLogApi'] = $dir . 'WikiLoveImageLog.api.php';
 59+$wgAutoloadClasses['ApiWikiLove'] = $dir . 'ApiWikiLove.php';
 60+$wgAutoloadClasses['ApiWikiLoveImageLog'] = $dir . 'ApiWikiLoveImageLog.php';
6161 $wgAutoloadClasses['WikiLoveHooks'] = $dir . 'WikiLove.hooks.php';
6262 $wgAutoloadClasses['WikiLoveLocal'] = $dir . 'WikiLove.local.php';
6363
@@ -72,8 +72,8 @@
7373 $wgHooks['MakeGlobalVariablesScript'][] = 'WikiLoveHooks::makeGlobalVariablesScript';
7474
7575 // api modules
76 -$wgAPIModules['wikilove'] = 'WikiLoveApi';
77 -$wgAPIModules['wikiloveimagelog'] = 'WikiLoveImageLogApi';
 76+$wgAPIModules['wikilove'] = 'ApiWikiLove';
 77+$wgAPIModules['wikiloveimagelog'] = 'ApiWikiLoveImageLog';
7878
7979 $extWikiLoveTpl = array(
8080 'localBasePath' => dirname( __FILE__ ) . '/modules/ext.wikiLove',
Index: trunk/extensions/WikiLove/ApiWikiLove.php
@@ -0,0 +1,179 @@
 2+<?php
 3+class ApiWikiLove extends ApiBase {
 4+ public function execute() {
 5+ global $wgRequest, $wgWikiLoveLogging, $wgParser;
 6+
 7+ $params = $this->extractRequestParams();
 8+
 9+ $title = Title::newFromText( $params['title'] );
 10+ if ( is_null( $title ) ) {
 11+ $this->dieUsageMsg( array( 'invaliduser', $params['title'] ) );
 12+ }
 13+
 14+ $talk = WikiLoveHooks::getUserTalkPage( $title );
 15+ if ( is_null( $talk ) ) {
 16+ $this->dieUsageMsg( array( 'invaliduser', $params['title'] ) );
 17+ }
 18+
 19+ if ( $wgWikiLoveLogging ) {
 20+ $this->saveInDb( $talk, $params['subject'], $params['message'], $params['type'], isset( $params['email'] ) ? 1 : 0 );
 21+ }
 22+
 23+ // not using section => 'new' here, as we like to give our own edit summary
 24+ $api = new ApiMain( new FauxRequest( array(
 25+ 'action' => 'edit',
 26+ 'title' => $talk->getFullText(),
 27+ // need to do this, as Article::replaceSection fails for non-existing pages
 28+ 'appendtext' => ( $talk->exists() ? "\n\n" : '' ) . wfMsgForContent( 'newsectionheaderdefaultlevel', $params['subject'] )
 29+ . "\n\n" . $params['text'],
 30+ 'token' => $params['token'],
 31+ 'summary' => wfMsgForContent( 'wikilove-summary', $wgParser->stripSectionName( $params['subject'] ) ),
 32+ 'notminor' => true,
 33+ ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
 34+
 35+ $api->execute();
 36+
 37+ if ( isset( $params['email'] ) ) {
 38+ $this->emailUser( $talk, $params['subject'], $params['email'], $params['token'] );
 39+ }
 40+
 41+ $this->getResult()->addValue( 'redirect', 'pageName', $talk->getPrefixedDBkey() );
 42+ $this->getResult()->addValue( 'redirect', 'fragment', Title::escapeFragmentForURL( $params['subject'] ) );
 43+ // note that we cannot use Title::makeTitle here as it doesn't sanitize the fragment
 44+ }
 45+
 46+ /**
 47+ * @param $talk Title
 48+ * @param $subject
 49+ * @param $message
 50+ * @param $type
 51+ * @param $email
 52+ * @return void
 53+ */
 54+ private function saveInDb( $talk, $subject, $message, $type, $email ) {
 55+ global $wgUser;
 56+ $dbw = wfGetDB( DB_MASTER );
 57+ $receiver = User::newFromName( $talk->getSubjectPage()->getBaseText() );
 58+ if ( $receiver === false || $receiver->isAnon() ) {
 59+ $this->setWarning( 'Not logging anonymous recipients' );
 60+ return;
 61+ }
 62+
 63+ $values = array(
 64+ 'wll_timestamp' => $dbw->timestamp(),
 65+ 'wll_sender' => $wgUser->getId(),
 66+ 'wll_sender_editcount' => $wgUser->getEditCount(),
 67+ 'wll_sender_registration' => $wgUser->getRegistration(),
 68+ 'wll_receiver' => $receiver->getId(),
 69+ 'wll_receiver_editcount' => $receiver->getEditCount(),
 70+ 'wll_receiver_registration' => $receiver->getRegistration(),
 71+ 'wll_type' => $type,
 72+ 'wll_subject' => $subject,
 73+ 'wll_message' => $message,
 74+ 'wll_email' => $email,
 75+ );
 76+
 77+ try{
 78+ $dbw->insert( 'wikilove_log', $values, __METHOD__ );
 79+ } catch( DBQueryError $dbqe ) {
 80+ $this->setWarning( 'Action was not logged' );
 81+ }
 82+ }
 83+
 84+ /**
 85+ * @param $talk Title
 86+ * @param $subject string
 87+ * @param $text string
 88+ * @param $token string
 89+ */
 90+ private function emailUser( $talk, $subject, $text, $token ) {
 91+ global $wgRequest;
 92+ $api = new ApiMain( new FauxRequest( array(
 93+ 'action' => 'emailuser',
 94+ 'target' => User::newFromName( $talk->getSubjectPage()->getBaseText() )->getName(),
 95+ 'subject' => $subject,
 96+ 'text' => $text,
 97+ 'token' => $token,
 98+ ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
 99+ try{
 100+ $api->execute();
 101+ } catch( DBQueryError $dbqe ) {
 102+ $this->setWarning( 'E-mail was not sent' );
 103+ }
 104+ }
 105+
 106+ public function getAllowedParams() {
 107+ return array(
 108+ 'title' => array(
 109+ ApiBase::PARAM_TYPE => 'string',
 110+ ApiBase::PARAM_REQUIRED => true,
 111+ ),
 112+ 'text' => array(
 113+ ApiBase::PARAM_TYPE => 'string',
 114+ ApiBase::PARAM_REQUIRED => true,
 115+ ),
 116+ 'message' => array(
 117+ ApiBase::PARAM_TYPE => 'string',
 118+ ),
 119+ 'token' => array(
 120+ ApiBase::PARAM_TYPE => 'string',
 121+ ApiBase::PARAM_REQUIRED => true,
 122+ ),
 123+ 'subject' => array(
 124+ ApiBase::PARAM_TYPE => 'string',
 125+ ApiBase::PARAM_REQUIRED => true,
 126+ ),
 127+ 'type' => array(
 128+ ApiBase::PARAM_TYPE => 'string',
 129+ ),
 130+ 'email' => array(
 131+ ApiBase::PARAM_TYPE => 'string',
 132+ ),
 133+ );
 134+ }
 135+
 136+ public function getParamDescription() {
 137+ return array(
 138+ 'title' => 'Title of the user or user talk page to send WikiLove to',
 139+ 'text' => 'Raw wikitext to add in the new section',
 140+ 'message' => 'Actual message the user has entered, for logging purposes',
 141+ 'token' => 'Edit token. You can get one of these through prop=info',
 142+ 'subject' => 'Subject header of the new section',
 143+ 'email' => 'Content of the optional e-mail message to send to the user',
 144+ 'type' => array( 'Type of WikiLove (for statistics); this corresponds with a type',
 145+ 'selected in the left menu, and optionally a subtype after that',
 146+ '(e.g. "barnstar-normal" or "kitten")',
 147+ ),
 148+ );
 149+ }
 150+
 151+ public function getDescription() {
 152+ return array(
 153+ 'Give WikiLove to another user.',
 154+ "WikiLove is a positive message posted to a user's talk page through a",
 155+ 'convenient interface with preset or locally defined templates. This action',
 156+ 'adds the specified wikitext to a certain talk page. For statistical purposes,',
 157+ 'the type and other data are logged.',
 158+ );
 159+ }
 160+
 161+ public function getPossibleErrors() {
 162+ return array_merge( parent::getPossibleErrors(), array(
 163+ array( 'invalidtitle', 'title' ),
 164+ array(
 165+ 'code' => 'nologging',
 166+ 'info' => 'Warning: action was not logged!'
 167+ ),
 168+ ) );
 169+ }
 170+
 171+ public function getExamples() {
 172+ return array(
 173+ 'api.php?action=wikilove&title=User:Dummy&text=Love&subject=Hi&token=%2B\\',
 174+ );
 175+ }
 176+
 177+ public function getVersion() {
 178+ return __CLASS__ . ': $Id$';
 179+ }
 180+}
Property changes on: trunk/extensions/WikiLove/ApiWikiLove.php
___________________________________________________________________
Added: svn:eol-style
1181 + native
Added: svn:keywords
2182 + Id
Index: trunk/extensions/WikiLove/ApiWikiLoveImageLog.php
@@ -0,0 +1,64 @@
 2+<?php
 3+
 4+/**
 5+ * This API is for logging each time a user attempts to use a custom image via the Make your own
 6+ * feature. This is basically just to see if users can grok the concept. Once usage analysis is
 7+ * complete, this API can be deleted.
 8+ */
 9+class ApiWikiLoveImageLog extends ApiBase {
 10+ public function execute() {
 11+ global $wgRequest, $wgWikiLoveLogging, $wgParser;
 12+
 13+ $params = $this->extractRequestParams();
 14+
 15+ if ( $wgWikiLoveLogging ) {
 16+ $this->saveInDb( $params['image'], $params['success'] );
 17+ }
 18+ }
 19+
 20+ /**
 21+ * @param $user User ID
 22+ * @param $image string
 23+ * @param $success integer
 24+ */
 25+ private function saveInDb( $image, $success ) {
 26+ global $wgUser;
 27+ $dbw = wfGetDB( DB_MASTER );
 28+
 29+ $values = array(
 30+ 'wlil_timestamp' => $dbw->timestamp(),
 31+ 'wlil_user_id' => $wgUser->getId(),
 32+ 'wlil_image' => $image,
 33+ 'wlil_success' => $success,
 34+ );
 35+
 36+ try{
 37+ $dbw->insert( 'wikilove_image_log', $values, __METHOD__ );
 38+ } catch( DBQueryError $dbqe ) {
 39+ $this->setWarning( 'Action was not logged' );
 40+ }
 41+ }
 42+
 43+ public function getDescription() {
 44+ return array(
 45+ 'This API is for logging each time a user attempts to use a custom image via WikiLove.',
 46+ );
 47+ }
 48+
 49+ public function getAllowedParams() {
 50+ return array(
 51+ 'image' => array(
 52+ ApiBase::PARAM_TYPE => 'string',
 53+ ApiBase::PARAM_REQUIRED => true,
 54+ ),
 55+ 'success' => array(
 56+ ApiBase::PARAM_TYPE => 'integer',
 57+ ApiBase::PARAM_REQUIRED => true,
 58+ )
 59+ );
 60+ }
 61+
 62+ public function getVersion() {
 63+ return __CLASS__ . ': $Id$';
 64+ }
 65+}
Property changes on: trunk/extensions/WikiLove/ApiWikiLoveImageLog.php
___________________________________________________________________
Added: svn:eol-style
166 + native
Added: svn:keywords
267 + Id

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87294Added first very experimental -- but working! -- version of the WikiLove exte...janpaul12320:34, 2 May 2011
r91032adding functionality for custom image use loggingkaldari00:20, 29 June 2011

Status & tagging log