Jump to content

Automatic page creation

From Meta, a Wikimedia project coordination wiki

I am using wikimedia as a bibliographical management system, defining pages for every item in the library. One issue was to make uploading of .pdf files easy, so you could upload and generate a library page in only one step.

All this code goes into /includes/SpecialUploads.php.

First stop. I added two parameters in the UploadForm, a checkbox for enabling library uploads, and a text box for the wiki library page:

               $this->mWatchthis         = $request->getBool( 'wpWatchthis' );
# MOD BEGIN
               $this->mUploadLibrary     = $request->getBool( 'wpUploadLibrary' );
               $this->mUploadLibraryPage = $request->getText( 'wpUploadLibraryPage' );
# MOD END

This is the code for generating a page. You can put it right after the PDF doc search modification.

#MOD START
# Generate the library page, MSR 2005
   $libraryURL = "";
   if ($this->mUploadLibrary) {
       $articleName = $this->mUploadLibraryPage;
       $wl_title = Title::newFromText ( $articleName );
       if (!$wl_title->exists()) {
           $wl_article = new Article ( $wl_title ) ;
           $articleContent = "[[:Image:" . $this->mUploadSaveName . "]]\n\n" .
               "BIBTEX REPLACE\n\nDESCRIPTION REPLACE\n\nCOMMENTS REPLACE\n\n" .
               "Category:New\n\n";
           $wl_article->insertNewArticle( $articleContent, "",
               false, $this->mWatchthis);
       }
       $libraryURL = $wl_title->getFullURL( "action=edit&editintro=Template:New library upload intro" );
   }
# MOD END

This modification redirects to the created page:

                       if ( $success ) {
# MOD START
                           if ($this->mUploadLibrary)
                               $wgOut->redirect( $libraryURL );
                           else
# MOD END
                               $this->showSuccess();

--Mressl 19:01, 22 November 2005 (UTC)[reply]