r6887 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r6886‎ | r6887 | r6888 >
Date:13:46, 29 December 2004
Author:magnus_manske
Status:old
Tags:
Comment:
separate metadata editor, pre-alpha
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -16,6 +16,7 @@
1717 class EditPage {
1818 var $mArticle;
1919 var $mTitle;
 20+ var $mMetaData = '';
2021
2122 # Form values
2223 var $save = false, $preview = false;
@@ -35,6 +36,80 @@
3637 }
3738
3839 /**
 40+ * This is the function that extracts metadata from the article body on the first view.
 41+ * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
 42+ */
 43+ function extractMetaDataFromArticle ()
 44+ {
 45+ global $wgUseMetadataEdit , $wgLang ;
 46+ $this->mMetaData = "" ;
 47+ if ( !$wgUseMetadataEdit ) return ;
 48+ $s = "" ;
 49+ $t = $this->mArticle->getContent ( true ) ;
 50+
 51+ # MISSING : <nowiki> filtering
 52+
 53+ # Categories and language links
 54+ $t = explode ( "\n" , $t ) ;
 55+ $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY ) ) ;
 56+ $cat = $ll = array() ;
 57+ foreach ( $t AS $key => $x )
 58+ {
 59+ $y = trim ( strtolower ( $x ) ) ;
 60+ while ( substr ( $y , 0 , 2 ) == "[[" )
 61+ {
 62+ $y = explode ( "]]" , trim ( $x ) ) ;
 63+ $first = array_shift ( $y ) ;
 64+ $first = explode ( ":" , $first ) ;
 65+ $ns = array_shift ( $first ) ;
 66+ $ns = trim ( str_replace ( "[" , "" , $ns ) ) ;
 67+ if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
 68+ {
 69+ $add = "[[" . $ns . ":" . implode ( ":" , $first ) . "]]" ;
 70+ if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
 71+ else $ll[] = $add ;
 72+ $x = implode ( "]]" , $y ) ;
 73+ $t[$key] = $x ;
 74+ $y = trim ( strtolower ( $x ) ) ;
 75+ }
 76+ }
 77+ }
 78+ if ( count ( $cat ) ) $s .= implode ( " " , $cat ) . "\n" ;
 79+ if ( count ( $ll ) ) $s .= implode ( " " , $ll ) . "\n" ;
 80+ $t = implode ( "\n" , $t ) ;
 81+
 82+ # Templates, but only some
 83+ $sat = array ( "meta-template" ) ; # stand-alone-templates; must be lowercase
 84+ $t = explode ( "{{" , $t ) ;
 85+ $tl = array () ;
 86+ foreach ( $t AS $key => $x )
 87+ {
 88+ $y = explode ( "}}" , $x , 2 ) ;
 89+ if ( count ( $y ) == 2 )
 90+ {
 91+ $z = $y[0] ;
 92+ $z = explode ( "|" , $z ) ;
 93+ $tn = array_shift ( $z ) ;
 94+ if ( in_array ( strtolower ( $tn ) , $sat ) )
 95+ {
 96+ $tl[] = "{{" . $y[0] . "}}" ;
 97+ $t[$key] = $y[1] ;
 98+ $y = explode ( "}}" , $y[1] , 2 ) ;
 99+ }
 100+ else $t[$key] = "{{" . $x ;
 101+ }
 102+ else if ( $key != 0 ) $t[$key] = "{{" . $x ;
 103+ else $t[$key] = $x ;
 104+ }
 105+ if ( count ( $tl ) ) $s .= implode ( " " , $tl ) ;
 106+ $t = implode ( "" , $t ) ;
 107+
 108+ $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
 109+ $this->mArticle->mContent = $t ;
 110+ $this->mMetaData = $s ;
 111+ }
 112+
 113+ /**
39114 * This is the function that gets called for "action=edit".
40115 */
41116 function edit() {
@@ -77,6 +152,7 @@
78153 if( $wgUser->getOption('previewonfirst') ) {
79154 $this->editForm( 'preview', true );
80155 } else {
 156+ $this->extractMetaDataFromArticle () ;
81157 $this->editForm( 'initial', true );
82158 }
83159 }
@@ -91,6 +167,7 @@
92168 # whitespace from the text boxes. This may be significant formatting.
93169 $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) );
94170 $this->textbox2 = rtrim( $request->getText( 'wpTextbox2' ) );
 171+ $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
95172 $this->summary = trim( $request->getText( 'wpSummary' ) );
96173
97174 $this->edittime = $request->getVal( 'wpEdittime' );
@@ -159,6 +236,10 @@
160237 # in the back door with a hand-edited submission URL.
161238
162239 if ( 'save' == $formtype ) {
 240+ # Reintegrate metadata
 241+ if ( $this->mMetaData != "" ) $this->textbox1 .= "\n" . $this->mMetaData ;
 242+ $this->mMetaData = "" ;
 243+
163244 # Check for spam
164245 if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) {
165246 $this->spamPage ( $matches[0] );
@@ -478,17 +559,29 @@
479560 $liveOnclick = '';
480561 }
481562
 563+ global $wgUseMetadataEdit ;
 564+ if ( $wgUseMetadataEdit )
 565+ {
 566+ $metadata = $this->mMetaData ;
 567+ $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
 568+ $metadata = "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
 569+ }
 570+ else $metadata = "" ;
 571+
 572+
482573 $wgOut->addHTML( <<<END
483574 {$toolbar}
484575 <form id="editform" name="editform" method="post" action="$action"
485576 enctype="multipart/form-data">
486577 {$commentsubject}
 578+{$mbegin}
487579 <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}'
488580 cols='{$cols}'{$ew}>
489581 END
490582 . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) .
491583 "
492584 </textarea>
 585+{$metadata}
493586 <br />{$editsummary}
494587 {$checkboxhtml}
495588 <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"".
@@ -549,7 +642,10 @@
550643 $this->textbox1 = $this->mArticle->getContent(true);
551644 }
552645
553 - $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $this->textbox1 ) ."\n\n",
 646+ $toparse = $this->textbox1 ;
 647+ if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData ;
 648+
 649+ $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ) ."\n\n",
554650 $wgTitle, $parserOptions );
555651
556652 $previewHTML = $parserOutput->mText;

Follow-up revisions

RevisionCommit summaryAuthorDate
r40925* Added $wgUseMetadataEdit and $wgMetadataWhitelist to DefaultSettings.php, t...ialex19:09, 16 September 2008

Status & tagging log