Topic on Project:Support desk

125.19.34.86 (talkcontribs)

n mediawiki 1.21, i want to append some text in wikitag format at prefix and postfix of the original content(page_content), on which file and where i want to make change regarding this. Please guide me.


Mediawiki 1.21 Postgresql 9.2

Florianschmidtwelzow (talkcontribs)

Hello,

unhappily i'm not really sure, what you want to do :) Do you want to add some text before and after each content page (but not on Special pages or Category pages?)? If so, you can use templates to add before and after every page, or edit the skin files, or using hooks to add the content (so you can use this one to add content after the content e.g. https://www.mediawiki.org/wiki/Manual:Hooks/SkinAfterContent).

Hope that helps you :)

88.130.87.113 (talkcontribs)

Florian's ideas are good, except the one to edit the skin files. If you are using one of the MediaWiki default skins (or a skin, which you do not maintain yourself), you should not edit its files as your changes will e.g. be overwritten after an update.

Florianschmidtwelzow (talkcontribs)

Yeah, right :) Sorry, sometimes i forget, that i'm using a custom skin :) If you created itself there are much more posibillities (and more problems you have to solve too :P)

59.163.27.11 (talkcontribs)

@Florianschmidtwelzow Thanx for your response.Actually in mediawiki 1.12 what we did, we created one customized module like page_precontent and page_postcontent two column we added in page table, by using our module user can add what should print at the beginning of the content and what should print at end of the content can able to add and modify. For ex consider "Test_Page" is containing original content like "Hi This is test Page", by using our customized extension user have to enter only the title of the page then two text area user can able to see ,like precontent and post content, if user is adding some text in precontent text area like "''This this before text''" and in post content text area like "'''This is end of the content'''", if you load the page "Test_Page" it will show like

This this before text Hi This is test Page This is end of the content


In mediawiki 1.12 we customized the article.php like below in custom code you can see.,

