Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | class EditPage { |
18 | 18 | var $mArticle; |
19 | 19 | var $mTitle; |
| 20 | + var $mMetaData = ''; |
20 | 21 | |
21 | 22 | # Form values |
22 | 23 | var $save = false, $preview = false; |
— | — | @@ -35,6 +36,80 @@ |
36 | 37 | } |
37 | 38 | |
38 | 39 | /** |
| 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 | + /** |
39 | 114 | * This is the function that gets called for "action=edit". |
40 | 115 | */ |
41 | 116 | function edit() { |
— | — | @@ -77,6 +152,7 @@ |
78 | 153 | if( $wgUser->getOption('previewonfirst') ) { |
79 | 154 | $this->editForm( 'preview', true ); |
80 | 155 | } else { |
| 156 | + $this->extractMetaDataFromArticle () ; |
81 | 157 | $this->editForm( 'initial', true ); |
82 | 158 | } |
83 | 159 | } |
— | — | @@ -91,6 +167,7 @@ |
92 | 168 | # whitespace from the text boxes. This may be significant formatting. |
93 | 169 | $this->textbox1 = rtrim( $request->getText( 'wpTextbox1' ) ); |
94 | 170 | $this->textbox2 = rtrim( $request->getText( 'wpTextbox2' ) ); |
| 171 | + $this->mMetaData = rtrim( $request->getText( 'metadata' ) ); |
95 | 172 | $this->summary = trim( $request->getText( 'wpSummary' ) ); |
96 | 173 | |
97 | 174 | $this->edittime = $request->getVal( 'wpEdittime' ); |
— | — | @@ -159,6 +236,10 @@ |
160 | 237 | # in the back door with a hand-edited submission URL. |
161 | 238 | |
162 | 239 | if ( 'save' == $formtype ) { |
| 240 | + # Reintegrate metadata |
| 241 | + if ( $this->mMetaData != "" ) $this->textbox1 .= "\n" . $this->mMetaData ; |
| 242 | + $this->mMetaData = "" ; |
| 243 | + |
163 | 244 | # Check for spam |
164 | 245 | if ( $wgSpamRegex && preg_match( $wgSpamRegex, $this->textbox1, $matches ) ) { |
165 | 246 | $this->spamPage ( $matches[0] ); |
— | — | @@ -478,17 +559,29 @@ |
479 | 560 | $liveOnclick = ''; |
480 | 561 | } |
481 | 562 | |
| 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 | + |
482 | 573 | $wgOut->addHTML( <<<END |
483 | 574 | {$toolbar} |
484 | 575 | <form id="editform" name="editform" method="post" action="$action" |
485 | 576 | enctype="multipart/form-data"> |
486 | 577 | {$commentsubject} |
| 578 | +{$mbegin} |
487 | 579 | <textarea tabindex='1' accesskey="," name="wpTextbox1" rows='{$rows}' |
488 | 580 | cols='{$cols}'{$ew}> |
489 | 581 | END |
490 | 582 | . htmlspecialchars( $wgContLang->recodeForEdit( $this->textbox1 ) ) . |
491 | 583 | " |
492 | 584 | </textarea> |
| 585 | +{$metadata} |
493 | 586 | <br />{$editsummary} |
494 | 587 | {$checkboxhtml} |
495 | 588 | <input tabindex='5' id='wpSave' type='submit' value=\"{$save}\" name=\"wpSave\" accesskey=\"".wfMsg('accesskey-save')."\"". |
— | — | @@ -549,7 +642,10 @@ |
550 | 643 | $this->textbox1 = $this->mArticle->getContent(true); |
551 | 644 | } |
552 | 645 | |
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", |
554 | 650 | $wgTitle, $parserOptions ); |
555 | 651 | |
556 | 652 | $previewHTML = $parserOutput->mText; |