r75423 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75422‎ | r75423 | r75424 >
Date:14:18, 26 October 2010
Author:ashley
Status:deferred
Tags:
Comment:
Drafts: cleanup
Modified paths:
  • /trunk/extensions/Drafts/Drafts.classes.php (modified) (history)
  • /trunk/extensions/Drafts/Drafts.hooks.php (modified) (history)
  • /trunk/extensions/Drafts/Drafts.js (modified) (history)
  • /trunk/extensions/Drafts/Drafts.pages.php (modified) (history)
  • /trunk/extensions/Drafts/Drafts.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Drafts/Drafts.classes.php
@@ -17,14 +17,12 @@
1818
1919 /**
2020 * Counts the number of existing drafts for a specific user
 21+ *
 22+ * @param $title Object: [optional] Title of article, defaults to all articles
 23+ * @param $userID Integer: [optional] ID of user, defaults to current user
2124 * @return Number of drafts which match condition parameters
22 - * @param object $title[optional] Title of article, defaults to all articles
23 - * @param integer $userID[optional] ID of user, defaults to current user
2425 */
25 - public static function num(
26 - $title = null,
27 - $userID = null
28 - ) {
 26+ public static function num( $title = null, $userID = null ) {
2927 global $wgUser;
3028 // Get database connection
3129 $dbr = wfGetDB( DB_SLAVE );
@@ -63,11 +61,11 @@
6462
6563 /**
6664 * Removes drafts which have not been modified for a period of time defined
67 - * by $wgDraftsLifeSpan
 65+ * by $egDraftsCleanRatio
6866 */
6967 public static function clean() {
7068 global $egDraftsCleanRatio;
71 -
 69+
7270 // Only perform this action a fraction of the time
7371 if ( rand( 0, $egDraftsCleanRatio ) == 0 ) {
7472 // Get database connection
@@ -89,10 +87,7 @@
9088 * Re-titles drafts which point to a particlar article, as a response to the
9189 * article being moved.
9290 */
93 - public static function move(
94 - $oldTitle,
95 - $newTitle
96 - ) {
 91+ public static function move( $oldTitle, $newTitle ) {
9792 // Get database connection
9893 $dbw = wfGetDB( DB_MASTER );
9994 // Updates title and namespace of drafts upon moving
@@ -110,14 +105,12 @@
111106
112107 /**
113108 * Gets a list of existing drafts for a specific user
114 - * @return
115 - * @param object $title[optional] Title of article, defaults to all articles
116 - * @param integer $userID[optional] ID of user, defaults to current user
 109+ *
 110+ * @param $title Object: [optional] Title of article, defaults to all articles
 111+ * @param $userID Integer: [optional] ID of user, defaults to current user
 112+ * @return List of drafts or null
117113 */
118 - public static function get(
119 - $title = null,
120 - $userID = null
121 - ) {
 114+ public static function get( $title = null, $userID = null ) {
122115 global $wgUser;
123116 // Removes expired drafts for a more accurate list
124117 Drafts::clean();
@@ -167,14 +160,12 @@
168161
169162 /**
170163 * Outputs a table of existing drafts
 164+ *
 165+ * @param $title Object: [optional] Title of article, defaults to all articles
 166+ * @param $userID Integer: [optional] ID of user, defaults to current user
171167 * @return Number of drafts in the table
172 - * @param object $title[optional] Title of article, defaults to all articles
173 - * @param integer $userID[optional] ID of user, defaults to current user
174168 */
175 - public static function display(
176 - $title = null,
177 - $userID = null
178 - ) {
 169+ public static function display( $title = null, $userID = null ) {
179170 global $wgOut, $wgRequest, $wgUser, $wgLang;
180171 // Gets draftID
181172 $currentDraft = Draft::newFromID( $wgRequest->getIntOrNull( 'draft' ) );
@@ -226,11 +217,11 @@
227218 // Get article title text
228219 $htmlTitle = $draft->getTitle()->getEscapedText();
229220 // Build Article Load link
230 - $urlLoad = $draft->getTitle()->getFullUrl(
 221+ $urlLoad = $draft->getTitle()->getFullURL(
231222 'action=edit&draft=' . urlencode( $draft->getID() )
232223 );
233224 // Build discard link
234 - $urlDiscard = SpecialPage::getTitleFor( 'Drafts' )->getFullUrl(
 225+ $urlDiscard = SpecialPage::getTitleFor( 'Drafts' )->getFullURL(
235226 sprintf( 'discard=%s&token=%s',
236227 urlencode( $draft->getID() ),
237228 urlencode( $wgUser->editToken() )
@@ -314,7 +305,6 @@
315306 class Draft {
316307
317308 /* Members */
318 -
319309 private $exists = false;
320310 private $id;
321311 private $token;
@@ -324,7 +314,7 @@
325315 private $starttime;
326316 private $edittime;
327317 private $savetime;
328 - private $scrolltop ;
 318+ private $scrolltop;
329319 private $text;
330320 private $summary;
331321 private $minoredit;
@@ -333,25 +323,22 @@
334324
335325 /**
336326 * Creates a new Draft object from a draft ID
 327+ *
 328+ * @param $id Integer: ID of draft
 329+ * @param $autoload Boolean: [optional] Whether to load draft information
337330 * @return New Draft object
338 - * @param integer $id ID of draft
339 - * @param boolean $autoload[optional] Whether to load draft information
340331 */
341 - public static function newFromID(
342 - $id,
343 - $autoload = true
344 - ) {
 332+ public static function newFromID( $id, $autoload = true ) {
345333 return new Draft( $id, $autoload );
346334 }
347335
348336 /**
349337 * Creates a new Draft object from a database row
 338+ *
 339+ * @param $row Array: Database row to create Draft object with
350340 * @return New Draft object
351 - * @param array $row Database row to create Draft object with
352341 */
353 - public static function newFromRow(
354 - $row
355 - ) {
 342+ public static function newFromRow( $row ) {
356343 $draft = new Draft( $row['draft_id'], false );
357344 $draft->setToken( $row['draft_token'] );
358345 $draft->setTitle(
@@ -393,28 +380,24 @@
394381
395382 /**
396383 * Sets the edit token, like one generated by wfGenerateToken()
397 - * @param string $token
 384+ * @param $token String
398385 */
399 - public function setToken(
400 - $token
401 - ) {
 386+ public function setToken( $token ) {
402387 $this->token = $token;
403388 }
404 -
 389+
405390 /**
406391 * @return User ID of draft creator
407392 */
408393 public function getUserID() {
409394 return $this->userID;
410395 }
411 -
 396+
412397 /**
413398 * Sets user ID of draft creator
414 - * @param integer $userID
 399+ * @param $userID Integer: user ID
415400 */
416 - public function setUserID(
417 - $userID
418 - ) {
 401+ public function setUserID( $userID ) {
419402 $this->userID = $userID;
420403 }
421404
@@ -424,14 +407,12 @@
425408 public function getTitle() {
426409 return $this->title;
427410 }
428 -
 411+
429412 /**
430413 * Sets title of article of draft
431 - * @param object $title
 414+ * @param $title Object
432415 */
433 - public function setTitle(
434 - $title
435 - ) {
 416+ public function setTitle( $title ) {
436417 $this->title = $title;
437418 }
438419
@@ -441,14 +422,12 @@
442423 public function getSection() {
443424 return $this->section;
444425 }
445 -
 426+
446427 /**
447428 * Sets section of the article of draft
448 - * @param integer $section
 429+ * @param $section Integer
449430 */
450 - public function setSection(
451 - $section
452 - ) {
 431+ public function setSection( $section ) {
453432 $this->section = $section;
454433 }
455434
@@ -458,14 +437,12 @@
459438 public function getStartTime() {
460439 return $this->starttime;
461440 }
462 -
 441+
463442 /**
464443 * Sets time when draft of the article started
465 - * @param string $starttime
 444+ * @param $starttime String
466445 */
467 - public function setStartTime(
468 - $starttime
469 - ) {
 446+ public function setStartTime( $starttime ) {
470447 $this->starttime = $starttime;
471448 }
472449
@@ -475,14 +452,12 @@
476453 public function getEditTime() {
477454 return $this->edittime;
478455 }
479 -
 456+
480457 /**
481458 * Sets time of most recent revision of article when this draft started
482 - * @param string $edittime
 459+ * @param $edittime String
483460 */
484 - public function setEditTime(
485 - $edittime
486 - ) {
 461+ public function setEditTime( $edittime ) {
487462 $this->edittime = $edittime;
488463 }
489464
@@ -492,14 +467,12 @@
493468 public function getSaveTime() {
494469 return $this->savetime;
495470 }
496 -
 471+
497472 /**
498473 * Sets time when draft was last modified
499 - * @param string $savetime
 474+ * @param $savetime String
500475 */
501 - public function setSaveTime(
502 - $savetime
503 - ) {
 476+ public function setSaveTime( $savetime ) {
504477 $this->savetime = $savetime;
505478 }
506479
@@ -509,14 +482,12 @@
510483 public function getScrollTop() {
511484 return $this->scrolltop;
512485 }
513 -
 486+
514487 /**
515488 * Sets scroll position of editor when draft was last modified
516 - * @param integer $scrolltop
 489+ * @param $scrolltop Integer
517490 */
518 - public function setScrollTop(
519 - $scrolltop
520 - ) {
 491+ public function setScrollTop( $scrolltop ) {
521492 $this->scrolltop = $scrolltop;
522493 }
523494
@@ -526,14 +497,12 @@
527498 public function getText() {
528499 return $this->text;
529500 }
530 -
 501+
531502 /**
532503 * Sets text of draft version of article
533 - * @param string $text
 504+ * @param $text String
534505 */
535 - public function setText(
536 - $text
537 - ) {
 506+ public function setText( $text ) {
538507 $this->text = $text;
539508 }
540509
@@ -543,14 +512,12 @@
544513 public function getSummary() {
545514 return $this->summary;
546515 }
547 -
 516+
548517 /**
549518 * Sets summary of changes
550 - * @param string $summary
 519+ * @param $summary String
551520 */
552 - public function setSummary(
553 - $summary
554 - ) {
 521+ public function setSummary( $summary ) {
555522 $this->summary = $summary;
556523 }
557524
@@ -560,7 +527,7 @@
561528 public function getMinorEdit() {
562529 return $this->minoredit;
563530 }
564 -
 531+
565532 /**
566533 * Sets whether edit is considdered to be a minor change
567534 * @param boolean $minoredit
@@ -575,22 +542,19 @@
576543
577544 /**
578545 * Generic constructor
579 - * @param integer $id[optional] ID to use
580 - * @param boolean $autoload[optional] Whether to load from database
 546+ * @param $id Integer: [optional] ID to use
 547+ * @param $autoload Boolean: [optional] Whether to load from database
581548 */
582 - public function __construct(
583 - $id = null,
584 - $autoload = true
585 - ) {
 549+ public function __construct( $id = null, $autoload = true ) {
586550 // If an ID is a number the existence is actually checked on load
587 - // If an ID is false the existance is always false durring load
 551+ // If an ID is false the existance is always false during load
588552 $this->id = $id;
589553 // Load automatically
590554 if ( $autoload ) {
591555 $this->load();
592556 }
593557 }
594 -
 558+
595559 /**
596560 * Selects draft row from database and populates object properties
597561 */
@@ -640,7 +604,7 @@
641605 // Updates state
642606 $this->exists = true;
643607 }
644 -
 608+
645609 /**
646610 * Inserts or updates draft row in database
647611 */
@@ -704,14 +668,12 @@
705669 // Returns success
706670 return true;
707671 }
708 -
 672+
709673 /**
710674 * Deletes draft row from database
711 - * @param integer $user[optional] User ID, defaults to current user ID
 675+ * @param $user Integer: [optional] User ID, defaults to current user ID
712676 */
713 - public function discard(
714 - $user = null
715 - ) {
 677+ public function discard( $user = null ) {
716678 global $wgUser;
717679 // Uses $wgUser as a fallback
718680 $user = $user === null ? $wgUser : $user;
Index: trunk/extensions/Drafts/Drafts.pages.php
@@ -22,7 +22,8 @@
2323
2424 /**
2525 * Executes special page rendering and data processing
26 - * @param string $sub MediaWiki supplied sub-page path
 26+ *
 27+ * @param $sub Mixed: MediaWiki supplied sub-page path
2728 */
2829 public function execute( $sub ) {
2930 global $wgRequest, $wgOut, $wgUser;
Index: trunk/extensions/Drafts/Drafts.php
@@ -19,7 +19,7 @@
2020 // Check environment
2121 if ( !defined( 'MEDIAWIKI' ) ) {
2222 echo( "This is an extension to MediaWiki and cannot be run standalone.\n" );
23 - die( - 1 );
 23+ die( -1 );
2424 }
2525
2626 /* Configuration */
@@ -28,6 +28,7 @@
2929 $wgExtensionCredits['other'][] = array(
3030 'path' => __FILE__,
3131 'name' => 'Drafts',
 32+ 'version' => '0.1.0',
3233 'author' => 'Trevor Parscal',
3334 'url' => 'http://www.mediawiki.org/wiki/Extension:Drafts',
3435 'descriptionmsg' => 'drafts-desc',
Index: trunk/extensions/Drafts/Drafts.hooks.php
@@ -9,9 +9,9 @@
1010 class DraftHooks {
1111
1212 /* Static Functions */
13 -public static function schema() {
 13+ public static function schema() {
1414 global $wgExtNewTables, $wgExtModifiedFields;
15 -
 15+
1616 $wgExtNewTables[] = array(
1717 'drafts',
1818 dirname( __FILE__ ) . '/Drafts.sql'
@@ -21,18 +21,14 @@
2222 'draft_token',
2323 dirname( __FILE__ ) . '/patch-draft_token.sql'
2424 );
25 -
 25+
2626 return true;
2727 }
2828
2929 /**
3030 * SpecialMovepageAfterMove hook
3131 */
32 - public static function move(
33 - $this,
34 - $ot,
35 - $nt
36 - ) {
 32+ public static function move( $this, $ot, $nt ) {
3733 // Update all drafts of old article to new article for all users
3834 Drafts::move( $ot, $nt );
3935 // Continue
@@ -42,16 +38,8 @@
4339 /**
4440 * ArticleSaveComplete hook
4541 */
46 - public static function discard(
47 - $article,
48 - $user,
49 - $text,
50 - $summary,
51 - $m,
52 - $watchthis,
53 - $section,
54 - $flags,
55 - $rev
 42+ public static function discard( $article, $user, $text, $summary, $m,
 43+ $watchthis, $section, $flags, $rev
5644 ) {
5745 global $wgRequest;
5846 // Check if the save occured from a draft
@@ -68,9 +56,7 @@
6957 * EditPage::showEditForm:initial hook
7058 * Load draft...
7159 */
72 - public static function loadForm(
73 - $editpage
74 - ) {
 60+ public static function loadForm( $editpage ) {
7561 global $wgUser, $wgRequest, $wgOut, $wgTitle, $wgLang;
7662 // Check permissions
7763 if ( $wgUser->isAllowed( 'edit' ) && $wgUser->isLoggedIn() ) {
@@ -155,12 +141,7 @@
156142 * Intercept the saving of an article to detect if the submission was from
157143 * the non-javascript save draft button
158144 */
159 - public static function interceptSave(
160 - $editor,
161 - $text,
162 - $section,
163 - $error
164 - ) {
 145+ public static function interceptSave( $editor, $text, $section, $error ) {
165146 global $wgRequest;
166147 // Don't save if the save draft button caused the submit
167148 if ( $wgRequest->getText( 'wpDraftSave' ) !== '' ) {
@@ -175,10 +156,7 @@
176157 * EditPageBeforeEditButtons hook
177158 * Add draft saving controls
178159 */
179 - public static function controls(
180 - $editpage,
181 - $buttons
182 - ) {
 160+ public static function controls( $editpage, $buttons ) {
183161 global $wgUser, $wgTitle, $wgRequest;
184162 global $egDraftsAutoSaveWait, $egDraftsAutoSaveTimeout;
185163 // Check permissions
@@ -294,14 +272,12 @@
295273
296274 /**
297275 * AjaxAddScript hook
298 - * Add ajax support script
 276+ * Add AJAX support script
299277 */
300 - public static function addJS(
301 - $out
302 - ) {
 278+ public static function addJS( $out ) {
303279 global $wgScriptPath, $wgJsMimeType, $wgDraftsStyleVersion;
304280 // FIXME: assumes standard dir structure
305 - // Add javascript to support ajax draft saving
 281+ // Add JavaScript to support AJAX draft saving
306282 $out->addScript(
307283 Xml::element(
308284 'script',
@@ -320,14 +296,12 @@
321297
322298 /**
323299 * BeforePageDisplay hook
324 - * Add css style sheet
 300+ * Add CSS style sheet
325301 */
326 - public static function addCSS(
327 - $out
328 - ) {
 302+ public static function addCSS( $out ) {
329303 global $wgScriptPath, $wgDraftsStyleVersion;
330304 // FIXME: assumes standard dir structure
331 - // Add css for various styles
 305+ // Add CSS for various styles
332306 $out->addLink(
333307 array(
334308 'rel' => 'stylesheet',
@@ -342,20 +316,10 @@
343317
344318 /**
345319 * AJAX function export DraftHooks::AjaxSave
346 - * Respond to ajax queries
 320+ * Respond to AJAX queries
347321 */
348 - public static function save(
349 - $dtoken,
350 - $etoken,
351 - $id,
352 - $title,
353 - $section,
354 - $starttime,
355 - $edittime,
356 - $scrolltop,
357 - $text,
358 - $summary,
359 - $minoredit
 322+ public static function save( $dtoken, $etoken, $id, $title, $section,
 323+ $starttime, $edittime, $scrolltop, $text, $summary, $minoredit
360324 ) {
361325 global $wgUser, $wgRequest;
362326 // Verify token
Index: trunk/extensions/Drafts/Drafts.js
@@ -1,9 +1,9 @@
22 /* JavaScript for Drafts extension */
33
44 function Draft() {
5 -
 5+
66 /* Private Members */
7 -
 7+
88 // Reference to object's self
99 var self = this;
1010 // Configuration settings
@@ -16,16 +16,14 @@
1717 var timer = null;
1818 // Reference to edit form draft is being edited with
1919 var form = null;
20 -
 20+
2121 /* Functions */
22 -
 22+
2323 /**
2424 * Sets the state of the draft
2525 * @param {String} newState
2626 */
27 - this.setState = function(
28 - newState
29 - ) {
 27+ this.setState = function( newState ) {
3028 // Stores state information
3129 state = newState;
3230 // Updates UI elements
@@ -53,14 +51,14 @@
5452 default: break;
5553 }
5654 }
57 -
 55+
5856 /**
5957 * Gets the state of the draft
6058 */
6159 this.getState = function() {
6260 return state;
6361 }
64 -
 62+
6563 /**
6664 * Sends draft data to server to be saved
6765 */
@@ -75,10 +73,10 @@
7674 // Saves current request type
7775 var oldRequestType = sajax_request_type;
7876 // Changes request type to post
79 - sajax_request_type = "POST";
 77+ sajax_request_type = 'POST';
8078 // Performs asynchronous save on server
8179 sajax_do_call(
82 - "DraftHooks::save",
 80+ 'DraftHooks::save',
8381 [
8482 form.wpDraftToken.value,
8583 form.wpEditToken.value,
@@ -92,7 +90,7 @@
9391 form.wpSummary.value,
9492 form.wpMinoredit.checked ? 1 : 0
9593 ],
96 - new Function( "request", "wgDraft.respond( request )" )
 94+ new Function( 'request', 'wgDraft.respond( request )' )
9795 );
9896 // Restores current request type
9997 sajax_request_type = oldRequestType;
@@ -119,11 +117,11 @@
120118 if ( configuration.autoSaveWait && configuration.autoSaveWait > 0 ) {
121119 // Sets timer to save automatically after a period of time
122120 timer = setTimeout(
123 - "wgDraft.save()", configuration.autoSaveWait * 1000
 121+ 'wgDraft.save()', configuration.autoSaveWait * 1000
124122 );
125123 }
126124 }
127 -
 125+
128126 /**
129127 * Initializes the user interface
130128 */
@@ -165,9 +163,7 @@
166164 * Responds to the server after a save request has been handled
167165 * @param {Object} request
168166 */
169 - this.respond = function(
170 - request
171 - ) {
 167+ this.respond = function( request ) {
172168 // Checks that an error did not occur
173169 if ( request.responseText > -1 ) {
174170 // Changes state to saved
@@ -184,4 +180,4 @@
185181 // Instantiates a draft object
186182 var wgDraft = new Draft();
187183 // Registers hooks
188 -hookEvent( "load", wgDraft.initialize );
 184+hookEvent( 'load', wgDraft.initialize );

Status & tagging log