public function outputWikiText( $text, $cache = true ) {
		global $wgParser, $wgUser, $wgOut, $wgEnableParserCache;

		$popts = $wgOut->parserOptions();
		$popts->setTidy(true);
		$popts->enableLimitReport();
		
		/**************** CUSTOME CODE **************************/

                $this->mPreContent = Title::getPreContent($this->mTitle);
                $this->mPostContent= Title::getPostContent($this->mTitle);
                $text = $this->mPreContent.$text.$this->mPostContent;
                
		/********************************************************

In mediawiki 1.21 im not able to find where to make this change.

Florianschmidtwelzow (talkcontribs)

Like 88.130.87.113 said: Never change skin files, the same is for all other files provided by core, see for this: Do not hack MediaWiki core

Better is to do this with an extension, if possible.

But like i said: I really don't know, what you want to do? You want to save a pre and post content into the database for each text? Then maybe it's really better to instruct your users that they can add this content into the "normal" textfield for content of page?!

125.19.34.86 (talkcontribs)

@Florianschmidtwelzow it is not possible to instruct the user.already in production if i want to change more than 2000 pages i want to modify it, So i want to customize mediawiki core only, so guide me on which file i want to make change yaar, It is very difficult. Developing extension also right now it is not possible, i want to complete this task within 2 days , so please guide.

Florianschmidtwelzow (talkcontribs)

Sorry for the direct answer: I think you go a totally false way. This what we discuss here is one of the reasons why it's never an alternative to hack the core: At some point you don't know, what to do (if you are not in the actual development process or are the Wiki administrator, not the developer). I will give you a possible solution for your problem next to this text, but please (really!) notice, that it will comes the point, where this solution again won't work. And in my opinion, that can't be the right approach.

So, to solve this problem (I have still the opinion that you shouldn't do this) you can change inclueds/page/Article.php (in MW1.24wmf11+) or includes/Article.php (in MW1.24wmf11 and under): Find function getContentObject() (somewhere around line 280 or 250):
Add following before
fProfileOut( __METHOD__ );
return $content;

$text = ContentHandler::getContentText( $content );
$newText = 'preContent' . $text . 'postContent';
$content = ContentHandler::makeContent( $newText, $this->getTitle() );

Like ever: use it for your own risk.

125.19.34.86 (talkcontribs)

@Florianschmidtwelzow I added in the below function, but it is not working, even this function is not calling for content.

protected function getContentObject() {
                wfProfileIn( __METHOD__ );

                if ( $this->mPage->getID() === 0 ) {
                        # If this is a MediaWiki:x message, then load the messages
                        # and return the message value for x.
                        if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
                                $text = $this->getTitle()->getDefaultMessageText();
                                if ( $text === false ) {
                                        $text = '';
                                }
                             
                                $text = "'''test----------------------'''".$text;
                                $content = ContentHandler::makeContent( $text, $this->getTitle() );
                        } else {
                                $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
                        //      $content = new MessageContent( $message, null, 'parsemag' );
                        }
                } else {
                        $this->fetchContentObject();
                        $content = $this->mContentObject;
                }
                wfProfileOut( __METHOD__ );
//              echo '<pre>';print_r($content);die();
                return $content;
        }
Florianschmidtwelzow (talkcontribs)

Hmm, this isn't that, what i said ;) You have added some code to the first branch of the if/else control structure. This is only called for non existent pages, not for pages, that exist. Maybe you want to try it again, like i said to you :) Add the code i give you before wfProfileOut( __METHOD__ );.

P.S.: And please uncomment $content = new MessageContent( $message, null, 'parsemag' ); ;)

125.19.34.86 (talkcontribs)

@Florianschmidtwelzow thanx lot for ur response, you are only my hope to fix this issue. still no chance , it is not working

 protected function getContentObject() {
                wfProfileIn( __METHOD__ );
                if ( $this->mPage->getID() === 0 ) {
                        # If this is a MediaWiki:x message, then load the messages
                        # and return the message value for x.
                        if ( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
                                $text = $this->getTitle()->getDefaultMessageText();
                                if ( $text === false ) {
                                        $text = '';
                                }
                                 $content = ContentHandler::makeContent( $text, $this->getTitle() );
                        } else {
                                $message = $this->getContext()->getUser()->isLoggedIn() ? 'noarticletext' : 'noarticletextanon';
                                $content = new MessageContent( $message, null, 'parsemag' );
                        }
                } else {
                        $this->fetchContentObject();
                        $content = $this->mContentObject;
                }

                #******* CUSTOM CODE START*************
                $text = ContentHandler::getContentText( $content );
                $newText = 'preContent' . $text . 'postContent';
                $content = ContentHandler::makeContent( $newText, $this->getTitle() );
                #******* CUSTOM CODE END*************
                wfProfileOut( __METHOD__ );
                return $content;
        }
Florianschmidtwelzow (talkcontribs)

Have you used ?action=purge to clear the parser cache?

125.19.34.86 (talkcontribs)

@Florianschmidtwelzow Great Help thanx lot for ur support, it is working after ?action=purge. Once again thnk you lot.

59.163.27.11 (talkcontribs)

@Florianschmidtwelzow if make any change immediately it is not coming after ?action=purge only it is working.. any solution for that?

Florianschmidtwelzow (talkcontribs)

That's normal because of the ParserCache. If you don't want to do this, you can revert the change i said to you and add the text directly before the body is outputted. In includes/SkinTemplate.php you can change (if i'm right):
Find $tpl->setRef( 'bodytext', $out->mBodytext ); and add before:

$out->mBodytext = 'preContent'.$out->mBodytext.'postContent';
125.19.34.86 (talkcontribs)

here the pblm is my wikitext is not parsing it is printing as it is

$out->mBodytext = "'''bold'''.$out->mBodytext."''italic''";

-(
Florianschmidtwelzow (talkcontribs)

> here the pblm is my wikitext is not parsing it is printing as it is

That'c totally correct ;) If you want to use wikitext you can use the above example in article.php. Parsing is an intensive operation, so it is cached. It's possible to parse the text everytime your wiki pages requested, but this is a more unuseful solution as all others here ;)

125.19.34.86 (talkcontribs)

i want to parse everytime, so guide me yaar, Please give me some solution,really stucked with this.you r only my hope to solve this issue.

125.19.34.86 (talkcontribs)

@Florianschmidtwelzow added below line in Localsettings, and i made your mentioned changes in Article.php, It is working now.

$wgEnableParserCache = false;

Florianschmidtwelzow (talkcontribs)
O In my opinion this is the complete false solution for solving this, sorry. With this you turn off the parser cache for all, yeah i mean ALL, parser actions MediaWiki will ever do. There is a reason, why it's default to true :)

Better solution would be to (i hope that you don't change the post and pre content so often) do your changes to pre and post content and run the maintenance script purgeList.php with parameter --all (see https://www.mediawiki.org/wiki/Manual:PurgeList.php)

Reply to "Pagecontent Help"