r92187 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92186‎ | r92187 | r92188 >
Date:20:19, 14 July 2011
Author:demon
Status:resolved (Comments)
Tags:
Comment:
Various cleanups to ExternalEdit. Documentation, code style, removed some unused variables, removed silly 'm' prefix, etc.
Modified paths:
  • /trunk/phase3/includes/ExternalEdit.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ExternalEdit.php
@@ -19,38 +19,54 @@
2020 *
2121 */
2222 class ExternalEdit {
 23+ /**
 24+ * Title to perform the edit on
 25+ * @var Title
 26+ */
 27+ private $title;
2328
24 - function __construct( $article, $mode ) {
25 - $this->mArticle =& $article;
26 - $this->mTitle = $article->getTitle();
27 - $this->mCharset = 'UTF-8';
28 - $this->mMode = $mode;
 29+ /**
 30+ * Mode of editing
 31+ * @var String
 32+ */
 33+ private $mode;
 34+
 35+ /**
 36+ * Constructor
 37+ * @param $title Title object we're performing the edit on
 38+ * @param $mode String What mode we're using. Only 'file' has any effect
 39+ */
 40+ public function __construct( $title, $mode ) {
 41+ $this->title = $article->getTitle();
 42+ $this->mode = $mode;
2943 }
3044
31 - function edit() {
 45+ /**
 46+ * Output the information for the external editor
 47+ */
 48+ public function edit() {
3249 global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang;
3350 $wgOut->disable();
34 - $name=$this->mTitle->getText();
35 - $pos=strrpos($name,".")+1;
36 - header ( "Content-type: application/x-external-editor; charset=".$this->mCharset );
37 - header( "Cache-control: no-cache" );
 51+ header( 'Content-type: application/x-external-editor; charset=utf-8' );
 52+ header( 'Cache-control: no-cache' );
3853
3954 # $type can be "Edit text", "Edit file" or "Diff text" at the moment
4055 # See the protocol specifications at [[m:Help:External editors/Tech]] for
4156 # details.
42 - if(!isset($this->mMode)) {
43 - $type="Edit text";
44 - $url=$this->mTitle->getFullURL("action=edit&internaledit=true");
 57+ if( $this->mode == "file" ) {
 58+ $type = "Edit file";
 59+ $image = wfLocalFile( $this->title );
 60+ $url = $image->getFullURL();
 61+ $extension = $image->getExtension();
 62+ } else {
 63+ $type = "Edit text";
 64+ $url = $this->title->getFullURL(
 65+ array( 'action' => 'edit', 'internaledit' => 'true' ) );
4566 # *.wiki file extension is used by some editors for syntax
4667 # highlighting, so we follow that convention
47 - $extension="wiki";
48 - } elseif($this->mMode=="file") {
49 - $type="Edit file";
50 - $image = wfLocalFile( $this->mTitle );
51 - $url = $image->getFullURL();
52 - $extension=substr($name, $pos);
 68+ $extension = "wiki";
5369 }
54 - $special=$wgLang->getNsText(NS_SPECIAL);
 70+ $special = $wgLang->getNsText( NS_SPECIAL );
5571 $control = <<<CONTROL
5672 ; You're seeing this file because you're using Mediawiki's External Editor
5773 ; feature. This is probably because you selected use external editor
Index: trunk/phase3/includes/Wiki.php
@@ -498,7 +498,7 @@
499499 && ( $external || $user->getOption( 'externaleditor' ) ) )
500500 {
501501 $mode = $request->getVal( 'mode' );
502 - $extedit = new ExternalEdit( $article, $mode );
 502+ $extedit = new ExternalEdit( $article->getTitle(), $mode );
503503 $extedit->edit();
504504 }
505505 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r92227Fix for r92187demon05:32, 15 July 2011

Comments

#Comment by Nikerabbit (talk | contribs)   05:25, 15 July 2011
+	public function __construct( $title, $mode ) {
+		$this->title = $article->getTitle();
#Comment by 😂 (talk | contribs)   13:02, 15 July 2011

Fixed in followup, setting back to new.

Status & tagging log